3 # Copyright (c) 2020 Project CHIP Authors
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
9 # http://www.apache.org/licenses/LICENSE-2.0
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.
20 CHIP_ROOT="$(dirname "$0")"
23 echo -e "\033[0;31m$*\033[0m"
27 echo -e "\033[0;33m$*\033[0m"
31 _chip_yellow '.--------------------------------'
33 _chip_yellow "'--------------------------------"
36 _chip_banner "Environment bringup"
38 git -C "$CHIP_ROOT" submodule update --init
40 # TODO: Fix pigweed to bootstrap if necessary in activate.sh.
42 echo "NB: If this fails run \"source scripts/bootstrap.sh\""
44 source "$CHIP_ROOT/scripts/activate.sh"
46 _chip_banner "Instructions"
49 echo 'To activate existing build environment in your shell, run (do this first):'
50 echo source "$CHIP_ROOT/scripts/activate.sh"
53 echo 'To re-create the build environment from scratch, run:'
54 echo source "$CHIP_ROOT/scripts/bootstrap.sh"
57 echo 'To build a debug build:'
58 echo gn gen "$CHIP_ROOT/out/debug" --args=\''target_os="all"'"$extra_args"\'
59 echo ninja -C "$CHIP_ROOT/out/debug"
62 echo 'To run tests (idempotent):'
63 echo ninja -C "$CHIP_ROOT/out/debug" check
66 echo 'To build & test an optimized build:'
67 echo gn gen "$CHIP_ROOT/out/release" --args=\''target_os="all" is_debug=false'"$extra_args"\'
68 echo ninja -C "$CHIP_ROOT/out/release" check
71 echo 'To build a custom build (for help run "gn args --list out/debug")'
72 echo gn args "$CHIP_ROOT/out/custom"
73 echo ninja -C "$CHIP_ROOT/out/custom"
79 while getopts :d:j:k:l:nt:vw: opt; do
85 ninja_args+=("-$opt" "$OPTARG")
88 printf '\nError: unknown option -%s\n' "$OPTARG"
89 printf 'Usage: %s [ninja-options] [gn-args]\n' "$0"
98 enable_qpg6100_builds=true)
101 enable_efr32_builds=true)
111 if [[ -d "${ANDROID_NDK_HOME}/toolchains" && -d "${ANDROID_HOME}/platforms" ]]; then
112 android_sdk_args+="android_sdk_root=\"$ANDROID_HOME\" android_ndk_root=\"$ANDROID_NDK_HOME\""
113 extra_args+=" $android_sdk_args enable_android_builds=true"
116 echo "Hint: Set \$ANDROID_HOME and \$ANDROID_NDK_HOME to enable building for Android"
122 if [[ -z "$efr32_enabled" ]]; then
123 echo "Hint: Pass enable_efr32_builds=true to enable building for EFR32"
125 echo 'To build the EFR32 lock sample as a standalone project':
126 echo "(cd $CHIP_ROOT/examples/lock-app/efr32; gn gen out/debug; ninja -C out/debug)"
132 if [[ -d "$K32W061_SDK_ROOT" ]]; then
133 k32w_sdk_args+="k32w_sdk_root=\"$K32W061_SDK_ROOT\""
134 extra_args+=" $k32w_sdk_args enable_k32w_builds=true"
138 if [[ ! -d "$K32W061_SDK_ROOT" ]]; then
139 echo "Hint: Set \$K32W061_SDK_ROOT to enable building for K32W061"
141 echo 'To build the K32W lock sample as a standalone project':
142 echo "(cd $CHIP_ROOT/examples/lock-app/k32w; gn gen out/debug --args='$k32w_sdk_args'; ninja -C out/debug)"
146 if [[ -z "$qpg6100_enabled" ]]; then
147 echo "Hint: Pass enable_qpg6100_builds=true to this script to enable building for QPG6100"
149 echo 'To build the QPG6100 lock sample as a standalone project:'
150 echo "(cd $CHIP_ROOT/examples/lock-app/qpg6100; gn gen out/debug; ninja -C out/debug)"
155 _chip_banner "Build: GN configure"
157 gn --root="$CHIP_ROOT" gen --check --fail-on-unused-args "$CHIP_ROOT/out/debug" --args='target_os="all"'"$extra_args$user_args"
158 gn --root="$CHIP_ROOT" gen --check --fail-on-unused-args "$CHIP_ROOT/out/release" --args='target_os="all" is_debug=false'"$extra_arg$user_args"
160 _chip_banner "Build: Ninja build"
162 time ninja -C "$CHIP_ROOT/out/debug" "${ninja_args[@]}" all check