This repository has been archived by the owner on Aug 29, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
libzmq.sh
executable file
·170 lines (146 loc) · 4.91 KB
/
libzmq.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
#!/bin/sh
# A script to download and build libzmq for iOS, including arm64
# Adapted from https://raw2.github.com/seb-m/CryptoPill/master/libsodium.sh
set -e
LIBNAME="libzmq.a"
ROOTDIR=`pwd`
#libsodium
LIBSODIUM_DIST="${ROOTDIR}/libsodium-ios/libsodium_dist/"
echo "Building dependency 'libsodium-ios'..."
cd libsodium-ios
bash libsodium.sh
cd $ROOTDIR
ARCHS=${ARCHS:-"armv7 armv7s arm64 i386 x86_64"}
DEVELOPER=$(xcode-select -print-path)
LIPO=$(xcrun -sdk iphoneos -find lipo)
#LIPO=lipo
# Script's directory
SCRIPTDIR=$( (cd -P $(dirname $0) && pwd) )
# libsodium root directory
LIBDIR="libzeromq"
mkdir -p $LIBDIR
LIBDIR=$( (cd "${LIBDIR}" && pwd) )
# Destination directory for build and install
DSTDIR=${SCRIPTDIR}
BUILDDIR="${DSTDIR}/libzmq_build"
DISTDIR="${DSTDIR}/libzmq_dist"
DISTLIBDIR="${DISTDIR}/lib"
TARVER=4.1.5
TARNAME="zeromq-$TARVER"
TARFILE=${TARNAME}.tar.gz
TARURL=https://github.com/zeromq/zeromq4-1/releases/download/v$TARVER/$TARFILE
# http://libwebp.webm.googlecode.com/git/iosbuild.sh
# Extract the latest SDK version from the final field of the form: iphoneosX.Y
SDK=$(xcodebuild -showsdks \
| grep iphoneos | sort | tail -n 1 | awk '{print substr($NF, 9)}'
)
IOS_VERSION_MIN=8.0
OTHER_LDFLAGS=""
OTHER_CFLAGS="-Os -Qunused-arguments"
# Enable Bitcode
OTHER_CPPFLAGS="-Os -I${LIBSODIUM_DIST}/include -fembed-bitcode"
OTHER_CXXFLAGS="-Os"
# Download and extract ZeroMQ
rm -rf $LIBDIR
set -e
curl -O -L $TARURL
tar xzf $TARFILE
rm $TARFILE
mv $TARNAME $LIBDIR
# Cleanup
if [ -d $BUILDDIR ]
then
rm -rf $BUILDDIR
fi
if [ -d $DISTDIR ]
then
rm -rf $DISTDIR
fi
mkdir -p $BUILDDIR $DISTDIR
# Generate autoconf files
cd ${LIBDIR}
#cd ${LIBDIR}; ./autogen.sh
# Iterate over archs and compile static libs
for ARCH in $ARCHS
do
BUILDARCHDIR="$BUILDDIR/$ARCH"
mkdir -p ${BUILDARCHDIR}
case ${ARCH} in
armv7)
PLATFORM="iPhoneOS"
HOST="${ARCH}-apple-darwin"
export BASEDIR="${DEVELOPER}/Platforms/${PLATFORM}.platform/Developer"
export ISDKROOT="${BASEDIR}/SDKs/${PLATFORM}${SDK}.sdk"
export CXXFLAGS="${OTHER_CXXFLAGS}"
export CPPFLAGS="-arch ${ARCH} -isysroot ${ISDKROOT} -mios-version-min=${IOS_VERSION_MIN} ${OTHER_CPPFLAGS}"
export LDFLAGS="-arch ${ARCH} -isysroot ${ISDKROOT} ${OTHER_LDFLAGS}"
;;
armv7s)
PLATFORM="iPhoneOS"
HOST="${ARCH}-apple-darwin"
export BASEDIR="${DEVELOPER}/Platforms/${PLATFORM}.platform/Developer"
export ISDKROOT="${BASEDIR}/SDKs/${PLATFORM}${SDK}.sdk"
export CXXFLAGS="${OTHER_CXXFLAGS}"
export CPPFLAGS="-arch ${ARCH} -isysroot ${ISDKROOT} -mios-version-min=${IOS_VERSION_MIN} ${OTHER_CPPFLAGS}"
export LDFLAGS="-arch ${ARCH} -isysroot ${ISDKROOT} ${OTHER_LDFLAGS}"
;;
arm64)
PLATFORM="iPhoneOS"
HOST="arm-apple-darwin"
export BASEDIR="${DEVELOPER}/Platforms/${PLATFORM}.platform/Developer"
export ISDKROOT="${BASEDIR}/SDKs/${PLATFORM}${SDK}.sdk"
export CXXFLAGS="${OTHER_CXXFLAGS}"
export CPPFLAGS="-arch ${ARCH} -isysroot ${ISDKROOT} -mios-version-min=${IOS_VERSION_MIN} ${OTHER_CPPFLAGS}"
export LDFLAGS="-arch ${ARCH} -isysroot ${ISDKROOT} ${OTHER_LDFLAGS}"
;;
i386)
PLATFORM="iPhoneSimulator"
HOST="${ARCH}-apple-darwin"
export BASEDIR="${DEVELOPER}/Platforms/${PLATFORM}.platform/Developer"
export ISDKROOT="${BASEDIR}/SDKs/${PLATFORM}${SDK}.sdk"
export CXXFLAGS="${OTHER_CXXFLAGS}"
export CPPFLAGS="-m32 -arch ${ARCH} -isysroot ${ISDKROOT} -mios-version-min=${IOS_VERSION_MIN} ${OTHER_CPPFLAGS}"
export LDFLAGS="-m32 -arch ${ARCH} ${OTHER_LDFLAGS}"
;;
x86_64)
PLATFORM="iPhoneSimulator"
HOST="${ARCH}-apple-darwin"
export BASEDIR="${DEVELOPER}/Platforms/${PLATFORM}.platform/Developer"
export ISDKROOT="${BASEDIR}/SDKs/${PLATFORM}${SDK}.sdk"
export CXXFLAGS="${OTHER_CXXFLAGS}"
export CPPFLAGS="-arch ${ARCH} -isysroot ${ISDKROOT} -mios-version-min=${IOS_VERSION_MIN} ${OTHER_CPPFLAGS}"
export LDFLAGS="-arch ${ARCH} ${OTHER_LDFLAGS}"
echo "LDFLAGS $LDFLAGS"
;;
*)
echo "Unsupported architecture ${ARCH}"
exit 1
;;
esac
export PATH="${DEVELOPER}/Toolchains/XcodeDefault.xctoolchain/usr/bin:${DEVELOPER}/Toolchains/XcodeDefault.xctoolchain/usr/sbin:$PATH"
echo "Configuring for ${ARCH}..."
set +e
cd ${LIBDIR} && make distclean
set -e
${LIBDIR}/configure \
--prefix=${BUILDARCHDIR} \
--disable-shared \
--enable-static \
--host=${HOST}\
--with-libsodium=${LIBSODIUM_DIST}
echo "Building ${LIBNAME} for ${ARCH}..."
cd ${LIBDIR}
make -j8 V=0
make install
LIBLIST+="${BUILDARCHDIR}/lib/${LIBNAME} "
done
# Copy headers and generate a single fat library file
mkdir -p ${DISTLIBDIR}
${LIPO} -create ${LIBLIST} -output ${DISTLIBDIR}/${LIBNAME}
for ARCH in $ARCHS
do
cp -R $BUILDDIR/$ARCH/include ${DISTDIR}
break
done
# Cleanup
rm -rf ${BUILDDIR}