1#!/bin/bash
2#
3#  Copyright (c) 2020, The OpenThread Authors.
4#  All rights reserved.
5#
6#  Redistribution and use in source and binary forms, with or without
7#  modification, are permitted provided that the following conditions are met:
8#  1. Redistributions of source code must retain the above copyright
9#     notice, this list of conditions and the following disclaimer.
10#  2. Redistributions in binary form must reproduce the above copyright
11#     notice, this list of conditions and the following disclaimer in the
12#     documentation and/or other materials provided with the distribution.
13#  3. Neither the name of the copyright holder nor the
14#     names of its contributors may be used to endorse or promote products
15#     derived from this software without specific prior written permission.
16#
17#  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18#  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19#  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20#  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21#  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22#  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23#  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24#  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25#  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26#  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27#  POSSIBILITY OF SUCH DAMAGE.
28#
29
30set -euxo pipefail
31
32OT_BUILD_JOBS=$(getconf _NPROCESSORS_ONLN)
33readonly OT_BUILD_JOBS
34
35reset_source()
36{
37    rm -rf build output tmp
38}
39
40build_all_features()
41{
42    local options=(
43        "-DOPENTHREAD_CONFIG_ANNOUNCE_SENDER_ENABLE=1"
44        "-DOPENTHREAD_CONFIG_ANYCAST_LOCATOR=1"
45        "-DOPENTHREAD_CONFIG_BORDER_AGENT_ENABLE=1"
46        "-DOPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE=1"
47        "-DOPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE=1"
48        "-DOPENTHREAD_CONFIG_CHANNEL_MANAGER_ENABLE=1"
49        "-DOPENTHREAD_CONFIG_CHANNEL_MONITOR_ENABLE=1"
50        "-DOPENTHREAD_CONFIG_COAP_API_ENABLE=1"
51        "-DOPENTHREAD_CONFIG_COAP_SECURE_API_ENABLE=1"
52        "-DOPENTHREAD_CONFIG_COMMISSIONER_ENABLE=1"
53        "-DOPENTHREAD_CONFIG_DATASET_UPDATER_ENABLE=1"
54        "-DOPENTHREAD_CONFIG_DHCP6_CLIENT_ENABLE=1"
55        "-DOPENTHREAD_CONFIG_DHCP6_SERVER_ENABLE=1"
56        "-DOPENTHREAD_CONFIG_DIAG_ENABLE=1"
57        "-DOPENTHREAD_CONFIG_DNS_CLIENT_ENABLE=1"
58        "-DOPENTHREAD_CONFIG_DNS_DSO_ENABLE=1"
59        "-DOPENTHREAD_CONFIG_ECDSA_ENABLE=1"
60        "-DOPENTHREAD_CONFIG_HEAP_EXTERNAL_ENABLE=1"
61        "-DOPENTHREAD_CONFIG_HISTORY_TRACKER_ENABLE=1"
62        "-DOPENTHREAD_CONFIG_IP6_FRAGMENTATION_ENABLE=1"
63        "-DOPENTHREAD_CONFIG_IP6_SLAAC_ENABLE=1"
64        "-DOPENTHREAD_CONFIG_JAM_DETECTION_ENABLE=1"
65        "-DOPENTHREAD_CONFIG_JOINER_ENABLE=1"
66        "-DOPENTHREAD_CONFIG_LINK_RAW_ENABLE=1"
67        "-DOPENTHREAD_CONFIG_LOG_LEVEL_DYNAMIC_ENABLE=1"
68        "-DOPENTHREAD_CONFIG_MAC_BEACON_RSP_WHEN_JOINABLE_ENABLE=1"
69        "-DOPENTHREAD_CONFIG_MAC_FILTER_ENABLE=1"
70        "-DOPENTHREAD_CONFIG_MAC_RETRY_SUCCESS_HISTOGRAM_ENABLE=1"
71        "-DOPENTHREAD_CONFIG_MAC_SOFTWARE_ACK_TIMEOUT_ENABLE=1"
72        "-DOPENTHREAD_CONFIG_MAC_SOFTWARE_CSMA_BACKOFF_ENABLE=1"
73        "-DOPENTHREAD_CONFIG_MAC_SOFTWARE_ENERGY_SCAN_ENABLE=1"
74        "-DOPENTHREAD_CONFIG_MAC_SOFTWARE_RETRANSMIT_ENABLE=1"
75        "-DOPENTHREAD_CONFIG_MAC_SOFTWARE_TX_SECURITY_ENABLE=1"
76        "-DOPENTHREAD_CONFIG_MLE_ATTACH_BACKOFF_ENABLE=1"
77        "-DOPENTHREAD_CONFIG_MLE_STEERING_DATA_SET_OOB_ENABLE=1"
78        "-DOPENTHREAD_CONFIG_MPL_DYNAMIC_INTERVAL_ENABLE"
79        "-DOPENTHREAD_CONFIG_NCP_HDLC_ENABLE=1"
80        "-DOPENTHREAD_CONFIG_NCP_SPI_ENABLE=1"
81        "-DOPENTHREAD_CONFIG_PING_SENDER_ENABLE=1"
82        "-DOPENTHREAD_CONFIG_PLATFORM_FLASH_API_ENABLE=1"
83        "-DOPENTHREAD_CONFIG_PLATFORM_RADIO_COEX_ENABLE=1"
84        "-DOPENTHREAD_CONFIG_PLATFORM_USEC_TIMER_ENABLE=1"
85        "-DOPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE=1"
86        "-DOPENTHREAD_CONFIG_SNTP_CLIENT_ENABLE=1"
87        "-DOPENTHREAD_CONFIG_SRP_CLIENT_ENABLE=1"
88        "-DOPENTHREAD_CONFIG_TMF_NETDATA_SERVICE_ENABLE=1"
89        "-DOPENTHREAD_CONFIG_TMF_NETDIAG_CLIENT_ENABLE=1"
90        "-DOPENTHREAD_CONFIG_UDP_FORWARD_ENABLE=1"
91        "-DOPENTHREAD_CONFIG_MAC_BEACON_PAYLOAD_PARSING_ENABLE=1"
92        "-DOPENTHREAD_CONFIG_MAC_OUTGOING_BEACON_PAYLOAD_ENABLE=1"
93    )
94
95    local options_1_3=(
96        "-DOPENTHREAD_CONFIG_BACKBONE_ROUTER_ENABLE=1"
97        "-DOPENTHREAD_CONFIG_NAT64_BORDER_ROUTING_ENABLE=1"
98        "-DOPENTHREAD_CONFIG_NAT64_TRANSLATOR_ENABLE=1"
99        "-DOPENTHREAD_CONFIG_MAC_CSL_RECEIVER_ENABLE=1"
100        "-DOPENTHREAD_CONFIG_DUA_ENABLE=1"
101        "-DOPENTHREAD_CONFIG_MLR_ENABLE=1"
102    )
103
104    # Build Thread 1.1 with full features and no log
105    export CPPFLAGS="${options[*]}"
106    reset_source
107    make -f examples/Makefile-simulation THREAD_VERSION=1.1 LOG_OUTPUT=NONE
108
109    # Build Thread 1.1 with full features and full logs
110    export CPPFLAGS="${options[*]}"
111    reset_source
112    make -f examples/Makefile-simulation THREAD_VERSION=1.1 FULL_LOGS=1
113
114    # Build Thread 1.3 with full features and logs
115    export CPPFLAGS="${options[*]} ${options_1_3[*]}"
116    reset_source
117    make -f examples/Makefile-simulation THREAD_VERSION=1.3 LOG_OUTPUT=NONE
118
119    # Build Thread 1.3 with full features and full logs
120    export CPPFLAGS="${options[*]} ${options_1_3[*]}"
121    reset_source
122    make -f examples/Makefile-simulation THREAD_VERSION=1.3 FULL_LOGS=1
123
124    # Build Thread 1.1 with ASSERT disabled
125    export CPPFLAGS="${options[*]} -DOPENTHREAD_CONFIG_ASSERT_ENABLE=0"
126    reset_source
127    make -f examples/Makefile-simulation THREAD_VERSION=1.1
128
129    # Build Thread 1.1 OTNS
130    export CPPFLAGS="${options[*]}"
131    reset_source
132    make -f examples/Makefile-simulation THREAD_VERSION=1.1 OTNS=1
133
134    # Build Thread 1.3 with external heap and msg pool using heap
135    export CPPFLAGS="${options[*]} ${options_1_3[*]} -DOPENTHREAD_CONFIG_MESSAGE_USE_HEAP_ENABLE=1"
136    reset_source
137    make -f examples/Makefile-simulation THREAD_VERSION=1.3
138}
139
140build_nest_common()
141{
142    local options=(
143        "-DOPENTHREAD_CONFIG_BORDER_ROUTER_ENABLE=1"
144        "-DOPENTHREAD_CONFIG_CHANNEL_MANAGER_ENABLE=1"
145        "-DOPENTHREAD_CONFIG_CHANNEL_MONITOR_ENABLE=1"
146        "-DOPENTHREAD_CONFIG_DATASET_UPDATER_ENABLE=1"
147        "-DOPENTHREAD_CONFIG_DIAG_ENABLE=1"
148        "-DOPENTHREAD_CONFIG_JAM_DETECTION_ENABLE=1"
149        "-DOPENTHREAD_CONFIG_MAC_FILTER_ENABLE=1"
150        "-DOPENTHREAD_CONFIG_PING_SENDER_ENABLE=1"
151        "-DOPENTHREAD_CONFIG_NCP_SPI_ENABLE=1"
152        "-DOPENTHREAD_CONFIG_PLATFORM_FLASH_API_ENABLE=1"
153        "-DOPENTHREAD_CONFIG_TMF_NETDATA_SERVICE_ENABLE=1"
154    )
155    export CPPFLAGS="${options[*]}"
156
157    reset_source
158    mkdir build && cd build
159    ../configure \
160        --enable-cli \
161        --enable-mtd \
162        --with-examples=simulation \
163        --disable-docs \
164        --disable-tests
165    make -j"${OT_BUILD_JOBS}"
166    cd ..
167
168    options=(
169        "-DOPENTHREAD_CONFIG_ANOUNCE_SENDER_ENABLE=1"
170        "-DOPENTHREAD_CONFIG_PLATFORM_FLASH_API_ENABLE=1"
171        "-DOPENTHREAD_CONFIG_TIME_SYNC_ENABLE=1"
172        "-DOPENTHREAD_CONFIG_NCP_HDLC_ENABLE=1"
173    )
174    export CPPFLAGS="${options[*]}"
175
176    reset_source
177    mkdir build && cd build
178    ../configure \
179        --enable-cli \
180        --enable-ftd \
181        --enable-mtd \
182        --enable-ncp \
183        --enable-radio-only \
184        --enable-radio-cli \
185        --disable-docs \
186        --disable-tests \
187        --with-examples=simulation
188    make -j"${OT_BUILD_JOBS}"
189    cd ..
190
191    options=(
192        "-DOPENTHREAD_CONFIG_NCP_HDLC_ENABLE=1"
193        "-DOPENTHREAD_CONFIG_PLATFORM_FLASH_API_ENABLE=1"
194    )
195    export CPPFLAGS="${options[*]}"
196
197    reset_source
198    mkdir build && cd build
199    ../configure \
200        --enable-ftd \
201        --enable-mtd \
202        --enable-ncp \
203        --with-examples=simulation \
204        --disable-docs \
205        --disable-tests \
206        --with-vendor-extension=../src/core/common/extension_example.cpp \
207        --with-ncp-vendor-hook-source=../src/ncp/example_vendor_hook.cpp
208    make -j"${OT_BUILD_JOBS}"
209    cd ..
210}
211
212build_multi_radio_links()
213{
214    # TREL radio link only.
215    local options=(
216        "-DOPENTHREAD_CONFIG_NCP_HDLC_ENABLE=1"
217        "-DOPENTHREAD_CONFIG_PLATFORM_FLASH_API_ENABLE=1"
218        "-DOPENTHREAD_CONFIG_LOG_LEVEL=OT_LOG_LEVEL_DEBG"
219        "-DOPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE=0"
220        "-DOPENTHREAD_CONFIG_RADIO_LINK_TREL_ENABLE=1"
221    )
222    export CPPFLAGS="${options[*]}"
223
224    reset_source
225    mkdir build && cd build
226    ../configure \
227        --enable-cli \
228        --enable-ftd \
229        --enable-mtd \
230        --enable-ncp \
231        --enable-radio-only \
232        --enable-radio-cli \
233        --with-examples=simulation \
234        --disable-docs \
235        --disable-tests
236    make -j"${OT_BUILD_JOBS}"
237    cd ..
238
239    # Multi radio link - 15.4 and TREL.
240    options=(
241        "-DOPENTHREAD_CONFIG_NCP_HDLC_ENABLE=1"
242        "-DOPENTHREAD_CONFIG_PLATFORM_FLASH_API_ENABLE=1"
243        "-DOPENTHREAD_CONFIG_DIAG_ENABLE=1"
244        "-DOPENTHREAD_CONFIG_LINK_RAW_ENABLE=1"
245        "-DOPENTHREAD_CONFIG_LOG_LEVEL_DYNAMIC_ENABLE=1"
246        "-DOPENTHREAD_CONFIG_LOG_LEVEL=OT_LOG_LEVEL_DEBG"
247        "-DOPENTHREAD_CONFIG_MAC_FILTER_ENABLE=1"
248        "-DOPENTHREAD_CONFIG_RADIO_LINK_IEEE_802_15_4_ENABLE=1"
249        "-DOPENTHREAD_CONFIG_RADIO_LINK_TREL_ENABLE=1"
250    )
251    export CPPFLAGS="${options[*]}"
252
253    reset_source
254    mkdir build && cd build
255    ../configure \
256        --enable-cli \
257        --enable-ftd \
258        --enable-mtd \
259        --enable-ncp \
260        --enable-radio-only \
261        --enable-radio-cli \
262        --with-examples=simulation \
263        --disable-docs \
264        --disable-tests
265    make -j"${OT_BUILD_JOBS}"
266    cd ..
267}
268
269main()
270{
271    ./bootstrap
272
273    build_all_features
274    build_nest_common
275    build_multi_radio_links
276}
277
278main "$@"
279