forked from superpea/xbmc-fork
-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.sh
executable file
·679 lines (637 loc) · 15.6 KB
/
build.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
#!/bin/bash
error() {
RET=$?
if [[ $RET != 0 ]]
then
echo
echo -e "\n FAILED! Exiting. ($RET)"
exit
fi
}
usage() {
echo " build.sh by default checks that your source is up-to-date, updates it"
echo " if not, compile, and create a working build of XBMC in ./BUILD."
echo " UserData and scripts dirs as well as 3rd party skins will be backed"
echo " up if existing."
echo " Usage: build.sh [OPTIONS]"
echo " OPTIONS:"
echo " --help [-h] : Display this text."
echo " DEST=<build-dest> : Path to install XBMC to"
echo " NOUPDATE : Don't update source."
echo " NOCOMPILE : Don't compile."
echo " NOCLEAN : Don't run \"make clean\" first."
echo " NOCOPY : Don't create XBMC file structure."
echo " NODEBUG : Don't create debugging info, strip binary."
echo " CONFIRM : Don't ask about anything"
# echo " SHOWMAKE : Don't suppress make output"
## SHOWMAKE requires changes to Makefile.in
echo " NOCONFIG : Don't automatically run configure"
echo " CONFIGOPT=<config-option> : Option to pass to configure."
echo " One option per CONFIGOPT=,"
echo " can pass more than one"
echo " WEB=<path/to/web_int.rar> : Web interface to use."
echo " Default = PM3"
echo " VERBOSE : Print way too much stuff than to"
echo " be useful in most cases."
echo " These options can be defaulted in ~/.xbmc-build-settings."
echo " Just make a white space separated list on the first line."
exit
}
view_log() {
PROMPT=""
while [[ $PROMPT != "y" && $PROMPT != "n" ]]
do
printf "\r View compile log? (y/n) : \b"
read -n 1 PROMPT
done
echo
if [[ $PROMPT = "y" ]]
then
less "${SOURCEDIR}/compile.log"
fi
exit
}
parse_args() {
for I in "$@"
do
OPT=${I%=*}
PAR=${I#*=}
case $OPT in
--help|-h)
usage
;;
DEST)
BUILDDIR=$PAR
;;
NOUPDATE)
(( UPDATE=0 ))
;;
NOCOMPILE)
(( COMPILE=0 ))
;;
NOCLEAN)
(( CLEAN=0 ))
;;
NOCOPY)
(( COPY=0 ))
;;
QUICKCOPY)
(( QUICKCOPY=1 ))
;;
NOCHANGELOG)
(( CHANGELOG=0 ))
;;
CONFIRM)
(( CONFIRM=1 ))
;;
SHOWMAKE)
(( SHOW_MAKE=1 ))
;;
CONFIGOPT)
(( CONFIGURE=1 ))
CONFIGOPTS="$CONFIGOPTS $PAR"
;;
NODEBUG)
(( DEBUG=0 ))
CONFIGOPTS="$CONFIGOPTS --disable-debug"
;;
WEB)
if [[ -e $PAR ]]
then
WEB=$PAR
else
echo " $PAR doesn't exist!"
exit
fi
;;
NOCONFIG)
CONFIGURE=0
;;
VERBOSE)
VERBOSE=1
;;
*)
echo " Invalid option $OPT"
usage
;;
esac
done
}
update() {
echo " Local source revision : $LOCAL_REVISION"
echo -n " Repository revision : Checking..."
HEAD_REVISION=$(expr "$(svn info "$SOURCEDIR" -r HEAD 2>&1 | grep "Revision")" : '.*: \(.*\)')
printf "\r Repository revision : %-11.11s\n" $HEAD_REVISION
if [[ $LOCAL_REVISION = "" || $HEAD_REVISION = "" ]]
then
echo " Couldn't determine if source is upto date!"
echo " This is probably due to network errors, skipping update."
PROMPT=""
while [[ $PROMPT != "y" && $PROMPT != "n" ]]
do
printf "\r Continue? (y/n) : \b"
read -n 1 PROMPT
done
echo
if [[ $PROMPT == "n" ]]
then
exit
fi
else
if (( $LOCAL_REVISION < $HEAD_REVISION ))
then
if (( CONFIRM ))
then
PROMPT="y"
else
PROMPT=""
fi
echo " Your source is outdated."
while [[ $PROMPT != "y" && $PROMPT != "n" ]]
do
printf "\r Update? (y/n) : \b"
read -n 1 PROMPT
done
if ! (( CONFIRM ))
then
echo
fi
if [[ $PROMPT == "y" ]]
then
echo " Updating source code."
# a bit of a sorry hack to account for the odd chance that
# a commit occurs while we're waiting for user input
HEAD_REVISION=$(expr "$(svn info "$SOURCEDIR" -r HEAD 2>&1 | grep "Revision")" : '.*: \(.*\)')
svn up "$SOURCEDIR" 2>&1 | tee "$SOURCEDIR/.build.sh.svn"
grep "$HEAD_REVISION" "$SOURCEDIR/.build.sh.svn" &> /dev/null
error
LOCAL_REVISION="$HEADREVISION"
fi
else
echo " Your source is up to date."
UPDATE=0
fi
fi
}
config() {
if [[ $CONFIGOPTS = "" ]]
then
echo " Configuring build."
else
echo " Configuring build with $CONFIGOPTS."
fi
DIR=$PWD
cd "$SOURCEDIR"
./configure $CONFIGOPTS
error
cd "$DIR"
}
compile() {
if (( CONFIGURE ))
then
config
fi
if (( COMPILE ))
then
if ! [[ -e "$SOURCEDIR/Makefile" ]]
then
config
fi
if (( CLEAN ))
then
echo " Cleaning source directory."
if (( VERBOSE ))
then
make -C "${SOURCEDIR}" clean
else
make -C "${SOURCEDIR}" clean &> /dev/null
fi
else
echo " Skipping source directory cleaning."
fi
echo " Compiling source."
if [[ $MAKEFLAGS = "" ]]
then
CORES=$(grep "^processor" /proc/cpuinfo | wc -l)
echo " Detected ${CORES} procs/cores, using -j${CORES}"
MAKEFLAGS=-j${CORES}
else
echo "Using MAKEFLAGS=${MAKEFLAGS}"
fi
if (( $SHOW_MAKE ))
then
make ${MAKEFLAGS} -C "${SOURCEDIR}" 2>&1 | tee "${SOURCEDIR}/compile.log"
else
make ${MAKEFLAGS} -C "${SOURCEDIR}" 2>&1 | tee "${SOURCEDIR}/compile.log" | grep -E "Linking|Building|Compiling"
fi
grep Error "${SOURCEDIR}/compile.log"
if [[ $? == "0" ]]
then
echo
echo " Errors have occurred!"
view_log
fi
fi
}
copy() {
BACKUPDIR="${BUILDDIR}.bak"
if [[ -e "$BUILDDIR" ]]
then
#backup
echo " Backing up old ${BUILDDIR} to ${BACKUPDIR}."
if [[ -e "$BACKUPDIR" ]]
then
echo " Removing old $BACKUPDIR first."
if (( VERBOSE ))
then
rm -vrf "$BACKUPDIR"
else
rm -rf "$BACKUPDIR" &> /dev/null
fi
fi
if (( VERBOSE ))
then
mv -v "$BUILDDIR" "${BACKUPDIR}"
else
mv "$BUILDDIR" "${BACKUPDIR}" &> /dev/null
fi
if [[ $? != 0 ]]
then
echo " You don't have permission to move"
echo " the old $BUILDDIR. Please fix this"
echo " and rerun with options NOUPDATE"
echo " and NOCOMPILE"
exit
fi
fi
echo " Creating ${BUILDDIR}."
if (( VERBOSE ))
then
mkdir -v "$BUILDDIR"
else
mkdir "$BUILDDIR" &> /dev/null
fi
error
for I in credits language media screensavers scripts skin sounds system userdata visualisations web xbmc-xrandr xbmc.bin README.linux copying.txt Changelog.txt
do
printf "\r Copying %-16.16s" $I
if [[ "$I" == "skin" ]]
then
if (( VERBOSE ))
then
mkdir -vp "${BUILDDIR}/skin/Project Mayhem III"
else
mkdir -p "${BUILDDIR}/skin/Project Mayhem III" &> /dev/null
fi
for J in $(ls "${SOURCEDIR}/skin/Project Mayhem III")
do
if [[ "$J" == "media" ]]
then
if (( VERBOSE ))
then
mkdir -v "${BUILDDIR}/skin/Project Mayhem III/media"
cp "${SOURCEDIR}/skin/Project Mayhem III/media/Textures.xpr" "${BUILDDIR}/skin/Project Mayhem III/media"
else
mkdir "${BUILDDIR}/skin/Project Mayhem III/media" &> /dev/null
cp "${SOURCEDIR}/skin/Project Mayhem III/media/Textures.xpr" "${BUILDDIR}/skin/Project Mayhem III/media" &> /dev/null
fi
else
if (( VERBOSE ))
then
cp -vrf "${SOURCEDIR}/skin/Project Mayhem III/${J}" "${BUILDDIR}/skin/Project Mayhem III"
else
cp -rf "${SOURCEDIR}/skin/Project Mayhem III/${J}" "${BUILDDIR}/skin/Project Mayhem III" &> /dev/null
fi
fi
done
elif [[ "$I" == "userdata" ]]
then
if [[ -e "$BACKUPDIR/UserData" ]]
then
if (( VERBOSE ))
then
cp -vrf "$BACKUPDIR/UserData" "$BUILDDIR"
else
cp -rf "$BACKUPDIR/UserData" "$BUILDDIR" &> /dev/null
fi
else
if (( VERBOSE ))
then
cp -vrf "${SOURCEDIR}/${I}" "$BUILDDIR"
else
cp -rf "${SOURCEDIR}/${I}" "$BUILDDIR" &> /dev/null
fi
fi
elif [[ "$I" == "web" ]]
then
RAR="$(which unrar)"
if [[ $RAR == "" ]]
then
RAR="$(which rar)"
fi
if ! [[ $RAR == "" ]]
then
if (( VERBOSE ))
then
mkdir -vp "$BUILDDIR/web"
"$RAR" x -y "$WEB" "$BUILDDIR/web/"
else
mkdir -p "$BUILDDIR/web" &> /dev/null
"$RAR" x -y -inul "$WEB" "$BUILDDIR/web/"
fi
fi
elif [[ "$I" == "xbmc.bin" ]]
then
if [[ -e "${SOURCEDIR}/$I" ]]
then
if (( VERBOSE ))
then
mv -v "${SOURCEDIR}/${I}" "$BUILDDIR"
else
mv "${SOURCEDIR}/${I}" "$BUILDDIR" &> /dev/null
fi
elif [[ -e "${BACKUPDIR}/${I}" ]]
then
echo
echo " Couldn't find new binary, using old one from backup!"
if (( VERBOSE ))
then
cp -vf "${BACKUPDIR}/${I}" "${BUILDDIR}/${I}"
else
cp -f "${BACKUPDIR}/${I}" "${BUILDDIR}/${I}" &> /dev/null
fi
else
ls "..." &> /dev/null # force $? to be non-zero
fi
else
if (( VERBOSE ))
then
cp -vrf "${SOURCEDIR}/${I}" "$BUILDDIR"
else
cp -rf "${SOURCEDIR}/${I}" "$BUILDDIR" &> /dev/null
fi
fi
error
done
if ! (( DEBUG ))
then
echo " Stripping binary."
strip "$BUILDDIR/xbmc.bin"
fi
printf "\r Copying %-16.16s\n" "complete!"
if [[ $RAR == "" ]]
then
echo " Couldn't find \"rar\" or \"unrar\" please install one to use web interface"
fi
}
cleanup() {
if [ -d $1 ]
then
printf "\r Cleaning %-60.60s" $1
if (( VERBOSE ))
then
rm -vrf $I/src $I/.svn $I/*.DLL $I/*.dll $I/*osx.so
else
rm -rf $I/src $I/.svn $I/*.DLL $I/*.dll $I/*osx.so &> /dev/null
fi
for I in $1/* #$(ls -d $1/* 2> /dev/null)
do
cleanup "${I}"
done
fi
}
merge() {
if [[ -d "$BACKUPDIR/$1" ]]
then
if [[ -e "$BUILDDIR/$1" ]]
then
for I in $(ls -d $BACKUPDIR/$1/* 2> /dev/null)
do
I=${I#"${BACKUPDIR}/"}
merge "$I"
done
else
echo " Merged ${1#"${BACKUPDIR}/"}"
if (( VERBOSE ))
then
cp -vrf "$BACKUPDIR/$1" "$BUILDDIR/$1"
else
cp -rf "$BACKUPDIR/$1" "$BUILDDIR/$1" &> /dev/null
fi
fi
else
if ! [[ -e "$BUILDDIR/$1" ]]
then
echo " Merged ${1#"${BACKUPDIR}/"}"
if (( VERBOSE ))
then
cp -vf "$BACKUPDIR/$1" "$BUILDDIR/$1"
else
cp -f "$BACKUPDIR/$1" "$BUILDDIR/$1" &> /dev/null
fi
fi
fi
}
fix() {
echo " Fixing some case-sensitivity issues."
echo " Renaming arial.ttf to Arial.ttf."
mv "${BUILDDIR}/media/Fonts/arial.ttf" "${BUILDDIR}/media/Fonts/Arial.ttf"
echo " Renaming Splash.png to splash.png."
mv "${BUILDDIR}/media/Splash.png" "${BUILDDIR}/media/splash.png"
if [[ -e "$BACKUPDIR" ]]
then
echo " Merging 3rd party files from backup."
for I in $(ls $BACKUPDIR) #screensavers scripts skin sounds system visualisations
do
IFS=$'\t\n'
merge "$I"
IFS=$_IFS
done
echo " Merge complete!"
fi
_IFS=$IFS
IFS=$'\t\n'
cleanup "$BUILDDIR"
printf "\r Cleaning %-60.60s\n" "complete!"
IFS=$_IFS
}
SOURCEDIR=${0%/*}
BACKUPDIR="$SOURCEDIR/.backup"
# Don't touch these. Make a ~/.xbmc-build-settings instead.
# See ./build.sh --help
BUILDDIR="./BUILD"
WEB=""
CONFIGOPTS=""
(( UPDATE=1 ))
(( COMPILE=1 ))
(( CLEAN=1 ))
(( COPY=1 ))
(( QUICKCOPY=0 ))
(( CHANGELOG=1 ))
(( CONFIRM=0 ))
(( SHOW_MAKE=1 ))
(( CONFIGURE=1 ))
(( DEBUG=1 ))
(( VERBOSE=0 ))
if ! [[ -e "$SOURCEDIR/.firstrun" ]]
then
touch "$SOURCEDIR/.firstrun"
echo
echo "*** FIRST RUN DETECTED. YOU'D BETTER READ THIS CAREFULLY! ***"
echo
usage
fi
echo -ne "]0;Building XBMC"
if (( VERBOSE ))
then
touch "/root/.test"
else
touch "/root/.test" &> /dev/null
fi
if ! (( $? ))
then
rm "/root/.test" &> /dev/null
PROMPT=""
echo " There is really no reason to run this as root or with sudo."
while [[ $PROMPT != "y" && $PROMPT != "n" ]]
do
printf "\r Run anyway? (y/n) : \b"
read -n 1 PROMPT
done
echo
if [[ $PROMPT = "n" ]]
then
exit
fi
fi
if [[ -e ~/.xbmc-build-settings ]]
then
SETTINGS=$(head -n1 ~/.xbmc-build-settings)
parse_args $SETTINGS
fi
parse_args "$@"
if [[ "${BUILDDIR:(-1)}" = "/" ]]
then
BUILDDIR="${BUILDDIR%/}"
fi
LOCAL_REVISION=$(expr "$(svn info "$SOURCEDIR" 2>&1 | grep "Revision")" : '.*: \(.*\)')
if [[ -e "$BUILDDIR" ]]
then
if ! [[ -dwr "$BUILDDIR" ]]
then
echo " $BUILDDIR exists, but you can't modify it or it is a file."
exit
fi
else
if (( VERBOSE ))
then
mkdir -vp "$BUILDDIR"
else
mkdir -p "$BUILDDIR" &> /dev/null
fi
if [[ $? != 0 ]]
then
echo " You don't have permission to create $BUILDDIR"
exit
fi
if (( VERBOSE ))
then
rm -vrf "$BUILDDIR"
else
rm -rf "$BUILDDIR" &> /dev/null
fi
fi
if [[ $WEB == "" ]]
then
WEB="$SOURCEDIR/web/Project_Mayem_III_webserver_v1.0.rar"
fi
if (( UPDATE ))
then
update
else
echo " Skipping update."
fi
if [[ -e "$SOURCEDIR/.build.sh.svn" ]]
then
CMD="$0 $*"
grep -E "configure$|\.in$" "$SOURCEDIR/.build.sh.svn" &> /dev/null
if ! (($?))
then
CONFIGURE=1
fi
if ! (( $CONFIRM ))
then
grep -E "README.linux$" "$SOURCEDIR/.build.sh.svn" &> /dev/null
if ! (($?))
then
sed -i "s/README.linux//g" "$SOURCEDIR/.build.sh.svn" #&> /dev/null
echo " **************************************************"
echo " Detected changes to README.linux"
echo " You will now be forced to read it :)"
echo " Use pgup, pgdn or space to navigate"
echo " PAY ATTENTION to the aptget line for your distro!"
echo " **************************************************"
echo " Press any key to continue..."
read -n1
less -e "$SOURCEDIR/README.linux"
PROMPT=""
while [[ $PROMPT != "y" && $PROMPT != "n" ]]
do
printf "\r Continue? (y/n) : \b"
read -n 1 PROMPT
done
echo
if [[ $PROMPT == "n" ]]
then
exit
fi
fi
fi
grep -E "build.sh$" "$SOURCEDIR/.build.sh.svn" &> /dev/null
if ! (( $? ))
then
CMD="$CMD NOUPDATE"
sed -i "s/build.sh//g" "$SOURCEDIR/.build.sh.svn" #&> /dev/null
echo " Detected new version of build.sh"
echo " Rerunning with \"$CMD\""
$CMD
exit
fi
rm -f "$SOURCEDIR/.build.sh.svn" &> /dev/null
fi
if (( COMPILE ))
then
compile
else
echo " Skipping compile."
fi
if (( (UPDATE || COMPILE || COPY) && CHANGELOG ))
then
echo " Generating Changelog.txt"
"$SOURCEDIR/tools/Changelog/Changelog.py" -r $LOCAL_REVISION -d "$SOURCEDIR"
fi
if (( COPY ))
then
if (( QUICKCOPY ))
then
if [[ -e "${SOURCEDIR}/xbmc.bin" ]]
then
if (( VERBOSE ))
then
mv -v "${SOURCEDIR}/xbmc.bin" "$BUILDDIR"
else
mv "${SOURCEDIR}/xbmc.bin" "$BUILDDIR" &> /dev/null
fi
fi
else
copy
fix
fi
else
echo " Skipping XBMC file structure creation."
fi
echo " All done!"
if (( COMPILE && !CONFIRM))
then
view_log
fi