lib.sh.in/mkrootfs.sh.in: proper native platform detection

This commit is contained in:
q66 2019-05-28 02:15:19 +02:00 committed by Daniel Kolesa
parent 51d4a5f4c2
commit 7d30d331eb
2 changed files with 31 additions and 6 deletions

View File

@ -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

View File

@ -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"