blob: 1060f12e8f29f7991ec041521df882797cbc7196 (
plain)
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
|
#!/bin/bash
#
# build libevent for iOS and iOS simulator
#
# make sure this is not set
unset MACOSX_DEPLOYMENT_TARGET
# be ridiculously conservative with regard to ios features
export IPHONEOS_DEPLOYMENT_TARGET="1.0"
# exit on error
set -e
ME=`basename $0`
DIR="$( cd "$( dirname "$0" )" && pwd )"
#SDK_VER="6.1"
SDK_VER="5.1"
DEST_DIR="${DIR}/../prebuilt/ios/${SDK_VER}-libevent-build"
if [ ! -f event.c ]; then
echo
echo "Cannot find event.c"
echo "Run script from within libevent directory:"
echo "libevent $ ../../${ME}"
echo
exit
fi
mkdir -p ${DEST_DIR} &> /dev/null
# see http://stackoverflow.com/questions/2424770/floating-point-comparison-in-shell-script
if [ $(bc <<< "$SDK_VER >= 6.1") -eq 1 ]; then
DEV_ARCHS="-arch armv7 -arch armv7s"
elif [ $(bc <<< "$SDK_VER >= 5.1") -eq 1 ]; then
DEV_ARCHS="-arch armv6 -arch armv7"
else
echo
echo "Building for SDK < 5.1 not supported"
exit
fi
#
# Build for Device
#
if [ ! -d ${DEST_DIR}/device ]; then
TOOLCHAIN_ROOT="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer"
SYSROOT="${TOOLCHAIN_ROOT}/SDKs/iPhoneOS${SDK_VER}.sdk"
if [ ! -d ${SYSROOT} ]; then
echo
echo "Cannot find iOS developer tools at ${SYSROOT}."
echo
exit
fi
if [ -f Makefile ]; then
make clean
fi
mkdir -p ${DEST_DIR}/device &> /dev/null
./configure \
CPP="cpp" \
CXXCPP="cpp" \
CXX=${TOOLCHAIN_ROOT}/usr/bin/g++ \
CC=${TOOLCHAIN_ROOT}/usr/bin/gcc \
LD=${TOOLCHAIN_ROOT}/usr/bin/ld\ -r \
CFLAGS="-O -isysroot ${SYSROOT} ${DEV_ARCHS}" \
CXXFLAGS="-O -isysroot ${SYSROOT} ${DEV_ARCHS}" \
--disable-debug-mode \
--disable-libevent-regress \
--disable-openssl \
--host=arm-apple-darwin10 \
--target=arm-apple-darwin10 \
--disable-shared \
--disable-dependency-tracking \
LDFLAGS="-isysroot ${SYSROOT} ${DEV_ARCHS}" \
AR=${TOOLCHAIN_ROOT}/usr/bin/ar \
AS=${TOOLCHAIN_ROOT}/usr/bin/as \
LIBTOOL=${TOOLCHAIN_ROOT}/usr/bin/libtool \
STRIP=${TOOLCHAIN_ROOT}/usr/bin/strip \
RANLIB=${TOOLCHAIN_ROOT}/usr/bin/ranlib \
--prefix=${DEST_DIR}/device
make -j2 install
else
echo
echo "${DEST_DIR}/device already exists - not rebuilding."
echo
fi
#
# Simulator
#
if [ ! -d ${DEST_DIR}/simulator ]; then
TOOLCHAIN_ROOT="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer"
SYSROOT="${TOOLCHAIN_ROOT}/SDKs/iPhoneSimulator${SDK_VER}.sdk"
if [ ! -d ${SYSROOT} ]; then
echo
echo "Cannot find iOS developer tools at ${SYSROOT}."
echo
exit
fi
if [ -f Makefile ]; then
make clean
fi
mkdir -p ${DEST_DIR}/simulator &> /dev/null
./configure \
CXX=${TOOLCHAIN_ROOT}/usr/bin/llvm-g++ \
CC=${TOOLCHAIN_ROOT}/usr/bin/llvm-gcc \
LD=${TOOLCHAIN_ROOT}/usr/bin/ld\ -r \
CFLAGS="-O -isysroot ${SYSROOT} -arch i386" \
CXXFLAGS="-O -isysroot ${SYSROOT} -arch i386" \
--disable-debug-mode \
--disable-libevent-regress \
--disable-openssl \
--disable-shared \
--disable-dependency-tracking \
LDFLAGS="-isysroot ${SYSROOT} -arch i386" \
AR=${TOOLCHAIN_ROOT}/usr/bin/ar \
AS=${TOOLCHAIN_ROOT}/usr/bin/as \
LIBTOOL=${TOOLCHAIN_ROOT}/usr/bin/libtool \
STRIP=${TOOLCHAIN_ROOT}/usr/bin/strip \
RANLIB=${TOOLCHAIN_ROOT}/usr/bin/ranlib \
--prefix=${DEST_DIR}/simulator
make -j2 install
else
echo
echo "${DEST_DIR}/device already exists - not rebuilding."
echo
fi
echo
echo "- Creating universal binaries --------------------------------------"
echo
LIBS=`find ${DIR}/../prebuilt/ios/*libevent-build* -name *.a`
set +e
for LIB in ${LIBS}; do
LIB_BASE=`basename $LIB .a`
ARCHS=`lipo -info $LIB`
ARCHS=`expr "$ARCHS" : '.*:\(.*\)$'`
for ARCH in ${ARCHS}; do
mkdir -p ${DIR}/../prebuilt/ios/arch/${ARCH} > /dev/null
lipo -extract $ARCH $LIB -output ${DIR}/../prebuilt/ios/arch/${ARCH}/${LIB_BASE}.a \
|| cp $LIB ${DIR}/../prebuilt/ios/arch/${ARCH}/${LIB_BASE}.a
UNIQUE_LIBS=`ls ${DIR}/../prebuilt/ios/arch/${ARCH}`
done
done
mkdir -p ${DIR}/../prebuilt/ios/lib
for LIB in ${UNIQUE_LIBS}; do
FILELIST=""
for ARCH in `ls ${DIR}/../prebuilt/ios/arch/`; do
FILELIST="${FILELIST} ${DIR}/../prebuilt/ios/arch/${ARCH}/${LIB}"
done
lipo -create ${FILELIST} -output ${DIR}/../prebuilt/ios/lib/${LIB}
done
rm -rf ${DIR}/../prebuilt/ios/arch/
|