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 | ;; |
Praveen Chandran | ab02839 | 2022-08-18 07:39:28 -0700 | [diff] [blame] | 109 | psoc6_board=*) |
Praveen Chandran | 080ae57 | 2021-08-12 07:58:27 -0700 | [diff] [blame] | 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 | |
Michael Spang | 284347d | 2020-09-11 19:24:51 -0400 | [diff] [blame] | 116 | # Android SDK setup |
| 117 | android_sdk_args="" |
Michael Spang | fdc49a3 | 2020-09-03 18:33:20 -0400 | [diff] [blame] | 118 | |
Michael Spang | 284347d | 2020-09-11 19:24:51 -0400 | [diff] [blame] | 119 | if [[ -d "${ANDROID_NDK_HOME}/toolchains" && -d "${ANDROID_HOME}/platforms" ]]; then |
Martin Turon | c83eab5 | 2022-05-06 08:21:55 -0700 | [diff] [blame] | 120 | # Android prebuilt JAR setup |
| 121 | python3 third_party/android_deps/set_up_android_deps.py |
| 122 | |
Michael Spang | 284347d | 2020-09-11 19:24:51 -0400 | [diff] [blame] | 123 | android_sdk_args+="android_sdk_root=\"$ANDROID_HOME\" android_ndk_root=\"$ANDROID_NDK_HOME\"" |
| 124 | extra_args+=" $android_sdk_args enable_android_builds=true" |
Michael Spang | fdc49a3 | 2020-09-03 18:33:20 -0400 | [diff] [blame] | 125 | else |
| 126 | echo |
Michael Spang | 284347d | 2020-09-11 19:24:51 -0400 | [diff] [blame] | 127 | 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] | 128 | echo " The required android sdk platform version is 21. It can be obtained from" |
Matthew Swartwout | f7977bc | 2023-03-30 10:37:22 -0700 | [diff] [blame] | 129 | echo " https://dl.google.com/android/repository/platform-26_r02.zip" |
Michael Spang | fdc49a3 | 2020-09-03 18:33:20 -0400 | [diff] [blame] | 130 | fi |
| 131 | |
Martin Turon | 52b6f03 | 2020-07-10 12:36:07 -0700 | [diff] [blame] | 132 | echo |
| 133 | |
jepenven-silabs | cec75ca | 2020-08-04 09:38:48 -0400 | [diff] [blame] | 134 | # EFR32 SDK setup |
jepenven-silabs | 72a368b | 2021-02-10 14:02:57 -0500 | [diff] [blame] | 135 | if [[ -z "$efr32_enabled" ]]; then |
| 136 | echo "Hint: Pass enable_efr32_builds=true to enable building for EFR32" |
jepenven-silabs | cec75ca | 2020-08-04 09:38:48 -0400 | [diff] [blame] | 137 | else |
jepenven-silabs | 72a368b | 2021-02-10 14:02:57 -0500 | [diff] [blame] | 138 | echo 'To build the EFR32 lock sample as a standalone project': |
| 139 | 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] | 140 | fi |
| 141 | |
Praveen Chandran | 080ae57 | 2021-08-12 07:58:27 -0700 | [diff] [blame] | 142 | echo |
| 143 | |
Praveen Chandran | ab02839 | 2022-08-18 07:39:28 -0700 | [diff] [blame] | 144 | # PSoC6 Build setup |
Praveen Chandran | 080ae57 | 2021-08-12 07:58:27 -0700 | [diff] [blame] | 145 | if [[ -z "$p6_builds_enabled" ]]; then |
| 146 | echo "Hint: Pass enable_p6_builds=true to this script to enable building for PSoC6-43012" |
| 147 | else |
Praveen Chandran | ab02839 | 2022-08-18 07:39:28 -0700 | [diff] [blame] | 148 | psoc6_sdk_args="" |
Praveen Chandran | 080ae57 | 2021-08-12 07:58:27 -0700 | [diff] [blame] | 149 | if [[ -z "$p6_board_selected" ]]; then |
Praveen Chandran | ab02839 | 2022-08-18 07:39:28 -0700 | [diff] [blame] | 150 | psoc6_sdk_args="psoc6_board=\"CY8CKIT-062S2-43012\"" |
Praveen Chandran | 080ae57 | 2021-08-12 07:58:27 -0700 | [diff] [blame] | 151 | fi |
| 152 | fi |
| 153 | |
doru91 | 04ac26b | 2020-10-13 18:23:28 +0300 | [diff] [blame] | 154 | # K32W SDK setup |
| 155 | k32w_sdk_args="" |
| 156 | |
doru91 | 9b2c889 | 2022-07-22 21:40:26 +0300 | [diff] [blame] | 157 | if [[ -d "$NXP_K32W0_SDK_ROOT" ]]; then |
| 158 | k32w_sdk_args+="k32w0_sdk_root=\"$NXP_K32W0_SDK_ROOT\"" |
Andrei Litvin | 41300eb | 2022-02-17 00:39:14 -0500 | [diff] [blame] | 159 | extra_args+=" $k32w0_sdk_args enable_k32w_builds=true" |
doru91 | 04ac26b | 2020-10-13 18:23:28 +0300 | [diff] [blame] | 160 | fi |
| 161 | |
| 162 | echo |
doru91 | 9b2c889 | 2022-07-22 21:40:26 +0300 | [diff] [blame] | 163 | if [[ ! -d "$NXP_K32W0_SDK_ROOT" ]]; then |
| 164 | echo "Hint: Set \$NXP_K32W0_SDK_ROOT to enable building for K32W061" |
doru91 | 04ac26b | 2020-10-13 18:23:28 +0300 | [diff] [blame] | 165 | else |
| 166 | echo 'To build the K32W lock sample as a standalone project': |
Marius Tache | 83dc1c8 | 2024-08-06 22:53:49 +0300 | [diff] [blame] | 167 | echo "(cd $CHIP_ROOT/examples/lock-app/nxp/k32w0; gn gen out/debug --args='$k32w_sdk_args'; ninja -C out/debug)" |
doru91 | 04ac26b | 2020-10-13 18:23:28 +0300 | [diff] [blame] | 168 | fi |
| 169 | echo |
| 170 | |
Timothy Maes | 2478e02 | 2021-07-02 04:03:46 +0200 | [diff] [blame] | 171 | if [[ -z "$qpg_enabled" ]]; then |
| 172 | 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] | 173 | else |
| 174 | echo 'To build the QPG6100 lock sample as a standalone project:' |
Timothy Maes | 2478e02 | 2021-07-02 04:03:46 +0200 | [diff] [blame] | 175 | 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] | 176 | fi |
| 177 | |
jepenven-silabs | cec75ca | 2020-08-04 09:38:48 -0400 | [diff] [blame] | 178 | echo |
| 179 | |
Seth Rickard | bbbf7ce | 2022-03-30 14:53:24 -0500 | [diff] [blame] | 180 | # TI SimpleLink Build setup |
Michael Spang | 3369875 | 2021-04-08 16:04:01 -0400 | [diff] [blame] | 181 | ti_simplelink_sdk_args="" |
| 182 | |
Seth Rickard | bbbf7ce | 2022-03-30 14:53:24 -0500 | [diff] [blame] | 183 | if [[ -f "${TI_SYSCONFIG_ROOT}/sysconfig_cli.sh" ]]; then |
| 184 | ti_simplelink_sdk_args+="ti_sysconfig_root=\"$TI_SYSCONFIG_ROOT\"" |
Michael Spang | 3369875 | 2021-04-08 16:04:01 -0400 | [diff] [blame] | 185 | extra_args+=" $ti_simplelink_sdk_args enable_ti_simplelink_builds=true" |
| 186 | |
| 187 | echo 'To build the cc13x2x7_26x2x7 lock sample as a standalone project': |
| 188 | echo "(cd $CHIP_ROOT/examples/lock-app/cc13x2x7_26x2x7; gn gen out/debug --args='$ti_simplelink_sdk_args'; ninja -C out/debug)" |
| 189 | else |
Seth Rickard | bbbf7ce | 2022-03-30 14:53:24 -0500 | [diff] [blame] | 190 | echo "Hint: Set \$TI_SYSCONFIG_ROOT to enable building for cc13x2_26x2" |
Michael Spang | 3369875 | 2021-04-08 16:04:01 -0400 | [diff] [blame] | 191 | fi |
| 192 | |
| 193 | echo |
| 194 | |
Jakub | 9c1660c | 2022-06-06 15:12:52 +0200 | [diff] [blame] | 195 | tizen_sdk_args="" |
| 196 | |
| 197 | if [[ -d "${TIZEN_SDK_ROOT}" && -d "${TIZEN_SDK_SYSROOT}" ]]; then |
| 198 | tizen_sdk_args+="tizen_sdk_root=\"$TIZEN_SDK_ROOT\" tizen_sdk_sysroot=\"$TIZEN_SDK_SYSROOT\"" |
| 199 | extra_args+=" $tizen_sdk_args enable_tizen_builds=true" |
| 200 | else |
| 201 | echo |
| 202 | echo "Hint: Set \$TIZEN_SDK_ROOT and \$TIZEN_SDK_SYSROOT to enable building for Tizen" |
| 203 | echo " Required Tizen SDK can be obtained from" |
| 204 | echo " https://developer.tizen.org/development/tizen-studio/download" |
| 205 | fi |
| 206 | |
| 207 | echo |
| 208 | |
Martin Turon | 52b6f03 | 2020-07-10 12:36:07 -0700 | [diff] [blame] | 209 | _chip_banner "Build: GN configure" |
| 210 | |
Michael Spang | 6b3293e | 2021-02-02 13:05:01 -0500 | [diff] [blame] | 211 | 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] | 212 | 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] | 213 | |
| 214 | _chip_banner "Build: Ninja build" |
| 215 | |
Kevin Schoedel | 654dd88 | 2021-03-02 16:51:27 -0500 | [diff] [blame] | 216 | time ninja -C "$CHIP_ROOT/out/debug" "${ninja_args[@]}" all check |