From a3c31732a6ef105ca7fdafdecb077e98ce9aacbe Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Mon, 26 Nov 2018 13:16:49 +0000 Subject: [PATCH] Bring `native' architectures into the collection. Also fix Android `cross-gcc'. And other stuff. --- Makefile | 49 ++++++++++++++++++++++++++----------------- android-cross-setup.sh.in | 11 ++++++++++ bin/crosstool | 8 +++++-- etc/android-cross-config.site | 8 ------- etc/common-cross-config.site | 15 +++++++++---- linux-cross-setup.sh.in | 3 +++ linux-native-setup.sh.in | 18 ++++++++++++++++ 7 files changed, 79 insertions(+), 33 deletions(-) create mode 100644 linux-native-setup.sh.in diff --git a/Makefile b/Makefile index 268ff6d..b1c4d9f 100644 --- a/Makefile +++ b/Makefile @@ -3,34 +3,45 @@ .SECONDEXPANSION: #sorry all:: -FLAVOURS += linux -linux_ARCHS = armel armhf arm64 -linux/armel_ARCH = arm-linux-gnueabi -linux/armhf_ARCH = arm-linux-gnueabihf -linux/arm64_ARCH = aarch64-linux-gnu - -FLAVOURS += android -android_ARCHS = arm arm64 x86 x86_64 -android/arm_ARCH = arm-linux-androideabi -android/arm64_ARCH = aarch64-linux-android -android/x86_ARCH = i686-linux-android -android/x86_64_ARCH = x86_64-linux-android +FLAVOURS += linux-cross +linux-cross_ARCHS = linux-armel linux-armhf linux-arm64 +linux-armel_ARCH = arm-linux-gnueabi +linux-armhf_ARCH = arm-linux-gnueabihf +linux-arm64_ARCH = aarch64-linux-gnu + +FLAVOURS += linux-native +linux-native_ARCHS = linux-i386 linux-amd64 +linux-i386_ARCH = i686-linux-gnu +linux-amd64_ARCH = x86_64-linux-gnu + +FLAVOURS += android-cross +android-cross_ARCHS = android-arm android-arm64 android-x86 android-x86_64 +android-arm_ARCH = arm-linux-androideabi +android-arm64_ARCH = aarch64-linux-android +android-x86_ARCH = i686-linux-android +android-x86_64_ARCH = x86_64-linux-android V = 0 v_tag = $(call v_tag_$V,$1) v_tag_0 = @printf " %-8s %s\n" "$1" "$@"; -SETUPS = \ - $(foreach f,$(FLAVOURS),\ - $(foreach a,$($f_ARCHS),etc/$f-$a-setup.sh)) +define define-setup +SETUPS += etc/$2-setup.sh +$2_FLAVOUR = $1 +endef +$(foreach f,$(FLAVOURS), \ + $(foreach a,$($f_ARCHS), \ + $(eval $(call define-setup,$f,$a)))) + TARGETS += $(SETUPS) -setup-flavour = $(word 1,$(subst -, ,$1)) -setup-arch = $(word 2,$(subst -, ,$1)) +setup-flavour = $($1_FLAVOUR) -$(SETUPS): etc/%-setup.sh: $$(call setup-flavour,$$*)-cross-setup.sh.in Makefile - $(call v_tag,GEN)sed 's/@arch@/$($(call setup-flavour,$*)/$(call setup-arch,$*)_ARCH)/g' $< >$@.new && mv $@.new $@ +$(SETUPS): etc/%-setup.sh: $$(call setup-flavour,$$*)-setup.sh.in Makefile + $(call v_tag,GEN)sed 's/@arch@/$($*_ARCH)/g' $< >$@.new && mv $@.new $@ all:: $(TARGETS) CLEANFILES += $(TARGETS) clean::; rm -f $(CLEANFILES) + +show:; : $(VAR) diff --git a/android-cross-setup.sh.in b/android-cross-setup.sh.in index 4da5d85..06d82c3 100644 --- a/android-cross-setup.sh.in +++ b/android-cross-setup.sh.in @@ -4,3 +4,14 @@ ANDROID_NDK_TARGETARCH=@arch@ . $CROSSDIR/etc/android.sh CONFIG_SITE=$CROSSDIR/etc/android-cross-config.site PATH=$PATH:$ANDROID_NDK_TOOLS + +CROSS_gcc_FLAGS=" --sysroot=$ANDROID_NDK_SYSROOT \ + -D__ANDROID_API__=$ANDROID_NDK_TARGETVER \ + -isystem $ANDROID_NDK/sysroot/usr/include \ + -isystem $ANDROID_NDK/sysroot/usr/include/$ANDROID_NDK_TARGETARCH \ + -fPIE -pie" +CROSS_gxx_FLAGS=$CROSS_gcc_FLAGS +export CROSS_gcc_FLAGS CROSS_gxx_FLAGS + +PKG_CONFIG_PATH=$prefix/lib/pkgconfig:/usr/lib/pkgconfig +export PKG_CONFIG_PATH diff --git a/bin/crosstool b/bin/crosstool index cfb800c..bf9a221 100755 --- a/bin/crosstool +++ b/bin/crosstool @@ -1,6 +1,10 @@ -#! /bin/sh -ex +#! /bin/sh -e tool=${0##*/cross-} xtool=$(printf %s "$tool" | tr -c a-zA-Z0-9 x) eval flags=\$CROSS_${xtool}_FLAGS -exec $CROSS_COMPILER_PREFIX $CROSS_ARCH-$tool $flags "$@" + +case ${CROSS_NATIVE_P-nil} in + t) exec $CROSS_COMPILER_PREFIX $tool $flags "$@" ;; + nil) exec $CROSS_COMPILER_PREFIX $CROSS_ARCH-$tool $flags "$@" ;; +esac diff --git a/etc/android-cross-config.site b/etc/android-cross-config.site index 5bd822e..4932b14 100644 --- a/etc/android-cross-config.site +++ b/etc/android-cross-config.site @@ -4,13 +4,5 @@ ANDROID_NDK_TARGETARCH=$CROSS_ARCH . $CROSSDIR/etc/android.sh . $CROSSDIR/etc/common-cross-config.site -CROSS_gcc_FLAGS=" --sysroot=$ANDROID_NDK_SYSROOT \ - -D__ANDROID_API__=$ANDROID_NDK_TARGETVER \ - -isystem $ANDROID_NDK/sysroot/usr/include \ - -isystem $ANDROID_NDK/sysroot/usr/include/$ANDROID_NDK_TARGETARCH \ - -fPIE -pie" -CROSS_gxx_FLAGS=$CROSS_gcc_FLAGS -export CROSS_gcc_FLAGS - CC="$CROSS_ARCH-gcc $CROSS_gcc_FLAGS" CXX="$CROSS_ARCH-g++ $CROSS_gxx_FLAGS" diff --git a/etc/common-cross-config.site b/etc/common-cross-config.site index b1d01da..0679213 100644 --- a/etc/common-cross-config.site +++ b/etc/common-cross-config.site @@ -5,8 +5,15 @@ libexecdir=\${exec_prefix}/lib sysconfdir=\${prefix}/etc host_alias=$CROSS_ARCH -cross_compiling=yes -CC="$CROSS_COMPILER_PREFIX$CROSS_ARCH-gcc$CROSS_CFLAGS" -PKG_CONFIG_PATH=$prefix/lib/pkgconfig:/usr/lib/pkgconfig -export PKG_CONFIG_PATH +case ${CROSS_NATIVE_P-nil} in + t) + CC="${CROSS_COMPILER_PREFIX}gcc$CROSS_gcc_FLAGS" + CXX="${CROSS_COMPILER_PREFIX}g++$CROSS_gxx_FLAGS" + ;; + nil) + cross_compiling=yes + CC="$CROSS_COMPILER_PREFIX$CROSS_ARCH-gcc$CROSS_gcc_FLAGS" + CXX="$CROSS_COMPILER_PREFIX$CROSS_ARCH-g++$CROSS_gxx_FLAGS" + ;; +esac diff --git a/linux-cross-setup.sh.in b/linux-cross-setup.sh.in index 5335d59..6ba0ef0 100644 --- a/linux-cross-setup.sh.in +++ b/linux-cross-setup.sh.in @@ -2,3 +2,6 @@ CROSS_ARCH=@arch@ QEMU_LD_PREFIX=/usr/$CROSS_ARCH; export QEMU_LD_PREFIX + +PKG_CONFIG_PATH=$prefix/lib/pkgconfig:/usr/lib/pkgconfig +export PKG_CONFIG_PATH diff --git a/linux-native-setup.sh.in b/linux-native-setup.sh.in new file mode 100644 index 0000000..3b94110 --- /dev/null +++ b/linux-native-setup.sh.in @@ -0,0 +1,18 @@ +### -*-sh-*- + +CROSS_ARCH=@arch@ +case $CROSS_ARCH in + i686-linux-gnu) CROSS_gcc_FLAGS=" -m32" ;; + x86_64-linux-gnu) CROSS_gcc_FLAGS=" -m64" ;; + *) + echo 2>&1 "${0##*/}: unrecognized native architecture \`$CROSS_ARCH'"; + exit 2 + ;; +esac +CROSS_gxx_FLAGS=$CROSS_gcc_FLAGS +export CROSS_gcc_FLAGS CROSS_gxx_FLAGS + +PKG_CONFIG_PATH=$prefix/lib/pkgconfig:/usr/lib/pkgconfig +export PKG_CONFIG_PATH + +CROSS_NATIVE_P=t; export CROSS_NATIVE_P -- 2.11.0