From 06f44cda629165867769b5f6975ee6f77a62c32c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Wed, 26 Apr 2023 09:47:24 +0300 Subject: [PATCH] Support cross compilation to non-windows targets Don't have --host/$HOST imply targeting Windows, but actually inspect the target triple where necessary. --- build-lldb-mi.sh | 15 +++++++++++++-- build-llvm.sh | 38 ++++++++++++++++++++++++++------------ build-mingw-w64-tools.sh | 6 +++++- install-wrappers.sh | 22 +++++++++++++--------- 4 files changed, 57 insertions(+), 24 deletions(-) diff --git a/build-lldb-mi.sh b/build-lldb-mi.sh index 59c5730..926d109 100755 --- a/build-lldb-mi.sh +++ b/build-lldb-mi.sh @@ -89,10 +89,21 @@ fi if [ -n "$HOST" ]; then BUILDDIR=$BUILDDIR-$HOST - CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_SYSTEM_NAME=Windows" CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_C_COMPILER=$HOST-gcc" CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_CXX_COMPILER=$HOST-g++" - CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_RC_COMPILER=$HOST-windres" + case $HOST in + *-mingw32) + CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_SYSTEM_NAME=Windows" + CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_RC_COMPILER=$HOST-windres" + ;; + *-linux*) + CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_SYSTEM_NAME=Linux" + ;; + *) + echo "Unrecognized host $HOST" + exit 1 + ;; + esac CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_FIND_ROOT_PATH=$LLVM_DIR" CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER" diff --git a/build-llvm.sh b/build-llvm.sh index 34ce680..5db883b 100755 --- a/build-llvm.sh +++ b/build-llvm.sh @@ -122,16 +122,19 @@ fi [ -z "$CHECKOUT_ONLY" ] || exit 0 -case $(uname) in -MINGW*) - TARGET_WINDOWS=1 - ;; -*) - if [ -n "$HOST" ]; then +if [ -n "$HOST" ]; then + case $HOST in + *-mingw32) TARGET_WINDOWS=1 - fi - ;; -esac + ;; + esac +else + case $(uname) in + MINGW*) + TARGET_WINDOWS=1 + ;; + esac +fi if command -v ninja >/dev/null; then CMAKE_GENERATOR="Ninja" @@ -153,10 +156,21 @@ fi CMAKEFLAGS="$LLVM_CMAKEFLAGS" if [ -n "$HOST" ]; then - CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_SYSTEM_NAME=Windows" CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_C_COMPILER=$HOST-gcc" CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_CXX_COMPILER=$HOST-g++" - CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_RC_COMPILER=$HOST-windres" + case $HOST in + *-mingw32) + CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_SYSTEM_NAME=Windows" + CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_RC_COMPILER=$HOST-windres" + ;; + *-linux*) + CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_SYSTEM_NAME=Linux" + ;; + *) + echo "Unrecognized host $HOST" + exit 1 + ;; + esac native="" for dir in llvm-project/llvm/build/bin llvm-project/llvm/build-asserts/bin; do @@ -185,7 +199,7 @@ if [ -n "$HOST" ]; then BUILDDIR=$BUILDDIR-$HOST - if [ -n "$WITH_PYTHON" ]; then + if [ -n "$WITH_PYTHON" ] && [ -n "$TARGET_WINDOWS" ]; then # The python3-config script requires executing with bash. It outputs # an extra trailing space, which the extra 'echo' layer gets rid of. EXT_SUFFIX="$(echo $(bash $PREFIX/python/bin/python3-config --extension-suffix))" diff --git a/build-mingw-w64-tools.sh b/build-mingw-w64-tools.sh index 71ba459..1d23834 100755 --- a/build-mingw-w64-tools.sh +++ b/build-mingw-w64-tools.sh @@ -62,7 +62,11 @@ fi if [ -n "$HOST" ]; then CONFIGFLAGS="$CONFIGFLAGS --host=$HOST" CROSS_NAME=-$HOST - EXEEXT=.exe + case $HOST in + *-mingw32) + EXEEXT=.exe + ;; + esac else case $(uname) in MINGW*) diff --git a/install-wrappers.sh b/install-wrappers.sh index 9be1516..0ce5663 100755 --- a/install-wrappers.sh +++ b/install-wrappers.sh @@ -44,14 +44,18 @@ if [ -n "$HOST" ] && [ -z "$CC" ]; then fi : ${CC:=cc} -case $(uname) in -MINGW*) - EXEEXT=.exe - ;; -esac - if [ -n "$HOST" ]; then - EXEEXT=.exe + case $HOST in + *-mingw32) + EXEEXT=.exe + ;; + esac +else + case $(uname) in + MINGW*) + EXEEXT=.exe + ;; + esac fi if [ -n "$MACOS_REDIST" ]; then @@ -70,7 +74,7 @@ fi mkdir -p "$PREFIX/bin" cp wrappers/*-wrapper.sh "$PREFIX/bin" -if [ -n "$HOST" ]; then +if [ -n "$HOST" ] && [ -n "$EXEEXT" ]; then # TODO: If building natively on msys, pick up the default HOST value from there. WRAPPER_FLAGS="$WRAPPER_FLAGS -DDEFAULT_TARGET=\"$HOST\"" for i in wrappers/*-wrapper.sh; do @@ -94,7 +98,7 @@ for arch in $ARCHS; do ln -sf clang-target-wrapper$CTW_SUFFIX $arch-w64-$target_os-$exec$CTW_LINK_SUFFIX done for exec in addr2line ar ranlib nm objcopy readelf size strings strip llvm-ar llvm-ranlib; do - if [ -n "$HOST" ]; then + if [ -n "$EXEEXT" ]; then link_target=llvm-wrapper else case $exec in