forked from ghc-ios/ghc-ios-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
arm-apple-darwin10-clang
executable file
·98 lines (79 loc) · 3.14 KB
/
arm-apple-darwin10-clang
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
#!/bin/sh
TARGET_PLATFORM=`xcrun --show-sdk-path --sdk iphoneos`
TARGET_GCC=`xcrun -f clang`
TARGET_CFLAGS="-isysroot $TARGET_PLATFORM -miphoneos-version-min=7.0"
args=$@
# When we see a .s output file:
# -o ABC.s
# replace with two calls:
# -o ABC-armv7.s -arch armv7
# -o ABC-armv7s.s -arch armv7s
# When we see a .s input file and a .o output file:
# -c ABC.s -o DEF.o
# replace with two calls:
# -c ABC-armv7.s -o DEF-armv7.o -arch armv7
# -c ABC-armv7s.s -o DEF-armv7s.o -arch armv7s
# and then:
# lipo DEF-armv7.o DEF-armv7s.o to DEF.o
# When we see
# -o ABC.o
# replace with two calls:
# -o ABC-armv7.o -arch armv7
# -o ABC-armv7s.o -arch armv7s
# and then:
# lipo ABC-armv7.o ABC-armv7s.o to ABC.o
# Check if we're building an object file by looking for "-o file.o", and find its filename
# we use s|_|\1|p where _ is the match, \1 replaces it with the group in the match
# sed's -E allows extended regexes (cleaner syntax), -n suppresses non-matching input, the |p flag prints matches.
# Support for profiling libraries used by ghc
# Only need lipo when we're outputting object files
#generate -armv7 and -armv7s variants of any .s and .o (and ghc's variants of .o)
argsArmv7=${args/.s/-armv7.s}
argsArmv7s=${args/.s/-armv7s.s}
for ext in o p_o l_o debug_o thr_o thr_debug_o thr_l_o thr_p_o
do
argsArmv7=${argsArmv7/.$ext/-armv7.$ext}
argsArmv7s=${argsArmv7s/.$ext/-armv7s.$ext}
done
for ext in o p_o l_o debug_o thr_o thr_debug_o thr_l_o thr_p_o
do
match="s|.*-o ([^.]*)\.$ext.*|\1|p"
outFileName=$(echo "$args" | sed -En "$match")
if [[ -n $outFileName ]]; then
objectExt=$ext
needLipo=true
needFatCall=true
break
fi
done
outFileNameS=$(echo "$args" | sed -En 's|.*-o ([^.]*)\.s.*|\1|p')
# A silly hack:
# If the .s file is generated by llc rather than us, llc won't generate the -armv7 and -armv7s variants
# (we could write a arm-apple-darwin10-llc to do that, and then we could correctly pass '-mattr=+v7,+vfp3' to armv7 and '-mattr=+v7,+vfp4' to armv7s)
# So we just copy its output here.
inFileNameS=$(echo "$args" | sed -En 's|.*-c ([^.]*)\.s.*|\1|p')
if [[ -f $inFileNameS.s ]]; then
cp $inFileNameS.s $inFileNameS-armv7.s
cp $inFileNameS.s $inFileNameS-armv7s.s
fi
# Need fat calls for generating either .s or .o files
if [[ -n $outFileNameS ]]; then
needFatCall=true
fi
if [[ $needFatCall == true ]]; then
# Call clang twice, once for each architecture, outputting to our filename variants
$TARGET_GCC $TARGET_CFLAGS -arch armv7 $argsArmv7
$TARGET_GCC $TARGET_CFLAGS -arch armv7s $argsArmv7s
else
# echo "Non-object-generating compile command: $TARGET_GCC $TARGET_CFLAGS -arch armv7s $@"
# If not building object files, call regularly. Still need to include an arch to configure clang for arm mode.
exec $TARGET_GCC $TARGET_CFLAGS -arch armv7s "$@"
fi
if [[ $needLipo == true ]]; then
outFileNameOArmv7=$outFileName-armv7.$objectExt
outFileNameOArmv7s=$outFileName-armv7s.$objectExt
# Lipo the two filename variants together
lipo $outFileNameOArmv7 $outFileNameOArmv7s -create -output $outFileName.$objectExt
# Clean up
rm $outFileNameOArmv7 $outFileNameOArmv7s
fi