forked from securesystemslab/multicompiler
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Pods-setup
executable file
·223 lines (197 loc) · 6.55 KB
/
Pods-setup
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
#!/bin/bash
TAG="[Pods-setup]:"
# Get argument flags
ALL=0
CONFIG=0
MAKE=0
UPDATE=0
NONE=0
case $1 in
-a|--all) ALL=1 ;;
-c|--config) CONFIG=1 ;;
-m|--make) MAKE=1 ;;
-n|--none) NONE=1 ;;
-ua|--uall) ALL=1; UPDATE=1 ;;
-uc|--uconfig) CONFIG=1; UPDATE=1 ;;
-um|--umake) MAKE=1; UPDATE=1 ;;
-un|--unone) NONE=1; UPDATE=1 ;;
''|-h|--help)
echo ""
echo "usage: ./Pods-setup [ <option> ]"
echo ""
echo " Requires exactly one flag."
echo ""
echo " -a, --all ... Attempt to automate all necessary changes, including"
echo " compile and install multipiler and clang."
echo " -c, --config ... configure only"
echo " -m, --make ... configure and make"
echo " -n, --none ... bare minimum directory changes only"
echo ""
echo " -u[flag] ... Ignore 'tools/clang' contents and force overwite with"
echo " original 'multicompiler-clang' directory"
echo " (e.g. --uall, -uc, --unone)"
echo ""
exit 0
;;
*) echo "unknown argument $1"; echo "do --help for help" ;;
esac
# Setup directory variables
LLVM_DIR="$( cd "$( dirname "$0" )"; pwd )"
PODS_DIR="$( cd "$LLVM_DIR"; cd ..; pwd )"
if [[ ${PODS_DIR##*/} != "Pods" ]]; then
echo "$TAG file structure error"
exit -1
fi
APP_DIR="$( cd "$PODS_DIR"; cd ..; pwd )"
APP_NAME="${APP_DIR##*/}"
CLANG_DIR="$PODS_DIR/multicompiler-clang"
TOOLS_DIR="$LLVM_DIR/tools/clang"
BUILD_DIR="$LLVM_DIR/build"
PODSPEC="$TOOLS_DIR/multicompiler-clang.podspec"
PBXPROJ="$APP_DIR/$APP_NAME.xcodeproj/project.pbxproj"
PODS_RESRC="$PODS_DIR/Pods-$APP_NAME-resources.sh"
XCCONFIG="$PODS_DIR/Pods-$APP_NAME.xcconfig"
RET="$(grep "frandom-seed" "$PBXPROJ" "$XCCONFIG")"
if [[ $RET == "" ]]; then
# try in the pbxproj file
echo "$TAG Adding compiler flags to build settings..."
echo "sed -i.bak s/OTHER_CFLAGS\.\*$/OTHER_CFLAGS\ =\ \(\"\-fdiversify\"\,\"\-frandom-seed=0xcafe\"\,/g \"$PBXPROJ\""
sed -i.bak s/OTHER_CFLAGS\.\*$/OTHER_CFLAGS\ =\ \(\"\-fdiversify\"\,\"\-frandom-seed=0xcafe\"\,/g "$PBXPROJ"
#try in the Pods/Pods-.xcconfig file
echo "sed -i.bak s/OTHER_CFLAGS\ =\ /OTHER_CFLAGS\ =\ \-fdiversify\ \-frandom-seed=0xcafefeed\ /g \"$XCCONFIG\""
sed -i.bak s/OTHER_CFLAGS\ =\ /OTHER_CFLAGS\ =\ \-fdiversify\ \-frandom-seed=0xcafefeed\ /g "$XCCONFIG"
else
echo "$TAG compiler flags found in build settings. skipping..."
fi
RET="$(grep "Pods-setup" "$PODS_RESRC")"
if [[ $RET == "" ]]; then
echo "$TAG Adding random seed generation to Pods resources script..."
echo "" >> "$PODS_RESRC"
echo "# [Pods-setup]: Random seed generation for -frandom-seed= flag" >> "$PODS_RESRC"
echo "X=\$RANDOM;Y=\$RANDOM;Z=\$RANDOM;W=\$RANDOM; HEXME=\$(echo \$X \$Y \$Z \$W | awk '{printf \"%x%x%x%x\",\$1,\$2,\$3,\$4}');" >> "$PODS_RESRC"
echo "sed -i.bak s/frandom-seed=0x\[a-zA-Z0-9\]\[a-zA-Z0-9\]\*/frandom-seed=0x\$HEXME/g \"$PBXPROJ\"" >> "$PODS_RESRC"
echo "sed -i.bak s/frandom-seed=0x\[a-zA-Z0-9\]\[a-zA-Z0-9\]\*/frandom-seed=0x\$HEXME/g \"$XCCONFIG\"" >> "$PODS_RESRC"
else
echo "$TAG random seed generation already added to script. skipping..."
fi
# Directory configuration
if [[ -d $TOOLS_DIR ]]; then
echo "$TAG tools/clang exists..."
if [[ -f $PODSPEC ]]; then
if [[ $UPDATE -eq 0 ]]; then
echo "$TAG tools/clang ready!"
else
echo "$TAG Updating tools/clang..."
echo "rm -rf \"$TOOLS_DIR\""
rm -rf "$TOOLS_DIR"
echo "cp -r \"$CLANG_DIR \"$TOOLS_DIR\""
cp -r "$CLANG_DIR $TOOLS_DIR"
fi
else
# tools/clang is incomplete. attempt to copy
echo "$TAG clang directory incomplete. Attempting to move original."
if [[ -d $CLANG_DIR ]]; then
# Move clang into tools directory
echo "$TAG Moving '$CLANG_DIR' to '$TOOLS_DIR'..."
echo "rm -rf \"$TOOLS_DIR\""
rm -rf "$TOOLS_DIR"
echo "cp -r \"$CLANG_DIR\" \"$TOOLS_DIR\""
cp -r "$CLANG_DIR" "$TOOLS_DIR"
else
echo "$TAG '$CLANG_DIR' directory does not exist."
echo "$TAG Please run 'pod install' from your app's top directory."
echo "$TAG Exiting..."
exit -1
fi
fi
else
if [[ -d $CLANG_DIR ]]; then
echo "$TAG Copying '$CLANG_DIR' to '$TOOLS_DIR'..."
echo "cp -r \"$CLANG_DIR\" \"$TOOLS_DIR\""
cp -r "$CLANG_DIR" "$TOOLS_DIR"
else
echo "$TAG '$CLANG_DIR' directory does not exist."
echo "$TAG Please run 'pod install' from your app's top directory."
echo "$TAG Exiting..."
exit -1
fi
fi
# Make 'build' directory for clang compile prefix
if [[ ! -d $BUILD_DIR ]]; then
echo "$TAG Creating '$BUILD_DIR' prefix for clang installation..."
echo "mkdir \"$BUILD_DIR\""
mkdir "$BUILD_DIR"
else
echo "$TAG build directory already exists..."
fi
CLANG_SELECT=1
if [[ -f "$BUILD_DIR/bin/clang" ]]; then
echo ""
echo "$TAG Setting up clang-select... "
echo "sudo \"$LLVM_DIR/clang-select\" --vsetup \"$BUILD_DIR/bin\""
sudo "$LLVM_DIR/clang-select" --vsetup "$BUILD_DIR/bin"
CLANG_SELECT=0
fi
echo ""
if [[ $NONE -eq 1 ]]; then
echo "$TAG -n (--none) flag given: stopping before configure..."
echo "$TAG Please './configure [flags]', 'make', and 'make install' the multicompiler."
echo "$TAG Exiting..."
exit 1
fi
echo "$TAG Starting configuration of multicompiler..."
pushd "$LLVM_DIR"
echo "./configure --prefix=\"$BUILD_DIR\" --enable-optimized"
./configure --prefix="$BUILD_DIR" --enable-optimized
RET=$?
if [[ $RET -eq 0 ]]; then
echo "$TAG Multicompiler configured successfully."
else
echo "$TAG Error configuring multicompiler. (exit code $RET)"
echo "$TAG Exiting..."
exit -1
fi
if [[ $CONFIG -eq 1 ]]; then
echo "$TAG -c (--config) flag given: stopping before make..."
echo "$TAG Please 'make' and 'make install' the multicompiler."
echo "$TAG Exiting..."
exit 2
fi
echo "$TAG Starting make of multicompiler... (this may take some time)"
echo "make"
make
RET=$?
if [[ $RET -eq 0 ]]; then
echo "$TAG Multicompiler made successfully."
else
echo "$TAG Error making multicompiler. (exit code $RET)"
echo "$TAG Exiting..."
exit -1
fi
if [[ $MAKE -eq 1 ]]; then
echo "$TAG -m (--make) flag given: stopping before install..."
echo "$TAG Please 'make install' to install into $BUILD_DIR."
echo "$TAG Exiting..."
exit 3
fi
echo "$TAG Starting make install... "
echo "make install"
make install
RET=$?
if [[ $RET -eq 0 ]]; then
echo "$TAG Multicompiler installed successfully."
else
echo "$TAG Error installing multicompiler. (exit code $RET)"
echo "$TAG Exiting..."
exit -1
fi
if [[ -f "$BUILD_DIR/bin/clang" && CLANG_SELECT -eq 1 ]]; then
echo ""
echo "$TAG Setting up clang-select... "
echo "sudo \"$LLVM_DIR/clang-select\" --vsetup \"$BUILD_DIR/bin\""
sudo "$LLVM_DIR/clang-select" --vsetup "$BUILD_DIR/bin"
echo ""
fi
echo "$TAG Finished."
popd
exit 0