aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts/include.sh/build-dep.sh
blob: e7724e66788735405f7a7319a6c8cbc4e94dd9bf (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
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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
#!/bin/sh

build_git_ios()
{
  if test "x$name" = x ; then
    return
  fi

  simarchs="i386 x86_64"
  sdkminversion="7.0"
  sdkversion="`xcodebuild -showsdks 2>/dev/null | grep iphoneos | sed 's/.*iphoneos\(.*\)/\1/'`"
  devicearchs="armv7 armv7s arm64"

  versions_path="$scriptpath/deps-versions.plist"
  version="`defaults read "$versions_path" "$name" 2>/dev/null`"
  version="$(($version+1))"
  if test x$build_for_external = x1 ; then
    version=0
  fi

  if test x$build_for_external = x1 ; then
    builddir="$scriptpath/../Externals/tmp/dependencies"
  else
    builddir="$HOME/MailCore-Builds/dependencies"
  fi
  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"

  echo "working in $tempbuilddir"

  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 "$name" ; then
    cd "$name"
    git checkout master
    git pull --rebase
  else
    git clone $url "$name"
    cd "$name"
  fi
  #version=`echo $rev | cut -c1-10`

  popd >/dev/null

  pushd . >/dev/null

  cp -R "$builddir/downloads/$name" "$srcdir/$name"
  cd "$srcdir/$name"
  if test "x$branch" != x ; then
    if ! git checkout -b "$branch" "origin/$branch" ; then
      git checkout "$branch"
    fi
  fi
  git checkout -q $rev
  echo building $name $version - $rev

  BITCODE_FLAGS="-fembed-bitcode"
  if test "x$NOBITCODE" != x ; then
     BITCODE_FLAGS=""
     XCODE_BITCODE_FLAGS="ENABLE_BITCODE=NO"
  fi
  XCTOOL_OTHERFLAGS='$(inherited)'
  XCTOOL_OTHERFLAGS="$XCTOOL_OTHERFLAGS $BITCODE_FLAGS"
  cd "$srcdir/$name/build-mac"
  sdk="iphoneos$sdkversion"
  echo building $sdk
  xctool -project "$xcode_project" -sdk $sdk -scheme "$xcode_target" -configuration Release SYMROOT="$tmpdir/bin" OBJROOT="$tmpdir/obj" ARCHS="$devicearchs" IPHONEOS_DEPLOYMENT_TARGET="$sdkminversion" OTHER_CFLAGS="$XCTOOL_OTHERFLAGS" $XCODE_BITCODE_FLAGS
  if test x$? != x0 ; then
    echo failed
    exit 1
  fi
  sdk="iphonesimulator$sdkversion"
  echo building $sdk
  xctool -project "$xcode_project" -sdk $sdk -scheme "$xcode_target" -configuration Release SYMROOT="$tmpdir/bin" OBJROOT="$tmpdir/obj" ARCHS="$simarchs" IPHONEOS_DEPLOYMENT_TARGET="$sdkminversion" OTHER_CFLAGS='$(inherited)'
  if test x$? != x0 ; then
    echo failed
    exit 1
  fi
  echo finished

  if echo $library|grep '\.framework$'>/dev/null ; then
    cd "$tmpdir/bin/Release"
    defaults write "$tmpdir/bin/Release/$library/Resources/Info.plist" "git-rev" "$rev"
    mkdir -p "$resultdir/$name"
    zip -qry "$resultdir/$name/$name-$version.zip" "$library"
  else
    cd "$tmpdir/bin"
    mkdir -p "$name-$version/$name"
    mkdir -p "$name-$version/$name/lib"
    if test x$build_mailcore = x1 ; then
      mkdir -p "$name-$version/$name/include"
      mv Release-iphoneos/include/MailCore "$name-$version/$name/include"
    else
      mv Release-iphoneos/include "$name-$version/$name"
    fi
    lipo -create "Release-iphoneos/$library" \
      "Release-iphonesimulator/$library" \
        -output "$name-$version/$name/lib/$library"
    for dep in $embedded_deps ; do
      if test -d "$srcdir/$name/build-mac/$dep" ; then
        mv "$srcdir/$name/build-mac/$dep" "$name-$version"
      elif test -d "$srcdir/$name/Externals/$dep" ; then
        mv "$srcdir/$name/Externals/$dep" "$name-$version"
      else
        echo Dependency $dep not found
      fi
      if test x$build_mailcore = x1 ; then
        cp -R "$name-$version/$dep/lib" "$name-$version/$name"
        rm -rf "$name-$version/$dep"
      fi
    done
    if test x$build_mailcore = x1 ; then
      mv "$name-$version/$name/lib" "$name-$version"
      mv "$name-$version/$name/include" "$name-$version"
      rm -rf "$name-$version/$name"
      libtool -static -o "$name-$version/$library" "$name-$version/lib"/*.a
      rm -rf "$name-$version/lib"
      mkdir -p "$name-$version/lib"
      mv "$name-$version/$library" "$name-$version/lib"
    fi
    echo "$rev"> "$name-$version/git-rev"
    if test x$build_for_external = x1 ; then
      mkdir -p "$scriptpath/../Externals"
      cp -R "$name-$version"/* "$scriptpath/../Externals"
      rm -f "$scriptpath/../Externals/git-rev"
    else
      mkdir -p "$resultdir/$name"
      zip -qry "$resultdir/$name/$name-$version.zip" "$name-$version"
    fi
  fi

  echo build of $name-$version done

  popd >/dev/null

  echo cleaning
  rm -rf "$tempbuilddir"

  if test x$build_for_external != x1 ; then
    defaults write "$versions_path" "$name" "$version"
    plutil -convert xml1 "$versions_path"
  fi
}

build_git_osx()
{
  sdk="`xcodebuild -showsdks 2>/dev/null | grep macosx | sed 's/.*macosx\(.*\)/\1/'`"
  archs="x86_64"
  sdkminversion="10.7"
  
  if test "x$name" = x ; then
    return
  fi
  
  versions_path="$scriptpath/deps-versions.plist"
  version="`defaults read "$versions_path" "$name" 2>/dev/null`"
  version="$(($version+1))"
  if test x$build_for_external = x1 ; then
    version=0
  fi

  if test x$build_for_external = x1 ; then
    builddir="$scriptpath/../Externals/tmp/dependencies"
  else
    builddir="$HOME/MailCore-Builds/dependencies"
  fi
  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"

  echo "working in $tempbuilddir"

  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 "$name" ; then
  	cd "$name"
    git checkout master
  	git pull --rebase
  else
  	git clone $url "$name"
  	cd "$name"
  fi
  #version=`echo $rev | cut -c1-10`

  popd >/dev/null

  pushd . >/dev/null

  cp -R "$builddir/downloads/$name" "$srcdir/$name"
  cd "$srcdir/$name"
  if test "x$branch" != x ; then
    if ! git checkout -b "$branch" "origin/$branch" ; then
      git checkout "$branch"
    fi
  fi
  git checkout -q $rev
  echo building $name $version - $rev

  cd "$srcdir/$name/build-mac"
  xctool -project "$xcode_project" -sdk macosx$sdk -scheme "$xcode_target" -configuration Release ARCHS="$archs" SYMROOT="$tmpdir/bin" OBJROOT="$tmpdir/obj" MACOSX_DEPLOYMENT_TARGET="$sdkminversion"
  if test x$? != x0 ; then
    echo failed
    exit 1
  fi
  echo finished
  
  if echo $library|grep '\.framework$'>/dev/null ; then
    cd "$tmpdir/bin/Release"
    defaults write "$tmpdir/bin/Release/$library/Resources/Info.plist" "git-rev" "$rev"
    mkdir -p "$resultdir/$name"
    zip -qry "$resultdir/$name/$name-$version.zip" "$library"
  else
    cd "$tmpdir/bin"
    mkdir -p "$name-$version/$name"
    mkdir -p "$name-$version/$name/lib"
    if test x$build_mailcore = x1 ; then
      mkdir -p "$name-$version/$name/include"
      mv Release/include/MailCore "$name-$version/$name/include"
    else
      mv Release/include "$name-$version/$name"
    fi
    mv "Release/$library" "$name-$version/$name/lib"
    for dep in $embedded_deps ; do
      if test -d "$srcdir/$name/build-mac/$dep" ; then
        mv "$srcdir/$name/build-mac/$dep" "$name-$version"
      elif test -d "$srcdir/$name/Externals/$dep" ; then
        mv "$srcdir/$name/Externals/$dep" "$name-$version"
      else
        echo Dependency $dep not found
      fi
      if test x$build_mailcore = x1 ; then
        cp -R "$name-$version/$dep/lib" "$name-$version/$name"
        rm -rf "$name-$version/$dep"
      fi
    done
    if test x$build_mailcore = x1 ; then
      mv "$name-$version/$name/lib" "$name-$version"
      mv "$name-$version/$name/include" "$name-$version"
      rm -rf "$name-$version/$name"
      libtool -static -o "$name-$version/$library" "$name-$version/lib"/*.a
      rm -rf "$name-$version/lib"
      mkdir -p "$name-$version/lib"
      mv "$name-$version/$library" "$name-$version/lib"
    fi
    echo "$rev"> "$name-$version/git-rev"
    if test x$build_for_external = x1 ; then
      mkdir -p "$scriptpath/../Externals"
      cp -R "$name-$version"/* "$scriptpath/../Externals"
      rm -f "$scriptpath/../Externals/git-rev"
    else
      mkdir -p "$resultdir/$name"
      zip -qry "$resultdir/$name/$name-$version.zip" "$name-$version"
    fi
  fi

  echo build of $name-$version done

  popd >/dev/null

  echo cleaning
  #rm -rf "$tempbuilddir"

  if test x$build_for_external != x1 ; then
    defaults write "$versions_path" "$name" "$version"
    plutil -convert xml1 "$versions_path"
  fi
}

get_prebuilt_dep()
{
  url="http://d.etpan.org/mailcore2-deps"

  if test "x$name" = x ; then
    return
  fi
  
  versions_path="$scriptpath/deps-versions.plist"
  installed_versions_path="$scriptpath/installed-deps-versions.plist"
  if test ! -f "$versions_path" ; then
    build_for_external=1 "$scriptpath/build-$name.sh"
    return;
  fi
  
  installed_version="`defaults read "$installed_versions_path" "$name" 2>/dev/null`"
  if test ! -d "$scriptpath/../Externals/$name" ; then
    installed_version=
  fi
  if test "x$installed_version" = x ; then
    installed_version="none"
  fi
  version="`defaults read "$versions_path" "$name" 2>/dev/null`"

  echo $name, installed: $installed_version, required: $version
  if test "x$installed_version" = "x$version" ; then
    return
  fi

  BUILD_TIMESTAMP=`date +'%Y%m%d%H%M%S'`
  tempbuilddir="$scriptpath/../Externals/workdir/$BUILD_TIMESTAMP"
  
  mkdir -p "$tempbuilddir"
  cd "$tempbuilddir"
  echo "Downloading $name-$version"
  curl -O "$url/$name/$name-$version.zip"
  unzip -q "$name-$version.zip"
  rm -rf "$scriptpath/../Externals/$name"
  cd "$name-$version"
  for folder in * ; do
      rm -rf "$scriptpath/../Externals/$folder"
      mv "$folder" "$scriptpath/../Externals"
  done
  cd ..
  rm -f "$scriptpath/../Externals/git-rev"
  rm -rf "$tempbuilddir"
  
  if test -d "$scriptpath/../Externals/$name" ; then
    defaults write "$installed_versions_path" "$name" "$version"
    plutil -convert xml1 "$installed_versions_path"
  fi
}