blob: e9110442a522936ad045c40162723a49fe33fb63 [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 ;;
Praveen Chandranab028392022-08-18 07:39:28 -0700109 psoc6_board=*)
Praveen Chandran080ae572021-08-12 07:58:27 -0700110 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
Michael Spang284347d2020-09-11 19:24:51 -0400116# Android SDK setup
117android_sdk_args=""
Michael Spangfdc49a32020-09-03 18:33:20 -0400118
Michael Spang284347d2020-09-11 19:24:51 -0400119if [[ -d "${ANDROID_NDK_HOME}/toolchains" && -d "${ANDROID_HOME}/platforms" ]]; then
Martin Turonc83eab52022-05-06 08:21:55 -0700120 # Android prebuilt JAR setup
121 python3 third_party/android_deps/set_up_android_deps.py
122
Michael Spang284347d2020-09-11 19:24:51 -0400123 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 Spangfdc49a32020-09-03 18:33:20 -0400125else
126 echo
Michael Spang284347d2020-09-11 19:24:51 -0400127 echo "Hint: Set \$ANDROID_HOME and \$ANDROID_NDK_HOME to enable building for Android"
cecille2cb4bf02021-05-07 16:54:25 -0400128 echo " The required android sdk platform version is 21. It can be obtained from"
Matthew Swartwoutf7977bc2023-03-30 10:37:22 -0700129 echo " https://dl.google.com/android/repository/platform-26_r02.zip"
Michael Spangfdc49a32020-09-03 18:33:20 -0400130fi
131
Martin Turon52b6f032020-07-10 12:36:07 -0700132echo
133
jepenven-silabscec75ca2020-08-04 09:38:48 -0400134# EFR32 SDK setup
jepenven-silabs72a368b2021-02-10 14:02:57 -0500135if [[ -z "$efr32_enabled" ]]; then
136 echo "Hint: Pass enable_efr32_builds=true to enable building for EFR32"
jepenven-silabscec75ca2020-08-04 09:38:48 -0400137else
jepenven-silabs72a368b2021-02-10 14:02:57 -0500138 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-silabscec75ca2020-08-04 09:38:48 -0400140fi
141
Praveen Chandran080ae572021-08-12 07:58:27 -0700142echo
143
Praveen Chandranab028392022-08-18 07:39:28 -0700144# PSoC6 Build setup
Praveen Chandran080ae572021-08-12 07:58:27 -0700145if [[ -z "$p6_builds_enabled" ]]; then
146 echo "Hint: Pass enable_p6_builds=true to this script to enable building for PSoC6-43012"
147else
Praveen Chandranab028392022-08-18 07:39:28 -0700148 psoc6_sdk_args=""
Praveen Chandran080ae572021-08-12 07:58:27 -0700149 if [[ -z "$p6_board_selected" ]]; then
Praveen Chandranab028392022-08-18 07:39:28 -0700150 psoc6_sdk_args="psoc6_board=\"CY8CKIT-062S2-43012\""
Praveen Chandran080ae572021-08-12 07:58:27 -0700151 fi
152fi
153
doru9104ac26b2020-10-13 18:23:28 +0300154# K32W SDK setup
155k32w_sdk_args=""
156
doru919b2c8892022-07-22 21:40:26 +0300157if [[ -d "$NXP_K32W0_SDK_ROOT" ]]; then
158 k32w_sdk_args+="k32w0_sdk_root=\"$NXP_K32W0_SDK_ROOT\""
Andrei Litvin41300eb2022-02-17 00:39:14 -0500159 extra_args+=" $k32w0_sdk_args enable_k32w_builds=true"
doru9104ac26b2020-10-13 18:23:28 +0300160fi
161
162echo
doru919b2c8892022-07-22 21:40:26 +0300163if [[ ! -d "$NXP_K32W0_SDK_ROOT" ]]; then
164 echo "Hint: Set \$NXP_K32W0_SDK_ROOT to enable building for K32W061"
doru9104ac26b2020-10-13 18:23:28 +0300165else
166 echo 'To build the K32W lock sample as a standalone project':
Marius Tache83dc1c82024-08-06 22:53:49 +0300167 echo "(cd $CHIP_ROOT/examples/lock-app/nxp/k32w0; gn gen out/debug --args='$k32w_sdk_args'; ninja -C out/debug)"
doru9104ac26b2020-10-13 18:23:28 +0300168fi
169echo
170
Timothy Maes2478e022021-07-02 04:03:46 +0200171if [[ -z "$qpg_enabled" ]]; then
172 echo "Hint: Pass enable_qpg_builds=true to this script to enable building for QPG"
Michael Spang2182a382020-10-23 09:55:34 -0400173else
174 echo 'To build the QPG6100 lock sample as a standalone project:'
Timothy Maes2478e022021-07-02 04:03:46 +0200175 echo "(cd $CHIP_ROOT/examples/lock-app/qpg; gn gen out/debug; ninja -C out/debug)"
Michael Spang2182a382020-10-23 09:55:34 -0400176fi
177
jepenven-silabscec75ca2020-08-04 09:38:48 -0400178echo
179
Seth Rickardbbbf7ce2022-03-30 14:53:24 -0500180# TI SimpleLink Build setup
Michael Spang33698752021-04-08 16:04:01 -0400181ti_simplelink_sdk_args=""
182
Seth Rickardbbbf7ce2022-03-30 14:53:24 -0500183if [[ -f "${TI_SYSCONFIG_ROOT}/sysconfig_cli.sh" ]]; then
184 ti_simplelink_sdk_args+="ti_sysconfig_root=\"$TI_SYSCONFIG_ROOT\""
Michael Spang33698752021-04-08 16:04:01 -0400185 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)"
189else
Seth Rickardbbbf7ce2022-03-30 14:53:24 -0500190 echo "Hint: Set \$TI_SYSCONFIG_ROOT to enable building for cc13x2_26x2"
Michael Spang33698752021-04-08 16:04:01 -0400191fi
192
193echo
194
Jakub9c1660c2022-06-06 15:12:52 +0200195tizen_sdk_args=""
196
197if [[ -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"
200else
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"
205fi
206
207echo
208
Martin Turon52b6f032020-07-10 12:36:07 -0700209_chip_banner "Build: GN configure"
210
Michael Spang6b3293e2021-02-02 13:05:01 -0500211gn --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 -0400212gn --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 -0700213
214_chip_banner "Build: Ninja build"
215
Kevin Schoedel654dd882021-03-02 16:51:27 -0500216time ninja -C "$CHIP_ROOT/out/debug" "${ninja_args[@]}" all check