This repository has been archived by the owner on Oct 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
rebuild-functions.sh
executable file
·187 lines (158 loc) · 4.68 KB
/
rebuild-functions.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
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
#!/bin/sh
OSX_MIN_VERSION="10.8"
OSX_ARCHS="x86_64"
IOS_MIN_VERSION="8.0"
IOS_SIMULATOR_ARCHS="i386 x86_64"
IOS_DEVICE_ARCHS="armv7 arm64"
IOS_SDK_VERSION=`xcodebuild -version -sdk | grep -A 1 '^iPhone' | tail -n 1 | awk '{ print $2 }'`
OSX_SDK_VERSION=`xcodebuild -version -sdk | grep -A 1 '^MacOSX' | tail -n 1 | awk '{ print $2 }'`
DEVELOPER_DIR=`xcode-select --print-path`
BASE_DIR=`pwd`
function post_build_hook() {
echo "Post build hook"
}
function post_package_hook() {
echo "Post package hook"
}
function configure() {
local PLATFORM="$1"
local ARCH="$2"
local PREFIX="$3"
local LOG="$4"
if [ "$ARCH" == "x86_64" ] || [ "$ARCH" == "i386" ]
then
HOST="i386-apple-darwin"
elif [ "$ARCH" == "arm64" ] || [ "$ARCH" == "armv7" ]
then
HOST="arm-apple-darwin"
fi
./configure --prefix="$PREFIX" --host="$HOST" --enable-static --disable-shared $EXTRA_CONFIGURE_OPTIONS >> "$LOG"
}
function build_library_arch () {
local DESTINATION="$1"
local PLATFORM="$2"
local ARCH="$3"
local PREFIX="$DESTINATION-$ARCH"
local LOG="$PREFIX.log"
# Find SDK
DEVROOT="$DEVELOPER_DIR/Platforms/$PLATFORM.platform/Developer"
if [ "$PLATFORM" == "MacOSX" ]
then
SDKROOT="$DEVROOT/SDKs/$PLATFORM$OSX_SDK_VERSION.sdk"
else
SDKROOT="$DEVROOT/SDKs/$PLATFORM$IOS_SDK_VERSION.sdk"
fi
# Find tools
export CC=`xcrun -find clang`
export CPP="$CC -E"
export CXX=`xcrun -find clang++`
export CXXCPP="$CC -E"
export LD=`xcrun -find ld`
export AR=`xcrun -find ar`
export RANLIB=`xcrun -find ranlib`
export LIPO=`xcrun -find lipo`
export STRIP=`xcrun -find strip`
export CC_FOR_BUILD=`xcrun -find clang`
# Override tools to compile for SDK
CC_FLAGS="-isysroot $SDKROOT -arch $ARCH"
LD_FLAGS="-isysroot $SDKROOT -arch $ARCH"
if [ "$PLATFORM" == "MacOSX" ]
then
CC_FLAGS="$CC_FLAGS -mmacosx-version-min=$OSX_MIN_VERSION"
elif [ "$PLATFORM" == "iPhoneSimulator" ]
then
CC_FLAGS="$CC_FLAGS -mios-simulator-version-min=$IOS_MIN_VERSION"
elif [ "$PLATFORM" == "iPhoneOS" ]
then
CC_FLAGS="$CC_FLAGS -miphoneos-version-min=$IOS_MIN_VERSION"
if (( $(echo "$IOS_SDK_VERSION >= 9.0" | bc -l) ))
then
CC_FLAGS="$CC_FLAGS -fembed-bitcode"
fi
fi
export CC="$CC $CC_FLAGS $EXTRA_CFLAGS"
export CPP="$CPP $CC_FLAGS $EXTRA_CFLAGS"
export CXX="$CXX $CC_FLAGS $EXTRA_CFLAGS"
export CXXCPP="$CXXCPP $CC_FLAGS $EXTRA_CFLAGS"
export LD="$LD $LD_FLAGS"
# Work around libtool bug (see http://stackoverflow.com/questions/32622284/)
if [ "$PLATFORM" != "MacOSX" ]
then
export MACOSX_DEPLOYMENT_TARGET="10.4"
fi
# Configure and build
rm -f "$LOG"
touch "$LOG"
rm -rf "$PREFIX"
configure "$PLATFORM" "$ARCH" "$PREFIX" "$LOG"
make -j >> "$LOG"
make install >> "$LOG"
make clean >> "$LOG"
# Archive configure log if available
if [ -e "config.log" ]
then
mv "config.log" "$DESTINATION/configure-$ARCH.log"
fi
# Hook
post_build_hook "$PLATFORM" "$ARCH" "$PREFIX" "$DESTINATION"
# Copy "bin/" for first architecture and on OS X only
if [ "$PLATFORM" == "MacOSX" ] && [ -d "$PREFIX/bin" ] && [ ! -d "$DESTINATION/bin" ]
then
mv "$PREFIX/bin" "$DESTINATION/bin"
fi
# Copy "include/" for first architecture only
if [ ! -d "$DESTINATION/include" ]
then
mv "$PREFIX/include" "$DESTINATION/include"
fi
# Copy and merge "lib/"
mkdir -p "$DESTINATION/lib"
pushd "$PREFIX/lib"
for LIBRARY in *.a
do
if [ -L "$LIBRARY" ] # Preserve symbolic link as-is
then
if [ ! -e "$DESTINATION/lib/$LIBRARY" ]
then
mv "$LIBRARY" "$DESTINATION/lib/$LIBRARY"
fi
else
$STRIP -S -o "$LIBRARY~" "$LIBRARY" # Strip debugging symbols
mv -f "$LIBRARY~" "$LIBRARY"
if [ -e "$DESTINATION/lib/$LIBRARY" ]
then
$LIPO -create "$DESTINATION/lib/$LIBRARY" "$LIBRARY" -output "$DESTINATION/lib/$LIBRARY"
else
mv "$LIBRARY" "$DESTINATION/lib/$LIBRARY"
fi
fi
done
popd
# Hook
post_package_hook "$PLATFORM" "$ARCH" "$PREFIX" "$DESTINATION"
# Clean up
rm -rf "$PREFIX"
rm -f "$LOG"
}
function build_library_platform () {
local PREFIX="$1"
local PLATFORM="$2"
local ARCHS="$3"
local PREFIX="$PREFIX/$PLATFORM"
# Build each arch for the platform
rm -rf "$PREFIX"
mkdir -p "$PREFIX"
for ARCH in ${ARCHS}
do
build_library_arch "$PREFIX" "$PLATFORM" "$ARCH"
done
}
function build_library_macosx () {
build_library_platform "$BASE_DIR" "MacOSX" "$OSX_ARCHS"
}
function build_library_iphonesimulator () {
build_library_platform "$BASE_DIR" "iPhoneSimulator" "$IOS_SIMULATOR_ARCHS"
}
function build_library_iphoneos () {
build_library_platform "$BASE_DIR" "iPhoneOS" "$IOS_DEVICE_ARCHS"
}