Rob Walker | 9eb6ba5 | 2020-07-10 07:32:30 -0700 | [diff] [blame] | 1 | #!/usr/bin/env bash |
Michael Spang | efa630b | 2020-07-08 22:23:08 -0400 | [diff] [blame] | 2 | # |
| 3 | # Copyright (c) 2020 Project CHIP Authors |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | # |
Michael Spang | 5132d61 | 2020-09-11 14:11:38 -0400 | [diff] [blame] | 17 | |
Rob Walker | 9eb6ba5 | 2020-07-10 07:32:30 -0700 | [diff] [blame] | 18 | set -e |
Michael Spang | efa630b | 2020-07-08 22:23:08 -0400 | [diff] [blame] | 19 | |
| 20 | CHIP_ROOT="$(dirname "$0")" |
| 21 | |
| 22 | _chip_red() { |
| 23 | echo -e "\033[0;31m$*\033[0m" |
| 24 | } |
| 25 | |
| 26 | _chip_yellow() { |
| 27 | echo -e "\033[0;33m$*\033[0m" |
| 28 | } |
| 29 | |
| 30 | _chip_banner() { |
| 31 | _chip_yellow '.--------------------------------' |
| 32 | _chip_yellow "-- $1" |
| 33 | _chip_yellow "'--------------------------------" |
| 34 | } |
| 35 | |
| 36 | _chip_banner "Environment bringup" |
| 37 | |
| 38 | git -C "$CHIP_ROOT" submodule update --init |
| 39 | |
Michael Spang | d6523c8 | 2020-09-16 10:16:12 -0400 | [diff] [blame] | 40 | # TODO: Fix pigweed to bootstrap if necessary in activate.sh. |
| 41 | echo |
| 42 | echo "NB: If this fails run \"source scripts/bootstrap.sh\"" |
| 43 | |
Michael Spang | efa630b | 2020-07-08 22:23:08 -0400 | [diff] [blame] | 44 | source "$CHIP_ROOT/scripts/activate.sh" |
Michael Spang | efa630b | 2020-07-08 22:23:08 -0400 | [diff] [blame] | 45 | |
Martin Turon | 52b6f03 | 2020-07-10 12:36:07 -0700 | [diff] [blame] | 46 | _chip_banner "Instructions" |
Michael Spang | efa630b | 2020-07-08 22:23:08 -0400 | [diff] [blame] | 47 | |
| 48 | echo |
| 49 | echo 'To activate existing build environment in your shell, run (do this first):' |
| 50 | echo source "$CHIP_ROOT/scripts/activate.sh" |
| 51 | |
| 52 | echo |
| 53 | echo 'To re-create the build environment from scratch, run:' |
| 54 | echo source "$CHIP_ROOT/scripts/bootstrap.sh" |
| 55 | |
| 56 | echo |
Michael Spang | 8cad33b | 2021-06-14 09:50:44 -0400 | [diff] [blame] | 57 | echo 'To compile the generated debug build:' |
Michael Spang | efa630b | 2020-07-08 22:23:08 -0400 | [diff] [blame] | 58 | echo ninja -C "$CHIP_ROOT/out/debug" |
| 59 | |
| 60 | echo |
Michael Spang | 8cad33b | 2021-06-14 09:50:44 -0400 | [diff] [blame] | 61 | echo 'To test the generated debug build (idempotent):' |
Michael Spang | efa630b | 2020-07-08 22:23:08 -0400 | [diff] [blame] | 62 | echo ninja -C "$CHIP_ROOT/out/debug" check |
| 63 | |
| 64 | echo |
Michael Spang | 8cad33b | 2021-06-14 09:50:44 -0400 | [diff] [blame] | 65 | echo 'To compile the generated release build': |
| 66 | echo ninja -C "$CHIP_ROOT/out/release" |
| 67 | |
| 68 | echo |
| 69 | echo 'To test the generated release build (idempotent):' |
Michael Spang | efa630b | 2020-07-08 22:23:08 -0400 | [diff] [blame] | 70 | echo ninja -C "$CHIP_ROOT/out/release" check |
| 71 | |
| 72 | echo |
| 73 | echo 'To build a custom build (for help run "gn args --list out/debug")' |
| 74 | echo gn args "$CHIP_ROOT/out/custom" |
| 75 | echo ninja -C "$CHIP_ROOT/out/custom" |
| 76 | |
Michael Spang | 2182a38 | 2020-10-23 09:55:34 -0400 | [diff] [blame] | 77 | extra_args="" |
Michael Spang | 6b3293e | 2021-02-02 13:05:01 -0500 | [diff] [blame] | 78 | user_args="" |
Kevin Schoedel | 654dd88 | 2021-03-02 16:51:27 -0500 | [diff] [blame] | 79 | ninja_args=() |
| 80 | |
| 81 | while getopts :d:j:k:l:nt:vw: opt; do |
| 82 | case "$opt" in |
| 83 | [nv]) |
| 84 | ninja_args+=("-$opt") |
| 85 | ;; |
| 86 | [djkltw]) |
| 87 | ninja_args+=("-$opt" "$OPTARG") |
| 88 | ;; |
| 89 | '?') |
| 90 | printf '\nError: unknown option -%s\n' "$OPTARG" |
| 91 | printf 'Usage: %s [ninja-options] [gn-args]\n' "$0" |
| 92 | exit 1 |
| 93 | ;; |
| 94 | esac |
| 95 | done |
| 96 | shift $((OPTIND - 1)) |
Michael Spang | 2182a38 | 2020-10-23 09:55:34 -0400 | [diff] [blame] | 97 | |
| 98 | for arg; do |
| 99 | case $arg in |
Timothy Maes | 2478e02 | 2021-07-02 04:03:46 +0200 | [diff] [blame] | 100 | enable_qpg_builds=true) |
| 101 | qpg_enabled=1 |
Michael Spang | 2182a38 | 2020-10-23 09:55:34 -0400 | [diff] [blame] | 102 | ;; |
jepenven-silabs | 72a368b | 2021-02-10 14:02:57 -0500 | [diff] [blame] | 103 | enable_efr32_builds=true) |
| 104 | efr32_enabled=1 |
| 105 | ;; |
Praveen Chandran | 080ae57 | 2021-08-12 07:58:27 -0700 | [diff] [blame] | 106 | enable_p6_builds=true) |
| 107 | p6_builds_enabled=1 |
| 108 | ;; |
| 109 | p6_board=*) |
| 110 | p6_board_selected=1 |
| 111 | ;; |
Michael Spang | 2182a38 | 2020-10-23 09:55:34 -0400 | [diff] [blame] | 112 | esac |
Michael Spang | 6b3293e | 2021-02-02 13:05:01 -0500 | [diff] [blame] | 113 | user_args+=" $arg" |
Michael Spang | 2182a38 | 2020-10-23 09:55:34 -0400 | [diff] [blame] | 114 | done |
Michael Spang | fdc49a3 | 2020-09-03 18:33:20 -0400 | [diff] [blame] | 115 | |
Austin Hsieh | 50b044f | 2021-10-04 06:37:35 -0700 | [diff] [blame] | 116 | # Android prebuilt JAR setup |
| 117 | python3 build/chip/java/tests/generate_jars_for_test.py |
| 118 | python3 third_party/android_deps/set_up_android_deps.py |
| 119 | |
Michael Spang | 284347d | 2020-09-11 19:24:51 -0400 | [diff] [blame] | 120 | # Android SDK setup |
| 121 | android_sdk_args="" |
Michael Spang | fdc49a3 | 2020-09-03 18:33:20 -0400 | [diff] [blame] | 122 | |
Michael Spang | 284347d | 2020-09-11 19:24:51 -0400 | [diff] [blame] | 123 | if [[ -d "${ANDROID_NDK_HOME}/toolchains" && -d "${ANDROID_HOME}/platforms" ]]; then |
| 124 | android_sdk_args+="android_sdk_root=\"$ANDROID_HOME\" android_ndk_root=\"$ANDROID_NDK_HOME\"" |
| 125 | extra_args+=" $android_sdk_args enable_android_builds=true" |
Michael Spang | fdc49a3 | 2020-09-03 18:33:20 -0400 | [diff] [blame] | 126 | else |
| 127 | echo |
Michael Spang | 284347d | 2020-09-11 19:24:51 -0400 | [diff] [blame] | 128 | echo "Hint: Set \$ANDROID_HOME and \$ANDROID_NDK_HOME to enable building for Android" |
cecille | 2cb4bf0 | 2021-05-07 16:54:25 -0400 | [diff] [blame] | 129 | echo " The required android sdk platform version is 21. It can be obtained from" |
| 130 | echo " https://dl.google.com/android/repository/android-21_r02.zip" |
Michael Spang | fdc49a3 | 2020-09-03 18:33:20 -0400 | [diff] [blame] | 131 | fi |
| 132 | |
Martin Turon | 52b6f03 | 2020-07-10 12:36:07 -0700 | [diff] [blame] | 133 | echo |
| 134 | |
jepenven-silabs | cec75ca | 2020-08-04 09:38:48 -0400 | [diff] [blame] | 135 | # EFR32 SDK setup |
jepenven-silabs | 72a368b | 2021-02-10 14:02:57 -0500 | [diff] [blame] | 136 | if [[ -z "$efr32_enabled" ]]; then |
| 137 | echo "Hint: Pass enable_efr32_builds=true to enable building for EFR32" |
jepenven-silabs | cec75ca | 2020-08-04 09:38:48 -0400 | [diff] [blame] | 138 | else |
jepenven-silabs | 72a368b | 2021-02-10 14:02:57 -0500 | [diff] [blame] | 139 | echo 'To build the EFR32 lock sample as a standalone project': |
| 140 | echo "(cd $CHIP_ROOT/examples/lock-app/efr32; gn gen out/debug; ninja -C out/debug)" |
jepenven-silabs | cec75ca | 2020-08-04 09:38:48 -0400 | [diff] [blame] | 141 | fi |
| 142 | |
Praveen Chandran | 080ae57 | 2021-08-12 07:58:27 -0700 | [diff] [blame] | 143 | echo |
| 144 | |
| 145 | # P6 Build setup |
| 146 | if [[ -z "$p6_builds_enabled" ]]; then |
| 147 | echo "Hint: Pass enable_p6_builds=true to this script to enable building for PSoC6-43012" |
| 148 | else |
| 149 | p6_sdk_args="" |
| 150 | if [[ -z "$p6_board_selected" ]]; then |
| 151 | p6_sdk_args="p6_board=\"CY8CKIT-062S2-43012\"" |
| 152 | fi |
| 153 | fi |
| 154 | |
doru91 | 04ac26b | 2020-10-13 18:23:28 +0300 | [diff] [blame] | 155 | # K32W SDK setup |
| 156 | k32w_sdk_args="" |
| 157 | |
| 158 | if [[ -d "$K32W061_SDK_ROOT" ]]; then |
| 159 | k32w_sdk_args+="k32w_sdk_root=\"$K32W061_SDK_ROOT\"" |
| 160 | extra_args+=" $k32w_sdk_args enable_k32w_builds=true" |
| 161 | fi |
| 162 | |
| 163 | echo |
| 164 | if [[ ! -d "$K32W061_SDK_ROOT" ]]; then |
| 165 | echo "Hint: Set \$K32W061_SDK_ROOT to enable building for K32W061" |
| 166 | else |
| 167 | echo 'To build the K32W lock sample as a standalone project': |
| 168 | echo "(cd $CHIP_ROOT/examples/lock-app/k32w; gn gen out/debug --args='$k32w_sdk_args'; ninja -C out/debug)" |
| 169 | fi |
| 170 | echo |
| 171 | |
Timothy Maes | 2478e02 | 2021-07-02 04:03:46 +0200 | [diff] [blame] | 172 | if [[ -z "$qpg_enabled" ]]; then |
| 173 | echo "Hint: Pass enable_qpg_builds=true to this script to enable building for QPG" |
Michael Spang | 2182a38 | 2020-10-23 09:55:34 -0400 | [diff] [blame] | 174 | else |
| 175 | echo 'To build the QPG6100 lock sample as a standalone project:' |
Timothy Maes | 2478e02 | 2021-07-02 04:03:46 +0200 | [diff] [blame] | 176 | echo "(cd $CHIP_ROOT/examples/lock-app/qpg; gn gen out/debug; ninja -C out/debug)" |
Michael Spang | 2182a38 | 2020-10-23 09:55:34 -0400 | [diff] [blame] | 177 | fi |
| 178 | |
jepenven-silabs | cec75ca | 2020-08-04 09:38:48 -0400 | [diff] [blame] | 179 | echo |
| 180 | |
Michael Spang | 3369875 | 2021-04-08 16:04:01 -0400 | [diff] [blame] | 181 | # TI SimpleLink SDK setup |
| 182 | ti_simplelink_sdk_args="" |
| 183 | |
| 184 | if [[ -d "${TI_SIMPLELINK_SDK_ROOT}/source" && -f "${TI_SYSCONFIG_ROOT}/sysconfig_cli.sh" ]]; then |
| 185 | ti_simplelink_sdk_args+="ti_simplelink_sdk_root=\"$TI_SIMPLELINK_SDK_ROOT\" ti_sysconfig_root=\"$TI_SYSCONFIG_ROOT\"" |
| 186 | extra_args+=" $ti_simplelink_sdk_args enable_ti_simplelink_builds=true" |
| 187 | |
| 188 | echo 'To build the cc13x2x7_26x2x7 lock sample as a standalone project': |
| 189 | echo "(cd $CHIP_ROOT/examples/lock-app/cc13x2x7_26x2x7; gn gen out/debug --args='$ti_simplelink_sdk_args'; ninja -C out/debug)" |
| 190 | else |
| 191 | echo "Hint: Set \$TI_SIMPLELINK_SDK_ROOT and \$TI_SYSCONFIG_ROOT to enable building for cc13x2_26x2" |
| 192 | fi |
| 193 | |
| 194 | echo |
| 195 | |
Martin Turon | 52b6f03 | 2020-07-10 12:36:07 -0700 | [diff] [blame] | 196 | _chip_banner "Build: GN configure" |
| 197 | |
Michael Spang | 6b3293e | 2021-02-02 13:05:01 -0500 | [diff] [blame] | 198 | gn --root="$CHIP_ROOT" gen --check --fail-on-unused-args "$CHIP_ROOT/out/debug" --args='target_os="all"'"$extra_args$user_args" |
Michael Spang | 441350a | 2021-04-23 08:55:18 -0400 | [diff] [blame] | 199 | gn --root="$CHIP_ROOT" gen --check --fail-on-unused-args "$CHIP_ROOT/out/release" --args='target_os="all" is_debug=false'"$extra_args$user_args" |
Martin Turon | 52b6f03 | 2020-07-10 12:36:07 -0700 | [diff] [blame] | 200 | |
| 201 | _chip_banner "Build: Ninja build" |
| 202 | |
Kevin Schoedel | 654dd88 | 2021-03-02 16:51:27 -0500 | [diff] [blame] | 203 | time ninja -C "$CHIP_ROOT/out/debug" "${ninja_args[@]}" all check |