blob: 084eb03aef40b2324259b1fa81a5c596787f476a [file] [log] [blame]
# Copyright 2018 Oticon A/S
# SPDX-License-Identifier: Apache-2.0
function compile(){
: "${app:?app must be defined}"
local app_root="${app_root:-${ZEPHYR_BASE}}"
local conf_file="${conf_file:-prj.conf}"
local conf_overlay="${conf_overlay:-""}"
local cmake_args="${cmake_args:-"-DCONFIG_COVERAGE=y \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON"}"
local ninja_args="${ninja_args:-""}"
local cc_flags="${cc_flags:-"-Werror"}"
local exe_name="${exe_name:-bs_${BOARD}_${app}_${conf_file}}"
local exe_name=${exe_name//\//_}
local exe_name=${exe_name//./_}
local exe_name=${BSIM_OUT_PATH}/bin/$exe_name
local map_file_name=${exe_name}.Tsymbols
local this_dir=${WORK_DIR}/${app}/${conf_file}
echo "Building $exe_name"
# Set INCR_BUILD when calling to only do an incremental build
if [ ! -v INCR_BUILD ] || [ ! -d "${this_dir}" ]; then
[ -d "${this_dir}" ] && rm ${this_dir} -rf
mkdir -p ${this_dir} && cd ${this_dir}
cmake -GNinja -DBOARD_ROOT=${BOARD_ROOT} -DBOARD=${BOARD} \
-DCONF_FILE=${conf_file} -DOVERLAY_CONFIG=${conf_overlay} \
${cmake_args} -DCMAKE_C_FLAGS="${cc_flags}" ${app_root}/${app} \
&> cmake.out || { cat cmake.out && return 0; }
else
cd ${this_dir}
fi
ninja ${ninja_args} &> ninja.out || { cat ninja.out && return 0; }
cp ${this_dir}/zephyr/zephyr.exe ${exe_name}
nm ${exe_name} | grep -v " [U|w] " | sort | cut -d" " -f1,3 > ${map_file_name}
sed -i "1i $(wc -l ${map_file_name} | cut -d" " -f1)" ${map_file_name}
}