Files
runc/script/lib.sh
Aleksa Sarai 321aa20c49 scripts: add proper 386 and amd64 target triples and builds
We need these to match the Makefile detection of the right gcc for
runc-dmz, as well as making sure that everything builds properly for our
cross-i386 tests. While we're at it, add x86 to the list of build
targets for release builds (presumably nobody will use it, but since we
do test builds of this anyway it probably won't hurt).

In addition, clean up the handling of the native architecture build by
treating it the same as any other build (ensuring that building runc
from a different platform will work the same way regardless of the
native architecture). In practice, the build works the same way as
before.

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
2023-09-22 15:13:18 +10:00

75 lines
1.5 KiB
Bash

#!/bin/bash
# NOTE: Make sure you keep this file in sync with cc_platform.mk.
# set_cross_vars sets a few environment variables used for cross-compiling,
# based on the architecture specified in $1.
function set_cross_vars() {
GOARCH="$1" # default, may be overridden below
unset GOARM
PLATFORM=linux-gnu
# openSUSE has a custom PLATFORM
if grep -iq "ID_LIKE=.*suse" /etc/os-release; then
PLATFORM=suse-linux
is_suse=1
fi
case $1 in
386)
# Always use the 64-bit compiler to build the 386 binary, which works
# for the more common cross-build method for x86 (namely, the
# equivalent of dpkg --add-architecture).
local cpu_type
if [ -v is_suse ]; then
# There is no x86_64-suse-linux-gcc, so use the native one.
HOST=
cpu_type=i586
else
HOST=x86_64-${PLATFORM}
cpu_type=i686
fi
CFLAGS="-m32 -march=$cpu_type ${CFLAGS[*]}"
;;
amd64)
if [ -n "${is_suse:-}" ]; then
# There is no x86_64-suse-linux-gcc, so use the native one.
HOST=
else
HOST=x86_64-${PLATFORM}
fi
;;
arm64)
HOST=aarch64-${PLATFORM}
;;
armel)
HOST=arm-${PLATFORM}eabi
GOARCH=arm
GOARM=6
;;
armhf)
HOST=arm-${PLATFORM}eabihf
GOARCH=arm
GOARM=7
;;
ppc64le)
HOST=powerpc64le-${PLATFORM}
;;
riscv64)
HOST=riscv64-${PLATFORM}
;;
s390x)
HOST=s390x-${PLATFORM}
;;
*)
echo "set_cross_vars: unsupported architecture: $1" >&2
exit 1
;;
esac
CC="${HOST:+$HOST-}gcc"
STRIP="${HOST:+$HOST-}strip"
export HOST CFLAGS GOARM GOARCH CC STRIP
}