forked from xbianonpi/xbian
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.package
541 lines (457 loc) · 17.6 KB
/
build.package
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
##
## Copyright (C) 2012 - 2014 XBian
##
## Find us at: http://www.xbian.org http://github.com/xbianonpi/xbian
##
## This Program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2, or (at your option)
## any later version.
##
## This Program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with XBMC; see the file COPYING. If not, see
## <http://www.gnu.org/licenses/>.
##
##
config_patch_fuzzy=5
opt_arch=''
opt_action=''
result=0
use_debug=no
use_silent=no
if [ -e $XBIANROOT/common.functions ]; then
. $XBIANROOT/common.functions
else
echo "Wrong setup. Open folder containing xbianonpi/xbian clone and rerun \"./run.me prepare\""
exit 500
fi
do_prep()
{
dir="$1"
do_hooks pre-configure.d
cd "$dir/working"
[ "$2" = force ] && runprepare=1 || runprepare=0
if [ -n "$config_source_prepare" ]; then
if [ -e configure ]; then
[ "$( find ./ -maxdepth 1 -iname configure.\* -newer configure | grep -c .; )" -gt 0 ] && runprepare=1 || :
else
runprepare=1
fi
# [ $runprepare -eq 1 ] && ( rexp ../env; do_run $config_build_env $config_source_prepare; )
[ $runprepare -eq 1 ] && ( do_run $config_source_prepare; ) || :
fi
[ "$2" = force ] && runconfigure=1 || runconfigure=0
if [ -n "$config_source_configure" ]; then
if [ -e configure ]; then
if [ -e Makefile ]; then
[ "$( find ./ -maxdepth 1 -iname Makefile\* ! -newer configure | grep -c .; )" -gt 0 ] && runconfigure=1 || :
else
runconfigure=1
fi
else
runconfigure=1
fi
[ $runconfigure -eq 1 ] && ( rexp ../env && do_run $config_build_env $config_source_configure; )
fi
do_hooks post-configure.d
}
do_make()
{
dir="$1"
do_hooks pre-build.d
cd "$dir/working"
if [ -n "$config_build_targets" ]; then
for t in $config_build_targets; do
( rexp ../env; do_run $config_build_env $config_build_make $t; )
done
else
( rexp ../env; do_run $config_build_env $config_build_make; )
fi
do_hooks post-build.d
}
do_patch()
{
dir=$(basename "$1")
if [ -e build/$dir/working/.force.nopatch -a "$2" = fullrun ]; then
rm -f build/$dir/working/.force.nopatch
return 0
fi
[ ! -d ./patches ] && return 0
cd ./patches
for p in $({ find -L ./ -maxdepth 1 -iname \*.patch -type f 2>/dev/null | sort; find -L "./$dir" -type d 2>/dev/null| sort | xargs -L1 -I%% sh -c 'find -L %% -maxdepth 1 -iname \*.patch -type f | sort'; }); do
(
cd ../build/$dir/working
[ $use_silent = yes ] || echo "checking $p"
if ! patch -p1 --dry-run -F $config_patch_fuzzy < ../../../patches/$p >/dev/null; then
echo "! won't patch with $p" >/dev/stderr
continue
fi
[ $use_silent = yes ] || echo "Patching with $p"
do_run patch -p1 -F $config_patch_fuzzy < ../../../patches/$p
echo "-----------------"
)
done
cd ..
if [ -d extra-files/$dir ]; then
(
cd extra-files/$dir
find ./ -type f -print0 | xargs -0 cp -avr --parents --target-directory="../../$1/working" 2>/dev/null|| :
find ./ -type l -print0 | xargs -0 cp -avr --parents --target-directory="../../$1/working" 2>/dev/null|| :
)
fi
}
do_wipe()
{
dir="$1"
while sudo /bin/umount "$dir/working"; do :; done
do_run rm -fr "$dir/working"
}
do_clean()
{
dir="$1"
cd "$dir/working"
do_run $config_build_env $config_build_make clean
do_hooks post-clean.d
}
do_clone()
{
do_hooks pre-clone.d
dir="$1"
if [ "$config_source_keep" != yes ]; then
do_wipe "$dir"
fi
if [ -n "$WORKSPACE" ]; then
do_wipe "$dir" && mkdir -p "$dir/working"
sudo /bin/mount -o bind "$WORKSPACE" "$dir/working"
(
cd "$dir/working"
do_run git fetch --all
do_run git checkout "$config_source_branch"
do_run git reset --hard "origin/$config_source_branch"
do_run git clean -dfx
do_hooks post-clone.d
)
return 0
fi
initialrun=no
cd "$dir" || { mkdir -p "$dir" && cd "$dir"; }
if [ ! -d "./working/.git" ]; then
initialrun=yes
case "$config_source_type" in
git)
config_branch=''
[ -n "$config_source_branch" ] && export config_branch="-b "
do_run git clone $config_branch$config_source_branch $config_source_type_extra $config_source_addr working
;;
tar)
do_run wget $config_source_addr -O $(basename $config_source_addr)
mkdir -p working
tar -xf $(basename $config_source_addr) -C ./working --strip-components 1
cd ./working
cd ..
;;
*)
;;
esac
cd ./working
else
cd ./working
if [ "$config_source_reset" = yes ]; then
case "$config_source_type" in
git)
do_run git clean -xdf -e .force*
do_run git reset --hard origin/$config_source_branch
;;
tar)
rm -fr ./*
( cd ../; tar -zxf $(basename $config_source_addr) -C ./working --strip-components 1; )
;;
*)
;;
esac
fi
if [ "$config_source_branch" = yes ]; then
case "$config_source_type" in
git)
do_run git checkout -t -b "$config_source_branch"
;;
*)
;;
esac
fi
if [ "$config_source_refresh" = yes -a $initialrun = no ]; then
[ "$config_source_reset" = yes ] || touch .force.nopatch
case "$config_source_type" in
git)
ep=''; cmtnr=''
### commit local changes into new tmp branch
if git status | grep -q 'Changes not staged\|Untracked files'; then
git add --all .; sync
git commit -m "$(echo auto commit on action clone at - $(date))" --no-edit || :
fi
### reset main branch and pull changes from upstream
#grep -qi 'url = git://' -m1 .git/config && ep='--depth=1'
#git pull $ep origin $config_source_branch 2>&1 || :
echo "Trying pull from remote..."
do_run git pull origin $config_source_branch
;;
*)
;;
esac
fi
fi
do_hooks post-clone.d
}
do_install()
{
# export MAKEFLAGS=-j1
do_hooks pre-install.d
export INSTALL_MOD_PATH=$(readlink -f ./content)
export INSTALL_FW_PATH=$(readlink -f ./content)
export DESTDIR=$(readlink -f ./content)
dir="$1"
if [ "$config_deb_contentclean" = yes -a -e ./content ]; then
find ./content/ -mindepth 1 -maxdepth 1 ! -regex '.*/DEBIAN' -print0 | \
xargs -0 -L1 rm -r >/dev/null 2>&1|| :
fi
mkdir -p ./content
cd "$dir/working"
for t in $config_install_targets; do
( rexp ../env; do_run $config_build_env $config_build_make $t; )
done
unset DESTDIR
do_hooks post-install.d
}
do_deb()
{
DESTDIR=$(pwd)/build/$config_platform_branch
[ -d "$dir/working" ] && \
(
cd "$dir/working"
commit_src=$(git log -n1 --format=oneline --remotes= | awk '{print $1}')
echo "commit_src=$commit_src" > $DESTDIR/src_repo_hash_HEAD
)
[ -d ./content ] || mkdir ./content
rm -f ./content/DEBIAN/*
# backcompatibility only, should be removed
[ -e ./content-tpl ] && cp -ar ./content-tpl/* ./content
[ -e build/content-tpl ] && cp -ar build/content-tpl/* ./content
[ -n "$config_platform_branch" ] && \
[ -e build/$config_platform_branch/content-tpl ] && cp -ar build/$config_platform_branch/content-tpl/* ./content
export MAKEFLAGS=-j1
if [ "$config_deb_pkgcreatenative" = yes ] || [ "$config_deb_pkgcreatenative" = auto ]; then
[ -d "$dir/working" ] || return 0
cd "$dir/working"
rm -f ../*.deb
rexp ../env; do_hooks '##withbuildenv##' pre-deb.d
if [ "$config_deb_pkgcreatenative" = auto ] && [ -x debian/rules ]; then
do_run $config_build_env fakeroot debian/rules binary
DATE=$(date +%s)
for cl in $(find ./debian/ -maxdepth 1 -mindepth 1 -type f -name \*changelog\*); do
ver=$(grep . -m1 $cl | awk '{print $2}'); ver=${ver#\(}; ver=${ver%\)};
vernew="$ver-$DATE"
for d in $(find ./debian/ -maxdepth 2 -mindepth 2 -type d -name DEBIAN); do
sed -i "s%$ver%$vernew%g" $d/control
done
done
else
for h in dh_auto_install dh_install dh_installdocs dh_installchangelogs dh_installman \
dh_perl dh_link dh_compress dh_fixperms dh_strip dh_makeshlibs dh_shlibdeps \
dh_installdeb dh_gencontrol dh_md5sums; do
echo "Running $h"
do_run $config_build_env fakeroot $h -O--parallel \
$([ $h = dh_shlibdeps ] && echo '-- --ignore-missing-info') \
$([ $h = dh_autoinstall ] && echo "-O=-j$MAKEFLAGS")
done
ver=$(grep . -m1 debian/changelog | awk '{print $2}'); ver=${ver#\(}; ver=${ver%\)};
vernew="$ver-$(date +%s)"
for d in $(find ./debian/ -maxdepth 2 -mindepth 2 -type d -name DEBIAN); do
sed -i "s%$ver%$vernew%g" $d/control
done
fi
do_run $config_build_env fakeroot dh_builddeb
return 0
fi
if [ -d hooks.d/pre-deb.d ]; then
for f in $(ls hooks.d/pre-deb.d); do
( cd "./content"; do_run sh ../hooks.d/pre-deb.d/$f; )
done
fi
do_readconfig "$dir"
[ -e content/DEBIAN/control-dbg ] && ctrldbg=content/DEBIAN/control-dbg
[ -z "$config_distro" ] && config_deb_version="$config_deb_version-$(date +%s)"
sed -i "s%__VERSION__%$config_deb_version%" content/DEBIAN/control $ctrldbg
sed -i "s%__ARCHBRANCH__%$config_platform/$config_branch%" content/DEBIAN/control $ctrldbg
sed -i "s%__PKGNAME__%$config_deb_pkgname%" content/DEBIAN/control $ctrldbg
sed -i "s%__PKGDEPS__%Depends: $config_deb_depends%" content/DEBIAN/control $ctrldbg
if [ -n "$config_deb_ctrlextra" ]; then
sed -i "s%__CTRLEXTRA__%$config_deb_ctrlextra%" content/DEBIAN/control
printf "%b\n" "$(cat content/DEBIAN/control)" > content/DEBIAN/control.new
mv content/DEBIAN/control.new content/DEBIAN/control
else
sed -i '/__CTRLEXTRA__/d' content/DEBIAN/control $ctrldbg
fi
### git log -n1 --format=oneline | awk '{print $1}'
### git ls-remote $config_source_addr -h master | awk '{print $1}'
[ ! -e $DESTDIR/src_repo_hash_HEAD ] || . $DESTDIR/src_repo_hash_HEAD
rm -f $DESTDIR/src_repo_hash_HEAD
[ -n "$commit_src" ] && commit_src="at commit src $commit_src,"
echo " ($commit_src commit xbian repo $( [ -e .git ] && git log -n1 --format=oneline --remotes= | awk '{print $1}'))" >> content/DEBIAN/control
eval export $config_build_env 2>/dev/null && eval export $config_build_env
[ -e ./content/DEBIAN/control-dbg ] || find ./content -type f \( -executable -o -iname \*.so -o -iname \*.ko -o -iname \*.a \) -print0 | eval $config_build_env xargs -0 ${CROSS_COMPILE}strip --strip-unneeded -p 2>/dev/null || :
sync
do_run $SHELL $XBIANROOT/gen.package
rm -f "$dir"/*.deb
do_hooks post-deb.d
mv *.deb "$dir"
[ ! -d $(pwd)/build/$config_platform_branch/working ] || touch $(pwd)/build/$config_platform_branch/working/.force.aptonly
}
do_show_help()
{
echo "
Usage summary:
--arch, -m [platform/buildconfig] existing configurations as listed by --list
--action, -a [action] action to perform:
wipe - will completely remove working directory (including git clone of src repository)
clean - will run "make clean" in the working tree
clone - will run "git clone". if source is already cloned then reset/pull is part of this action
and finer control is allowed through three paramters - look at "patch" description
patch - will try to re-apply patches. if source is not reset to HEAD, nothing will be applied
(git reset operation is running in "clone" action as it is needed for correct auto
git pull. wheter reset is performed is controled by parameters config_source_keep,
config_source_reset and config_source_refresh - default values is YES)
prepare - will prepare sources for compilation. usually ./autogen.sh or ./bootstrap is started,
then ./configure. controlled via parameters config_source_prepare and
config_source_configure
make - runs "make". if finishes successfully, package is compiled and ready to be packaged
install - will run "make install". this will copy binaries into ./content folder, in final folder
structure
deb - will build package out of ./content folder. part of this action is also updating the
control files (version, commits, etc). binaries will be also stripped and final
.deb package will be moved into ./build/platform
--list, -l - list all available configured platforms / branches
--debug, -d - debug output
"
}
# ----------------------
GETOPT=$(getopt \
--longoptions=action:,list,arch:,config_source_refresh:,help,debug,silent \
--options=a:m:hlo:ds \
-- "$@" ) \
|| exit 128
export XBIANPKGDIR="$(pwd)"
if [ -e $XBIANPKGDIR/build.~lock ]; then
echo "another process running... or stale lock exists at $XBIANPKGDIR/build.~lock"
exit 100
fi
do_readconfig "$(pwd)/build"
[ $config_source_type = raw ] && { rm -fr "$(pwd)/content/"* && do_deb "$(pwd)/build"; exit 0; }
unset $(env | grep config_ | awk -F'=' '{print $1}'); opt_arch=''
for dir in $(find build/ -mindepth 1 -maxdepth 1 \( -type d -o -type l \) | grep -vw content-tpl |sort); do
export XBIANARCHDIR=$(readlink -f "$dir")
unset $(env | grep config_ | awk -F'=' '{print $1}'); opt_arch=''
result=0
eval set -- ${GETOPT}
do_readconfig "$dir"
while [ "$#" -gt '0' ]; do
case "$1" in
(-l|--list)
printf "ConfigName: %s\n\tTarget: %s\n\tBranch: %s\n\t URL: %s\n\n" "${dir#*build/}" "$(printf "%s" "$config_build_env" | grep -ow ['armhfjessie'\|'armhfwheezy']\*)" $config_source_branch $config_source_addr
continue 2
;;
(--action|-a)
opt_action=$2
shift 2
;;
(--arch|-m)
opt_arch=$2
shift 2
;;
(-o)
do_run export $2
shift 2
;;
(--help|-h)
do_show_help
exit 0
;;
(-d|--debug)
use_debug=yes
shift
;;
(-s|--silent)
use_silent=yes
shift
;;
(-o|--sources)
source_branch="$2"
shift 2
;;
*)
shift 1
;;
esac
done
[ "$use_debug" = no ] || set -x
if [ -n "$opt_arch" -a "$opt_arch" != $(basename "$dir") ]; then
if [ -n "$source_branch" ]; then
! grep -q "^config_source_branch=$source_branch" "$dir/config" && continue
fi
continue
fi
echo "-------------------------------"
echo "PROCESSING $(basename $dir)";
echo "-------------------------------"
[ -z "$opt_arch" ] && opt_arch=$(basename "$dir")
export config_platform=${opt_arch%%-*}
export config_platform_branch=$opt_arch
export config_branch=${opt_arch##*-}
[ $config_branch = $config_platform ] && export config_branch=$config_source_branch
trap "kill_gitbuilder; sync; mountpoint -q $dir/working && sudo /bin/umount $dir/working; " EXIT TERM
git_preloader
[ "$opt_action" = '' ] && opt_action="build" || opt_action=$(echo $opt_action | tr ',' ' ')
for a in $opt_action; do
case $a in
wipe)
( do_wipe "$dir" )
;;
clean)
( do_clean "$dir" )
;;
patch)
( do_patch "$dir" )
;;
prepare)
( do_prep "$dir" force )
;;
make)
( do_make "$dir" )
;;
clone)
( do_clone "$dir" )
;;
install)
( do_install "$dir" )
;;
deb)
( do_deb "$dir" )
;;
''|build)
dr=$(pwd)
[ -e "./.autowipe" ] && . "./.autowipe"
[ "$config_wipe_before" = "yes" ] && do_wipe "$dir" fullrun
for act in do_clone do_patch do_prep do_make do_install do_deb; do
( $act "$dir" fullrun )
done
[ "$config_wipe_after" = "yes" ] && do_wipe "$dir" fullrun
;;
esac
done
printf "\n-------------------------------\nFINISHED OK\n-------------------------------\n"
exit 0
done