blob: 361382dbdcef7cf520402f388966c88d715bc596 [file] [log] [blame]
Rob Walker9eb6ba52020-07-10 07:32:30 -07001#!/usr/bin/env bash
Michael Spangefa630b2020-07-08 22:23:08 -04002#
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 Spang5132d612020-09-11 14:11:38 -040017
Rob Walker9eb6ba52020-07-10 07:32:30 -070018set -e
Michael Spangefa630b2020-07-08 22:23:08 -040019
20CHIP_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
38git -C "$CHIP_ROOT" submodule update --init
39
Michael Spangd6523c82020-09-16 10:16:12 -040040# TODO: Fix pigweed to bootstrap if necessary in activate.sh.
41echo
42echo "NB: If this fails run \"source scripts/bootstrap.sh\""
43
Michael Spangefa630b2020-07-08 22:23:08 -040044source "$CHIP_ROOT/scripts/activate.sh"
Michael Spangefa630b2020-07-08 22:23:08 -040045
Martin Turon52b6f032020-07-10 12:36:07 -070046_chip_banner "Instructions"
Michael Spangefa630b2020-07-08 22:23:08 -040047
48echo
49echo 'To activate existing build environment in your shell, run (do this first):'
50echo source "$CHIP_ROOT/scripts/activate.sh"
51
52echo
53echo 'To re-create the build environment from scratch, run:'
54echo source "$CHIP_ROOT/scripts/bootstrap.sh"
55
56echo
Michael Spang8cad33b2021-06-14 09:50:44 -040057echo 'To compile the generated debug build:'
Michael Spangefa630b2020-07-08 22:23:08 -040058echo ninja -C "$CHIP_ROOT/out/debug"
59
60echo
Michael Spang8cad33b2021-06-14 09:50:44 -040061echo 'To test the generated debug build (idempotent):'
Michael Spangefa630b2020-07-08 22:23:08 -040062echo ninja -C "$CHIP_ROOT/out/debug" check
63
64echo
Michael Spang8cad33b2021-06-14 09:50:44 -040065echo 'To compile the generated release build':
66echo ninja -C "$CHIP_ROOT/out/release"
67
68echo
69echo 'To test the generated release build (idempotent):'
Michael Spangefa630b2020-07-08 22:23:08 -040070echo ninja -C "$CHIP_ROOT/out/release" check
71
72echo
73echo 'To build a custom build (for help run "gn args --list out/debug")'
74echo gn args "$CHIP_ROOT/out/custom"
75echo ninja -C "$CHIP_ROOT/out/custom"
76
Michael Spang2182a382020-10-23 09:55:34 -040077extra_args=""
Michael Spang6b3293e2021-02-02 13:05:01 -050078user_args=""
Kevin Schoedel654dd882021-03-02 16:51:27 -050079ninja_args=()
80
81while 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
95done
96shift $((OPTIND - 1))
Michael Spang2182a382020-10-23 09:55:34 -040097
98for arg; do
99 case $arg in
Timothy Maes2478e022021-07-02 04:03:46 +0200100 enable_qpg_builds=true)
101 qpg_enabled=1
Michael Spang2182a382020-10-23 09:55:34 -0400102 ;;
jepenven-silabs72a368b2021-02-10 14:02:57 -0500103 enable_efr32_builds=true)
104 efr32_enabled=1
105 ;;
Praveen Chandran080ae572021-08-12 07:58:27 -0700106 enable_p6_builds=true)
107 p6_builds_enabled=1
108 ;;
109 p6_board=*)
110 p6_board_selected=1
111 ;;
Michael Spang2182a382020-10-23 09:55:34 -0400112 esac
Michael Spang6b3293e2021-02-02 13:05:01 -0500113 user_args+=" $arg"
Michael Spang2182a382020-10-23 09:55:34 -0400114done
Michael Spangfdc49a32020-09-03 18:33:20 -0400115
Austin Hsieh50b044f2021-10-04 06:37:35 -0700116# Android prebuilt JAR setup
117python3 build/chip/java/tests/generate_jars_for_test.py
118python3 third_party/android_deps/set_up_android_deps.py
119
Michael Spang284347d2020-09-11 19:24:51 -0400120# Android SDK setup
121android_sdk_args=""
Michael Spangfdc49a32020-09-03 18:33:20 -0400122
Michael Spang284347d2020-09-11 19:24:51 -0400123if [[ -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 Spangfdc49a32020-09-03 18:33:20 -0400126else
127 echo
Michael Spang284347d2020-09-11 19:24:51 -0400128 echo "Hint: Set \$ANDROID_HOME and \$ANDROID_NDK_HOME to enable building for Android"
cecille2cb4bf02021-05-07 16:54:25 -0400129 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 Spangfdc49a32020-09-03 18:33:20 -0400131fi
132
Martin Turon52b6f032020-07-10 12:36:07 -0700133echo
134
jepenven-silabscec75ca2020-08-04 09:38:48 -0400135# EFR32 SDK setup
jepenven-silabs72a368b2021-02-10 14:02:57 -0500136if [[ -z "$efr32_enabled" ]]; then
137 echo "Hint: Pass enable_efr32_builds=true to enable building for EFR32"
jepenven-silabscec75ca2020-08-04 09:38:48 -0400138else
jepenven-silabs72a368b2021-02-10 14:02:57 -0500139 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-silabscec75ca2020-08-04 09:38:48 -0400141fi
142
Praveen Chandran080ae572021-08-12 07:58:27 -0700143echo
144
145# P6 Build setup
146if [[ -z "$p6_builds_enabled" ]]; then
147 echo "Hint: Pass enable_p6_builds=true to this script to enable building for PSoC6-43012"
148else
149 p6_sdk_args=""
150 if [[ -z "$p6_board_selected" ]]; then
151 p6_sdk_args="p6_board=\"CY8CKIT-062S2-43012\""
152 fi
153fi
154
doru9104ac26b2020-10-13 18:23:28 +0300155# K32W SDK setup
156k32w_sdk_args=""
157
158if [[ -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"
161fi
162
163echo
164if [[ ! -d "$K32W061_SDK_ROOT" ]]; then
165 echo "Hint: Set \$K32W061_SDK_ROOT to enable building for K32W061"
166else
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)"
169fi
170echo
171
Timothy Maes2478e022021-07-02 04:03:46 +0200172if [[ -z "$qpg_enabled" ]]; then
173 echo "Hint: Pass enable_qpg_builds=true to this script to enable building for QPG"
Michael Spang2182a382020-10-23 09:55:34 -0400174else
175 echo 'To build the QPG6100 lock sample as a standalone project:'
Timothy Maes2478e022021-07-02 04:03:46 +0200176 echo "(cd $CHIP_ROOT/examples/lock-app/qpg; gn gen out/debug; ninja -C out/debug)"
Michael Spang2182a382020-10-23 09:55:34 -0400177fi
178
jepenven-silabscec75ca2020-08-04 09:38:48 -0400179echo
180
Michael Spang33698752021-04-08 16:04:01 -0400181# TI SimpleLink SDK setup
182ti_simplelink_sdk_args=""
183
184if [[ -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)"
190else
191 echo "Hint: Set \$TI_SIMPLELINK_SDK_ROOT and \$TI_SYSCONFIG_ROOT to enable building for cc13x2_26x2"
192fi
193
194echo
195
Martin Turon52b6f032020-07-10 12:36:07 -0700196_chip_banner "Build: GN configure"
197
Michael Spang6b3293e2021-02-02 13:05:01 -0500198gn --root="$CHIP_ROOT" gen --check --fail-on-unused-args "$CHIP_ROOT/out/debug" --args='target_os="all"'"$extra_args$user_args"
Michael Spang441350a2021-04-23 08:55:18 -0400199gn --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 Turon52b6f032020-07-10 12:36:07 -0700200
201_chip_banner "Build: Ninja build"
202
Kevin Schoedel654dd882021-03-02 16:51:27 -0500203time ninja -C "$CHIP_ROOT/out/debug" "${ninja_args[@]}" all check