-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcook
executable file
·1967 lines (1652 loc) · 53 KB
/
cook
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/sh
#
# Cook - A tool to cook and generate SliTaz packages. Read the README
# before adding or modifying any code in cook!
#
# Copyright (C) SliTaz GNU/Linux - GNU GPL v3
# Author: Christophe Lincoln <[email protected]>
#
. /usr/lib/slitaz/libcook.sh
VERSION="3.2"
export output=raw
prev_ts="/home/slitaz/cache/prev_ts"; touch $prev_ts
# Internationalization.
export TEXTDOMAIN='cook'
#
# Functions
#
usage() {
cat <<EOT
$(boldify "$(_ 'Usage:')") $(_ 'cook [package|command] [list|--option]')
$(boldify "$(_ 'Commands:')")
usage|help $(_ 'Display this short usage.')
setup $(_ 'Setup your build environment.')
*-setup $(_ 'Setup a cross environment.')
* = {arm|armv6hf|armv7|x86_64}
test $(_ 'Test environment and cook a package.')
list-wok $(_ 'List packages in the wok.')
search $(_ 'Simple packages search function.')
new $(_ 'Create a new package with a receipt.')
list $(_ 'Cook a list of packages.')
clean-wok $(_ 'Clean-up all packages files.')
clean-src $(_ 'Clean-up all packages sources.')
uncook $(_ 'Check for uncooked packages')
pkgdb $(_ 'Create packages DB lists and flavors.')
$(boldify "$(_ 'Options:')")
cook <pkg>
--clean -c $(_ 'clean the package in the wok.')
--getsrc -gs $(_ 'get the package source tarball.')
--block -b $(_ 'block a package so cook will skip it.')
--unblock -ub $(_ 'unblock a blocked package.')
--cdeps $(_ 'check dependencies of cooked package.')
--pack $(_ 'repack an already built package.')
--debug $(_ 'display debugging messages.')
--continue $(_ 'continue running compile_rules.')
cook new <pkg>
--interactive -x $(_ 'create a receipt interactively.')
cook setup
--wok $(_ 'clone the cooking wok from Hg repo.')
--stable $(_ 'clone the stable wok from Hg repo.')
--undigest $(_ 'clone the undigest wok from Hg repo.')
--tiny $(_ 'clone the tiny SliTaz wok from Hg repo.')
--forced $(_ 'force reinstall of chroot packages.')
cook pkgdb
--flavors $(_ 'create up-to-date flavors files.')
cook splitdb $(_ 'create up-to-date split.db file.')
EOT
exit 0
}
# We don't want these escapes in web interface.
clean_log() {
sed -i -e 's|\[70G\[ \[1;32m| |' \
-e 's|\[0;39m \]||' $LOGS/${1:-$pkg}.log
}
# Be sure package exists in wok.
check_pkg_in_wok() {
[ -d "$WOK/$pkg" ] || die 'Unable to find package "%s" in the wok' "$pkg"
}
# Find the package, return the receipt name where it was found
# for example, libpcreposix -> pcre
find_pkg_in_wok() {
awk -F$'\t' -vi=" $1 " '{
if (index(" " $2 " ", i)) {print $1; exit}
}' $cache/split.db
}
# Initialize files used in $CACHE
init_db_files() {
_ 'Creating directories structure in "%s"' "$SLITAZ"
mkdir -p $WOK $PKGS $SRC $CACHE $LOGS $FEEDS
_ 'Creating DB files in "%s"' "$CACHE"
touch $activity $command $broken $blocked $CACHE/webstat
chown www:www $cache/webstat
}
# Paths used in receipt and by cook itself.
set_paths() {
# Kernel version is set from wok/linux or installed/linux-api-headers(wok-undigest)
if [ -f "$WOK/linux/receipt" ]; then
kvers=$(. $WOK/linux/receipt; echo $VERSION)
kbasevers=$(echo $kvers | cut -d. -f1,2)
elif [ -f "$INSTALLED/linux-api-headers/receipt" ]; then
kvers=$(. $INSTALLED/linux-api-headers/receipt; echo $VERSION)
kbasevers=$(echo $kvers | cut -d. -f1,2)
fi
# Python version
[ -f "$WOK/python/receipt" ] && pyvers=$(. $WOK/python/receipt; echo $VERSION)
# Perl version for some packages needed it
[ -f "$WOK/perl/receipt" ] && perlvers=$(. $WOK/perl/receipt; echo $VERSION)
pkgdir="$WOK/$pkg"
. "$pkgdir/receipt"
basesrc="$pkgdir/source"
tmpsrc="$basesrc/tmp"
src="$basesrc/$PACKAGE-$VERSION"
taz="$pkgdir/taz"
pack="$taz/${1:-$PACKAGE}-$VERSION$EXTRAVERSION" # v2: multiple taz/* folders
fs="$pack/fs"
stuff="$pkgdir/stuff"
install="$pkgdir/install"
pkgsrc="${SOURCE:-$PACKAGE}-${KBASEVER:-$VERSION}"
lzma_tarball="$pkgsrc.tar.lzma"
[ -n "$PATCH" -a -z "$PTARBALL" ] && PTARBALL="$(basename $PATCH)"
if [ -n "$WANTED" ]; then
basesrc="$WOK/$WANTED/source"
src="$basesrc/$WANTED-$VERSION"
install="$WOK/$WANTED/install"
wanted_stuff="$WOK/$WANTED/stuff"
fi
[ -n "$SOURCE" ] && source_stuff="$WOK/$SOURCE/stuff"
# Old way compatibility.
_pkg="$install"
}
# Create source tarball when URL is a SCM.
create_tarball() {
local tarball
tarball="$pkgsrc.tar.bz2"
[ -n "$LZMA_SRC" ] && tarball="$lzma_tarball"
_ 'Creating tarball "%s"' "$tarball"
if [ -n "$LZMA_SRC" ]; then
tar -c $pkgsrc | lzma e $SRC/$tarball -si $LZMA_SET_DIR || exit 1
LZMA_SRC=''
else
tar -cjf $tarball $pkgsrc || exit 1
mv $tarball $SRC; rm -rf $pkgsrc
fi
TARBALL="$tarball"
}
# Get package source. For SCM we are in cache so clone here and create a
# tarball here.
get_source() {
local url
url=${WGET_URL#*|}
set_paths
pwd=$(pwd)
case "$WGET_URL" in
http://*|ftp://*|https://*)
url="$MIRROR_URL/sources/packages/${TARBALL:0:1}/$TARBALL"
wget -T 60 -c -O $SRC/$TARBALL $WGET_URL ||
wget -T 60 -c -O $SRC/$TARBALL $url ||
die 'ERROR: %s' "wget $WGET_URL"
;;
hg*|mercurial*)
_ 'Getting source from %s...' 'Hg'
_ 'URL: %s' "$url"
_ 'Cloning to "%s"' "$pwd/$pkgsrc"
if [ -n "$BRANCH" ]; then
_ 'Hg branch: %s' "$BRANCH"
hg clone $url --rev $BRANCH $pkgsrc ||
die 'ERROR: %s' "hg clone $url --rev $BRANCH"
else
hg clone $url $pkgsrc || die 'ERROR: %s' "hg clone $url"
fi
rm -rf $pkgsrc/.hg
create_tarball
;;
git*)
_ 'Getting source from %s...' 'Git'
_ 'URL: %s' "$url"
cd $SRC
git clone $url $pkgsrc || die 'ERROR: %s' "git clone $url"
if [ -n "$BRANCH" ]; then
_ 'Git branch: %s' "$BRANCH"
cd $pkgsrc; git checkout $BRANCH; cd ..
fi
cd $SRC
create_tarball
;;
cvs*)
mod=$PACKAGE
[ -n "$CVS_MODULE" ] && mod=$CVS_MODULE
_ 'Getting source from %s...' 'CVS'
_ 'URL: %s' "$url"
[ -n "$CVS_MODULE" ] && _ 'CVS module: %s' "$mod"
_ 'Cloning to "%s"' "$pwd/$mod"
cvs -d:$url co $mod && mv $mod $pkgsrc
create_tarball
;;
svn*|subversion*)
_ 'Getting source from %s...' 'SVN'
_ 'URL: %s' "$url"
if [ -n "$BRANCH" ]; then
echo t | svn co $url -r $BRANCH $pkgsrc
else
echo t | svn co $url $pkgsrc
fi
create_tarball
;;
bzr*)
_ 'Getting source from %s...' 'bazaar'
cd $SRC
pkgsrc=${url#*:}
if [ -n "$BRANCH" ]; then
echo "bzr -Ossl.cert_reqs=none branch $url -r $BRANCH"
bzr -Ossl.cert_reqs=none branch $url -r $BRANCH
else
echo "bzr -Ossl.cert_reqs=none branch $url"
bzr -Ossl.cert_reqs=none branch $url
cd $pkgsrc; BRANCH=$(bzr revno); cd ..
_ "Don't forget to add to receipt:"
echo -e "BRANCH=\"$BRANCH\"\n"
fi
mv $pkgsrc $pkgsrc-$BRANCH
pkgsrc="$pkgsrc-$BRANCH"
create_tarball
;;
*)
broken; die 'ERROR: Unable to handle "%s"' "$WGET_URL"
;;
esac
}
# Extract source package.
extract_source() {
if [ ! -s "$SRC/$TARBALL" ]; then
local url
url="$MIRROR_URL/sources/packages"
url="$url/${TARBALL:0:1}/$TARBALL"
_ 'Getting source from %s...' 'mirror'
_ 'URL: %s' "$url"
busybox wget -c -P $SRC $url || _ 'ERROR: %s' "wget $url"
fi
_ 'Extracting source archive "%s"' "$TARBALL"
case "$TARBALL" in
*.tar.gz|*.tgz) tar -xzf $SRC/$TARBALL 2>/dev/null ;;
*.tar.bz2|*.tbz|*.tbz2) tar -xjf $SRC/$TARBALL 2>/dev/null ;;
*.tar.lzma) tar -xaf $SRC/$TARBALL ;;
*.tar.lz|*.tlz) lzip -d < $SRC/$TARBALL | tar -xf - 2>/dev/null ;;
*.tar) tar -xf $SRC/$TARBALL ;;
*.zip|*.xpi) unzip -o $SRC/$TARBALL 2>/dev/null >&2;;
*.xz) unxz -c $SRC/$TARBALL | tar -xf - || \
tar -xf $SRC/$TARBALL 2>/dev/null;;
*.7z) 7zr x $SRC/$TARBALL 2>/dev/null >&2 ;;
*.Z|*.z) uncompress -c $SRC/$TARBALL | tar -xf - ;;
*.rpm) rpm2cpio $SRC/$TARBALL | cpio -idm --quiet ;;
*.run) /bin/sh $SRC/$TARBALL $RUN_OPTS ;;
*) cp $SRC/$TARBALL $(pwd) ;;
esac
}
# Display time.
disp_time_old() {
local sec div min
sec="$1"
div=$(( ($1 + 30) / 60))
case $div in
0) min='';;
# L10n: 'm' is for minutes (approximate cooking time)
*) min=$(_n ' ~ %dm' "$div");;
esac
# L10n: 's' is for seconds (cooking time)
_ '%ds%s' "$sec" "$min"
}
# Display time.
disp_time() {
local sec="$1" day hour min out=''
day=$(( sec / 86400 )); sec=$(( sec % 86400 ))
hour=$(( sec / 3600 )); sec=$(( sec % 3600 ))
min=$(( sec / 60 )); sec=$(( sec % 60 ))
[ $day -gt 0 ] && out="${day}d "
[ -n "$out" -o $hour -gt 0 ] && out="$out$(printf '%02dh ' $hour)"
[ -n "$out" -o $min -gt 0 ] && out="$out$(printf '%02dm ' $min)"
[ -n "$out" ] && out=" ~ $out$(printf '%02ds' $sec)"
echo "${1}s$out"
}
# Display cooked package summary.
summary() {
# local arch=''
# case "$ARCH" in
# arm*|x86_64) arch="-$ARCH" ;;
# esac
set_paths
cd $WOK/$pkg
[ -d $WOK/$pkg/install ] && prod=$(du -sh $WOK/$pkg/install | awk '{print $1}' 2>/dev/null)
[ -d $WOK/$pkg/source ] && srcdir=$(du -sh $WOK/$pkg/source | awk '{print $1}' 2>/dev/null)
[ -n "$TARBALL" ] && srcsize=$(du -sh $SRC/$TARBALL | awk '{print $1}')
title 'Summary for: %s' "$PACKAGE $VERSION$EXTRAVERSION"
# L10n: keep the same width of translations to get a consistent view
[ -n "$TARBALL" ] && _ 'Src file : %s' "$TARBALL"
[ -n "$srcsize" ] && _ 'Src size : %s' "$srcsize"
[ -n "$srcdir" ] && _ 'Source dir : %s' "$srcdir"
[ -n "$prod" ] && _ 'Produced : %s' "$prod"
_ 'Cook time : %s' "$(disp_time "$time")"
_ 'Cook date : %s' "$(date "$(_ '+%%F %%R')")"
_ 'Target arch : %s' "$(cut -d$'\t' -f2 $pkgdir/.arch | sort -u | tr '\n' ' ' | sed 's| $||; s| |, |g')"
separator -
_ ' # : Packed : Compressed : Files : Package name'
separator -
pkgi=1
for i in $(all_names); do
version=$(awk -F$'\t' -vpkg="$i" '{
if ($1 == pkg) {print $2; exit}
}' "$PKGS/packages-$ARCH.info")
[ -n "$version" ] || continue
fs=$(du -sh $WOK/$pkg/taz/$i-$VERSION$EXTRAVERSION | awk '{print $1}')
arch=$(awk -F$'\t' -vi="$i" '{if ($1 == i) print $2}' $pkgdir/.arch)
pkgname="$i-$version-$arch.tazpkg"
[ -f "$PKGS/$pkgname" ] || continue
size=$(ls -lh $PKGS/$pkgname | awk '{print $5}')
files=$(wc -l < $WOK/$pkg/taz/$i-$VERSION$EXTRAVERSION/files.list)
printf "%2d : %7s : %10s : %5s : %s\n" "$pkgi" "$fs" "$size" "$files" "$pkgname"
pkgi=$((pkgi + 1))
done
separator
}
# Display debugging error info.
debug_info() {
title 'Debug information %s.' "$1"
# L10n: specify your format of date and time (to help: man date)
# L10n: not bad one is '+%x %R'
_ 'Cook date: %s' "$(date "$(_ '+%%F %%R')")"
if [ -n "$time" ]; then
times="$(($(date +%s) - $time))"
_ 'Wasted time : %s' "$(disp_time "$times")"
fi
for error in \
ERROR 'No package' "cp: can't" "can't open" "can't cd" \
'error:' 'fatal error:' 'undefined reference to' \
'Unable to connect to' 'link: cannot find the library' \
'CMake Error' ': No such file or directory' \
'Could not read symbols: File in wrong format'
do
# format "line number:line content"
fgrep -n "$error" $LOGS/$pkg.log
done > $LOGS/$pkg.log.debug_info 2>&1
# sort by line number, remove duplicates
sort -gk1,1 -t: -u $LOGS/$pkg.log.debug_info
rm -f $LOGS/$pkg.log.debug_info
footer
}
# A bit smarter function than the classic `cp` command
scopy() {
if [ "$(stat -c %h -- "$1")" -eq 1 ]; then
cp -a "$1" "$2" # copy generic files
else
cp -al "$1" "$2" # copy hardlinks
fi
}
# Copy all generic files (locale, pixmaps, .desktop) from $install to $fs.
# We use standard paths, so some packages need to copy these files with the
# receipt and genpkg_rules.
# This function executes inside the packaging process, before compressor call.
copy_generic_files() {
# Proceed only for "main" package (for v2), and for any packages (v1)
[ "$pkg" == "$PACKAGE" ] || return 0
# $LOCALE is set in cook.conf
if [ -n "$LOCALE" -a -z "$WANTED" ]; then
if [ -d "$install/usr/share/locale" ]; then
mkdir -p "$fs/usr/share/locale"
for i in $LOCALE; do
if [ -d "$install/usr/share/locale/$i" ]; then
cp -r $install/usr/share/locale/$i $fs/usr/share/locale
fi
done
fi
fi
# Generic pixmaps copy can be disabled with COOKOPTS="!pixmaps" (or GENERIC_PIXMAPS="no")
if [ "${COOKOPTS/!pixmaps/}" == "$COOKOPTS" -a "$GENERIC_PIXMAPS" != 'no' ]; then
if [ -d "$install/usr/share/pixmaps" ]; then
mkdir -p "$fs/usr/share/pixmaps"
for i in png xpm; do
[ -f "$install/usr/share/pixmaps/$PACKAGE.$i" -a ! -f "$fs/usr/share/pixmaps/$PACKAGE.$i" ] &&
cp -r $install/usr/share/pixmaps/$PACKAGE.$i $fs/usr/share/pixmaps
done
fi
fi
# Desktop entry (.desktop).
# Generic desktop entry copy can be disabled with COOKOPTS="!menus" (or GENERIC_MENUS="no")
if [ "${COOKOPTS/!menus/}" == "$COOKOPTS" -a "$GENERIC_MENUS" != 'no' ]; then
if [ -d "$install/usr/share/applications" -a -z "$WANTED" ]; then
mkdir -p "$fs/usr/share"
cp -r $install/usr/share/applications $fs/usr/share
fi
fi
}
# Copy pixmaps, desktop files and licenses from $stuff to $install.
# This function executes after the main compile_rules() is done.
copy_generic_stuff() {
# Custom or homemade PNG pixmap can be in stuff.
if [ -f "$stuff/$PACKAGE.png" ]; then
mkdir -p $install/usr/share/pixmaps
cp $stuff/$PACKAGE.png $install/usr/share/pixmaps
fi
# Homemade desktop file(s) can be in stuff.
if [ -d "$stuff/applications" ]; then
mkdir -p $install/usr/share
cp -r $stuff/applications $install/usr/share
fi
if [ -f "$stuff/$PACKAGE.desktop" ]; then
mkdir -p $install/usr/share/applications
cp $stuff/$PACKAGE.desktop $install/usr/share/applications
fi
# Add custom licenses
if [ -d "$stuff/licenses" ]; then
mkdir -p $install/usr/share/licenses
cp -r $stuff/licenses $install/usr/share/licenses/$PACKAGE
fi
}
# Update installed.cook.diff
update_installed_cook_diff() {
# If a cook failed deps are removed.
cd $root$INSTALLED; ls -1 > $CACHE/installed.cook
cd $CACHE
[ "$1" == 'force' -o ! -s '/tmp/installed.cook.diff' ] && \
busybox diff installed.list installed.cook > /tmp/installed.cook.diff
deps=$(grep ^+[a-zA-Z0-9] /tmp/installed.cook.diff | wc -l)
}
# Remove installed deps.
remove_deps() {
# Now remove installed build deps.
diff='/tmp/installed.cook.diff'
[ -s "$diff" ] || return
deps=$(grep ^+[a-zA-Z0-9] $diff | sed 's|^+||')
nb=$(grep ^+[a-zA-Z0-9] $diff | wc -l)
newline
_n 'Build dependencies to remove:'; echo " $nb"
[ -n "$root" ] && echo "root=\"$root\""
_n 'Removing:'
for dep in $deps; do
echo -n " $dep"
# Do not waste time uninstalling the packages if we are inside
# aufs chroot - unmounting chroot will "uninstall" all packages.
[ -s /aufs-umount.sh ] ||
echo 'y' | tazpkg remove $dep --root=$root >/dev/null
done
newline; newline
# Keep the last diff for debug and info.
mv -f $diff $CACHE/installed.diff
}
# Automatically patch the sources.
patchit() {
[ -f "$stuff/patches/series" ] || return
# Empty lines and comments (started with "#") are ignored
# Up to three fields (no spaces inside allowed) separated by "|":
# 1. patch options like "-p0" (optional);
# 2. patch file name or URL (mandatory);
# 3. patch checksum in form "sha1=..." or other *sum (optional).
local done="$pkgdir/.patch.done" var1 var2 var3
local patchname patchopts patchfile patchsum patchsum_type patchsum_sum
IFS=$'\n'
while read i; do
patchname=$(echo ${i%%#*} | cut -d' ' -f1) # allow comments (anything after the # or space)
[ -n "$patchname" ] || continue # skip empty lines
var1=$(echo "$patchname||" | cut -d'|' -f1) # options or name
var2=$(echo "$patchname||" | cut -d'|' -f2) # name or checksum or empty
var3=$(echo "$patchname||" | cut -d'|' -f3) # checksum or empty
if [ -n "$var3" ]; then
patchopts="$var1"; patchname="$var2"; patchsum="$var3"
elif [ -n "$var2" ]; then
case $var2 in
*=*) patchopts='-Np1'; patchname="$var1"; patchsum="$var2";;
*) patchopts="$var1"; patchname="$var2"; patchsum='';;
esac
else
patchopts='-Np1'; patchname="$var1"; patchsum=''
fi
case $patchname in
ftp://*|http://*|https://*)
patchfile="$SRC/$(basename $patchname)"
[ -e "$patchfile" ] || wget -q -T 60 -O $patchfile $patchname ||
die 'ERROR: %s' "can't get $patchname"
;;
*)
patchfile="$stuff/patches/$patchname"
;;
esac
if [ -n "$patchsum" ]; then
patchsum_type=${patchsum%=*}
patchsum_sum=${patchsum#*=}
echo "$patchsum_sum $patchfile" | ${patchsum_type}sum -cs ||
die 'ERROR: %s' "wrong ${patchsum_type}sum for $patchfile"
else
case $patchfile in
$SRC/*) echo "warning: no checksum for external patch!";;
esac
fi
touch $done
grep -q "^${patchname}$" $done && continue # already applied (useful with `cook --continue`)
newline
_ 'Applying patch %s' "$patchname"
patch $patchopts -i $patchfile | sed 's|^| |'
echo $patchname >> $done
done < $stuff/patches/series
newline
unset IFS
}
# Check source tarball integrity.
check_integrity() {
for i in sha1 sha3 sha256 sha512 md5; do
I=$(echo $i | tr 'a-z' 'A-Z')
eval sum=\$TARBALL_$I
if [ -n "$sum" ]; then
newline
_ 'Checking %ssum of source tarball...' "$i"
echo "$sum $SRC/$TARBALL" | ${i}sum -c || exit 1
fi
done
newline
}
# Misc fix functions
fix() {
case $1 in
# https://bugzilla.gnome.org/show_bug.cgi?id=655517
# https://wiki.gentoo.org/wiki/Project:Quality_Assurance/As-needed
ld)
export LDFLAGS="$LDFLAGS -Wl,-Os,--as-needed"
;;
libtool)
if [ -e 'libtool' ]; then
sed -i 's| -shared | -Wl,-Os,--as-needed\0|g' libtool
echo "fix.libtool" >> $pkgdir/.patch.done
else
echo "fix libtool: warning: libtool absent, nothing to fix."
fi
;;
math)
# fix C++ math issue introduced in Glibc 2.26:
# error: '__builtin_isnan' is not a member of 'std'
# if (std::isnan(N)) {
# ^
find $src -type f -exec sed -i '
s|std::signbit|__builtin_signbit|g;
s|std::isnan|__builtin_isnan|g;
s|std::isinf|__builtin_isinf_sign|g;
s|std::isfinite|__builtin_isfinite|g;
s|std::isnormal|__builtin_isnormal|g
' '{}' \;
;;
symlinks)
# make absolute symlinks relative
echo "fix symlinks"
local ifs="$IFS" link target
IFS=$'\n'
# step 1: fast job, prefix all the absolute symlinks with "$install"
for link in $(find $install -type l); do
target="$(readlink $link)"
case "$target" in
/*) ln -sfv "$install$target" "$link";;
esac
done
IFS="$ifs"
# step 2: fine tuning, make symlinks relative
tazpkg -gi --quiet --local --cookmode symlinks
symlinks -cr $install
;;
gem)
# some useful operations while Ruby gems cooking
_gems="$(ruby -e'puts Gem.default_dir')"
# remove unwanted empty folders
rmdir --ignore-fail-on-non-empty \
$install/$_gems/build_info/ \
$install/$_gems/cache/ \
$install/$_gems/doc/ \
$install/$_gems/extensions/
# move files to docdir
docdir=$install/usr/share/doc/$PACKAGE-$VERSION
for i in $(ls -ap $install/$_gems/gems/${PACKAGE#*-}-$VERSION/ | sed '
/\/$/d; /^\./d; /gemspec$/d; /Rakefile*/d; /Gemfile*/d; /Makefile/d;
/\.c$/d; /\.h$/d; /\.o$/d; /\.rb$/d; /\.so$/d; /\.yml$/d;
/Manifest/d; /\.inc$/d; /depend/d;
'); do
mkdir -p $docdir # docdir will not be created when nothing to move
mv $install/$_gems/gems/${PACKAGE#*-}-$VERSION/$i $docdir
done
if [ -d $install/$_gems/gems/${PACKAGE#*-}-$VERSION/doc/ ]; then
mkdir -p $docdir
mv $install/$_gems/gems/${PACKAGE#*-}-$VERSION/doc/ $docdir
fi
if [ -d $docdir ]; then
# move man pages
unset man_to_copy
for i in $(seq 1 8); do
for j in $(find $docdir -type f -name "*.$i" | sed '/LGPL-2\.1/d'); do
man_to_copy="$man_to_copy $j"
done
done
if [ -n "$man_to_copy" ]; then
cook_pick_manpages $man_to_copy
rm $man_to_copy
fi
# convert rdoc to markdown (thanks https://gist.github.com/teeparham/8a99e308884e1c32735a)
for i in $(find $docdir -type f -name '*.rdoc'); do
fix utf-8
LC_ALL=en_US.UTF-8 ruby -r rdoc -e 'puts RDoc::Markup::ToMarkdown.new.convert File.read(ARGV[0] || "'$i'")' >$i.md && rm $i || rm $i.md
done
fi
# move man pages (from the different place)
rubyman=$install/$_gems/gems/${PACKAGE#*-}-$VERSION/man
if [ -d $rubyman ]; then
unset man_to_copy
for i in $(seq 1 8); do
for j in $(find $rubyman -type f -name "*.$i" | sed '/LGPL-2\.1/d'); do
man_to_copy="$man_to_copy $j"
done
done
if [ -n "$man_to_copy" ]; then
cook_pick_manpages $man_to_copy
fi
rm -r $rubyman
fi
;;
utf-8)
# Install UTF-8 locale
tazpkg -gi --quiet --local --cookmode locale-en-base
mkdir -p /usr/lib/locale
localedef -i 'en_US' -c -f 'UTF-8' /usr/lib/locale/en_US.UTF-8
;;
esac
}
# Typical function used in compile_rules() to make perl modules packages
cook_perl() {
if [ -e "Makefile.PL" ]; then
# Up to 3 optional parameters supported
PERL_MM_USE_DEFAULT=1 perl Makefile.PL INSTALLDIRS=vendor $1 &&
make $2 &&
make $3 PERL_MM_USE_DEFAULT=1 DESTDIR=$install install &&
chmod -R u+w $install
elif [ -e "Build.PL" ]; then
echo "Not implemented yet"
return 1
else
echo "Unable to cook Perl module"
return 1
fi
}
# Store timestamps, log jobs length
timestamp() {
local ts_file="$WOK/$pkg/.ts"
local curr_ts=$(date '+%s')
case $1 in
init)
rm $ts_file 2>/dev/null
echo $curr_ts > $prev_ts
;;
job*)
# calculate time from the last timestamp
echo "$1='$(( $curr_ts - $(cat $prev_ts) ))'" >> $ts_file
echo $curr_ts > $prev_ts
;;
sets)
echo "sets='$2'" >> $ts_file
;;
esac
}
# Store time statsistics to the cache
store_timestats() {
# see doc/timestats.txt for file format
temp=$(mktemp)
{
for i in $(seq 1 30); do echo "job$i=0"; done
cat $WOK/$pkg/.ts
echo -n 'total=$(( 0'
for i in $(seq 1 30); do echo -n " + job$i"; done
echo ' ))'
} > $temp
. $temp
{
echo -n "$pkg $sets "
for i in $(seq 1 30); do echo -n "$((job$i)) "; done
echo "$total"
} >> /home/slitaz/cache/timestats
rm $temp $WOK/$pkg/.ts # clean
}
# Internal function to cook specified SET
cook_set() {
# Switch to the specified source set
set_paths
local suffix=''
[ -n "$SET" ] && suffix="-$SET"
export src="$WOK/$pkg/source/$PACKAGE-$VERSION$suffix"
export install="$WOK/$pkg/install$suffix"
export DESTDIR="$install"
if [ -n "$SETS" ]; then
if [ -n "$SET" ]; then
title "Switching to the set '$SET'"
else
title "Switching to the default set"
fi
echo "src : $src"
echo "install: $install"
fi
[ -d "$src" ] && cd $src # packages without sources exists
echo
[ -d "$install" ] && rm -r $install
#mkdir -p $install
compile_rules $@ || { broken; exit 1; }
# Stay compatible with _pkg
[ -d "$src/_pkg" ] && mv $src/_pkg $install
copy_generic_stuff
timestamp job$job_counter # compiling (set '$SET')
# Actions to do after compiling the package
# Skip all for split packages (already done in main package)
if [ -z "$WANTED" ]; then
footer
export COOKOPTS ARCH install
@@PREFIX@@/libexec/cookutils/compressor install
timestamp job$(($job_counter + 1)) # compressing (set '$SET')
fi
# Activate "instant-pack" mode
if [ "${COOKOPTS/instant-pack/}" != "$COOKOPTS" ]; then
echo " $SPLIT " | fgrep -q " $PACKAGE " || SPLIT="$PACKAGE $SPLIT"
export PACKAGE
# determine the list of the packages belongs to the current SET...
echo -n $SPLIT \
| awk -vset="$SET" '
BEGIN { RS = " "; FS = ":"; }
{ if ($2 == set) print $1; }' \
| xargs -n1 @@PREFIX@@/libexec/cookutils/pack # ... and then pack them
fi
job_counter=$(($job_counter + 2))
}
# The main cook function.
cookit() {
if [ -n "$SETUP_MD5" -a "$SETUP_MD5" != "$(ls $root$INSTALLED | md5sum | cut -c1-32)" ]; then
_ 'ERROR: Broken setup. Abort.'
return
fi
title 'Cook: %s' "$PACKAGE $VERSION"
set_paths
timestamp init # the very start
# Handle cross-tools.
[ "$BUILD_SYSTEM" != "$HOST_SYSTEM" ] &&
case "$ARCH" in
arm*|x86_64)
# CROSS_COMPILE is used by at least Busybox and the kernel to set
# the cross-tools prefix. Sysroot is the root of our target arch
sysroot="$CROSS_TREE/sysroot"
tools="$CROSS_TREE/tools"
# Set root path when cross compiling. ARM tested but not x86_64
# When cross compiling we must install build deps in $sysroot.
arch="-$ARCH"
root="$sysroot"
_ '%s sysroot: %s' "$ARCH" "$sysroot"
_ 'Adding "%s" to PATH' "$tools/bin"
export PATH="$PATH:$tools/bin"
export PKG_CONFIG_PATH="$sysroot/usr/lib/pkgconfig"
export CROSS_COMPILE="$HOST_SYSTEM-"
_ 'Using cross-tools: %s' "$CROSS_COMPILE"
if [ "$ARCH" == 'x86_64' ]; then
export CC="$HOST_SYSTEM-gcc -m64"
export CXX="$HOST_SYSTEM-g++ -m64"
else
export CC="$HOST_SYSTEM-gcc"
export CXX="$HOST_SYSTEM-g++"
fi
export AR="$HOST_SYSTEM-ar"
export AS="$HOST_SYSTEM-as"
export RANLIB="$HOST_SYSTEM-ranlib"
export LD="$HOST_SYSTEM-ld"
export STRIP="$HOST_SYSTEM-strip"
export LIBTOOL="$HOST_SYSTEM-libtool"
;;
esac
@@PREFIX@@/libexec/cookutils/precheck $receipt || exit 1 # former receipt_quality()
cd $pkgdir
if [ -z "$continue" ]; then
rm -rf source 2>/dev/null
rm .patch.done 2>/dev/null
fi
rm -rf install taz 2>/dev/null
# Disable -pipe if less than 512 MB free RAM.
free=$(awk '/^MemFree|^Buffers|^Cached/{s+=$2}END{print int(s/1024)}' /proc/meminfo)
if [ "$free" -lt 512 ] && [ "$CFLAGS" != "${CFLAGS/-pipe}" ]; then
_ 'Disabling -pipe compile flag: %d MB RAM free' "$free"
CFLAGS="${CFLAGS/-pipe}"; CFLAGS=$(echo "$CFLAGS" | tr -s ' ')
CXXFLAGS="${CXXFLAGS/-pipe}"; CXXFLAGS=$(echo "$CXXFLAGS" | tr -s ' ')
fi
unset free
# Export flags and path to be used by make and receipt.
DESTDIR="$pkgdir/install"
# FIXME: L10n: Is this the right time for 'LC_ALL=C LANG=C'?
export DESTDIR MAKEFLAGS CFLAGS CXXFLAGS CONFIG_SITE LC_ALL=C LANG=C \
LDFLAGS
timestamp job1 # pre-checks
# BUILD_DEPENDS may vary depending on the ARCH
case "$ARCH" in
arm*) [ -n "$BUILD_DEPENDS_arm" ] && BUILD_DEPENDS=$BUILD_DEPENDS_arm ;;
x86_64) [ -n "$BUILD_DEPENDS_x86_64" ] && BUILD_DEPENDS=$BUILD_DEPENDS_x86_64 ;;
esac
# Check for build deps and handle implicit depends of *-dev packages
# (ex: libusb-dev :: libusb).
[ -n "$BUILD_DEPENDS" ] && _ 'Checking build dependencies...'
[ -n "$root" ] && _ 'Using packages DB: %s' "$root$DB"
# Get the list of installed packages
cd $root$INSTALLED; ls > $CACHE/installed.list
for action in check install; do
for dep in $BUILD_DEPENDS; do
implicit="${dep%-dev}"; [ "$implicit" == "$dep" ] && implicit=''
for i in $dep $implicit; do
# Skip if package already installed
[ -f "$root$INSTALLED/$i/receipt" ] && continue
case $action in
check)
# Search for local package or local provided-package
name=$(awk -F$'\t' -vpkg="$i" '{
if (index(" " $1 " " $10 " ", " " pkg " ")) {print $1; exit}
}' "$PKGS/packages-$ARCH.info")
if [ -z "$name" ]; then
# Search for package in mirror
name="$(awk -F$'\t' -vi="$i" '$1==i{print $1; exit}' "$root$DB/packages.info")"
[ -z "$name" -a "$i" == "$dep" ] && die 'ERROR: unknown dep "%s"' "$i"
fi
;;
install)
tazpkg get-install $i --root=$root --local --quiet --cookmode || { broken; exit 1; }
;;
esac
done
done
done
update_installed_cook_diff
timestamp job2 # installing bdeps
# Get source tarball and make sure we have source dir named:
# $PACKAGE-$VERSION to be standard in receipts. Here we use tar.lzma
# tarball if it exists.
if [ -n "$WGET_URL" -a ! -f "$SRC/$TARBALL" ]; then
if [ -f "$SRC/${SOURCE:-$PACKAGE}-$VERSION.tar.lzma" ]; then
TARBALL="${SOURCE:-$PACKAGE}-$VERSION.tar.lzma"
LZMA_SRC=''
else
get_source || { broken; exit 1; }
fi
fi
if [ -z "$WANTED" -a -n "$TARBALL" -a ! -d "$src" ]; then
mkdir -p $pkgdir/source/tmp; cd $pkgdir/source/tmp
if ! extract_source ; then
get_source
extract_source || { broken; exit 1; }
fi
if [ -n "$LZMA_SRC" ]; then
cd $pkgdir/source
if [ "$(ls -A tmp | wc -l)" -gt 1 -o -f "$(echo tmp/*)" ]; then
mv tmp tmp-1; mkdir tmp
mv tmp-1 tmp/${SOURCE:-$PACKAGE}-$VERSION
fi
if [ -d "tmp/${SOURCE:-$PACKAGE}-$VERSION" ]; then
cd tmp; tar -c * | lzma e $SRC/$TARBALL -si
fi
fi
cd $pkgdir/source/tmp
# Some archives are not well done and don't extract to one dir (ex lzma).
files=$(ls | wc -l)