forked from mstorsjo/llvm-mingw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall-wrappers.sh
executable file
·87 lines (80 loc) · 2.75 KB
/
install-wrappers.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/sh
set -e
if [ $# -lt 1 ]; then
echo $0 dest
exit 1
fi
PREFIX="$1"
mkdir -p "$PREFIX"
PREFIX="$(cd "$PREFIX" && pwd)"
: ${ARCHS:=${TOOLCHAIN_ARCHS-i686 x86_64 armv7 aarch64}}
: ${TARGET_OSES:=${TOOLCHAIN_TARGET_OSES-mingw32 mingw32uwp}}
if [ -n "$HOST" ] && [ -z "$CC" ]; then
CC=$HOST-gcc
fi
: ${CC:=cc}
case $(uname) in
MINGW*)
EXEEXT=.exe
;;
esac
if [ -n "$EXEEXT" ]; then
CLANG_MAJOR=$(basename $(echo $PREFIX/lib/clang/* | awk '{print $NF}') | cut -f 1 -d .)
WRAPPER_FLAGS="$WRAPPER_FLAGS -municode -DCLANG=\"clang-$CLANG_MAJOR\""
fi
mkdir -p $PREFIX/bin
cp wrappers/*-wrapper.sh $PREFIX/bin
if [ -n "$HOST" ]; 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
cat $i | sed 's/^DEFAULT_TARGET=.*/DEFAULT_TARGET='$HOST/ > $PREFIX/bin/$(basename $i)
done
fi
$CC wrappers/clang-target-wrapper.c -o $PREFIX/bin/clang-target-wrapper$EXEEXT -O2 -Wl,-s $WRAPPER_FLAGS
$CC wrappers/windres-wrapper.c -o $PREFIX/bin/windres-wrapper$EXEEXT -O2 -Wl,-s $WRAPPER_FLAGS
$CC wrappers/llvm-wrapper.c -o $PREFIX/bin/llvm-wrapper$EXEEXT -O2 -Wl,-s $WRAPPER_FLAGS
if [ -n "$EXEEXT" ]; then
# For Windows, we should prefer the executable wrapper, which also works
# when invoked from outside of MSYS.
CTW_SUFFIX=$EXEEXT
CTW_LINK_SUFFIX=$EXEEXT
else
CTW_SUFFIX=.sh
fi
cd $PREFIX/bin
for arch in $ARCHS; do
for target_os in $TARGET_OSES; do
for exec in clang clang++ gcc g++ cc c99 c11 c++; 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 strings strip; do
if [ -n "$HOST" ]; then
link_target=llvm-wrapper
else
link_target=llvm-$exec
fi
ln -sf $link_target$EXEEXT $arch-w64-$target_os-$exec$EXEEXT || true
done
for exec in windres; do
ln -sf $exec-wrapper$EXEEXT $arch-w64-$target_os-$exec$EXEEXT
done
for exec in ld objdump dlltool; do
ln -sf $exec-wrapper.sh $arch-w64-$target_os-$exec
done
done
done
if [ -n "$EXEEXT" ]; then
if [ ! -L clang$EXEEXT ] && [ -f clang$EXEEXT ] && [ ! -f clang-$CLANG_MAJOR$EXEEXT ]; then
mv clang$EXEEXT clang-$CLANG_MAJOR$EXEEXT
fi
if [ -z "$HOST" ]; then
HOST=$(./clang-$CLANG_MAJOR -dumpmachine | sed 's/-.*//')-w64-mingw32
fi
for exec in clang clang++ gcc g++ cc c99 c11 c++ addr2line ar ranlib nm objcopy strings strip windres; do
ln -sf $HOST-$exec$EXEEXT $exec$EXEEXT
done
for exec in ld objdump dlltool; do
ln -sf $HOST-$exec $exec
done
fi