1#!/usr/bin/env bash
2# Copyright 2018 Oticon A/S
3# SPDX-License-Identifier: Apache-2.0
4
5# Compile all the applications needed by the bsim_bt tests
6
7#set -x #uncomment this line for debugging
8set -ue
9
10: "${BSIM_OUT_PATH:?BSIM_OUT_PATH must be defined}"
11: "${BSIM_COMPONENTS_PATH:?BSIM_COMPONENTS_PATH must be defined}"
12: "${ZEPHYR_BASE:?ZEPHYR_BASE must be set to point to the zephyr root\
13 directory}"
14
15WORK_DIR="${WORK_DIR:-${ZEPHYR_BASE}/bsim_bt_out}"
16BOARD="${BOARD:-nrf52_bsim}"
17BOARD_ROOT="${BOARD_ROOT:-${ZEPHYR_BASE}}"
18
19mkdir -p ${WORK_DIR}
20
21function compile(){
22  local app_root="${app_root:-${ZEPHYR_BASE}}"
23  local conf_file="${conf_file:-prj.conf}"
24  local cmake_args="${cmake_args:-"-DCONFIG_COVERAGE=y"}"
25  local ninja_args="${ninja_args:-""}"
26  local cc_flags="${cc_flags:-"-Werror"}"
27
28  local exe_name="${exe_name:-bs_${BOARD}_${app}_${conf_file}}"
29  local exe_name=${exe_name//\//_}
30  local exe_name=${exe_name//./_}
31  local exe_name=${BSIM_OUT_PATH}/bin/$exe_name
32  local map_file_name=${exe_name}.Tsymbols
33
34  local this_dir=${WORK_DIR}/${app}/${conf_file}
35
36  echo "Building $exe_name"
37
38  # Set INCR_BUILD when calling to only do an incremental build
39  if [ ! -v INCR_BUILD ] || [ ! -d "${this_dir}" ]; then
40      [ -d "${this_dir}" ] && rm ${this_dir} -rf
41      mkdir -p ${this_dir} && cd ${this_dir}
42      cmake -GNinja -DBOARD_ROOT=${BOARD_ROOT} -DBOARD=${BOARD} \
43        -DCONF_FILE=${conf_file} ${cmake_args} \
44        -DCMAKE_C_FLAGS="${cc_flags}" ${app_root}/${app} \
45        &> cmake.out || { cat cmake.out && return 0; }
46  else
47      cd ${this_dir}
48  fi
49  ninja ${ninja_args} &> ninja.out || { cat ninja.out && return 0; }
50  cp ${this_dir}/zephyr/zephyr.exe ${exe_name}
51
52  nm ${exe_name} | grep -v " [U|w] " | sort | cut -d" " -f1,3 > ${map_file_name}
53  sed -i "1i $(wc -l ${map_file_name} | cut -d" " -f1)" ${map_file_name}
54}
55
56app=tests/bluetooth/bsim_bt/bsim_test_app conf_file=prj_split.conf \
57	compile
58app=tests/bluetooth/bsim_bt/bsim_test_app conf_file=prj_split_privacy.conf \
59  compile
60app=tests/bluetooth/bsim_bt/bsim_test_app conf_file=prj_split_low_lat.conf \
61  compile
62app=tests/bluetooth/bsim_bt/bsim_test_multiple compile
63app=tests/bluetooth/bsim_bt/bsim_test_advx compile
64app=tests/bluetooth/bsim_bt/bsim_test_l2cap_stress compile
65app=tests/bluetooth/bsim_bt/bsim_test_iso compile
66app=tests/bluetooth/bsim_bt/bsim_test_audio compile
67app=tests/bluetooth/bsim_bt/edtt_ble_test_app/hci_test_app \
68  conf_file=prj_dut.conf compile
69app=tests/bluetooth/bsim_bt/edtt_ble_test_app/hci_test_app \
70  conf_file=prj_tst.conf compile
71app=tests/bluetooth/bsim_bt/edtt_ble_test_app/gatt_test_app compile
72app=tests/bluetooth/bsim_bt/bsim_test_mesh compile
73app=tests/bluetooth/bsim_bt/bsim_test_mesh conf_file=prj_low_lat.conf compile
74app=tests/bluetooth/bsim_bt/bsim_test_mesh conf_file=prj_pst.conf compile
75