2020-12-17 13:12:06 +00:00
|
|
|
#!/bin/bash
|
|
|
|
(return 0 2>/dev/null) && SOURCED="true" || SOURCED="false"
|
2020-08-20 07:38:10 +00:00
|
|
|
export LC_ALL=C.UTF-8
|
|
|
|
export LANG=C.UTF-8
|
|
|
|
set -x
|
2020-12-17 13:12:06 +00:00
|
|
|
set -e
|
2020-08-20 07:38:10 +00:00
|
|
|
|
2020-12-17 13:12:06 +00:00
|
|
|
# Default locations if the var isn't already set
|
|
|
|
export TOOLS_DIR="${TOOLS_DIR:=/opt}"
|
|
|
|
export SOURCES_DIR="${SOURCES_DIR:=/sources}"
|
|
|
|
export BUILD_DIR="${BUILD_DIR:=$SOURCES_DIR/build}"
|
2022-05-15 08:50:12 +00:00
|
|
|
export OUTPUT_DIR="${OUTPUT_DIR:=$SOURCES_DIR/build/output}"
|
2020-08-20 07:38:10 +00:00
|
|
|
|
2022-09-11 10:43:30 +00:00
|
|
|
# Specify a folder with read/write access to NPM
|
|
|
|
export NPM_DIR="$BUILD_DIR/npm"
|
|
|
|
export npm_config_cache="${NPM_DIR}"
|
|
|
|
|
2020-12-17 13:12:06 +00:00
|
|
|
export BUILD_TYPE=${BUILD_TYPE:=Release}
|
2022-06-26 20:14:35 +00:00
|
|
|
export GCC_ARM_VER=${GCC_ARM_VER:="10.3-2021.10"}
|
2020-12-17 13:12:06 +00:00
|
|
|
export NRF_SDK_VER=${NRF_SDK_VER:="nRF5_SDK_15.3.0_59ac345"}
|
2020-08-20 07:38:10 +00:00
|
|
|
|
2020-12-17 13:12:06 +00:00
|
|
|
MACHINE="$(uname -m)"
|
|
|
|
[[ "$MACHINE" == "arm64" ]] && MACHINE="aarch64"
|
|
|
|
|
2022-06-26 20:14:35 +00:00
|
|
|
export GCC_ARM_PATH="gcc-arm-none-eabi-$GCC_ARM_VER"
|
2022-05-10 18:26:41 +00:00
|
|
|
|
2020-12-17 13:12:06 +00:00
|
|
|
main() {
|
|
|
|
local target="$1"
|
2020-12-22 11:38:57 +00:00
|
|
|
|
|
|
|
mkdir -p "$TOOLS_DIR"
|
2022-05-15 08:50:12 +00:00
|
|
|
|
2022-05-10 18:26:41 +00:00
|
|
|
[[ ! -d "$TOOLS_DIR/$GCC_ARM_PATH" ]] && GetGcc
|
2020-12-17 13:12:06 +00:00
|
|
|
[[ ! -d "$TOOLS_DIR/$NRF_SDK_VER" ]] && GetNrfSdk
|
|
|
|
[[ ! -d "$TOOLS_DIR/mcuboot" ]] && GetMcuBoot
|
|
|
|
|
|
|
|
mkdir -p "$BUILD_DIR"
|
|
|
|
|
|
|
|
CmakeGenerate
|
2020-12-18 17:58:34 +00:00
|
|
|
CmakeBuild $target
|
2022-05-15 08:50:12 +00:00
|
|
|
BUILD_RESULT=$?
|
2021-01-23 00:51:07 +00:00
|
|
|
if [ "$DISABLE_POSTBUILD" != "true" -a "$BUILD_RESULT" == 0 ]; then
|
2020-12-17 13:12:06 +00:00
|
|
|
source "$BUILD_DIR/post_build.sh"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
GetGcc() {
|
2022-06-26 20:14:35 +00:00
|
|
|
wget -q https://developer.arm.com/-/media/Files/downloads/gnu-rm/$GCC_ARM_VER/$GCC_ARM_PATH-$MACHINE-linux.tar.bz2 -O - | tar -xj -C $TOOLS_DIR/
|
2020-12-17 13:12:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GetMcuBoot() {
|
2021-10-16 23:31:21 +00:00
|
|
|
git clone https://github.com/mcu-tools/mcuboot.git "$TOOLS_DIR/mcuboot"
|
2020-12-17 13:12:06 +00:00
|
|
|
pip3 install -r "$TOOLS_DIR/mcuboot/scripts/requirements.txt"
|
|
|
|
}
|
|
|
|
|
|
|
|
GetNrfSdk() {
|
|
|
|
wget -q "https://developer.nordicsemi.com/nRF5_SDK/nRF5_SDK_v15.x.x/$NRF_SDK_VER.zip" -O /tmp/$NRF_SDK_VER
|
|
|
|
unzip -q /tmp/$NRF_SDK_VER -d "$TOOLS_DIR/"
|
|
|
|
rm /tmp/$NRF_SDK_VER
|
|
|
|
}
|
|
|
|
|
|
|
|
CmakeGenerate() {
|
|
|
|
cmake -G "Unix Makefiles" \
|
2022-05-15 08:50:12 +00:00
|
|
|
-S "$SOURCES_DIR" \
|
|
|
|
-B "$BUILD_DIR" \
|
2020-12-17 13:12:06 +00:00
|
|
|
-DCMAKE_BUILD_TYPE=$BUILD_TYPE \
|
|
|
|
-DUSE_OPENOCD=1 \
|
2022-05-10 18:26:41 +00:00
|
|
|
-DARM_NONE_EABI_TOOLCHAIN_PATH="$TOOLS_DIR/$GCC_ARM_PATH" \
|
2020-12-17 13:12:06 +00:00
|
|
|
-DNRF5_SDK_PATH="$TOOLS_DIR/$NRF_SDK_VER" \
|
2022-09-11 10:43:30 +00:00
|
|
|
-DBUILD_DFU=1 \
|
|
|
|
-DBUILD_RESOURCES=1
|
2020-12-17 13:12:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CmakeBuild() {
|
|
|
|
local target="$1"
|
|
|
|
[[ -n "$target" ]] && target="--target $target"
|
2021-01-23 00:51:07 +00:00
|
|
|
if cmake --build "$BUILD_DIR" --config $BUILD_TYPE $target -- -j$(nproc)
|
|
|
|
then return 0; else return 1;
|
|
|
|
fi
|
2020-12-17 13:12:06 +00:00
|
|
|
}
|
|
|
|
|
2022-05-10 18:26:41 +00:00
|
|
|
[[ $SOURCED == "false" ]] && main "$@" || echo "Sourced!"
|