From 7d30d331eb02ec40196eecd543b7a368a9f5ae16 Mon Sep 17 00:00:00 2001 From: q66 Date: Tue, 28 May 2019 02:15:19 +0200 Subject: [PATCH] lib.sh.in/mkrootfs.sh.in: proper native platform detection --- lib.sh.in | 31 ++++++++++++++++++++++++++++--- mkrootfs.sh.in | 6 +++--- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/lib.sh.in b/lib.sh.in index e60a3ae..d219cc0 100644 --- a/lib.sh.in +++ b/lib.sh.in @@ -6,6 +6,33 @@ readonly LIBTOOLS="cp echo cat printf which mountpoint mount umount modprobe" readonly HOSTARCH=$(xbps-uhelper arch) +is_target_native() { + # Because checking whether the target is runnable is ugly, stuff + # it into a single function. That makes it easy to check anywhere. + local target_arch + + target_arch="$1" + # this will cover most + if [ "${target_arch%-musl}" = "${HOSTARCH%-musl}" ]; then + return 0 + fi + + case "$HOSTARCH" in + # ppc64le has no 32-bit variant, only runs its own stuff + ppc64le*) return 1 ;; + # x86_64 also runs i686 + x86_64*) test -z "${target_arch##*86*}" ;; + # aarch64 also runs armv* + aarch64*) test -z "${target_arch##armv*}" ;; + # bigendian ppc64 also runs ppc + ppc64*) test "${target_arch%-musl}" = "ppc" ;; + # anything else is just their own + *) return 1 ;; + esac + + return $? +} + info_msg() { # This function handles the printing that is bold within all # scripts. This is a convenience function so that the rather ugly @@ -80,9 +107,7 @@ umount_pseudofs() { run_cmd_target() { info_msg "Running $* for target $XBPS_TARGET_ARCH ..." - if [ "$XBPS_TARGET_ARCH" = "${HOSTARCH}" ] || - [ -z "${XBPS_TARGET_ARCH##*86*}" ] && - [ -z "${HOSTARCH##*86*}" ] ; then + if is_target_native "$XBPS_TARGET_ARCH"; then # This is being run on the same architecture as the host, # therefore we should set XBPS_ARCH. if ! eval XBPS_ARCH="$XBPS_TARGET_ARCH" "$@" ; then diff --git a/mkrootfs.sh.in b/mkrootfs.sh.in index 96e2bb9..3d7f9b1 100644 --- a/mkrootfs.sh.in +++ b/mkrootfs.sh.in @@ -168,9 +168,9 @@ info_msg "Reconfiguring packages for ${XBPS_TARGET_ARCH} ..." # This step sets up enough of the base-files that the chroot will work # and they can be reconfigured natively. Without this step there # isn't enough configured for ld to work. This step runs as the host -# architecture, but on x86 some special extra steps have to be taken -# to make this work. -if [ -z "${XBPS_TARGET_ARCH##*86*}" ] && [ -z "${HOSTARCH##*86*}" ] ; then +# architecture, but we may need to set up XBPS_ARCH for the target +# architecture (but only when compatible). +if is_target_native "$XBPS_TARGET_ARCH"; then run_cmd_target "xbps-reconfigure --rootdir $ROOTFS base-files" else run_cmd "xbps-reconfigure --rootdir $ROOTFS base-files"