Skip to content

Commit 06f44cd

Browse files
committed
Support cross compilation to non-windows targets
Don't have --host/$HOST imply targeting Windows, but actually inspect the target triple where necessary.
1 parent c49af43 commit 06f44cd

File tree

4 files changed

+57
-24
lines changed

4 files changed

+57
-24
lines changed

build-lldb-mi.sh

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,21 @@ fi
8989
if [ -n "$HOST" ]; then
9090
BUILDDIR=$BUILDDIR-$HOST
9191

92-
CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_SYSTEM_NAME=Windows"
9392
CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_C_COMPILER=$HOST-gcc"
9493
CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_CXX_COMPILER=$HOST-g++"
95-
CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_RC_COMPILER=$HOST-windres"
94+
case $HOST in
95+
*-mingw32)
96+
CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_SYSTEM_NAME=Windows"
97+
CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_RC_COMPILER=$HOST-windres"
98+
;;
99+
*-linux*)
100+
CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_SYSTEM_NAME=Linux"
101+
;;
102+
*)
103+
echo "Unrecognized host $HOST"
104+
exit 1
105+
;;
106+
esac
96107

97108
CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_FIND_ROOT_PATH=$LLVM_DIR"
98109
CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER"

build-llvm.sh

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -122,16 +122,19 @@ fi
122122

123123
[ -z "$CHECKOUT_ONLY" ] || exit 0
124124

125-
case $(uname) in
126-
MINGW*)
127-
TARGET_WINDOWS=1
128-
;;
129-
*)
130-
if [ -n "$HOST" ]; then
125+
if [ -n "$HOST" ]; then
126+
case $HOST in
127+
*-mingw32)
131128
TARGET_WINDOWS=1
132-
fi
133-
;;
134-
esac
129+
;;
130+
esac
131+
else
132+
case $(uname) in
133+
MINGW*)
134+
TARGET_WINDOWS=1
135+
;;
136+
esac
137+
fi
135138

136139
if command -v ninja >/dev/null; then
137140
CMAKE_GENERATOR="Ninja"
@@ -153,10 +156,21 @@ fi
153156
CMAKEFLAGS="$LLVM_CMAKEFLAGS"
154157

155158
if [ -n "$HOST" ]; then
156-
CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_SYSTEM_NAME=Windows"
157159
CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_C_COMPILER=$HOST-gcc"
158160
CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_CXX_COMPILER=$HOST-g++"
159-
CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_RC_COMPILER=$HOST-windres"
161+
case $HOST in
162+
*-mingw32)
163+
CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_SYSTEM_NAME=Windows"
164+
CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_RC_COMPILER=$HOST-windres"
165+
;;
166+
*-linux*)
167+
CMAKEFLAGS="$CMAKEFLAGS -DCMAKE_SYSTEM_NAME=Linux"
168+
;;
169+
*)
170+
echo "Unrecognized host $HOST"
171+
exit 1
172+
;;
173+
esac
160174

161175
native=""
162176
for dir in llvm-project/llvm/build/bin llvm-project/llvm/build-asserts/bin; do
@@ -185,7 +199,7 @@ if [ -n "$HOST" ]; then
185199

186200
BUILDDIR=$BUILDDIR-$HOST
187201

188-
if [ -n "$WITH_PYTHON" ]; then
202+
if [ -n "$WITH_PYTHON" ] && [ -n "$TARGET_WINDOWS" ]; then
189203
# The python3-config script requires executing with bash. It outputs
190204
# an extra trailing space, which the extra 'echo' layer gets rid of.
191205
EXT_SUFFIX="$(echo $(bash $PREFIX/python/bin/python3-config --extension-suffix))"

build-mingw-w64-tools.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,11 @@ fi
6262
if [ -n "$HOST" ]; then
6363
CONFIGFLAGS="$CONFIGFLAGS --host=$HOST"
6464
CROSS_NAME=-$HOST
65-
EXEEXT=.exe
65+
case $HOST in
66+
*-mingw32)
67+
EXEEXT=.exe
68+
;;
69+
esac
6670
else
6771
case $(uname) in
6872
MINGW*)

install-wrappers.sh

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,18 @@ if [ -n "$HOST" ] && [ -z "$CC" ]; then
4444
fi
4545
: ${CC:=cc}
4646

47-
case $(uname) in
48-
MINGW*)
49-
EXEEXT=.exe
50-
;;
51-
esac
52-
5347
if [ -n "$HOST" ]; then
54-
EXEEXT=.exe
48+
case $HOST in
49+
*-mingw32)
50+
EXEEXT=.exe
51+
;;
52+
esac
53+
else
54+
case $(uname) in
55+
MINGW*)
56+
EXEEXT=.exe
57+
;;
58+
esac
5559
fi
5660

5761
if [ -n "$MACOS_REDIST" ]; then
@@ -70,7 +74,7 @@ fi
7074

7175
mkdir -p "$PREFIX/bin"
7276
cp wrappers/*-wrapper.sh "$PREFIX/bin"
73-
if [ -n "$HOST" ]; then
77+
if [ -n "$HOST" ] && [ -n "$EXEEXT" ]; then
7478
# TODO: If building natively on msys, pick up the default HOST value from there.
7579
WRAPPER_FLAGS="$WRAPPER_FLAGS -DDEFAULT_TARGET=\"$HOST\""
7680
for i in wrappers/*-wrapper.sh; do
@@ -94,7 +98,7 @@ for arch in $ARCHS; do
9498
ln -sf clang-target-wrapper$CTW_SUFFIX $arch-w64-$target_os-$exec$CTW_LINK_SUFFIX
9599
done
96100
for exec in addr2line ar ranlib nm objcopy readelf size strings strip llvm-ar llvm-ranlib; do
97-
if [ -n "$HOST" ]; then
101+
if [ -n "$EXEEXT" ]; then
98102
link_target=llvm-wrapper
99103
else
100104
case $exec in

0 commit comments

Comments
 (0)