forked from MythTV/packaging
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mythbuild.sh
2394 lines (2143 loc) · 79.8 KB
/
mythbuild.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
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash -e
# Build script for MythTV
# Created by Lawrence Rust, lvr at softsystem dot co dot uk
#
###############################################################################
# - On Windows 2k/XP/Vista/7 to build a native MythTV using the MSYS environment and MingGW
# http://sourceforge.net/projects/mingw/files
# # NB Min specs: 1GB (2GB for debug build) VM, physical RAM preferable, and 5GB disk
# Click:
# Automated MinGW Installer > mingw-get-inst
# Then select a version e.g.
# mingw-get-inst-20101030 > mingw-get-inst-20101030.exe
# NB latest mingw-get-inst-20110211.exe doesn't work on Win2K & XP
# Run the installer and ensure to add:
# C++
# MSYS basic system
# MinGW Developer Toolkit
# Start an Msys shell from the Windows desktop by clicking:
# Start > All Programs > MinGW > MinGW Shell"
# Copy this script to C:\MinGW\msys\1.0\home\[username]
# At the Msys prompt enter:
# ./mythbuild.sh
# or for a debug build type:
# ./mythbuild.sh -d
#
###############################################################################
# - On Linux to cross build a Windows installation using the MinGW C cross compiler from
# http://sourceforge.net/projects/mingw/files/Cross-Hosted%20MinGW%20Build%20Tool/
# Install the cross compiler. On Debian:
# sudo apt-get install mingw32
# On Fedora:
# sudo yum install mingw32-gcc.i686 mingw32-gcc-g++.i686
# You will also need the Gnu C/C++ compiler and these packages:
# wget patch git-core
# At a command prompt type:
# ./mythbuild.sh -W
# or for a debug build type:
# ./mythbuild.sh -W -d
#
###############################################################################
# - On Linux to cross build to MacOSX using Apple's gcc and odcctools from
# http://www.opensource.apple.com/tarballs/gcc/gcc-5247.tar.gz
# http://svn.macosforge.org/repository/odcctools/release/odcctools-20090808.tar.bz2
#
# You will need a C compiler and these packages:
# wget patch git-core
#
# Create the cross-tools folder:
# export PREFIX=/opt/mac
# sudo mkdir -p $PREFIX
# sudo chown $USER:$USER $PREFIX
# Build the cross compiler and tools:
# mkdir -p xtools && cd xtools
# wget http://www.softsystem.co.uk/download/mythtv/mkodcctools
# chmod +x mkodcctools
# ./mkodcctools
# Add the path to the cross tools:
# PATH=$PATH:$PREFIX/bin
# At a command prompt type:
# ./mythbuild.sh -M
# or for a debug build type:
# ./mythbuild.sh -M -d
#
###############################################################################
# - On Linux to build a native MythTV.
# You will need the Gnu C/C++ compiler collection and these packages:
# wget patch git-core
# At a command prompt type:
# ./mythbuild.sh -H
# or for a debug build type:
# ./mythbuild.sh -H -d
#
# For an optimised build:
# CFLAGS="-march=native -O2" CXXFLAGS="-march=native -O2" mythbuild.sh -r -c host
#
# Package dependecies:
# MythTV Xv: libxxf86vm-dev libxv-dev
# MythTV ALSA: libasound2-dev
# MythTV Perl: libnet-upnp-perl
# Qt DBus: libdbus-1-dev
#
# Host dependencies:
# Mac B/W G3: mythbuild.sh -c g3
readonly version="0.6"
# Myth code repo
: ${MYTHREPO:="http://mythtv-for-windows.googlecode.com/files"}
# Myth git repo
: ${MYTHGIT:="git://github.com/MythTV"}
# SourceForge auto mirror re-direct
: ${SOURCEFORGE:="downloads.sourceforge.net"}
# The libraries to be installed:
: ${PTHREADS:="pthreads-w32-2-8-0-release"}
: ${PTHREADS_URL:="ftp://sourceware.org/pub/pthreads-win32/$PTHREADS.tar.gz"}
: ${ZLIB:="zlib-1.2.5"}
: ${ZLIB_URL:="http://$SOURCEFORGE/project/libpng/zlib/${ZLIB/zlib-/}/$ZLIB.tar.gz"}
: ${FREETYPE:="freetype-2.4.3"}
: ${FREETYPE_URL:="http://download.savannah.gnu.org/releases/freetype/$FREETYPE.tar.gz"}
: ${LAME:="lame-3.98.4"}
: ${LAME_URL:="http://$SOURCEFORGE/project/lame/lame/${LAME/lame-/}/$LAME.tar.gz"}
: ${WINE:="wine-1.3.6"}
: ${WINE_URL:="http://$SOURCEFORGE/project/wine/Source/$WINE.tar.bz2"}
: ${DXVA2_URL:="http://download.videolan.org/pub/videolan/contrib/dxva2api.h"}
: ${LIBEXIF:="libexif-0.6.19"}
: ${LIBEXIF_URL:="http://$SOURCEFORGE/project/libexif/libexif/${LIBEXIF/libexif-/}/$LIBEXIF.tar.bz2"}
: ${LIBOGG:="libogg-1.2.1"}
: ${LIBOGG_URL:="http://downloads.xiph.org/releases/ogg/$LIBOGG.tar.bz2"}
: ${LIBVORBIS:="libvorbis-1.3.2"}
: ${LIBVORBIS_URL:="http://downloads.xiph.org/releases/vorbis/$LIBVORBIS.tar.bz2"}
: ${FLAC:="flac-1.2.1"}
: ${FLAC_URL:="http://$SOURCEFORGE/project/flac/flac-src/$FLAC-src/$FLAC.tar.gz"}
: ${LIBCDIO:="libcdio-0.82"}
: ${LIBCDIO_URL:="ftp://mirror.cict.fr/gnu/libcdio/$LIBCDIO.tar.gz"}
: ${TAGLIB:="taglib-1.6.3"}
: ${TAGLIB_URL:="http://developer.kde.org/~wheeler/files/src/$TAGLIB.tar.gz"}
: ${FFTW:="fftw-3.2.2"}
: ${FFTW_URL:="http://www.fftw.org/$FFTW.tar.gz"}
: ${LIBSDL:="SDL-1.2.14"}
: ${LIBSDL_URL:="http://www.libsdl.org/release/$LIBSDL.tar.gz"}
: ${LIBVISUAL:="libvisual-0.4.0"}
: ${LIBVISUAL_URL:="http://$SOURCEFORGE/project/libvisual/libvisual/$LIBVISUAL/$LIBVISUAL.tar.gz"}
: ${LIBDVDCSS:="libdvdcss-1.2.10"}
: ${LIBDVDCSS_URL:="http://download.videolan.org/pub/libdvdcss/${LIBDVDCSS/libdvdcss-/}/$LIBDVDCSS.tar.bz2"}
: ${LIBXML2:="libxml2-2.7.8"}
: ${LIBXML2_URL:="ftp://xmlsoft.org/libxml2/$LIBXML2.tar.gz"}
# 16-Dec-2010 latest: mysql-5.5.8
: ${MYSQL:="mysql-5.1.58"}
: ${MYSQL_URL:="http://mirrors.ircam.fr/pub/mysql/Downloads/MySQL-${MYSQL:6:3}/$MYSQL.tar.gz"}
# Pre-built win32 install. NB mysql-5.1 requires winXP-SP2, 5.0 works on win2k
: ${MYSQLW:="mysql-5.1.58-win32"}
: ${MYSQLW_URL:="ftp://mirrors.ircam.fr/pub/mysql/Downloads/MySQL-${MYSQLW:6:3}/${MYSQLW/mysql-/mysql-noinstall-}.zip"}
#: ${MYSQLW_URL:="ftp://ftp.mirrorservice.org/sites/ftp.mysql.com/Downloads/MySQL-${MYSQLW:6:3}/${MYSQLW/mysql-/mysql-noinstall-}.zip"}
# Pre-built MacOSX install
: ${MYSQLM:="mysql-5.1.58-osx10.4-i686"}
: ${MYSQLM_URL:="ftp://mirrors.ircam.fr/pub/mysql/Downloads/MySQL-${MYSQLM:6:3}/$MYSQLM.tar.gz"}
# Pre-built MacOSX powerpc
: ${MYSQLX:="mysql-standard-4.1.22-apple-darwin7.9.0-powerpc"}
: ${MYSQLX_URL:="ftp://mirrors.ircam.fr/pub/mysql/Downloads/MySQL-${MYSQLX:15:3}/$MYSQLX.tar.gz"}
: ${QT:="qt-everywhere-opensource-src-4.7.0"}
: ${QT_URL:="http://get.qt.nokia.com/qt/source/$QT.tar.gz"}
# Configurable libraries
readonly packages1="MYTHTV MYTHPLUGINS QT MYSQL FREETYPE LAME LIBEXIF LIBXML2"
readonly packages2="LIBOGG LIBVORBIS FLAC LIBCDIO TAGLIB FFTW LIBSDL LIBVISUAL"
# Tools
: ${MYTHPATCHES:="mythpatches-0.24"}
: ${MYTHPATCHES_URL:="http://www.softsystem.co.uk/download/mythtv/$MYTHPATCHES.tar.bz2"}
: ${YASM:="yasm-1.1.0"}
: ${YASM_URL:="http://www.tortall.net/projects/yasm/releases/$YASM.tar.gz"}
: ${UNZIP:="unzip60"}
: ${UNZIP_URL:="ftp://ftp.info-zip.org/pub/infozip/src/$UNZIP.zip"}
# Windows hosted tools
: ${WINWGET:="wget-1.11.4"}
: ${WINWGET_URL:="ftp://ftp.gnu.org/gnu/wget/$WINWGET.tar.bz2"}
: ${WINUNZIP:="unz600xn"}
: ${WINUNZIP_URL:="ftp://ftp.info-zip.org/pub/infozip/win32/$WINUNZIP.exe"}
: ${WINZIP:="zip300xn"}
: ${WINZIP_URL:="ftp://ftp.info-zip.org/pub/infozip/win32/$WINZIP.zip"}
: ${WINGIT:="Git-1.7.3.1-preview20101002"}
: ${WINGIT_URL:="http://msysgit.googlecode.com/files/$WINGIT.exe"}
: ${WININSTALLER:="mythinstaller-win32"}
: ${WININSTALLER_URL:="http://www.softsystem.co.uk/download/mythtv/$WININSTALLER.tar.bz2"}
# Debug build: yes|no|auto, auto=follow MYTHBUILD
: ${QT_DEBUG:="auto"}
: ${MYSQL_DEBUG:="auto"}
: ${LAME_DEBUG:="auto"}
: ${FLAC_DEBUG:="no"}
: ${TAGLIB_DEBUG:="no"}
: ${FFTW_DEBUG:="no"}
: ${LIBVISUAL_DEBUG:="no"}
# These libs are rebuilt whenever MYTHBUILD changes
readonly debug_packages="QT MYSQL LAME FLAC TAGLIB FFTW LIBVISUAL"
# Dir for myth sources
: ${MYTHDIR:=$PWD}
# Working dir for downloads & sources
if [ -d "$MYTHDIR/mythwork" ]; then
# Backwards compatibility for v1 script
: ${MYTHWORK:="$MYTHDIR/mythwork"}
: ${MYTHINSTALL:="$MYTHDIR/mythbuild"}
else
: ${MYTHWORK:="$MYTHDIR/mythbuild"}
# prefix for package installs
: ${MYTHINSTALL:="$MYTHDIR/mythinstall"}
fi
# Default parameters
MYTHTARGET=
MYTHBUILD=
MYTHBRANCH=
readtimeout=60
logging="no"
patches=
cleanbuild="no"
reconfig="no"
themes="no"
cpu=
if [ -n "$NUMBER_OF_PROCESSORS" ]; then
cpus=$NUMBER_OF_PROCESSORS
elif [ -r "/proc/cpuinfo" ]; then
cpus=`grep -c "^processor" /proc/cpuinfo`
else
cpus=1
fi
[ $cpus -gt 1 ] && makejobs=`expr $cpus + 1` || makejobs=1
verbose="no"
dosudo=
patchmaster="no"
: ${DXVA2:="no"}
###############################################################
# Parse the command line
###############################################################
readonly myname="$0"
readonly myargs="$@"
readonly currdir="$PWD"
readonly logfile="mythbuild.log"
# Get the current git branch
# $1= path to .git
function gitbranch() {
[ -d "$1/.git" ] && git --git-dir="$1/.git" branch --no-color|grep "^\*"|cut -d ' ' -f 2
}
function myhelp() {
local branch="$MYTHBRANCH"
: ${branch:=`gitbranch "$MYTHDIR/mythtv"`}
echo "A script to build MythTV"
echo "Usage: $myname [options] [packages_to_make]"
echo "Options:"
echo " -b tag Checkout MythTV branch [$branch]"
echo " -r *Release build (sticky)"
echo " -d Debug build (sticky)"
echo " -p Profile build (sticky)"
echo " -I <path> Install prefix [${MYTHINSTALL#$MYTHDIR/}]"
echo " -H Build for Host (sticky)"
echo " -M Build for MacOSX-i686 (32-bit) (sticky)"
echo " -X Build for MacOSX-PPC (sticky)"
echo " -W *Build for Windows (sticky)"
echo " -l Tee stdout and stderr to $logfile"
echo " -c <cpu> Set target CPU (host|i?86|...) [$cpu]"
echo " -j n Number of parallel make jobs [$makejobs]"
echo " -t <n> Timeout after configure [$readtimeout Seconds]"
echo " -v Verbose build messages [$verbose]"
echo " -C Force a clean re-build"
echo " -F Enable mythtv and mythplugins master patches [$patchmaster]"
echo " -P Apply all patches to mythtv and mythplugins then exit"
echo " -R Reverse all patches applied to mythtv & mythplugins then exit"
echo " -S Run make install/uninstall with sudo"
echo " -T Build and install myththemes [$themes]"
echo " -h Display this help then exit"
echo " -V Display version then exit"
echo ""
echo "The following shell variables are influential:"
echo "MYTHDIR Build tree root [current directory]"
echo "MYTHWORK Directory to unpack and build packages [${MYTHWORK#$MYTHDIR/}]"
echo "MYTHPATCHES Patches to apply [$MYTHPATCHES]"
echo "MYTHVER MythTV version [$MYTHVER]"
echo "DXVA2 Windows DXVA2 support [$DXVA2]"
echo "MYTHGIT Myth git repository [$MYTHGIT]"
echo "MYTHREPO Primary mirror [$MYTHREPO]"
echo "SOURCEFORGE Sourceforge mirror [$SOURCEFORGE]"
echo "<name>_CFG Additional configure options for package <name> e.g."
echo " $packages1"
echo " $packages2"
echo " Set to \" \" to force configure & rebuild of the package."
local pkg dbg
for pkg in $debug_packages ; do
dbg=${pkg}_DEBUG
printf "%-15s %s debugging (yes|no|auto) [%s]\n" $dbg $pkg ${!dbg}
done
}
function version() {
echo "Version $version, last modified `date -Rr $myname`"
}
function die() {
echo "" >&2
echo -e "ERROR - $@" >&2
exit 1
}
# Options
while getopts ":b:c:dj:lprt:vhVCFHI:MPRSTWX" opt
do
case "$opt" in
b) [ "${OPTARG:0:1}" != "-" ] && MYTHBRANCH=$OPTARG || die "Invalid branch tag: $OPTARG" ;;
c) [ "${OPTARG:0:1}" != "-" ] && cpu=$OPTARG || die "Invalid CPU: $OPTARG" ;;
d) MYTHBUILD="debug" ;;
p) MYTHBUILD="profile" ;;
r) MYTHBUILD="release" ;;
j) [ $OPTARG -lt 0 -o $OPTARG -gt 99 ] && die "Invalid number of jobs: $OPTARG"
[ $OPTARG -lt 1 ] && die "Invalid make jobs: $OPTARG"
makejobs=$OPTARG ;;
t) [ $OPTARG \< 0 -o $OPTARG -gt 999 ] && die "Invalid timeout: $OPTARG"
readtimeout=$OPTARG ;;
v) verbose="yes" ;;
l) logging="yes" ;;
C) cleanbuild="yes" ;;
F) [ "$patchmaster" = "no" ] && patchmaster="yes" || patchmaster="no" ;;
H) MYTHTARGET="Host" ;;
M) MYTHTARGET="MacOSX-i686" ;;
X) MYTHTARGET="MacOSX-PPC" ;;
W) MYTHTARGET="Windows" ;;
I) MYTHINSTALL=`readlink -f "$OPTARG" 2>/dev/null` || die "Invalid path: $OPTARG" ;;
P) patches="apply" ;;
R) patches="reverse" ;;
S) dosudo="sudo" ;;
T) [ "$themes" = "no" ] && themes="yes" || themes="no" ;;
h) myhelp; exit ;;
V) version; exit ;;
\?) [ -n "$OPTARG" ] && die "Invalid option -$OPTARG" ;;
:) [ -n "$OPTARG" ] && die "-$OPTARG requires an argument" ;;
*) die "Unknown option $opt" ;;
esac
done
shift `expr $OPTIND - 1`
# Arguments - named packages to build
readonly forcebuild=$@
###############################################################
# Functions
###############################################################
# Install a package, $1= package
function install_pkg() {
echo "Installing $1..."
if which apt-get > /dev/null 2>&1 ; then
sudo apt-get install $1 || die "Failed to install $1"
elif which yum >/dev/null 2>&1 ; then
sudo yum install $1 || die "Failed to install $1"
elif which urpmi >/dev/null 2>&1 ; then
sudo urpmi $1 || die "Failed to install $1"
else
die "Don't know how to install $1"
fi
}
# Download a file. $1= URL
function download() {
local obj=`basename "$1"`
echo ""
echo "*********************************************************************"
echo "wget $obj"
# Try the myth code repo first, if not use the full URL
wget "$MYTHREPO/$obj" || wget $1
}
# FTP download. $1= URL
function ftpget() {
local host path filename
case "$1" in
ftp://*) ;;
*) die "Not an FTP URL: $1" ;;
esac
path=`dirname "${1#ftp://}"`
host=${path%%/*}
path=${path#$host}
filename=`basename "$1"`
echo ""
echo "*********************************************************************"
echo "ftp ftp://$host/$path/$filename"
ftp.exe -n $host <<-EOF
user anonymous mythbuildw32@$HOSTNAME
cd $path
binary
passive
get $filename
quit
EOF
}
# Display a timed message
# $1= seconds $2= message
function pause() {
local seconds
echo ""
echo "*********************************************************************"
if [ $1 -eq 0 ]; then
:
elif [ $1 -lt 0 ]; then
read -p "$2" || echo ""
else
for (( seconds=$1 ; seconds > 0 ; --seconds )) do
printf -v prompt "\r$2(%3u)" $seconds
read -t 1 -p "$prompt" && break || true
done
[ $seconds -le 0 ] && echo ""
fi
echo ""
}
# Print message and timed wait
# $1=seconds, $2=message
function pausecont() {
local msg=$2
if [ -z "$msg" ]; then
local pkg=`basename "$PWD"`
msg="Press [Return] to make ${pkg:0:26} or [Control-C] to abort "
fi
pause ${1:-$readtimeout} "$msg"
}
# Display a banner
# $1= message
function banner() {
echo ""
echo "*********************************************************************"
echo "${1:0:80}"
echo "*********************************************************************"
echo ""
}
# Unpack an archive
# $1= filename
function unpack() {
echo "Extracting `basename "$1"` ..."
case "$1" in
*.tar.gz) tar -zxf $@ ;;
*.tar.bz2) tar -jxf $@ ;;
*.zip) unzip -a -q $@ ;;
*) die "Unknown archive type: $1" ;;
esac
}
function patchapplied() {
local n x
case "$1" in
*.diff) x=".diff" ;;
*.patch) x=".patch" ;;
esac
n=`basename "$1" "$x"`
echo "patch-$n.applied"
}
# Apply patches to a component
# $1= component name, $2... args to patch
function dopatches() {
local d=$1 i ret=0 patched dryrun
shift
echo "$@" | grep -- --dry > /dev/null 2>&1 && dryrun="yes"
local patches=`ls 2>/dev/null $MYTHDIR/$MYTHPATCHES/$d/*.{patch,diff} | sort`
for i in $patches ; do
if [ -r "$i" ]; then
patched=`patchapplied "$i"`
if [ ! -e "$patched" ]; then
echo "Applying patch $d/`basename $i`"
patch -s -p1 -N -i "$i" $@
[ -z "$dryrun" ] && touch "$patched"
let ++ret
fi
fi
done
return $ret
}
# Undo patches to a component
# $1= component name, $2... args to patch
function undopatches() {
local d=$1 i patched
shift
local patches=`ls 2>/dev/null $MYTHDIR/$MYTHPATCHES/$d/*.{patch,diff} | sort -r`
for i in $patches ; do
if [ -r "$i" ]; then
patched=`patchapplied "$i"`
if [ -e "$patched" ]; then
echo "Reversing patch $d/`basename $i`"
patch -s -p1 -R -E -i "$i" $@ || true
rm -f "$patched"
fi
fi
done
}
# Download a git repo
# $1= URL $2= dir
function gitclone() {
banner "git clone $*"
git clone $@
}
# Get the most recent git tag
# $1= path to .git
function gitdescribe() {
[ -d "$1/.git" ] && git --git-dir="$1/.git" describe || echo "unknown"
}
# make distclean
function make_distclean() {
echo "make distclean..."
$make -s -k distclean >/dev/null 2>&1 || true
}
# make install
function make_install() {
echo "make install..."
$dosudo make -j1 -s install
}
# make uninstall
function make_uninstall() {
echo "make uninstall..."
$dosudo make -j1 -s -k uninstall >/dev/null 2>&1 || true
}
# Test if building debug version of package
# $1= package name
function isdebug() {
local tag=${1}_DEBUG
local dbg=${!tag}
case "$dbg" in
auto) [ "$MYTHBUILD" = "debug" ] && return 0 || return 1 ;;
y|yes|Y|YES) return 0 ;;
n|no|N|NO) return 1 ;;
"") return 2 ;;
*) die "Invalid debug value: $tag=$dbg" ;;
esac
}
# Test for altivec instructions
function isAltivec() {
case "$MYTHTARGET" in
[Ww]indows) ;;
MacOSX-i686) ;;
MacOSX-PPC) ;; # Safer to say no
[Hh]ost)
case "$cpu" in
[gG]3) ;;
*) [ -r "/proc/cpuinfo" ] && grep -i "altivec" /proc/cpuinfo >/dev/null && return 0 ;;
esac
;;
*) ;;
esac
return 1
}
# Recursive file listing
# $1= prefix
function listfiles() {
local d=$1 n
for n in *; do
if [ -d "$n" ]; then
pushd "$n" >/dev/null
listfiles "$d$n\\"
popd >/dev/null
else
echo "$d$n"
fi
done
}
# 'make install' done indicator filename
# $1= package
function installed() {
echo "$MYTHWORK/installed-$1"
}
# Print configuation and important environmental settings
function dumpenv() {
echo "$myname $myargs"
version
echo ""
echo "MythTV version: `gitdescribe "$MYTHDIR/mythtv"`"
echo ""
uname -a
which lscpu > /dev/null 2>&1 && { lscpu ; echo "" ; }
echo "PATH: $PATH"
echo "Cwd: $PWD"
which df > /dev/null 2>&1 && { df -h . ; echo "" ; }
which free > /dev/null 2>&1 && { free -m; echo "" ; }
local ev evs="MYTHDIR MYTHWORK MYTHPATCHES MYTHGIT MYTHREPO SOURCEFORGE"
for ev in $evs ; do
echo "$ev=${!ev}"
done
echo ""
local param param1="MYTHTARGET MYTHBUILD MYTHBRANCH readtimeout logging patches"
local param2="cleanbuild reconfig cpu cpus makejobs verbose dosudo themes patchmaster"
for param in $param1 $param2 ; do
echo "$param=${!param}"
done
echo ""
local pkg dbg
for pkg in $debug_packages ; do
dbg=${pkg}_DEBUG
echo "$dbg=${!dbg}"
done
echo ""
local cfg
for pkg in $packages1 $packages2 ; do
cfg=${pkg}_CFG
[ -n "${!cfg}" ] && echo "$cfg=\"${!cfg}\""
done
# Shell variable dump
#set -o posix; set
return 0
}
###############################################################
# Installation check
###############################################################
# ./configure done indicator
readonly stampconfig="stamp.mythtv.org"
# make done indicator
readonly stampbuild="stampbuild.mythtv.org"
# Myth build type
case "$MYTHBUILD" in
"") if [ -e "$MYTHDIR/mythtv/mythtv/$stampconfig.debug" -o \
-e "$MYTHDIR/mythtv/mythplugins/$stampconfig.debug" ]; then
MYTHBUILD="debug"
elif [ -e "$MYTHDIR/mythtv/mythtv/$stampconfig.profile" -o \
-e "$MYTHDIR/mythtv/mythplugins/$stampconfig.profile" ]; then
MYTHBUILD="profile"
elif [ -e "$MYTHWORK/$QT/$stampconfig.debug" ]; then
MYTHBUILD="debug"
else
MYTHBUILD="release"
fi
;;
debug|release|profile) ;;
*) die "Invalid MYTHBUILD: $MYTHBUILD" ;;
esac
# Determine Myth version from branch name
function branch2ver() {
case "$1" in
*master) echo "master" ;;
fixes/*) echo "${1#fixes/}" ;;
*-[0-9].[1-9]*) echo "${1#*-}" ;;
*) ;;
esac
}
branch=$MYTHBRANCH
[ -z "$branch" ] && branch=`gitbranch "$MYTHDIR/mythtv"`
case "$branch" in
"") : ${MYTHVER:="master"} ;;
fixes/*) : ${MYTHVER:=`branch2ver "$branch"`} ;;
esac
# Determine target build type
readonly stamptarget="$MYTHWORK/target"
if [ "$MSYSTEM" = "MINGW32" ]; then
# Native Windows
MYTHTARGET="Windows"
else
case "$MYTHTARGET" in
"") for t in MacOSX-i686 MacOSX-PPC Windows Host ; do
if [ -e "$stamptarget-$t" ]; then
MYTHTARGET="$t"
break
fi
done
: ${MYTHTARGET:="Windows"}
;;
# Cross compile to Windows
[Ww]indows) MYTHTARGET="Windows" ;;
# Cross compile to MacOSX
MacOSX-i686|MacOSX-PPC) ;;
# Native build
[Hh]ost) MYTHTARGET="Host" ;;
*) die "Unsupported target system: $MYTHTARGET" ;;
esac
fi
# Determine host architecture
machine=`uname -m`
case $machine in
i?86|x86|i86pc) arch="x86" ;;
x86_64) arch="x86_64" ;;
amd64|AMD64) arch="x86_64" ;;
ppc) arch="ppc" ;;
ppc64) arch="ppc64" ;;
ppc*) arch="ppc" ;;
*) arch=$machine ;;
esac
# Set host triplet if cross compiling
bprefix=
if [ "$MYTHTARGET" != "Host" -a "$MSYSTEM" != "MINGW32" ]; then
kernel=`uname -s`
platform=`uname -i`
os=`uname -o`
case "$os" in
GNU*|Gnu*|gnu*) os="gnu" ;;
esac
case "$arch:$kernel:$platform:$os" in
x86:Linux:*:*) bprefix="$machine-pc-linux-$os" ;;
x86_64:Linux:*:*) bprefix="$machine-unknown-linux-$os" ;;
*:Linux:*:*) bprefix="$machine-$platform-linux-$os" ;;
*) bprefix="$machine-$platform-$os" ;;
esac
# Set target architecture
case "$MYTHTARGET" in
[Ww]indows) arch="x86" ;;
MacOSX-i686) arch="x86" ;;
MacOSX-PPC) arch="ppc" ;;
*) die "Unhown target: $MYTHTARGET" ;;
esac
fi
# Redirect output to log file as if invoked by: mythbuild.sh 2>&1 | tee -a mythbuild.log
if [ "$logging" = "yes" ]; then
dumpenv >> "$logfile"
pipe=`mktemp -u`
if mkfifo "$pipe" >/dev/null 2>&1 ; then
trap "rm -f $pipe" EXIT
tee -a "$logfile" < "$pipe" &
exec > "$pipe" 2>&1
else
echo "Unable to create named FIFO, logging disabled" >&2
fi
fi
# Download the patches
function get_patches() {
pushd "$MYTHDIR" >/dev/null
local arc=`basename "$MYTHPATCHES_URL"`
if [ "$cleanbuild" = "yes" ]; then
[ ! -L "$MYTHPATCHES" ] && rm -rf "$MYTHPATCHES" "$arc"
fi
if [ ! -d "$MYTHPATCHES" ]; then
[ ! -e "$arc" ] && download "$MYTHPATCHES_URL"
unpack "$arc"
fi
popd >/dev/null
}
# Apply/reverse Myth patches
# $1=message $2=action $3.. args to patch
function patchmyth() {
local message=$1 action=$2
shift 2
banner "$message all MythTV $MYTHVER patches." >&2
read -p "Press [Return] to continue or [Control-C] to abort: "
get_patches
if [ -d "$MYTHDIR/mythtv" ]; then
pushd "$MYTHDIR/mythtv" >/dev/null
#rm -f $stampconfig*
$action "mythtv-$MYTHVER" $@ || true
popd >/dev/null
fi
}
case "$patches" in
"") ;;
apply) [ -n "$MYTHVER" ] && patchmyth "Apply" "dopatches" $@ ; exit ;;
reverse) [ -n "$MYTHVER" ] && patchmyth "Reverse" "undopatches" $@ ; exit ;;
*) die "Unknown patches option: $patches" ;;
esac
# Display Myth branch & build type and wait for OK
banner "Building MythTV${branch:+ branch '$branch'} ($MYTHBUILD) for $MYTHTARGET" >&2
[ "$cleanbuild" = "yes" ] && echo "WARNING: All packages will be rebuilt from scratch." >&2
read -p "Press [Return] to continue or [Control-C] to abort: "
echo ""
# Change to the working dir
mkdir -p "$MYTHWORK"
cd "$MYTHWORK"
###############################################################
# Check for & install required tools
###############################################################
banner "Checking for required tools..."
readonly bindir="$MYTHINSTALL/bin"
readonly incdir="$MYTHINSTALL/include"
readonly libdir="$MYTHINSTALL/lib"
readonly windir="$MYTHINSTALL/win32"
mkdir -p "$bindir" "$incdir" "$libdir" || true
# Set PATH for configure scripts needing freetype-config & taglib-config sh scripts
export PATH="$bindir:$PATH"
# Check make
make --version >/dev/null 2>&1 || install_pkg make
# Parallel make
[ $makejobs -gt 1 ] && make="make -j$makejobs" || make="make"
# Check the C & C++ compilers exist
gcc --version >/dev/null 2>&1 || install_pkg gcc
g++ --version >/dev/null 2>&1 || install_pkg g++
if [ "$MYTHTARGET" = "Windows" -a "$MSYSTEM" != "MINGW32" ]; then
# Cross compiling to Windows
if [ -z "$xprefix" ]; then
# Ubuntu 10.10
if which i586-mingw32msvc-gcc >/dev/null 2>&1 ; then
xprefix="i586-mingw32msvc"
# Mandriva 2010.2 (32 bit)
elif which i586-pc-mingw32-gcc >/dev/null 2>&1 ; then
xprefix="i586-pc-mingw32"
# Fedora 14
elif which i686-pc-mingw32-gcc >/dev/null 2>&1 ; then
xprefix="i686-pc-mingw32"
elif xcc=`locate "/usr/bin/*mingw32*-gcc" 2>/dev/null` ; then
xprefix=`basename "${xcc%-gcc}"`
else
die "mingw is required for cross compiling to Windows.\n"\
"Try: sudo apt-get install mingw32\n"\
"Or: sudo yum install mingw32-gcc.i686 mingw32-g++.i686"
fi
fi
elif [ "$MYTHTARGET" = "MacOSX-i686" ]; then
# Cross compiling to MacOSX
for xprefix in i686-apple-darwin11 i686-apple-darwin10 i686-apple-darwin9 i686-apple-darwin8 ; do
which "$xprefix-gcc" >/dev/null 2>&1 && break
done
elif [ "$MYTHTARGET" = "MacOSX-PPC" ]; then
# Cross compiling to MacOSX
for xprefix in powerpc-apple-darwin10 powerpc-apple-darwin9 powerpc-apple-darwin8 powerpc-apple-darwin7 ; do
which "$xprefix-gcc" >/dev/null 2>&1 && break
done
fi
# Check the C/C++ cross compilers exist
if [ -n "$xprefix" ]; then
# Check the C/C++ cross compilers exist
${xprefix}-gcc --version >/dev/null 2>&1 || \
die "The C cross compiler ${xprefix}-gcc is not installed."
${xprefix}-g++ --version >/dev/null 2>&1 || \
die "The C++ cross compiler ${xprefix}-g++ is not installed."fi
fi
# Check patch
patch --version >/dev/null 2>&1 || install_pkg patch
# Need wget http://www.gnu.org/software/wget/ to download everything
if ! wget --version >/dev/null 2>&1 ; then
if [ "$MSYSTEM" != "MINGW32" ]; then
install_pkg wget
# No wget so use ftp to download the wget source
else
if ! which ftp >/dev/null 2>&1 ; then
echo "There is no FTP client so you must manually install wget from:"
echo " http://$SOURCEFORGE/gnuwin32/wget-1.11.4-1-setup.exe"
echo "Run the installer and then add wget to the PATH:"
echo " Start > My Computer > RightClick: Properties"
echo " Tab: Advanced > Click: Environment Variables > Click: New"
echo " PATH=C:\Program Files\GnuWin32\bin"
echo "Then restart any shells."
exit 1
fi
name=$WINWGET; url=$WINWGET_URL; arc=`basename "$url"`
[ ! -e "$arc" ] && ftpget $url
[ ! -d $name ] && unpack $arc
banner "Building $name"
pushd "$name" >/dev/null
cmd /c "configure.bat --mingw"
cd src
$make
cp -p wget.exe /usr/bin/
popd >/dev/null
fi
fi
# Need unzip for mysql
if [ "$MYTHTARGET" = "Windows" ] && ! which unzip >/dev/null 2>&1 ; then
if [ "$MSYSTEM" != "MINGW32" ]; then
install_pkg unzip
else
name=$WINUNZIP; url=$WINUNZIP_URL; arc=`basename "$url"`
[ ! -e "$arc" ] && download "$url"
banner "Installing $name..."
./$arc -d "$name"
cp -p "$name/unzip.exe" /usr/bin/
fi
fi
# Need zip to create install archive
if [ "$MYTHTARGET" = "Windows" ] && ! which zip >/dev/null 2>&1 ; then
if [ "$MSYSTEM" != "MINGW32" ]; then
install_pkg zip
else
name=$WINZIP; url=$WINZIP_URL; arc=`basename "$url"`
[ ! -e "$arc" ] && download "$url"
banner "Installing $name..."
unzip -d "$name" "$arc"
cp -p "$name/zip.exe" /usr/bin/
fi
fi
# Need git to get myth sources
if ! git --version >/dev/null 2>&1 ; then
if [ "$MSYSTEM" != "MINGW32" ]; then
install_pkg git-core
else
gitexe="c:\Program Files\Git\bin\git.exe"
gitexe32="C:\Program Files (x86)\Git\bin\git.exe"
if [ ! -e "$gitexe" -a ! -e "$gitexe32" ]; then
name=$WINGIT; url=$WINGIT_URL; arc=`basename "$url"`
[ ! -e "$arc" ] && download "$url"
banner "Installing $name..."
./$arc
fi
[ -e "$gitexe32" ] && gitexe="$gitexe32"
args='$@'
cat >/usr/bin/git <<-EOF
#!/bin/sh
"$gitexe" $args
EOF
if ! git --version >/dev/null ; then
rm /usr/bin/git
echo "Although $WINGIT was installed, the git program cannot be found."
echo "You must add the directory containing git.exe to PATH and restart this script."
exit 1
fi
fi
fi
# Need YASM http://www.tortall.net/projects/yasm for FFMpeg
if [ "$arch" = "x86" ] && ! which yasm >/dev/null 2>&1 ; then
name=$YASM; url=$YASM_URL; arc=`basename "$url"`
[ ! -e "$arc" ] && download "$url"
banner "Building $name..."
[ ! -d "$name" ] && unpack "$arc"
pushd "$name" >/dev/null
./configure -q "--prefix=$MYTHINSTALL" $YASM_CFG
$make
make_install
popd >/dev/null
fi
# Download the patches
get_patches
# Apply the mingw <float.h> patch for Qt
# Qt tools/qlocale.cpp:6628: error: ‘_clear87’ was not declared in this scope
# Qt tools/qlocale.cpp:6629: error: ‘_control87’ was not declared in this scope
# $1= sudo
# $2.. patch args
function patchmingw() {
local gccversion=`${xprefix:+$xprefix-}gcc -dumpversion`
local path1 path2
local dosudo=$1
shift
case "$xprefix" in
i586-mingw32msvc) # Ubuntu 10.04, 10.10
path1="/usr/$xprefix/include"
path2="/usr/lib/gcc/$xprefix/$gccversion/include"
;;
i586-pc-mingw32) # Mandriva 2010.2 (32 bit)
path1="/usr/$xprefix/sys-root/mingw/include"
path2="/usr/lib/gcc/$xprefix/$gccversion/include"
;;
i686-pc-mingw32) # Fedora 14
path1="/usr/$xprefix/sys-root/mingw/include"
[ -d "/usr/lib64/gcc/$xprefix/$gccversion/include" ] && \
path2="/usr/lib64/gcc/$xprefix/$gccversion/include" ||
path2="/usr/lib/gcc/$xprefix/$gccversion/include"
;;
*mingw*)
echo "WARNING: Guessing include paths"
path1="/usr/${xprefix:+$xprefix/}include"
path2="/usr/lib/gcc/${xprefix:+$xprefix/}$gccversion/include"
;;
*) die "Unable to patch this compiler: $xprefix" ;;
esac