Skip to content

Commit

Permalink
enable build on native env where mbed-tools was installed
Browse files Browse the repository at this point in the history
example to prepare native env (RPi4/Ubuntu20)
```
sudo apt install pip
python -m pip install mbed-tools
echo "export PATH=~/.local/bin:${PATH}" >> ~/.bashrc
source ~/.bashrc

sudo apt install ninja-build
python -m pip install intelhex prettytable

sudo snap install cmake --classic
echo "export PATH=/snap/bin:${PATH}" >> ~/.bashrc
source ~/.bashrc

sudo apt uninstall gcc-arm-none-eabi
sudo apt autoremove
wget https://developer.arm.com/-/media/Files/downloads/gnu-rm/10.3-2021.07/gcc-arm-none-eabi-10.3-2021.07-aarch64-linux.tar.bz2
tar -xjvf gcc-arm-none-eabi-10.3-2021.07-aarch64-linux.tar.bz2
echo "export MBED_GCC_ARM_PATH=`pwd`/gcc-arm-none-eabi-10.3-2021.07/bin/" >> ~/.bashrc
source ~/.bashrc
echo "export PATH="${PATH}:${MBED_GCC_ARM_PATH}"" >> ~/.bashrc
source ~/.bashrc
```
  • Loading branch information
takasehideki committed Sep 27, 2022
1 parent 4c440f6 commit 90225c7
Showing 1 changed file with 33 additions and 21 deletions.
54 changes: 33 additions & 21 deletions build.bash
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/bin/bash

### setup operation ###
if [ $# -ne 1 -a $# -ne 3 ];
if [ $# -ne 1 -a $# -ne 3 -a $# -ne 4 ];
then
echo "ERROR: args invalid"
echo "USAGE: build.bash {all|rebuild|clean|disclean} [<TARGET> <APPNAME>]"
echo "USAGE: build.bash {all|rebuild|clean|disclean} [<TARGET> <APPNAME>] [{native|docker}]"
exit 1
fi

Expand All @@ -28,7 +28,7 @@ then
exit 0
else
echo "ERROR: args invalid"
echo "USAGE: build.bash {all|rebuild|clean|disclean} [<TARGET> <APPNAME>]"
echo "USAGE: build.bash {all|rebuild|clean|disclean} [<TARGET> <APPNAME>] [{native|docker}]"
exit 1
fi

Expand All @@ -42,21 +42,41 @@ else
APPNAME=$3
fi

DOCKERCMD_PRE="docker run --rm -it --mount type=bind,source=$(pwd),destination=/var/mbed \
-w /var/mbed -e APPNAME=${APPNAME} ghcr.io/armmbed/mbed-os-env \
/bin/bash -c \""
DOCKERCMD_SUF="\""
if [ $# == 4 ];
then
if [ ${4} = "native" ];
then
echo "INFO: build operation will be executed on native env"
DOCKERCMD_PRE=""
DOCKERCMD_SUF=""
elif [ ${4} = "docker" ];
then
echo "INFO: build operation will be executed on dokcer env"
else
echo "ERROR: args invalid"
echo "ERROR: \"native\" or \"docker\" should be specified as 4th arg"
echo "USAGE: build.bash {all|rebuild|clean|disclean} [<TARGET> <APPNAME>]"
exit 1
fi
else
echo "INFO: build operation will be executed on dokcer env"
fi

echo "INFO: build setting"
echo " TARGET=${TARGET}"
echo " APPNAME=${APPNAME}"


### build a project ###
# deploy mbed environment by mbed-tools
docker run --rm -it --mount=type=bind,source="$(pwd)",destination=/var/mbed -w /var/mbed \
-e APPNAME=${APPNAME} ghcr.io/armmbed/mbed-os-env \
/bin/bash -c "mbed-tools deploy"
eval ${DOCKERCMD_PRE}mbed-tools deploy${DOCKERCMD_SUF}

# configure mbed project by mbed-tools
docker run --rm -it --mount=type=bind,source="$(pwd)",destination=/var/mbed -w /var/mbed \
-e APPNAME=${APPNAME} ghcr.io/armmbed/mbed-os-env \
/bin/bash -c "mbed-tools configure -m ${TARGET} -t GCC_ARM"
eval ${DOCKERCMD_PRE}mbed-tools configure -m ${TARGET} -t GCC_ARM${DOCKERCMD_SUF}

# generate of header file for template functions of MsgType
MROS2DIR=../mros2
Expand All @@ -75,24 +95,16 @@ fi
cd ..

# set the build parameter
docker run --rm -it --mount=type=bind,source="$(pwd)",destination=/var/mbed -w /var/mbed \
-e APPNAME=${APPNAME} ghcr.io/armmbed/mbed-os-env \
/bin/bash -c "cmake -S . -B cmake_build/${TARGET}/develop/GCC_ARM -GNinja"
eval ${DOCKERCMD_PRE}cmake -S . -B cmake_build/${TARGET}/develop/GCC_ARM -GNinja${DOCKERCMD_SUF}

# build (switch according to arg1)
if [ ${MAKECMD} = "all" ];
then
docker run --rm -it --mount=type=bind,source="$(pwd)",destination=/var/mbed -w /var/mbed \
-e APPNAME=${APPNAME} ghcr.io/armmbed/mbed-os-env \
/bin/bash -c "cmake --build cmake_build/${TARGET}/develop/GCC_ARM"
eval ${DOCKERCMD_PRE}cmake --build cmake_build/${TARGET}/develop/GCC_ARM${DOCKERCMD_SUF}
elif [ ${MAKECMD} = "rebuild" ];
then
docker run --rm -it --mount=type=bind,source="$(pwd)",destination=/var/mbed -w /var/mbed \
-e APPNAME=${APPNAME} ghcr.io/armmbed/mbed-os-env \
/bin/bash -c "cmake --build cmake_build/${TARGET}/develop/GCC_ARM --clean-first"
eval ${DOCKERCMD_PRE}cmake --build cmake_build/${TARGET}/develop/GCC_ARM --clean-first${DOCKERCMD_SUF}
elif [ ${MAKECMD} = "clean" ];
then
docker run --rm -it --mount=type=bind,source="$(pwd)",destination=/var/mbed -w /var/mbed \
-e APPNAME=${APPNAME} ghcr.io/armmbed/mbed-os-env \
/bin/bash -c "cmake --build cmake_build/${TARGET}/develop/GCC_ARM --target clean"
eval ${DOCKERCMD_PRE}cmake --build cmake_build/${TARGET}/develop/GCC_ARM --target clean${DOCKERCMD_SUF}
fi

0 comments on commit 90225c7

Please sign in to comment.