forked from ghc-ios/ghc-ios-scripts
-
Notifications
You must be signed in to change notification settings - Fork 9
/
wrapper
executable file
·144 lines (136 loc) · 4.37 KB
/
wrapper
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/bin/bash
source raspberrypi-toolchain.config
source android-toolchain.config
source wasm-toolchain.config
name=${0##*/}
cmd=${name##*-}
target=${name%-*}
die () {
echo "ERROR: $1" >& 2
exit 1
}
check_android_toolchain() {
if [ -z "${ANDROID_SYSROOT}" -o ! -d "$ANDROID_SYSROOT" ]; then
die "ANDROID_SYSROOT ($ANDROID_SYSROOT) empty or not a directory"
fi
}
case $name in
*-android-*) check_android_toolchain ;;
esac
case $name in
*-cabal)
fcommon="--builddir=dist/${target}"
fcompile=" --with-ghc=${target}-ghc"
fcompile+=" --with-ghc-pkg=${target}-ghc-pkg"
fcompile+=" --with-gcc=${target}-clang"
fcompile+=" --with-ld=${target}-ld"
fcompile+=" --with-hsc2hs=${target}-hsc2hs"
fcompile+=" --hsc2hs-options=--cross-compile"
fconfig="--disable-shared --configure-option=--host=${target}"
case $1 in
configure|install) flags="${fcommon} ${fcompile} ${fconfig}" ;;
build) flags="${fcommon} ${fcompile}" ;;
new-configure|new-install)
flags="${fcompile} ${fconfig}" ;;
new-build) flags="${fcompile}" ;;
list|info|update) flags="" ;;
"") flags="" ;;
*) flags=$fcommon ;;
esac
;;
*-hsc2hs)
flags=" --cross-compile"
;;
# raspberry pi
arm-linux-gnueabihf-clang)
flags=" --target=${target}"
flags+=" --sysroot=${RPI_SYSROOT}"
flags+=" -isysroot ${RPI_SYSROOT}"
flags+=" -isystem ${RPI_SYSROOT}/usr/include/${target}/"
;;
arm-linux-gnueabihf-ld|arm-linux-gnueabihf-ld.gold)
flags=" --sysroot=${RPI_SYSROOT}"
flags+=" -L${RPI_SYSROOT}/lib/${target}"
flags+=" -L${RPI_TOOLCHAIN_LIB}"
;;
wasm32-unknown-unknown-wasm-clang)
flags=" --target=wasm32-unknown-unknown-wasm"
flags+=" --sysroot=${WASM_SYSROOT}"
flags+=" -fdebug-prefix-map=${WASM_BASE}=wasmception://v0.1"
# wasm-ld will dead-lock randomly if threads is on, which is
# the default.
flags+=" -Wl,--no-threads"
# silence clang complaining about -Wl,--no-threads when no
# linking is involved. This is a bit of a catch-all though :(
flags+=" -Wno-unused-command-line-argument"
;;
wasm32-unknown-unknown-wasm-ld|wasm32-unknown-unknown-wasm-ld.gold)
flags=" --sysroot=${WASM_SYSROOT}"
flags+=" -fdebug-prefix-map=${WASM_BASE}=wasmception://v0.1"
;;
# android (armv7)
armv7-linux-androideabi-clang)
flags=${ANDROID_ARM_CFLAGS}
;;
armv7-linux-androideabi-ld|armv7-linux-androideabi-ld.gold)
flags=${ANDROID_ARM_LDFLAGS}
;;
# android (aarch64)
aarch64-linux-android-clang)
flags=${ANDROID_ARM64_CFLAGS}
;;
aarch64-linux-android-ld|aarch64-linux-android-ld.gold)
flags=${ANDROID_ARM64_LDFLAGS}
;;
# android (x86_64)
x86_64-linux-android-clang)
flags=${ANDROID_X86_64_CFLAGS}
;;
x86_64-linux-android-ld|x86_64-linux-android-ld.gold)
flags=${ANDROID_X86_64_LDFLAGS}
;;
# iOS -- this us run though apples
# xcrun tool.
aarch64-apple-ios-clang|aarch64-apple-ios-ld)
flags="--sdk iphoneos ${cmd} -arch arm64"
cmd="xcrun"
;;
aarch64-apple-ios-*|aarch64-apple-ios-*)
flags="--sdk iphoneos ${cmd}"
cmd="xcrun"
;;
# iOS (64bit simulator)
x86_64-apple-ios-clang|x86_64-apple-ios-ld)
flags="--sdk iphonesimulator ${cmd} -arch x86_64"
cmd="xcrun"
;;
x86_64-apple-ios-*)
flags="--sdk iphonesimulator ${cmd}"
cmd="xcrun"
;;
aarch64-apple-darwin-clang|aarch64-apple-darwin-ld|arm64-apple-darwin-clang|arm64-apple-darwin-ld)
flags="--sdk macosx ${cmd} -arch arm64"
cmd="xcrun"
;;
aarch64-apple-darwin-*|arm64-apple-darwin-*)
flags="--sdk macosx ${cmd}"
cmd="xcrun"
;;
# default
*-llvm-*|wasm32-*-nm|wasm32-*-ar|wasm32-*-ranlib)
# if there is -llvm- in the name, we need to retain it
# if it's wasm32, force llvm toolchain.
cmd="llvm-$cmd"
;;
*-nm|*-ar|*-ranlib) ;;
*) echo "Unknown command: ${0##*/}" >&2; exit 1;;
esac
(>&2 echo "WRAPPED: $cmd $flags $@")
case $target in
*-linux-gnueabihf) exec env PATH="${RPI_PATH}:${PATH}" $cmd $flags "$@" ;;
armv7-linux-android*) exec env PATH="${ANDROID_ARM_PATH}:${PATH}" $cmd $flags "$@" ;;
aarch64-linux-android*) exec env PATH="${ANDROID_ARM64_PATH}:${PATH}" $cmd $flags "$@" ;;
x86_64-linux-android*) exec env PATH="${ANDROID_X86_64_PATH}:${PATH}" $cmd $flags "$@" ;;
wasm32-*) exec env PATH="${WASM_PATH}:${PATH}" $cmd $flags "$@" ;;
*) exec $cmd $flags "$@" ;;
esac