forked from rbouqueau/zenbuild
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathbuild_libsdl2.sh
698 lines (586 loc) · 13.5 KB
/
build_libsdl2.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
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
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
#!/bin/bash
# This file was generated by zenbuild,
# with the following command:
# ./make-extra.sh libsdl2
#
# This script builds the following packages:
# - libsdl2
#
function libsdl2_get_deps {
local a=0
}
function libsdl2_build {
local host=$1
pushDir $WORK/src
lazy_download "libsdl2.tar.gz" "https://www.libsdl.org/release/SDL2-2.0.4.tar.gz"
lazy_extract "libsdl2.tar.gz"
mkgit "libsdl2"
pushDir "libsdl2"
applyPatch $scriptDir/patches/libsdl2_01_D3D11Declarations.diff
popDir
autoconf_build $host "libsdl2"
popDir
}
#####################################
# ZenBuild utility functions
#####################################
set -e
function prefixLog {
pfx=$1
shift
"$@" 2>&1 | sed -u "s/^.*$/$pfx&/"
}
function printMsg
{
echo -n "[32m"
echo $*
echo -n "[0m"
}
function isMissing
{
progName=$1
echo -n "Checking for $progName ... "
if which $progName 1>/dev/null 2>/dev/null; then
echo "ok"
return 1
else
return 0
fi
}
function installErrorHandler
{
trap "printMsg 'Spawning a rescue shell in current build directory'; PS1='\\w: rescue$ ' bash --norc" EXIT
}
function uninstallErrorHandler
{
trap - EXIT
}
function lazy_download
{
local file="$1"
local url="$2"
if [ ! -e "$CACHE/$file" ]; then
echo "Downloading: $file"
wget "$url" -c -O "$CACHE/${file}.tmp" --no-verbose
mv "$CACHE/${file}.tmp" "$CACHE/$file"
fi
}
function lazy_extract
{
local archive="$1"
echo -n "Extracting $archive ... "
local name=$(basename $archive .tar.gz)
name=$(basename $name .tar.bz2)
name=$(basename $name .tar.xz)
local tar_cmd="tar"
if [ $(uname -s) == "Darwin" ]; then
tar_cmd="gtar"
fi
if [ -d $name ]; then
echo "already extracted"
else
rm -rf ${name}.tmp
mkdir ${name}.tmp
$tar_cmd -C ${name}.tmp -xlf "$CACHE/$archive" --strip-components=1
mv ${name}.tmp $name
echo "ok"
fi
}
function lazy_git_clone {
local url="$1"
local to="$2"
local rev="$3"
if [ -d "$to" ] ;
then
pushDir "$to"
git reset -q --hard
git clean -q -f
popDir
else
git clone "$url" "$to"
fi
pushDir "$to"
git checkout -q $rev
popDir
}
function mkgit {
dir="$1"
pushDir "$dir"
if [ -d ".git" ]; then
printMsg "Restoring $dir from git restore point"
git reset -q --hard
git clean -q -f
else
printMsg "Creating git for $dir"
git init
git config user.email "nobody@localhost"
git config user.name "Nobody"
git config core.autocrlf false
git add -f *
git commit -m "MinGW/GDC restore point"
fi
popDir
}
function applyPatch {
local patchFile=$1
printMsg "Patching $patchFile"
if [ $(uname -s) == "Darwin" ]; then
patch --no-backup-if-mismatch -p1 -i $patchFile
else
patch --no-backup-if-mismatch --merge -p1 -i $patchFile
fi
}
function main {
BUILD=$($scriptDir/config.guess | sed 's/-unknown//' | sed 's/-msys$/-mingw32/')
local packageName=$2
local hostPlatform=$3
if [ -z "$1" ] || [ -z "$packageName" ] || [ -z "$hostPlatform" ] ; then
echo "Usage: $0 <workDir> <packageName> <hostPlatform|->"
echo "Example: $0 /tmp/work libav i686-w64-mingw32"
echo "Example: $0 /tmp/work gpac -"
exit 1
fi
mkdir -p "$1"
WORK=$(get_abs_dir "$1")
if echo $PATH | grep " " ; then
echo "Your PATH contain spaces, this may cause build issues."
echo "Please clean-up your PATH and retry."
echo "Example:"
echo "$ PATH=/mingw32/bin:/bin:/usr/bin ./zenbuild.sh <options>"
exit 3
fi
printMsg "Building in: $WORK"
printMsg "Build platform: $BUILD"
printMsg "Target platform: $hostPlatform"
if [ $hostPlatform = "-" ]; then
hostPlatform=$BUILD
fi
initSymlinks
checkForCrossChain "$BUILD" "$hostPlatform"
checkForCommonBuildTools
CACHE=$WORK/cache
mkdir -p $CACHE
mkdir -p $WORK/src
export PREFIX="$WORK/release"
for dir in "lib" "bin" "include"
do
mkdir -p "$PREFIX/${hostPlatform}/${dir}"
done
initCflags
installErrorHandler
build ${hostPlatform} ${packageName}
uninstallErrorHandler
}
function initSymlinks {
local symlink_dir=$WORK/symlinks
mkdir -p $symlink_dir
local tools="gcc g++ ar as nm strings strip"
case $hostPlatform in
*darwin*)
echo "Detected new Darwin host ($host): disabling ranlib"
;;
*)
tools="$tools ranlib"
;;
esac
for tool in $tools
do
local dest=$symlink_dir/$hostPlatform-$tool
if [ ! -f $dest ]; then
ln -s $(which $tool) $dest
fi
done
export PATH=$PATH:$symlink_dir
}
function initCflags {
# avoid interferences from environment
unset CC
unset CXX
unset CFLAGS
unset CXXFLAGS
unset LDFLAGS
CFLAGS="-O2"
CXXFLAGS="-O2"
LDFLAGS="-s"
CFLAGS+=" -w"
CXXFLAGS+=" -w"
if [ $(uname -s) != "Darwin" ]; then
LDFLAGS+=" -static-libgcc"
LDFLAGS+=" -static-libstdc++"
fi
export CFLAGS
export CXXFLAGS
export LDFLAGS
if [ $(uname -s) == "Darwin" ]; then
local cores=$(sysctl -n hw.logicalcpu)
else
local cores=$(nproc)
fi
if [ -z "$MAKE" ]; then
MAKE="make -j$cores"
fi
export MAKE
}
function importPkgScript {
local name=$1
if ! test -f zen-${name}.sh; then
echo "Package $name does not have a zenbuild script"
exit 1
fi
source zen-${name}.sh
}
function lazy_build {
local host=$1
local name=$2
export PKG_CONFIG_PATH=$PREFIX/$host/lib/pkgconfig
export PKG_CONFIG_LIBDIR=$PREFIX/$host/lib/pkgconfig
if is_built $host $name ; then
printMsg "$name: already built"
return
fi
printMsg "$name: building ..."
local deps=$(${name}_get_deps)
for depName in $deps ; do
build $host $depName
done
${name}_build $host
printMsg "$name: build OK"
mark_as_built $host $name
}
function mark_as_built {
local host=$1
local name=$2
local flagfile="$WORK/flags/$host/${name}.built"
mkdir -p $(dirname $flagfile)
touch $flagfile
}
function is_built {
local host=$1
local name=$2
local flagfile="$WORK/flags/$host/${name}.built"
if [ -f "$flagfile" ] ;
then
return 0
else
return 1
fi
}
function autoconf_build {
local host=$1
shift
local name=$1
shift
if [ ! -f $name/configure ] ; then
printMsg "WARNING: package '$name' has no configure script, running autoreconf"
pushDir $name
autoreconf -i
popDir
fi
rm -rf $name/build/$host
mkdir -p $name/build/$host
pushDir $name/build/$host
../../configure \
--build=$BUILD \
--host=$host \
--prefix=$PREFIX/$host \
"$@"
$MAKE
$MAKE install
popDir
}
function build {
local host=$1
local name=$2
lazy_build $host $name
}
function pushDir {
local dir="$1"
pushd "$dir" 1>/dev/null 2>/dev/null
}
function popDir {
popd 1>/dev/null 2>/dev/null
}
function get_cross_prefix {
local build=$1
local host=$2
if [ "$host" = "-" ] ; then
echo ""
else
echo "$host-"
fi
}
function checkForCrossChain {
local build=$1
local host=$2
local error="0"
local cross_prefix=$(get_cross_prefix $build $host)
# ------------- GCC -------------
if isMissing "${cross_prefix}g++" ; then
echo "No ${cross_prefix}g++ was found in the PATH."
error="1"
fi
if isMissing "${cross_prefix}gcc" ; then
echo "No ${cross_prefix}gcc was found in the PATH."
error="1"
fi
# ------------- Binutils -------------
if isMissing "${cross_prefix}nm" ; then
echo "No ${cross_prefix}nm was found in the PATH."
error="1"
fi
if isMissing "${cross_prefix}ar" ; then
echo "No ${cross_prefix}ar was found in the PATH."
error="1"
fi
if [ $(uname -s) != "Darwin" ]; then
if isMissing "${cross_prefix}ranlib" ; then
echo "No ${cross_prefix}ranlib was found in the PATH."
error="1"
fi
fi
if isMissing "${cross_prefix}strip" ; then
echo "No ${cross_prefix}strip was found in the PATH."
error="1"
fi
if isMissing "${cross_prefix}strings" ; then
echo "No ${cross_prefix}strings was found in the PATH."
error="1"
fi
if isMissing "${cross_prefix}as" ; then
echo "No ${cross_prefix}as was found in the PATH."
error="1"
fi
local os=$(get_os "$host")
if [ $os == "mingw32" ] ; then
if isMissing "${cross_prefix}dlltool" ; then
echo "No ${cross_prefix}dlltool was found in the PATH."
error="1"
fi
if isMissing "${cross_prefix}windres" ; then
echo "No ${cross_prefix}windres was found in the PATH."
error="1"
fi
fi
if [ $error == "1" ] ; then
exit 1
fi
}
function checkForCommonBuildTools {
local error="0"
if isMissing "pkg-config"; then
echo "pkg-config not installed. Please install with:"
echo "pacman -S pkgconfig"
echo "or"
echo "apt-get install pkg-config"
echo ""
error="1"
fi
if isMissing "patch"; then
echo "patch not installed. Please install with:"
echo "pacman -S patch"
echo "or"
echo "apt-get install patch"
echo ""
error="1"
fi
if isMissing "python2"; then
echo "python2 not installed. Please install with:"
echo "pacman -S python2"
echo "or"
echo "apt-get install python2"
echo "or"
echo "port install python27 && ln -s /opt/local/bin/python2.7 /opt/local/bin/python2"
echo ""
error="1"
fi
if isMissing "autoreconf"; then
echo "autoreconf not installed. Please install with:"
echo "pacman -S autoconf"
echo "or"
echo "apt-get install autoconf"
echo "or"
echo "port install autoconf"
echo ""
error="1"
exit 1
fi
if isMissing "aclocal"; then
echo "aclocal not installed. Please install with:"
echo "pacman -S automake"
echo "or"
echo "apt-get install automake"
echo "or"
echo "port install automake"
echo ""
error="1"
exit 1
fi
if isMissing "libtool"; then
echo "libtool not installed. Please install with:"
echo "pacman -S msys/libtool"
echo "or"
echo "apt-get install libtool libtool-bin"
echo ""
error="1"
fi
# We still need to check that on Mac OS
if [ $(uname -s) == "Darwin" ]; then
if isMissing "glibtool"; then
echo "libtool is not installed. Please install with:"
echo "brew install libtool"
echo "or"
echo "port install libtool"
echo ""
error="1"
fi
fi
if isMissing "make"; then
echo "make not installed. Please install with:"
echo "pacman -S make"
echo "or"
echo "apt-get install make"
echo ""
error="1"
fi
if isMissing "cmake"; then
echo "make not installed. Please install with:"
echo "pacman -S mingw-cmake"
echo "or"
echo "apt-get install cmake"
echo ""
error="1"
fi
if isMissing "autopoint"; then
echo "autopoint not installed. Please install with:"
echo "pacman -S gettext gettext-devel"
echo "or"
echo "apt-get install autopoint"
echo ""
error="1"
fi
if isMissing "msgfmt"; then
echo "msgfmt not installed. Please install with:"
echo "pacman -S gettext gettext-devel"
echo "or"
echo "apt-get install gettext"
echo ""
error="1"
fi
if isMissing "yasm"; then
echo "yasm not installed. Please install with:"
echo "apt-get install yasm"
echo ""
error="1"
fi
if isMissing "wget"; then
echo "wget not installed. Please install with:"
echo "pacman -S msys/wget"
echo "or"
echo "apt-get install wget"
echo "or"
echo "sudo port install wget"
echo ""
error="1"
fi
if [ $(uname -s) == "Darwin" ]; then
if isMissing "gsed"; then
echo "gsed not installed. Please install with:"
echo "brew install gnu-sed"
echo "or"
echo "port install gsed"
echo ""
error="1"
else
sed=gsed
fi
else
if isMissing "sed"; then
echo "sed not installed. Please install with:"
echo "pacman -S msys/sed"
echo "or"
echo "apt-get install sed"
echo ""
error="1"
else
sed=sed
fi
fi
if [ $(uname -s) == "Darwin" ]; then
if isMissing "gtar"; then
echo "gnu-tar not installed. Please install with:"
echo "brew install gnu-tar"
echo "or"
echo "port install gnutar && sudo ln -s /opt/local/bin/gnutar /opt/local/bin/gtar"
echo ""
error="1"
fi
else
if isMissing "tar"; then
echo "tar not installed. Please install with:"
echo "mingw-get install tar"
echo "or"
echo "apt-get install tar"
echo ""
error="1"
fi
fi
if isMissing "xz"; then
echo "xz is not installed. Please install with:"
echo "apt-get install xz"
echo "or"
echo "brew install xz"
echo ""
error="1"
fi
if isMissing "git" ; then
echo "git not installed. Please install with:"
echo "pacman -S mingw-git"
echo "or"
echo "apt-get install git"
echo ""
error="1"
fi
if isMissing "hg" ; then
echo "hg not installed. Please install with:"
echo "pacman -S msys/mercurial"
echo "or"
echo "apt-get install mercurial"
echo ""
error="1"
fi
if isMissing "svn" ; then
echo "svn not installed. Please install with:"
echo "pacman -S msys/subversion"
echo "or"
echo "apt-get install subversion"
echo ""
error="1"
fi
if isMissing "gperf" ; then
echo "gperf not installed. Please install with:"
echo "pacman -S msys/gperf"
echo "or"
echo "apt-get install gperf"
echo ""
error="1"
fi
if [ $error == "1" ] ; then
exit 1
fi
}
function get_arch {
host=$1
echo $host | sed "s/-.*//"
}
function get_os {
host=$1
echo $host | sed "s/.*-//"
}
function get_abs_dir {
local relDir="$1"
pushDir $relDir
pwd
popDir
}
scriptDir=$(get_abs_dir $(dirname $0))
main extra libsdl2 $1