#!/bin/sh
#export DOCKER_DEFAULT_PLATFORM=linux/amd64
#export DOCKER_NETWORK="--network=host"
IMAGE_NAME="uvk5"
rm -rf "${PWD}/compiled-firmware/*"
mkdir -p "${PWD}/compiled-firmware"
echo "Building docker image $IMAGE_NAME"
if ! docker build -t $DOCKER_NETWORK $IMAGE_NAME .
then
    echo "Failed to build docker image"
    exit 1
fi

    echo "Custom compilation..."
    docker run --rm -v "${PWD}/compiled-firmware:/app/compiled-firmware" $IMAGE_NAME \
        /bin/bash -c "cd /app && make -j && cp f4hwn* /app/compiled-firmware/ && ls -l /app/compiled-firmware/ || echo 'No files to copy'"