forked from samsoir/libzmq-ios-universal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
compile_libzmq_ios_universal
executable file
·263 lines (215 loc) · 6.55 KB
/
compile_libzmq_ios_universal
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
#!/usr/bin/env bash
#
# Compile libzmq as iOS universal (fat) static library
# Supported architectures; armv7, armv7s, arm64, i386
#
# Created by Sam de Freyssinet
#
# Licensed under ISC License
# http://opensource.org/licenses/ISC
# For full terms please read LICENSE included with this
# project
#
# Please read the README.md file for use and more information
#
# Project hosted on Github http://github.com/samsoir/libzmq-ios-universal
#
# Copyright (c) 2012 Sam de Freyssinet, some rights reserved
#
# NOTE:
# There will be an error before compiling ARM codes:
# configure: error: C preprocessor "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cpp" fails sanity check
# You have to modify file (change the SDK version number if need)
# /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk/usr/include/sys/cdefs.h
# and remove the following line (around the end of file)
# #error Unsupported architecture
# before compile. (You can add back later)
set -e
# set -x # show executed command
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
GLOBAL_OUTDIR=$CURRENT_DIR/dependencies
BUILD_DIR=$CURRENT_DIR/build
LIBZMQ_DIR=$CURRENT_DIR/zeromq
LIBZMQ_FILE="libzmq.a"
LIBZMQ_ARMV7_PREFIX="armv7"
LIBZMQ_ARMV7S_PREFIX="armv7s"
LIBZMQ_ARM64_PREFIX="arm64"
LIBZMQ_I686_PREFIX="i386"
LIBZMQ_UNIVERSAL_FILE="libzmq.a"
LIBZMQ_UNIVERSAL_PREFIX="universal"
ZMQ_BUILD_LOG_FILE=$BUILD_DIR/build.log
IOS_BASE_SDK="7.0"
IOS_DEPLOY_TARGET="4.0"
VERSION_NUMBER="5.0.0" # Xcode 5
print_help_text ()
{
cat << EOF
Usage: $0 [options]
Build libzmq as an iOS Universal (fat) static library
for use with the iOS Simulator (i386) and iOS device
(armv7, armv7s) architectures.
Options:
-h show this message and exit
-v show version number and exit
-l libzmq configure autoconf location. e.g. /tmp/zeromq-3.2.2
If not supplied assumes ${LIBZMQ_DIR}
Requires:
libzmq 3.2.2 or later, plus libzmq required libraries
listed on zeromq download page http://www.zeromq.org/area:download
Xcode 4.3.3 or later, to discover your version type;
"xcodebuild -version"
EOF
exit 1
}
print_version_number ()
{
echo "$0 version ${VERSION_NUMBER}"
echo "Copyright (c) 2012 Sam de Freyssinet, same rights reserved"
exit 0
}
copy_zmq_headers ()
{
echo "Copying libzmq headers into universal library..."
mkdir -p ${BUILD_DIR}/${LIBZMQ_UNIVERSAL_PREFIX}/include
cp -R ${LIBZMQ_DIR}/include ${BUILD_DIR}/${LIBZMQ_UNIVERSAL_PREFIX}
}
create_universal_library ()
{
echo "Creating universal static library"
mkdir -p ${BUILD_DIR}/${LIBZMQ_UNIVERSAL_PREFIX}/lib
lipo -create "${BUILD_DIR}/${LIBZMQ_ARMV7_PREFIX}/lib/${LIBZMQ_FILE}" "${BUILD_DIR}/${LIBZMQ_ARMV7S_PREFIX}/lib/${LIBZMQ_FILE}" "${BUILD_DIR}/${LIBZMQ_ARM64_PREFIX}/lib/${LIBZMQ_FILE}" "${BUILD_DIR}/${LIBZMQ_I686_PREFIX}/lib/${LIBZMQ_FILE}" -output "${BUILD_DIR}/${LIBZMQ_UNIVERSAL_PREFIX}/lib/${LIBZMQ_FILE}"
copy_zmq_headers
}
clean_build_dir ()
{
echo "Initializing build directory..."
if [[ -d ${BUILD_DIR} ]]; then
rm -rf ${BUILD_DIR}
fi
}
clean_dependency_dir ()
{
echo "Initializing dependency directory..."
if [[ -d ${GLOBAL_OUTDIR} ]]; then
rm -rf ${GLOBAL_OUTDIR}
fi
mkdir -p ${GLOBAL_OUTDIR}/include ${GLOBAL_OUTDIR}/lib
}
tidy_up ()
{
echo "Tidying up..."
cd ${LIBZMQ_DIR}
make distclean >> ${ZMQ_BUILD_LOG_FILE}
cd ${CURRENT_DIR}
}
setenv_all ()
{
export CPP=`xcrun -find cpp`
export CC=`xcrun -find clang`
export CXXCPP=`xcrun -find cpp`
export CXX=`xcrun -find clang++`
export AR=`xcrun -find ar`
export AS=`xcrun -find as`
export LD=`xcrun -find ld`
export LDFLAGS="-L${SDKROOT}/usr/lib"
export LIBTOOL=`xcrun -find libtool`
export STRIP=`xcrun -find strip`
export RANLIB=`xcrun -find ranlib`
export CFLAGS="${CFLAGS}" # -I${GLOBAL_OUTDIR}/include -L${GLOBAL_OUTDIR}/lib"
export CXXFLAGS=${CFLAGS}
}
setenv_iphone ()
{
unset BUILD_HOST DEVROOT SDKROOT CFLAGS CC LD CPP CXX AR AS NM RANLIB LDFLAGS CXXFLAGS
export ARCH=$1
export DEVROOT="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer"
export SDKROOT=${DEVROOT}/SDKs/iPhoneOS${IOS_BASE_SDK}.sdk
export CFLAGS="-arch ${ARCH} -pipe -no-cpp-precomp -isysroot ${SDKROOT} -miphoneos-version-min=${IOS_DEPLOY_TARGET} -I{$SDKROOT}/usr/include/"
export BUILD_HOST="arm-apple-darwin"
setenv_all
}
setenv_simulator ()
{
unset BUILD_HOST DEVROOT SDKROOT CFLAGS CC LD CPP CXX AR AS NM RANLIB LDFLAGS CXXFLAGS
export ARCH=$1
export DEVROOT="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer"
export SDKROOT=${DEVROOT}/SDKs/iPhoneSimulator${IOS_BASE_SDK}.sdk
export CFLAGS="-arch ${ARCH} -pipe -no-cpp-precomp -isysroot ${SDKROOT} -miphoneos-version-min=${IOS_DEPLOY_TARGET} -I${SDKROOT}/usr/include/"
export BUILD_HOST="i686-apple-darwin"
setenv_all
}
compile_iphone ()
{
echo "Compiling libzmq for "$1"..."
mkdir -p ${BUILD_DIR}/$1
setenv_iphone $1
compile_zmq $1
}
compile_simulator ()
{
echo "Compiling libzmq for "$1"..."
mkdir -p ${BUILD_DIR}/$1
setenv_simulator $1
compile_zmq $1
}
compile_zmq ()
{
cd ${LIBZMQ_DIR}
./configure --disable-dependency-tracking --enable-static --disable-shared --host=${BUILD_HOST} --prefix=${BUILD_DIR}/$1 >> ${ZMQ_BUILD_LOG_FILE}
make >> ${ZMQ_BUILD_LOG_FILE}
make install >> ${ZMQ_BUILD_LOG_FILE}
make clean >> ${ZMQ_BUILD_LOG_FILE}
lipo -info ${BUILD_DIR}/$1/lib/libzmq.a
}
print_completion_text ()
{
cat << EOF
Finished compiling libzmq as a static library for iOS.
Universal library can be found in build/universal;
"lib" folder contains "libzmq.a" static library
"include" folder contains headers
To use in your project follow linking instructions
available on the iOS zeromq page
http://www.zeromq.org/build:iphone
EOF
}
begin_compile ()
{
clean_build_dir
clean_dependency_dir
compile_iphone ${LIBZMQ_ARMV7_PREFIX}
compile_iphone ${LIBZMQ_ARMV7S_PREFIX}
compile_iphone ${LIBZMQ_ARM64_PREFIX}
compile_simulator ${LIBZMQ_I686_PREFIX}
create_universal_library
tidy_up
print_completion_text
exit 0
}
print_unable_to_find_libzmq ()
{
echo "Unable to locate libzmq in ${LIBZMQ_DIR}"
exit 1
}
verify_libzmq_location ()
{
if [[ ! -f "${LIBZMQ_DIR}/configure" ]] || [[ ! -f "${LIBZMQ_DIR}/zeromq.spec" ]]; then
print_unable_to_find_libzmq
fi
}
while getopts ":hvl:" OPTION
do
case ${OPTION} in
h)
print_help_text
;;
v)
print_version_number
;;
l)
LIBZMQ_DIR=${OPTARG}
;;
esac
done
verify_libzmq_location
begin_compile