blob: fb80957a6dbf88072648d4dd9011b3c3c811361a [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 ;;
Michael Spang2182a382020-10-23 09:55:34 -0400106 esac
Michael Spang6b3293e2021-02-02 13:05:01 -0500107 user_args+=" $arg"
Michael Spang2182a382020-10-23 09:55:34 -0400108done
Michael Spangfdc49a32020-09-03 18:33:20 -0400109
Michael Spang284347d2020-09-11 19:24:51 -0400110# Android SDK setup
111android_sdk_args=""
Michael Spangfdc49a32020-09-03 18:33:20 -0400112
Michael Spang284347d2020-09-11 19:24:51 -0400113if [[ -d "${ANDROID_NDK_HOME}/toolchains" && -d "${ANDROID_HOME}/platforms" ]]; then
114 android_sdk_args+="android_sdk_root=\"$ANDROID_HOME\" android_ndk_root=\"$ANDROID_NDK_HOME\""
115 extra_args+=" $android_sdk_args enable_android_builds=true"
Michael Spangfdc49a32020-09-03 18:33:20 -0400116else
117 echo
Michael Spang284347d2020-09-11 19:24:51 -0400118 echo "Hint: Set \$ANDROID_HOME and \$ANDROID_NDK_HOME to enable building for Android"
cecille2cb4bf02021-05-07 16:54:25 -0400119 echo " The required android sdk platform version is 21. It can be obtained from"
120 echo " https://dl.google.com/android/repository/android-21_r02.zip"
Michael Spangfdc49a32020-09-03 18:33:20 -0400121fi
122
Martin Turon52b6f032020-07-10 12:36:07 -0700123echo
124
jepenven-silabscec75ca2020-08-04 09:38:48 -0400125# EFR32 SDK setup
jepenven-silabs72a368b2021-02-10 14:02:57 -0500126if [[ -z "$efr32_enabled" ]]; then
127 echo "Hint: Pass enable_efr32_builds=true to enable building for EFR32"
jepenven-silabscec75ca2020-08-04 09:38:48 -0400128else
jepenven-silabs72a368b2021-02-10 14:02:57 -0500129 echo 'To build the EFR32 lock sample as a standalone project':
130 echo "(cd $CHIP_ROOT/examples/lock-app/efr32; gn gen out/debug; ninja -C out/debug)"
jepenven-silabscec75ca2020-08-04 09:38:48 -0400131fi
132
doru9104ac26b2020-10-13 18:23:28 +0300133# K32W SDK setup
134k32w_sdk_args=""
135
136if [[ -d "$K32W061_SDK_ROOT" ]]; then
137 k32w_sdk_args+="k32w_sdk_root=\"$K32W061_SDK_ROOT\""
138 extra_args+=" $k32w_sdk_args enable_k32w_builds=true"
139fi
140
141echo
142if [[ ! -d "$K32W061_SDK_ROOT" ]]; then
143 echo "Hint: Set \$K32W061_SDK_ROOT to enable building for K32W061"
144else
145 echo 'To build the K32W lock sample as a standalone project':
146 echo "(cd $CHIP_ROOT/examples/lock-app/k32w; gn gen out/debug --args='$k32w_sdk_args'; ninja -C out/debug)"
147fi
148echo
149
Timothy Maes2478e022021-07-02 04:03:46 +0200150if [[ -z "$qpg_enabled" ]]; then
151 echo "Hint: Pass enable_qpg_builds=true to this script to enable building for QPG"
Michael Spang2182a382020-10-23 09:55:34 -0400152else
153 echo 'To build the QPG6100 lock sample as a standalone project:'
Timothy Maes2478e022021-07-02 04:03:46 +0200154 echo "(cd $CHIP_ROOT/examples/lock-app/qpg; gn gen out/debug; ninja -C out/debug)"
Michael Spang2182a382020-10-23 09:55:34 -0400155fi
156
jepenven-silabscec75ca2020-08-04 09:38:48 -0400157echo
158
Michael Spang33698752021-04-08 16:04:01 -0400159# TI SimpleLink SDK setup
160ti_simplelink_sdk_args=""
161
162if [[ -d "${TI_SIMPLELINK_SDK_ROOT}/source" && -f "${TI_SYSCONFIG_ROOT}/sysconfig_cli.sh" ]]; then
163 ti_simplelink_sdk_args+="ti_simplelink_sdk_root=\"$TI_SIMPLELINK_SDK_ROOT\" ti_sysconfig_root=\"$TI_SYSCONFIG_ROOT\""
164 extra_args+=" $ti_simplelink_sdk_args enable_ti_simplelink_builds=true"
165
166 echo 'To build the cc13x2x7_26x2x7 lock sample as a standalone project':
167 echo "(cd $CHIP_ROOT/examples/lock-app/cc13x2x7_26x2x7; gn gen out/debug --args='$ti_simplelink_sdk_args'; ninja -C out/debug)"
168else
169 echo "Hint: Set \$TI_SIMPLELINK_SDK_ROOT and \$TI_SYSCONFIG_ROOT to enable building for cc13x2_26x2"
170fi
171
172echo
173
Martin Turon52b6f032020-07-10 12:36:07 -0700174_chip_banner "Build: GN configure"
175
Michael Spang6b3293e2021-02-02 13:05:01 -0500176gn --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 -0400177gn --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 -0700178
179_chip_banner "Build: Ninja build"
180
Kevin Schoedel654dd882021-03-02 16:51:27 -0500181time ninja -C "$CHIP_ROOT/out/debug" "${ninja_args[@]}" all check