aboutsummaryrefslogtreecommitdiffstats
path: root/docker/build.sh
diff options
context:
space:
mode:
authorJoe Eaves <jinux@alluha.net>2020-12-17 13:12:06 +0000
committerJoe Eaves <jinux@alluha.net>2020-12-21 01:42:41 +0000
commita7df0a02799442ab38e1b365d4363cca6d93f029 (patch)
tree76fcab519c1a20991ad5e587957741f34011421c /docker/build.sh
parent276c8aa308f923aeeadc068967b15ee7c59fa32b (diff)
Unify the Dockerfiles by fleshing out build.sh
Script is written to handle it's own dependencies so it can be used within Docker or on the host system
Diffstat (limited to 'docker/build.sh')
-rwxr-xr-xdocker/build.sh73
1 files changed, 67 insertions, 6 deletions
diff --git a/docker/build.sh b/docker/build.sh
index fcb819a6..1c697d40 100755
--- a/docker/build.sh
+++ b/docker/build.sh
@@ -1,12 +1,73 @@
-#!/bin/sh
+#!/bin/bash
+(return 0 2>/dev/null) && SOURCED="true" || SOURCED="false"
export LC_ALL=C.UTF-8
export LANG=C.UTF-8
set -x
+set -e
-mkdir /sources/build
-cd /sources/build
+# 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}"
+export OUTPUT_DIR="${OUTPUT_DIR:=$BUILD_DIR/output}"
-cmake -DARM_NONE_EABI_TOOLCHAIN_PATH=/opt/gcc-arm-none-eabi-9-2020-q2-update -DNRF5_SDK_PATH=/opt/nRF5_SDK_15.3.0_59ac345 -DUSE_OPENOCD=1 ../
-make -j$(nproc)
+export BUILD_TYPE=${BUILD_TYPE:=Release}
+export GCC_ARM_VER=${GCC_ARM_VER:="gcc-arm-none-eabi-9-2020-q2-update"}
+export NRF_SDK_VER=${NRF_SDK_VER:="nRF5_SDK_15.3.0_59ac345"}
-sh /sources/docker/post_build.sh
+MACHINE="$(uname -m)"
+[[ "$MACHINE" == "arm64" ]] && MACHINE="aarch64"
+
+main() {
+ local target="$1"
+ [[ ! -d "$TOOLS_DIR/$GCC_ARM_VER" ]] && GetGcc
+ [[ ! -d "$TOOLS_DIR/$NRF_SDK_VER" ]] && GetNrfSdk
+ [[ ! -d "$TOOLS_DIR/mcuboot" ]] && GetMcuBoot
+
+ mkdir -p "$BUILD_DIR"
+
+ CmakeGenerate
+ CmakeBuild "$target"
+
+ if [[ "$DISABLE_POSTBUILD" != "true" ]]; then
+ source "$BUILD_DIR/post_build.sh"
+ fi
+}
+
+GetGcc() {
+ GCC_SRC="$GCC_ARM_VER-$MACHINE-linux.tar.bz"
+ wget -q https://developer.arm.com/-/media/Files/downloads/gnu-rm/9-2020q2/$GCC_SRC -O - | tar -xj -C $TOOLS_DIR/
+}
+
+GetMcuBoot() {
+ git clone https://github.com/JuulLabs-OSS/mcuboot.git "$TOOLS_DIR/mcuboot"
+ 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() {
+ # We can swap the CD and trailing SOURCES_DIR for -B and -S respectively
+ # once we go to newer CMake (Ubuntu 18.10 gives us CMake 3.10)
+ cd "$BUILD_DIR"
+
+ cmake -G "Unix Makefiles" \
+ -DCMAKE_BUILD_TYPE=$BUILD_TYPE \
+ -DUSE_OPENOCD=1 \
+ -DARM_NONE_EABI_TOOLCHAIN_PATH="$TOOLS_DIR/$GCC_ARM_VER" \
+ -DNRF5_SDK_PATH="$TOOLS_DIR/$NRF_SDK_VER" \
+ "$SOURCES_DIR"
+ cmake -L -N .
+}
+
+CmakeBuild() {
+ local target="$1"
+ [[ -n "$target" ]] && target="--target $target"
+ cmake --build "$BUILD_DIR" --config $BUILD_TYPE "$target" -- -j$(nproc)
+}
+
+[[ $SOURCED == "false" ]] && main "$@" || echo "Sourced!" \ No newline at end of file