-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.sh
executable file
·134 lines (110 loc) · 3.2 KB
/
build.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
#!/bin/bash
ARCHS_TO_BUILD="x86_64 arm64 armv7 armv7s i386"
# LIPO is used to combine static libraries
LIPO="xcrun -sdk iphoneos lipo"
# Need to include local path for gas-preprocessor.pl
PATH="$PATH:$(PWD)"
CPUS=$(sysctl -n hw.logicalcpu_max)
IOS_PLATFORM_BASE="/Applications/Xcode.app/Contents/Developer/Platforms"
IOS_SDK_VERSION=8.1
IOS_SDK_MIN_VERSION=5.1
################################################################################
IOS_PLATFORM_DIR=
IOS_GCC=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
ARCH=
IOS_CFLAGS=
CCASFLAGS=
function make_lib_for_arch() {
# reset flags
ARCH="$1"
IOS_CFLAGS="-arch $ARCH"
CCASFLAGS=
EXTRA_BUILD_FLAGS=
ARM32=
ARM=
if [ $ARCH == "i386" ] || [ $ARCH == "armv7" ] || [ $ARCH == "armv7s" ] ; then
# 32-bit build
IOS_CFLAGS="$IOS_CFLAGS -mfloat-abi=softfp"
if [ $ARCH != "i386" ] ; then
# ARM 32
ARM32=1
fi
fi
if [ $ARCH == "arm64" ] || [ $ARCH == "armv7" ] || [ $ARCH == "armv7s" ]
then
# device build
ARM=1
EXTRA_BUILD_FLAGS="--with-gas-preprocessor"
PLATFORM=iPhoneOS
MIN_VER_FLAG="-miphoneos-version-min=$IOS_SDK_MIN_VERSION"
HOST=aarch64-apple-darwin
if [ $ARCH != "arm64" ] ; then
HOST=arm-apple-darwin10
fi
else
# simulator build
PLATFORM=iPhoneSimulator
MIN_VER_FLAG="-mios-simulator-version-min=$IOS_SDK_MIN_VERSION"
HOST=$ARCH-apple-darwin
if [ $ARCH == "x86_64" ] ; then
EXTRA_BUILD_FLAGS="NASM=/usr/local/bin/nasm"
fi
fi
if [ "$ARM32" == "1" ] ; then
CCASFLAGS="-no-integrated-as $IOS_CFLAGS"
fi
IOS_PLATFORM_DIR="$IOS_PLATFORM_BASE/$PLATFORM.platform"
IOS_SYSROOT="$IOS_PLATFORM_DIR/Developer/SDKs/$PLATFORM$IOS_SDK_VERSION.sdk"
ORIG_PATH=$(pwd)
SRC_PATH="$ORIG_PATH/src"
BUILD_PATH="build-$ARCH"
cd $SRC_PATH
autoreconf -fiv
cd $ORIG_PATH
rm -rf $BUILD_PATH
mkdir -p $BUILD_PATH
cd $BUILD_PATH
if [ "$ARM32" == "1" ] ; then
sh $SRC_PATH/configure --host $HOST \
--enable-shared=no \
$EXTRA_BUILD_FLAGS \
CC="$IOS_GCC" LD="$IOS_GCC" \
CFLAGS="-isysroot $IOS_SYSROOT -O3 $MIN_VER_FLAG $IOS_CFLAGS" \
LDFLAGS="-isysroot $IOS_SYSROOT $MIN_VER_FLAG $IOS_CFLAGS" \
CCASFLAGS="$CCASFLAGS"
else
sh $SRC_PATH/configure --host $HOST \
--enable-shared=no \
$EXTRA_BUILD_FLAGS \
CC="$IOS_GCC" LD="$IOS_GCC" \
CFLAGS="-isysroot $IOS_SYSROOT -O3 $MIN_VER_FLAG $IOS_CFLAGS" \
LDFLAGS="-isysroot $IOS_SYSROOT $MIN_VER_FLAG $IOS_CFLAGS"
fi
# Check that configure succeeds
if [ $? -ne 0 ] ; then
echo "Failed to configure for arch $ARCH"
exit 1
fi
# build the lib
make -j$CPUS
# Check that make succeeds
if [ $? -ne 0 ] ; then
echo "Failed to build for arch $ARCH"
exit 1
fi
# Make a copy of the library
cd $ORIG_PATH
cp "$BUILD_PATH/.libs/libturbojpeg.a" "$ORIG_PATH/libturbojpeg.$ARCH.a"
}
function combine_libs() {
LIPO_ARGS=
for arch in "$@" ; do
LIPO_ARGS="$LIPO_ARGS -arch $arch libturbojpeg.$arch.a"
done
$LIPO $LIPO_ARGS -create -output libturbojpeg.a
file libturbojpeg.a
}
for arch in $ARCHS_TO_BUILD ; do
make_lib_for_arch $arch
done
combine_libs $ARCHS_TO_BUILD