From 6e1d80b78be07606ac9bf307ad9b66809e632f67 Mon Sep 17 00:00:00 2001 From: Michael Aldridge Date: Sun, 13 Aug 2017 17:44:25 -0700 Subject: [PATCH] Factor out architecture map --- lib.sh.in | 36 ++++++++++++++++++++++++++++++++++++ mkplatformfs.sh.in | 32 +++++++++++++++++--------------- 2 files changed, 53 insertions(+), 15 deletions(-) diff --git a/lib.sh.in b/lib.sh.in index 3399830..e3bce40 100644 --- a/lib.sh.in +++ b/lib.sh.in @@ -149,6 +149,14 @@ register_binfmt() { # kernel select an alternate interpreter. More values for this # map can be obtained from here: # https://github.com/qemu/qemu/blob/master/scripts/qemu-binfmt-conf.sh + + # If the XBPS_TARGET_ARCH is unset but the PLATFORM is known, it + # may be possible to set the architecture from the static + # platforms map. + if [ -z "$XBPS_TARGET_ARCH" ] && [ ! -z "$PLATFORM" ] ; then + set_target_arch_from_platform + fi + case "${XBPS_TARGET_ARCH}" in armv*) _cpu=arm @@ -213,6 +221,34 @@ register_binfmt() { fi } +set_target_arch_from_platform() { + # This function maintains a lookup from platform to target + # architecture. This is required for scripts that need to know + # the target architecture, but don't necessarily need to know it + # internally (i.e. only run_cmd_chroot). + case "$PLATFORM" in + bananapi*) XBPS_TARGET_ARCH="armv7l";; + beaglebone*) XBPS_TARGET_ARCH="armv7l";; + cubieboard2*|cubietruck*) XBPS_TARGET_ARCH="armv7l";; + dockstar*) XBPS_TARGET_ARCH="armv5tel";; + odroid-u2*) XBPS_TARGET_ARCH="armv7l";; + odroid-c2*) XBPS_TARGET_ARCH="aarch64";; + rpi3*) XBPS_TARGET_ARCH="aarch64";; + rpi2*) XBPS_TARGET_ARCH="armv7l";; + rpi*) XBPS_TARGET_ARCH="armv6l";; + usbarmory*) XBPS_TARGET_ARCH="armv7l";; + ci20*) XBPS_TARGET_ARCH="mipsel";; + i686*) XBPS_TARGET_ARCH="i686";; + x86_64*) XBPS_TARGET_ARCH="x86_64";; + GCP*) XBPS_TARGET_ARCH="x86_64";; + *) die "$PROGNAME: Unable to compute target architecture from platform";; + esac + + if [ -z "${PLATFORM##*-musl}" ] ; then + XBPS_TARGET_ARCH="${XBPS_TARGET_ARCH}-musl" + fi +} + set_cachedir() { # The package artifacts are cacheable, but they need to be isolated # from the host cache. diff --git a/mkplatformfs.sh.in b/mkplatformfs.sh.in index 5086d76..50c5aaf 100644 --- a/mkplatformfs.sh.in +++ b/mkplatformfs.sh.in @@ -105,29 +105,31 @@ check_tools # noarch though, so we strip off the -musl extention if it was # provided. case "$PLATFORM" in - bananapi*) XBPS_TARGET_ARCH="armv7l"; PKGS="$BASEPKG ${PLATFORM%-*}-base" ;; - beaglebone*) XBPS_TARGET_ARCH="armv7l"; PKGS="$BASEPKG ${PLATFORM%-*}-base" ;; - cubieboard2*|cubietruck*) XBPS_TARGET_ARCH="armv7l"; PKGS="$BASEPKG ${PLATFORM%-*}-base" ;; - dockstar*) XBPS_TARGET_ARCH="armv5tel"; PKGS="$BASEPKG ${PLATFORM%-*}-base" ;; - odroid-u2*) XBPS_TARGET_ARCH="armv7l"; PKGS="$BASEPKG ${PLATFORM%-*}-base" ;; - odroid-c2*) XBPS_TARGET_ARCH="aarch64"; PKGS="$BASEPKG ${PLATFORM%-musl}-base" ;; - rpi3*) XBPS_TARGET_ARCH="aarch64"; PKGS="$BASEPKG rpi3-base" ;; - rpi2*) XBPS_TARGET_ARCH="armv7l"; PKGS="$BASEPKG rpi-base" ;; - rpi*) XBPS_TARGET_ARCH="armv6l"; PKGS="$BASEPKG ${PLATFORM%-*}-base" ;; - usbarmory*) XBPS_TARGET_ARCH="armv7l"; PKGS="$BASEPKG ${PLATFORM%-*}-base" ;; - ci20*) XBPS_TARGET_ARCH="mipsel"; PKGS="$BASEPKG ${PLATFORM%-*}-base" ;; - i686*) XBPS_TARGET_ARCH="i686"; PKGS="$BASEPKG" ;; - x86_64*) XBPS_TARGET_ARCH="x86_64"; PKGS="$BASEPKG" ;; - GCP*) XBPS_TARGET_ARCH="x86_64"; PKGS="$BASEPKG ${PLATFORM%-*}-base" ;; + bananapi*) PKGS="$BASEPKG ${PLATFORM%-*}-base" ;; + beaglebone*) PKGS="$BASEPKG ${PLATFORM%-*}-base" ;; + cubieboard2*|cubietruck*) PKGS="$BASEPKG ${PLATFORM%-*}-base" ;; + dockstar*) PKGS="$BASEPKG ${PLATFORM%-*}-base" ;; + odroid-u2*) PKGS="$BASEPKG ${PLATFORM%-*}-base" ;; + odroid-c2*) PKGS="$BASEPKG ${PLATFORM%-musl}-base" ;; + rpi3*) PKGS="$BASEPKG rpi3-base" ;; + rpi2*) PKGS="$BASEPKG rpi-base" ;; + rpi*) PKGS="$BASEPKG ${PLATFORM%-*}-base" ;; + usbarmory*) PKGS="$BASEPKG ${PLATFORM%-*}-base" ;; + ci20*) PKGS="$BASEPKG ${PLATFORM%-*}-base" ;; + i686*) PKGS="$BASEPKG" ;; + x86_64*) PKGS="$BASEPKG" ;; + GCP*) PKGS="$BASEPKG ${PLATFORM%-*}-base" ;; *) die "$PROGNAME: invalid platform!";; esac # Check if we should be using the -musl variant if [ -z "${BASE_TARBALL##*-musl-*}" ] ; then - XBPS_TARGET_ARCH="${XBPS_TARGET_ARCH}-musl" PLATFORM="${PLATFORM}-musl" fi +# Derive the target architecture using the static map +set_target_arch_from_platform + # Append any additional packages if they were requested if [ -z "$EXTRA_PKGS" ] ; then PKGS="$PKGS $EXTRA_PKGS"