Skip to content

Commit

Permalink
build: HOST_ARCH command line option
Browse files Browse the repository at this point in the history
- allow passing in HOST_ARCH ofr Makefile and build.sh
- add -a option for build.sh

Signed-off-by: Gerwin Klein <gerwin.klein@proofcraft.systems>
  • Loading branch information
lsf37 committed May 12, 2024
1 parent 0630774 commit 17ca547
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ endif

ETC_LOCALTIME := $(realpath /etc/localtime)

HOST_ARCH := $(shell arch)
HOST_ARCH ?= $(shell arch)
ifeq ($(HOST_ARCH),x86_64)
DOCKER_PLATFORM := "linux/amd64"
else ifeq ($(HOST_ARCH),arm64)
Expand Down
31 changes: 20 additions & 11 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,8 @@ DOCKER_BUILD="docker build"
DOCKER_INSPECT="docker inspect"
DOCKER_FLAGS="--force-rm=true"

HOST_ARCH=`arch`
if [[ $HOST_ARCH == "x86_64" ]]; then
DOCKER_PLATFORM="linux/amd64"
elif [[ $HOST_ARCH == "arm64" ]]; then
DOCKER_PLATFORM="linux/arm64/v8"
else
echo "Unsupported host architecture: $HOST_ARCH"
exit 1
fi
# By default use host architecture
: "${HOST_ARCH:=`arch`}"

# Special variables to be passed through Docker to the build scripts
: "${SCM}"
Expand Down Expand Up @@ -182,14 +175,15 @@ show_help()
| sort \
| tr "\n" "|")
cat <<EOF
build.sh [-r] [-v] [-p] -b [sel4|camkes|l4v] -s [$available_software] -s ... -e MAKE_CACHES=no -e ...
build.sh [-r] [-v] [-p] [-a arch] -b [sel4|camkes|l4v] -s [$available_software] -s ... -e MAKE_CACHES=no -e ...
-r Rebuild docker images (don't use the docker cache)
-v Verbose mode
-s Software packages to install on top of the base image. Use -s for each package.
-e Build arguments (NAME=VALUE) to docker build. Use a -e for each build arg.
-p Pull base image first. Rather than build the base image,
get it from the web first
-a Supply x86_64 for building Intel images, and arm64 for Arm images
Sneaky hints:
- To build 'prebuilt' images, you can run:
Expand All @@ -206,7 +200,7 @@ img_to_build=
software_to_apply=
pull_base_first=

while getopts "h?pvb:rs:e:" opt
while getopts "h?pvb:rs:e:a:" opt
do
case "$opt" in
h|\?)
Expand All @@ -225,12 +219,27 @@ do
;;
e) build_args="$build_args\n$OPTARG"
;;
a) HOST_ARCH="$OPTARG"
;;
:) echo "Option -$opt requires an argument." >&2
exit 1
;;
esac
done

if [[ $HOST_ARCH == "x86_64" ]]; then
DOCKER_PLATFORM="linux/amd64"
elif [[ $HOST_ARCH == "amd64" ]]; then
DOCKER_PLATFORM="linux/amd64"
elif [[ $HOST_ARCH == "arm64" ]]; then
DOCKER_PLATFORM="linux/arm64/v8"
else
echo "Unsupported host architecture: $HOST_ARCH"
exit 1
fi

echo "Building for $DOCKER_PLATFORM"

if [ -z "$img_to_build" ]
then
echo "You need to supply a \`-b\`" >&2
Expand Down

0 comments on commit 17ca547

Please sign in to comment.