|
|
@ -1,37 +1,62 @@ |
|
|
|
#!/bin/bash |
|
|
|
#!/bin/bash |
|
|
|
|
|
|
|
|
|
|
|
set -e -x |
|
|
|
set -e |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TPUT=$(which tput 2>/dev/null || echo true) |
|
|
|
|
|
|
|
echo $TPUT |
|
|
|
|
|
|
|
|
|
|
|
DIR=$(cd "$(dirname "$0")"; pwd -P) |
|
|
|
DIR=$(cd "$(dirname "$0")"; pwd -P) |
|
|
|
|
|
|
|
|
|
|
|
TOOLCHAIN_IMAGE="esp32-toolchain:latest" |
|
|
|
TOOLCHAIN_IMAGE="esp32-toolchain:latest" |
|
|
|
: ${BUILD_DIR:="$DIR/cmake-build"} |
|
|
|
: ${BUILD_DIR:="$DIR/cmake-build"} |
|
|
|
DOCKERFILE="$DIR/Dockerfile" |
|
|
|
DOCKERFILE="$DIR/Dockerfile" |
|
|
|
DOCKER_RUN_FLAGS=(--interactive --rm) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# if stdin is a terminal, tell docker to allocate a tty |
|
|
|
echo_status() { |
|
|
|
if [ -t 0 ]; then |
|
|
|
echo "$($TPUT setaf 2)==> $@$($TPUT sgr0)" |
|
|
|
DOCKER_RUN_FLAGS+=(--tty) |
|
|
|
} |
|
|
|
fi |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
get_docker_run_flags() { |
|
|
|
|
|
|
|
if [ -z "$DOCKER_RUN_FLAGS" ]; then |
|
|
|
|
|
|
|
DOCKER_RUN_FLAGS=(--interactive --rm) |
|
|
|
|
|
|
|
# if stdin is a terminal, tell docker to allocate a tty |
|
|
|
|
|
|
|
if [ -t 0 ]; then |
|
|
|
|
|
|
|
DOCKER_RUN_FLAGS+=(--tty) |
|
|
|
|
|
|
|
fi |
|
|
|
|
|
|
|
USB_SERIAL_DEVICES=$(find /dev -name 'ttyUSB0' -o -name 'ttyACM*') |
|
|
|
|
|
|
|
for device in $USB_SERIAL_DEVICES; do |
|
|
|
|
|
|
|
DOCKER_RUN_FLAGS+=(--device $device) |
|
|
|
|
|
|
|
echo_status "Adding device $device to container" |
|
|
|
|
|
|
|
done |
|
|
|
|
|
|
|
fi |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
build_docker_container() { |
|
|
|
build_docker_container() { |
|
|
|
|
|
|
|
echo_status "Building docker container image" |
|
|
|
docker build -f "$DOCKERFILE" -t "$TOOLCHAIN_IMAGE" "$DIR" |
|
|
|
docker build -f "$DOCKERFILE" -t "$TOOLCHAIN_IMAGE" "$DIR" |
|
|
|
|
|
|
|
echo_status "Built docker container image and tagged as $TOOLCHAIN_IMAGE" |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
build_docker() { |
|
|
|
build_docker() { |
|
|
|
build_docker_container |
|
|
|
build_docker_container |
|
|
|
|
|
|
|
get_docker_run_flags |
|
|
|
|
|
|
|
local targets="$@" |
|
|
|
|
|
|
|
if [ -z "$targets" ]; then |
|
|
|
|
|
|
|
targets="all" |
|
|
|
|
|
|
|
fi |
|
|
|
|
|
|
|
echo_status "Building target(s) $targets in container" |
|
|
|
docker run \ |
|
|
|
docker run \ |
|
|
|
--volume="$DIR:/esp/uas-ugv" \ |
|
|
|
--volume="$DIR:/esp/uas-ugv" \ |
|
|
|
"${DOCKER_RUN_FLAGS[@]}" \ |
|
|
|
"${DOCKER_RUN_FLAGS[@]}" \ |
|
|
|
"$TOOLCHAIN_IMAGE" \ |
|
|
|
"$TOOLCHAIN_IMAGE" \ |
|
|
|
/esp/uas-ugv/build.sh cmake "$@" |
|
|
|
/esp/uas-ugv/build.sh cmake "$targets" |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
build_cmake() { |
|
|
|
build_cmake() { |
|
|
|
mkdir -p "$BUILD_DIR" |
|
|
|
mkdir -p "$BUILD_DIR" |
|
|
|
cd "$BUILD_DIR" |
|
|
|
cd "$BUILD_DIR" |
|
|
|
|
|
|
|
echo_status "CMake configure" |
|
|
|
cmake -G Ninja "$DIR" |
|
|
|
cmake -G Ninja "$DIR" |
|
|
|
|
|
|
|
echo_status "CMake build $@" |
|
|
|
cmake --build "$BUILD_DIR" -- "$@" |
|
|
|
cmake --build "$BUILD_DIR" -- "$@" |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|