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

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

if xcodebuild -showsdks|grep iphoneos6.1 >/dev/null ; then
	sdkversion=6.1
elif xcodebuild -showsdks|grep iphoneos7.0 >/dev/null ; then
	sdkversion=7.0
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`

if test -f "$resultdir/ctemplate-ios-$version.zip" ; then
	echo install from cache
	popd >/dev/null
	rm -rf ../Externals/ctemplate-ios
	mkdir -p ../Externals/tmp
	unzip -q "$resultdir/ctemplate-ios-$version.zip" -d ../Externals/tmp
	mv "../Externals/tmp/ctemplate-ios-$version/ctemplate-ios" ../Externals
  mkdir -p ../Externals/installed
  ln -sf "$resultdir/ctemplate-ios-$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=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
export CC=$TOOLCHAIN/clang
export CXX=$TOOLCHAIN/clang++

sdk="iphoneos$sdkversion"
sysroot="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS$sdkversion.sdk"

ARCH=arm
MARCHS="armv7 armv7s"
for MARCH in $MARCHS; do
  echo "$logdir/ctemplate-build.log"
  export CFLAGS="-arch ${MARCH} -isysroot $sysroot"
  export CXXFLAGS="$CFLAGS -stdlib=libstdc++ -std=gnu++11"
  export LDFLAGS="-lstdc++ -stdlib=libstdc++"
  
  ./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="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator$sdkversion.sdk"

ARCH=i386
MARCHS=i386

for MARCH in $MARCHS; do
  echo "$logdir/ctemplate-build.log"
  export CFLAGS="-arch ${MARCH} -isysroot $sysroot"
  export CXXFLAGS="$CFLAGS -stdlib=libstdc++ -std=gnu++11"
  export LDFLAGS="-lstdc++ -stdlib=libstdc++"
  
  ./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

echo finished

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

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

popd >/dev/null

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

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