aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts/prepare-ctemplate-ios.sh
blob: 228f229441f785a8f957385ee0355c5ddbfbf35f (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
170
171
#!/bin/sh

url="https://github.com/dinhviethoa/ctemplate"

if xcodebuild -showsdks|grep iphoneos8.1 >/dev/null ; then
	sdkversion=8.1
    MARCHS="armv7 armv7s arm64"
elif xcodebuild -showsdks|grep iphoneos8.0 >/dev/null ; then
	sdkversion=8.0
    MARCHS="armv7 armv7s arm64"
elif xcodebuild -showsdks|grep iphoneos7.1 >/dev/null ; then
	sdkversion=7.1
    MARCHS="armv7 armv7s arm64"
elif xcodebuild -showsdks|grep iphoneos7.0 >/dev/null ; then
 	sdkversion=7.0
    MARCHS="armv7 armv7s arm64"
elif xcodebuild -showsdks|grep iphoneos6.1 >/dev/null ; then
	sdkversion=6.1
    MARCHS="armv7 armv7s"
else
	echo SDK not found
	exit 1
fi	

pushd `dirname $0` > /dev/null
scriptpath=`pwd`
popd > /dev/null
builddir="$scriptpath/../Externals/builds"

#builddir="$HOME/MailCore-Builds/dependencies"
BUILD_TIMESTAMP=`date +'%Y%m%d%H%M%S'`
tempbuilddir="$builddir/workdir/$BUILD_TIMESTAMP"
mkdir -p "$tempbuilddir"
srcdir="$tempbuilddir/src"
logdir="$tempbuilddir/log"
resultdir="$builddir/builds"
tmpdir="$tempbuilddir/tmp"

mkdir -p "$resultdir"
mkdir -p "$logdir"
mkdir -p "$tmpdir"
mkdir -p "$srcdir"

pushd . >/dev/null
mkdir -p "$builddir/downloads"
cd "$builddir/downloads"
if test -d ctemplate ; then
	cd ctemplate
	git pull --rebase
else
	git clone $url
	cd ctemplate
fi
version=`git rev-parse HEAD | cut -c1-10`
build_version="$version~2"

if test -f "$resultdir/ctemplate-ios-$build_version.zip" ; then
	echo install from cache
	popd >/dev/null
	rm -rf ../Externals/ctemplate-ios
	mkdir -p ../Externals/tmp
	unzip -q "$resultdir/ctemplate-ios-$build_version.zip" -d ../Externals/tmp
	mv "../Externals/tmp/ctemplate-ios-$build_version/ctemplate-ios" ../Externals
  mkdir -p ../Externals/installed
  ln -sf "$resultdir/ctemplate-ios-$build_version.zip" ../Externals/installed
	rm -rf ../Externals/tmp
	exit 0
fi
popd >/dev/null

pushd . >/dev/null

cp -R "$builddir/downloads/ctemplate" "$srcdir/ctemplate"
echo building ctemplate
cd "$srcdir/ctemplate"

TOOLCHAIN=`xcode-select -p`/Toolchains/XcodeDefault.xctoolchain/usr/bin
export CC=$TOOLCHAIN/clang
export CXX=$TOOLCHAIN/clang++

sdk="iphoneos$sdkversion"
sysroot="`xcode-select -p`/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS$sdkversion.sdk"

ARCH=arm
for MARCH in $MARCHS; do
  echo build for $MARCH
  echo "$logdir/ctemplate-build.log"
  export CPPFLAGS="-arch ${MARCH} -isysroot $sysroot -miphoneos-version-min=$sdkversion"
  export CFLAGS="$CPPFLAGS"
  export CXXFLAGS="$CFLAGS -stdlib=libc++"
  export LDFLAGS="-lstdc++ -stdlib=libc++"
  
  ./configure --host=${ARCH} --disable-shared --disable-dependency-tracking >> "$logdir/ctemplate-build.log"
  make >> "$logdir/ctemplate-build.log"
  make install-libLTLIBRARIES "prefix=$tmpdir/bin/ctemplate-ios/$sdk/$MARCH" >> "$logdir/ctemplate-build.log"
  if test x$? != x0 ; then
    echo build of ctemplate failed
    exit 1
  fi
  make install-nodist_ctemplateincludeHEADERS "prefix=$tmpdir/bin/ctemplate-ios" >> "$logdir/ctemplate-build.log"
  if test x$? != x0 ; then
  	echo install of ctemplate failed
  	exit 1
  fi
  make distclean
  find . -name *.o | xargs rm
  find . -name config.cache -print0 | xargs -0 rm
done

sdk="iphonesimulator$sdkversion"
sysroot="`xcode-select -p`/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator$sdkversion.sdk"

ARCH=i386
MARCHS="i386 x86_64"

for MARCH in $MARCHS; do
  echo build for $MARCH
  echo "$logdir/ctemplate-build.log"
  export CPPFLAGS="-arch ${MARCH} -isysroot $sysroot -miphoneos-version-min=$sdkversion"
  export CFLAGS="$CPPFLAGS"
  export CXXFLAGS="$CFLAGS -stdlib=libc++"
  export LDFLAGS="-lstdc++ -stdlib=libc++"
  
  ./configure --host=${MARCH} --disable-shared --disable-dependency-tracking >> "$logdir/ctemplate-build.log"
  make >> "$logdir/ctemplate-build.log"
  make install-libLTLIBRARIES "prefix=$tmpdir/bin/ctemplate-ios/$sdk/$MARCH" >> "$logdir/ctemplate-build.log"
  if test x$? != x0 ; then
    echo build of ctemplate failed
    exit 1
  fi
  make install-nodist_ctemplateincludeHEADERS "prefix=$tmpdir/bin/ctemplate-ios" >> "$logdir/ctemplate-build.log"
  if test x$? != x0 ; then
  	echo install of ctemplate failed
  	exit 1
  fi
  make distclean
  find . -name *.o | xargs rm
  find . -name config.cache -print0 | xargs -0 rm
done

echo finished

cd "$tmpdir/bin"
mkdir -p "ctemplate-ios-$build_version/ctemplate-ios/lib"
mv ctemplate-ios/include "ctemplate-ios-$build_version/ctemplate-ios"
lipo -create ctemplate-ios/iphonesimulator$sdkversion/i386/lib/libctemplate.a \
  ctemplate-ios/iphonesimulator$sdkversion/x86_64/lib/libctemplate.a \
  ctemplate-ios/iphoneos$sdkversion/armv7/lib/libctemplate.a \
  ctemplate-ios/iphoneos$sdkversion/armv7s/lib/libctemplate.a \
  ctemplate-ios/iphoneos$sdkversion/arm64/lib/libctemplate.a \
  -output "ctemplate-ios-$build_version/ctemplate-ios/lib/libctemplate-ios.a"
rm -f "$resultdir/ctemplate-ios-$build_version.zip"
zip -qry "$resultdir/ctemplate-ios-$build_version.zip" "ctemplate-ios-$build_version"
rm -f "$resultdir/ctemplate-ios-latest.zip"
cd "$resultdir"
ln -s "ctemplate-ios-$build_version.zip" "ctemplate-ios-latest.zip"

echo build of ctemplate-ios-$build_version done
echo $tmpdir

popd >/dev/null

rm -rf ../Externals/ctemplate-ios
mkdir -p ../Externals/tmp
unzip -q "$resultdir/ctemplate-ios-$build_version.zip" -d ../Externals/tmp
mv "../Externals/tmp/ctemplate-ios-$build_version/ctemplate-ios" ../Externals
rm -rf ../Externals/tmp

echo cleaning
rm -rf "$tempbuilddir"
echo "$tempbuilddir"