1#!/bin/bash
2#
3#  Copyright (c) 2018, 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
30display_usage()
31{
32    echo ""
33    echo "Toranj Build script "
34    echo ""
35    echo "Usage: $(basename "$0") [options] <config>"
36    echo "    <config> can be:"
37    echo "        all             : Build OpenThread NCP, CLI, and RCP with simulation platform"
38    echo "        ncp             : Build OpenThread NCP mode with simulation platform"
39    echo "        ncp-15.4        : Build OpenThread NCP mode with simulation platform - 15.4 radio"
40    echo "        ncp-trel        : Build OpenThread NCP mode with simulation platform - TREL radio "
41    echo "        ncp-15.4+trel   : Build OpenThread NCP mode with simulation platform - multi radio (15.4+TREL)"
42    echo "        cli             : Build OpenThread CLI mode with simulation platform"
43    echo "        cli-15.4        : Build OpenThread CLI mode with simulation platform - 15.4 radio"
44    echo "        cli-trel        : Build OpenThread CLI mode with simulation platform - TREL radio "
45    echo "        cli-15.4+trel   : Build OpenThread CLI mode with simulation platform - multi radio (15.4+TREL)"
46    echo "        rcp             : Build OpenThread RCP (NCP in radio mode) with simulation platform"
47    echo "        posix           : Build OpenThread POSIX"
48    echo "        posix-15.4      : Build OpenThread POSIX - 15.4 radio"
49    echo "        posix-trel      : Build OpenThread POSIX - TREL radio "
50    echo "        posix-15.4+trel : Build OpenThread POSIX - multi radio (15.4+TREL)"
51    echo ""
52    echo "Options:"
53    echo "        -c/--enable-coverage      Enable code coverage"
54    echo "        -k/--enable-plat-key-ref  Enable OT_PLATFORM_KEY_REF"
55    echo ""
56}
57
58die()
59{
60    echo " *** ERROR: " "$*"
61    exit 1
62}
63
64cd "$(dirname "$0")" || die "cd failed"
65cd ../.. || die "cd failed"
66
67ot_coverage=OFF
68ot_plat_key_ref=OFF
69
70while [ $# -ge 2 ]; do
71    case $1 in
72        -c | --enable-coverage)
73            ot_coverage=ON
74            shift
75            ;;
76        -t | --enable-tests)
77            shift
78            ;;
79        -k | --enable-plat-key-ref)
80            ot_plat_key_ref=ON
81            shift
82            ;;
83        "")
84            shift
85            ;;
86        *)
87            echo "Error: Unknown option \"$1\""
88            display_usage
89            exit 1
90            ;;
91    esac
92done
93
94if [ "$#" -ne 1 ]; then
95    display_usage
96    exit 1
97fi
98
99build_config=$1
100
101if [ -n "${top_builddir}" ]; then
102    top_srcdir=$(pwd)
103    mkdir -p "${top_builddir}"
104else
105    top_srcdir=.
106    top_builddir=.
107fi
108
109case ${build_config} in
110    ncp | ncp-)
111        echo "==================================================================================================="
112        echo "Building OpenThread NCP with simulation platform (radios determined by config)"
113        echo "==================================================================================================="
114        cd "${top_builddir}" || die "cd failed"
115        cmake -GNinja -DOT_PLATFORM=simulation -DOT_COMPILE_WARNING_AS_ERROR=ON -DOT_COVERAGE=${ot_coverage} \
116            -DOT_THREAD_VERSION=1.4 -DOT_APP_CLI=OFF -DOT_APP_NCP=ON -DOT_APP_RCP=OFF \
117            -DOT_OPERATIONAL_DATASET_AUTO_INIT=ON -DOT_PLATFORM_KEY_REF=${ot_plat_key_ref} \
118            -DOT_BORDER_ROUTING=OFF \
119            -DOT_PROJECT_CONFIG=../tests/toranj/openthread-core-toranj-config-simulation.h \
120            "${top_srcdir}" || die
121        ninja || die
122        ;;
123
124    ncp-15.4)
125        echo "==================================================================================================="
126        echo "Building OpenThread NCP with simulation platform - 15.4 radio"
127        echo "==================================================================================================="
128        cd "${top_builddir}" || die "cd failed"
129        cmake -GNinja -DOT_PLATFORM=simulation -DOT_COMPILE_WARNING_AS_ERROR=ON -DOT_COVERAGE=${ot_coverage} \
130            -DOT_THREAD_VERSION=1.4 -DOT_APP_CLI=OFF -DOT_APP_NCP=ON -DOT_APP_RCP=OFF \
131            -DOT_15_4=ON -DOT_TREL=OFF -DOT_OPERATIONAL_DATASET_AUTO_INIT=ON \
132            -DOT_BORDER_ROUTING=OFF \
133            -DOT_PLATFORM_KEY_REF=${ot_plat_key_ref} \
134            -DOT_PROJECT_CONFIG=../tests/toranj/openthread-core-toranj-config-simulation.h \
135            "${top_srcdir}" || die
136        ninja || die
137        cp -p ${top_builddir}/examples/apps/ncp/ot-ncp-ftd ${top_builddir}/examples/apps/ncp/ot-ncp-ftd-15.4
138        ;;
139
140    ncp-trel)
141        echo "==================================================================================================="
142        echo "Building OpenThread NCP with simulation platform - TREL radio"
143        echo "==================================================================================================="
144        cd "${top_builddir}" || die "cd failed"
145        cmake -GNinja -DOT_PLATFORM=simulation -DOT_COMPILE_WARNING_AS_ERROR=ON -DOT_COVERAGE=${ot_coverage} \
146            -DOT_THREAD_VERSION=1.4 -DOT_APP_CLI=OFF -DOT_APP_NCP=ON -DOT_APP_RCP=OFF \
147            -DOT_15_4=OFF -DOT_TREL=ON -DOT_OPERATIONAL_DATASET_AUTO_INIT=ON \
148            -DOT_BORDER_ROUTING=OFF \
149            -DOT_PLATFORM_KEY_REF=${ot_plat_key_ref} \
150            -DOT_PROJECT_CONFIG=../tests/toranj/openthread-core-toranj-config-simulation.h \
151            "${top_srcdir}" || die
152        ninja || die
153        cp -p ${top_builddir}/examples/apps/ncp/ot-ncp-ftd ${top_builddir}/examples/apps/ncp/ot-ncp-ftd-trel
154        ;;
155
156    ncp-15.4+trel | ncp-trel+15.4)
157        echo "==================================================================================================="
158        echo "Building OpenThread NCP with simulation platform - multi radio (15.4 + TREL)"
159        echo "==================================================================================================="
160        cd "${top_builddir}" || die "cd failed"
161        cmake -GNinja -DOT_PLATFORM=simulation -DOT_COMPILE_WARNING_AS_ERROR=ON -DOT_COVERAGE=${ot_coverage} \
162            -DOT_THREAD_VERSION=1.4 -DOT_APP_CLI=OFF -DOT_APP_NCP=ON -DOT_APP_RCP=OFF \
163            -DOT_15_4=ON -DOT_TREL=ON -DOT_OPERATIONAL_DATASET_AUTO_INIT=ON \
164            -DOT_BORDER_ROUTING=OFF \
165            -DOT_PLATFORM_KEY_REF=${ot_plat_key_ref} \
166            -DOT_PROJECT_CONFIG=../tests/toranj/openthread-core-toranj-config-simulation.h \
167            "${top_srcdir}" || die
168        ninja || die
169        cp -p ${top_builddir}/examples/apps/ncp/ot-ncp-ftd ${top_builddir}/examples/apps/ncp/ot-ncp-ftd-15.4-trel
170        ;;
171
172    cli | cli-)
173        echo "==================================================================================================="
174        echo "Building OpenThread CLI with simulation platform (radios determined by config)"
175        echo "==================================================================================================="
176        cd "${top_builddir}" || die "cd failed"
177        cmake -GNinja -DOT_PLATFORM=simulation -DOT_COMPILE_WARNING_AS_ERROR=ON -DOT_COVERAGE=${ot_coverage} \
178            -DOT_THREAD_VERSION=1.4 -DOT_APP_CLI=ON -DOT_APP_NCP=OFF -DOT_APP_RCP=OFF \
179            -DOT_PLATFORM_KEY_REF=${ot_plat_key_ref} \
180            -DOT_PROJECT_CONFIG=../tests/toranj/openthread-core-toranj-config-simulation.h \
181            "${top_srcdir}" || die
182        ninja || die
183        ;;
184
185    cli-15.4)
186        echo "==================================================================================================="
187        echo "Building OpenThread CLI with simulation platform - 15.4 radio"
188        echo "==================================================================================================="
189        cd "${top_builddir}" || die "cd failed"
190        cmake -GNinja -DOT_PLATFORM=simulation -DOT_COMPILE_WARNING_AS_ERROR=ON -DOT_COVERAGE=${ot_coverage} \
191            -DOT_THREAD_VERSION=1.4 -DOT_APP_CLI=ON -DOT_APP_NCP=OFF -DOT_APP_RCP=OFF \
192            -DOT_15_4=ON -DOT_TREL=OFF \
193            -DOT_PLATFORM_KEY_REF=${ot_plat_key_ref} \
194            -DOT_PROJECT_CONFIG=../tests/toranj/openthread-core-toranj-config-simulation.h \
195            "${top_srcdir}" || die
196        ninja || die
197        cp -p ${top_builddir}/examples/apps/cli/ot-cli-ftd ${top_builddir}/examples/apps/cli/ot-cli-ftd-15.4
198        ;;
199
200    cli-trel)
201        echo "==================================================================================================="
202        echo "Building OpenThread CLI with simulation platform - TREL radio"
203        echo "==================================================================================================="
204        cd "${top_builddir}" || die "cd failed"
205        cmake -GNinja -DOT_PLATFORM=simulation -DOT_COMPILE_WARNING_AS_ERROR=ON -DOT_COVERAGE=${ot_coverage} \
206            -DOT_THREAD_VERSION=1.4 -DOT_APP_CLI=ON -DOT_APP_NCP=OFF -DOT_APP_RCP=OFF \
207            -DOT_15_4=OFF -DOT_TREL=ON \
208            -DOT_PLATFORM_KEY_REF=${ot_plat_key_ref} \
209            -DOT_PROJECT_CONFIG=../tests/toranj/openthread-core-toranj-config-simulation.h \
210            "${top_srcdir}" || die
211        ninja || die
212        cp -p ${top_builddir}/examples/apps/cli/ot-cli-ftd ${top_builddir}/examples/apps/cli/ot-cli-ftd-trel
213        ;;
214
215    cli-15.4+trel | cli-trel+15.4)
216        echo "==================================================================================================="
217        echo "Building OpenThread NCP with simulation platform - multi radio (15.4 + TREL)"
218        echo "==================================================================================================="
219        cd "${top_builddir}" || die "cd failed"
220        cmake -GNinja -DOT_PLATFORM=simulation -DOT_COMPILE_WARNING_AS_ERROR=ON -DOT_COVERAGE=${ot_coverage} \
221            -DOT_THREAD_VERSION=1.4 -DOT_APP_CLI=ON -DOT_APP_NCP=OFF -DOT_APP_RCP=OFF \
222            -DOT_15_4=ON -DOT_TREL=ON \
223            -DOT_PLATFORM_KEY_REF=${ot_plat_key_ref} \
224            -DOT_PROJECT_CONFIG=../tests/toranj/openthread-core-toranj-config-simulation.h \
225            "${top_srcdir}" || die
226        ninja || die
227        cp -p ${top_builddir}/examples/apps/cli/ot-cli-ftd ${top_builddir}/examples/apps/cli/ot-cli-ftd-15.4-trel
228        ;;
229
230    rcp)
231        echo "===================================================================================================="
232        echo "Building OpenThread RCP (NCP in radio mode) with simulation platform"
233        echo "===================================================================================================="
234        cd "${top_builddir}" || die "cd failed"
235        cmake -GNinja -DOT_PLATFORM=simulation -DOT_COMPILE_WARNING_AS_ERROR=ON -DOT_COVERAGE=${ot_coverage} \
236            -DOT_THREAD_VERSION=1.4 -DOT_APP_CLI=OFF -DOT_APP_NCP=OFF -DOT_APP_RCP=ON \
237            -DOT_PLATFORM_KEY_REF=${ot_plat_key_ref} \
238            -DOT_PROJECT_CONFIG=../tests/toranj/openthread-core-toranj-config-simulation.h \
239            "${top_srcdir}" || die
240        ninja || die
241        ;;
242
243    posix | posix- | cmake-posix-host | cmake-posix | cmake-p)
244        echo "===================================================================================================="
245        echo "Building OpenThread POSIX (radios determined by config)"
246        echo "===================================================================================================="
247        cd "${top_builddir}" || die "cd failed"
248        cmake -GNinja -DOT_PLATFORM=posix -DOT_COMPILE_WARNING_AS_ERROR=ON -DOT_COVERAGE=${ot_coverage} \
249            -DOT_THREAD_VERSION=1.4 -DOT_APP_CLI=ON -DOT_APP_NCP=ON -DOT_APP_RCP=OFF \
250            -DOT_PLATFORM_KEY_REF=${ot_plat_key_ref} \
251            -DOT_PROJECT_CONFIG=../tests/toranj/openthread-core-toranj-config-posix.h \
252            "${top_srcdir}" || die
253        ninja || die
254        ;;
255
256    posix-15.4)
257        echo "===================================================================================================="
258        echo "Building OpenThread POSIX - 15.4 radio"
259        echo "===================================================================================================="
260        cd "${top_builddir}" || die "cd failed"
261        cmake -GNinja -DOT_PLATFORM=posix -DOT_COMPILE_WARNING_AS_ERROR=ON -DOT_COVERAGE=${ot_coverage} \
262            -DOT_THREAD_VERSION=1.4 -DOT_APP_CLI=ON -DOT_APP_NCP=ON -DOT_APP_RCP=OFF \
263            -DOT_15_4=ON -DOT_TREL=OFF \
264            -DOT_PLATFORM_KEY_REF=${ot_plat_key_ref} \
265            -DOT_PROJECT_CONFIG=../tests/toranj/openthread-core-toranj-config-posix.h \
266            "${top_srcdir}" || die
267        ninja || die
268        ;;
269
270    posix-trel)
271        echo "===================================================================================================="
272        echo "Building OpenThread POSIX - TREL radio"
273        echo "===================================================================================================="
274        cd "${top_builddir}" || die "cd failed"
275        cmake -GNinja -DOT_PLATFORM=posix -DOT_COMPILE_WARNING_AS_ERROR=ON -DOT_COVERAGE=${ot_coverage} \
276            -DOT_THREAD_VERSION=1.4 -DOT_APP_CLI=ON -DOT_APP_NCP=ON -DOT_APP_RCP=OFF \
277            -DOT_15_4=OFF -DOT_TREL=ON \
278            -DOT_PLATFORM_KEY_REF=${ot_plat_key_ref} \
279            -DOT_PROJECT_CONFIG=../tests/toranj/openthread-core-toranj-config-posix.h \
280            "${top_srcdir}" || die
281        ninja || die
282        ;;
283
284    posix-trel+15.4 | posix-15.4+trel)
285        echo "===================================================================================================="
286        echo "Building OpenThread POSIX - multi radio link (15.4 + TREL)"
287        echo "===================================================================================================="
288        cd "${top_builddir}" || die "cd failed"
289        cmake -GNinja -DOT_PLATFORM=posix -DOT_COMPILE_WARNING_AS_ERROR=ON -DOT_COVERAGE=${ot_coverage} \
290            -DOT_THREAD_VERSION=1.4 -DOT_APP_CLI=ON -DOT_APP_NCP=ON -DOT_APP_RCP=OFF \
291            -DOT_15_4=ON -DOT_TREL=ON \
292            -DOT_PLATFORM_KEY_REF=${ot_plat_key_ref} \
293            -DOT_PROJECT_CONFIG=../tests/toranj/openthread-core-toranj-config-posix.h \
294            "${top_srcdir}" || die
295        ninja || die
296        ;;
297
298    all | cmake)
299        echo "===================================================================================================="
300        echo "Building OpenThread (NCP/CLI for FTD/MTD/RCP mode) with simulation platform using cmake"
301        echo "===================================================================================================="
302        cd "${top_builddir}" || die "cd failed"
303        cmake -GNinja -DOT_PLATFORM=simulation -DOT_COMPILE_WARNING_AS_ERROR=ON -DOT_COVERAGE=${ot_coverage} \
304            -DOT_THREAD_VERSION=1.4 -DOT_APP_CLI=ON -DOT_APP_NCP=ON -DOT_APP_RCP=ON \
305            -DOT_PLATFORM_KEY_REF=${ot_plat_key_ref} \
306            -DOT_PROJECT_CONFIG=../tests/toranj/openthread-core-toranj-config-simulation.h \
307            "${top_srcdir}" || die
308        ninja || die
309        ;;
310
311    *)
312        echo "Error: Unknown configuration \"$1\""
313        display_usage
314        exit 1
315        ;;
316esac
317
318exit 0
319