-
Notifications
You must be signed in to change notification settings - Fork 8
/
vita-makepkg
executable file
·1653 lines (1402 loc) · 45 KB
/
vita-makepkg
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
#
# makepkg - make packages compatible for use with pacman
# @configure_input@
#
# Copyright (c) 2006-2016 Pacman Development Team <pacman-dev@archlinux.org>
# Copyright (c) 2002-2006 by Judd Vinet <jvinet@zeroflux.org>
# Copyright (c) 2005 by Aurelien Foret <orelien@chez.com>
# Copyright (c) 2006 by Miklos Vajna <vmiklos@frugalware.org>
# Copyright (c) 2005 by Christian Hamar <krics@linuxforum.hu>
# Copyright (c) 2006 by Alex Smith <alex@alex-smith.me.uk>
# Copyright (c) 2006 by Andras Voroskoi <voroskoi@frugalware.org>
#
# 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 of the License, 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 this program. If not, see <http://www.gnu.org/licenses/>.
#
# makepkg uses quite a few external programs during its execution. You
# need to have at least the following installed for makepkg to function:
# awk, bsdtar (libarchive), bzip2, coreutils, fakeroot, file, find (findutils),
# gettext, gpg, grep, gzip, sed, tput (ncurses), xz
DIR="$( cd "$( dirname "$(readlink -f ${BASH_SOURCE[0]})" )" && pwd )"
LIBRARY="$DIR"/libmakepkg
# gettext initialization
export TEXTDOMAIN='pacman-scripts'
export TEXTDOMAINDIR='@localedir@'
# file -i does not work on Mac OSX unless legacy mode is set
export COMMAND_MODE='legacy'
# Ensure CDPATH doesn't screw with our cd calls
unset CDPATH
# Ensure GREP_OPTIONS doesn't screw with our grep calls
unset GREP_OPTIONS
declare -r makepkg_version='@PACKAGE_VERSION@'
declare -r confdir="$DIR"
declare -r BUILDSCRIPT='VITABUILD'
declare -r startdir="$PWD"
# LIBRARY=${LIBRARY:-'@libmakepkgdir@'}
build_options=('ccache' 'distcc' 'buildflags' 'makeflags')
splitpkg_overrides=('pkgdesc' 'arch' 'url' 'license' 'groups' 'depends'
'optdepends' 'provides' 'conflicts' 'replaces' 'backup'
'options' 'install' 'changelog')
readonly -a build_options splitpkg_overrides
known_hash_algos=('md5' 'sha1' 'sha224' 'sha256' 'sha384' 'sha512' 'whirlpool')
# Options
ASDEPS=0
BUILDFUNC=0
CHECKFUNC=0
CLEANBUILD=0
CLEANUP=0
DEP_BIN=0
FORCE=0
GENINTEG=0
HOLDVER=0
IGNOREARCH=0
INFAKEROOT=0
INSTALL=0
LOGGING=0
NEEDED=0
NOARCHIVE=0
NOBUILD=0
NODEPS=0
NOEXTRACT=0
PKGFUNC=0
PKGVERFUNC=0
PREPAREFUNC=0
REPKG=0
RMDEPS=0
SKIPCHECKSUMS=0
SKIPPGPCHECK=0
SIGNPKG=''
SPLITPKG=0
SOURCEONLY=0
VERIFYSOURCE=0
shopt -s extglob
### SUBROUTINES ###
# Import libmakepkg
for lib in "$LIBRARY"/*.sh; do
source "$lib"
done
##
# Special exit call for traps, Don't print any error messages when inside,
# the fakeroot call, the error message will be printed by the main call.
##
trap_exit() {
local signal=$1; shift
if (( ! INFAKEROOT )); then
echo
error "$@"
fi
[[ -n $srclinks ]] && rm -rf "$srclinks"
# unset the trap for this signal, and then call the default handler
trap -- "$signal"
kill "-$signal" "$$"
}
##
# Clean up function. Called automatically when the script exits.
##
clean_up() {
local EXIT_CODE=$?
if (( INFAKEROOT )); then
# Don't clean up when leaving fakeroot, we're not done yet.
return
fi
if (( ! EXIT_CODE && CLEANUP )); then
local pkg file
# If it's a clean exit and -c/--clean has been passed...
msg "$(gettext "Cleaning up...")"
rm -rf "$pkgdirbase" "$srcdir"
if [[ -n $pkgbase ]]; then
local fullver=$(get_full_version)
# Can't do this unless the BUILDSCRIPT has been sourced.
if (( BUILDFUNC )); then
rm -f "${pkgbase}-${fullver}-${CARCH}-build.log"*
fi
if (( CHECKFUNC )); then
rm -f "${pkgbase}-${fullver}-${CARCH}-check.log"*
fi
if (( PKGFUNC )); then
rm -f "${pkgbase}-${fullver}-${CARCH}-package.log"*
elif (( SPLITPKG )); then
for pkg in ${pkgname[@]}; do
rm -f "${pkgbase}-${fullver}-${CARCH}-package_${pkg}.log"*
done
fi
# clean up dangling symlinks to packages
for pkg in ${pkgname[@]}; do
for file in ${pkg}-*-*-*{${PKGEXT},${SRCEXT}}; do
if [[ -h $file && ! -e $file ]]; then
rm -f "$file"
fi
done
done
fi
fi
remove_deps
}
enter_fakeroot() {
msg "$(gettext "Entering %s environment...")" "fakeroot"
fakeroot -- $0 -F "${ARGLIST[@]}" || exit $?
}
# Automatically update pkgver variable if a pkgver() function is provided
# Re-sources the PKGBUILD afterwards to allow for other variables that use $pkgver
update_pkgver() {
newpkgver=$(run_function_safe pkgver)
if ! check_pkgver "$newpkgver"; then
error "$(gettext "pkgver() generated an invalid version: %s")" "$newpkgver"
exit 1
fi
if [[ -n $newpkgver && $newpkgver != "$pkgver" ]]; then
if [[ -f $BUILDFILE && -w $BUILDFILE ]]; then
if ! sed -i "s:^pkgver=[^ ]*:pkgver=$newpkgver:" "$BUILDFILE"; then
error "$(gettext "Failed to update %s from %s to %s")" \
"pkgver" "$pkgver" "$newpkgver"
exit 1
fi
sed -i "s:^pkgrel=[^ ]*:pkgrel=1:" "$BUILDFILE"
source_safe "$BUILDFILE"
local fullver=$(get_full_version)
msg "$(gettext "Updated version: %s")" "$pkgbase $fullver"
else
warning "$(gettext "%s is not writeable -- pkgver will not be updated")" \
"$BUILDFILE"
fi
fi
}
# Print 'source not found' error message and exit makepkg
missing_source_file() {
error "$(gettext "Unable to find source file %s.")" "$(get_filename "$1")"
plain "$(gettext "Aborting...")"
exit 1 # $E_MISSING_FILE
}
run_pacman() {
if (( "$1" == "-U" )); then
vdpm "${*:2}"
else
echo "asked to run pacman?"
exit 1
fi
}
check_deps() {
(( $# > 0 )) || return 0
if (( NODEPS )); then
return 0
fi
# forceful install if not exist dep libs
for pkg in ${@}; do
if [[ -n $(find ${VITASDK}/arm-vita-eabi/lib -maxdepth 1 -iname ${pkg}.a) ]] ||
[[ -n $(find ${VITASDK}/arm-vita-eabi/lib -maxdepth 1 -iname lib${pkg}.a) ]]; then
continue
fi
run_pacman -U "$pkg"
done
}
handle_deps() {
local R_DEPS_SATISFIED=0
local R_DEPS_MISSING=1
(( $# == 0 )) && return $R_DEPS_SATISFIED
local deplist=("$@")
if (( ! DEP_BIN )); then
return $R_DEPS_MISSING
fi
if (( DEP_BIN )); then
# install missing deps from binary packages (using pacman -S)
msg "$(gettext "Installing missing dependencies...")"
if ! run_pacman -S --asdeps "${deplist[@]}"; then
error "$(gettext "'%s' failed to install missing dependencies.")" "$PACMAN"
exit 1 # TODO: error code
fi
fi
# we might need the new system environment
# save our shell options and turn off extglob
local shellopts=$(shopt -p)
shopt -u extglob
source /etc/profile &>/dev/null
eval "$shellopts"
return $R_DEPS_SATISFIED
}
resolve_deps() {
local R_DEPS_SATISFIED=0
local R_DEPS_MISSING=1
# deplist cannot be declared like this: local deplist=$(foo)
# Otherwise, the return value will depend on the assignment.
local deplist
deplist=($(check_deps "$@")) || exit 1
[[ -z $deplist ]] && return $R_DEPS_SATISFIED
if handle_deps "${deplist[@]}"; then
# check deps again to make sure they were resolved
deplist=$(check_deps "$@") || exit 1
[[ -z $deplist ]] && return $R_DEPS_SATISFIED
fi
msg "$(gettext "Missing dependencies:")"
local dep
for dep in $deplist; do
msg2 "$dep"
done
return $R_DEPS_MISSING
}
remove_deps() {
(( ! RMDEPS )) && return
# check for packages removed during dependency install (e.g. due to conflicts)
# removing all installed packages is risky in this case
if [[ -n $(grep -xvFf <(printf '%s\n' "${current_pkglist[@]}") \
<(printf '%s\n' "${original_pkglist[@]}")) ]]; then
warning "$(gettext "Failed to remove installed dependencies.")"
return 0
fi
local deplist
deplist=($(grep -xvFf <(printf "%s\n" "${original_pkglist[@]}") \
<(printf "%s\n" "${current_pkglist[@]}")))
if [[ -z $deplist ]]; then
return 0
fi
msg "Removing installed dependencies..."
# exit cleanly on failure to remove deps as package has been built successfully
if ! run_pacman -Rn ${deplist[@]}; then
warning "$(gettext "Failed to remove installed dependencies.")"
return 0
fi
}
error_function() {
if [[ -p $logpipe ]]; then
rm "$logpipe"
fi
# first exit all subshells, then print the error
if (( ! BASH_SUBSHELL )); then
error "$(gettext "A failure occurred in %s().")" "$1"
plain "$(gettext "Aborting...")"
fi
exit 2 # $E_BUILD_FAILED
}
source_safe() {
shopt -u extglob
if ! source "$@"; then
error "$(gettext "Failed to source %s")" "$1"
exit 1
fi
shopt -s extglob
}
merge_arch_attrs() {
local attr supported_attrs=(
provides conflicts depends replaces optdepends
makedepends checkdepends)
for attr in "${supported_attrs[@]}"; do
eval "$attr+=(\"\${${attr}_$CARCH[@]}\")"
done
# ensure that calling this function is idempotent.
unset -v "${supported_attrs[@]/%/_$CARCH}"
}
source_buildfile() {
source_safe "$@"
}
prepare_buildenv() {
# clear user-specified buildflags if requested
if check_option "buildflags" "n"; then
unset CPPFLAGS CFLAGS CXXFLAGS LDFLAGS
fi
if check_option "debug" "y"; then
CFLAGS+=" $DEBUG_CFLAGS"
CXXFLAGS+=" $DEBUG_CXXFLAGS"
fi
# clear user-specified makeflags if requested
if check_option "makeflags" "n"; then
unset MAKEFLAGS
fi
# ensure all necessary build variables are exported
export CPPFLAGS CFLAGS CXXFLAGS LDFLAGS MAKEFLAGS CHOST
local ccache=0
# use ccache if it is requested (check buildenv and PKGBUILD opts)
if check_buildoption "ccache" "y" && [[ -d /usr/lib/ccache/bin ]]; then
export PATH="/usr/lib/ccache/bin:$PATH"
ccache=1
fi
# use distcc if it is requested (check buildenv and PKGBUILD opts)
if check_buildoption "distcc" "y"; then
if (( ccache )); then
export CCACHE_PREFIX="${CCACHE_PREFIX:+$CCACHE_PREFIX }distcc"
export CCACHE_BASEDIR="$srcdir"
elif [[ -d /usr/lib/distcc/bin ]]; then
export PATH="/usr/lib/distcc/bin:$PATH"
fi
export DISTCC_HOSTS
fi
}
run_function_safe() {
local restoretrap restoreset restoreshopt
# we don't set any special shopts of our own, but we don't want the user to
# muck with our environment.
restoreshopt=$(shopt -p)
restoreset=$(shopt -o -p)
shopt -o -s errexit errtrace
restoretrap=$(trap -p ERR)
trap "error_function '$1'" ERR
run_function "$1"
eval "$restoretrap"
eval "$restoreset"
eval "$restoreshopt"
}
run_function() {
if [[ -z $1 ]]; then
return 1
fi
local pkgfunc="$1"
msg "$(gettext "Starting %s()...")" "$pkgfunc"
cd_safe "$srcdir"
# save our shell options so pkgfunc() can't override what we need
local shellopts=$(shopt -p)
local ret=0
if (( LOGGING )); then
local fullver=$(get_full_version)
local BUILDLOG="$LOGDEST/${pkgbase}-${fullver}-${CARCH}-$pkgfunc.log"
if [[ -f $BUILDLOG ]]; then
local i=1
while true; do
if [[ -f $BUILDLOG.$i ]]; then
i=$(($i +1))
else
break
fi
done
mv "$BUILDLOG" "$BUILDLOG.$i"
fi
# ensure overridden package variables survive tee with split packages
logpipe=$(mktemp -u "$LOGDEST/logpipe.XXXXXXXX")
mkfifo "$logpipe"
tee "$BUILDLOG" < "$logpipe" &
local teepid=$!
$pkgfunc &>"$logpipe"
wait $teepid
rm "$logpipe"
else
"$pkgfunc"
fi
# reset our shell options
eval "$shellopts"
}
run_prepare() {
run_function_safe "prepare"
}
run_build() {
run_function_safe "build"
}
run_check() {
run_function_safe "check"
}
run_package() {
local pkgfunc
if [[ -z $1 ]]; then
pkgfunc="package"
else
pkgfunc="package_$1"
fi
run_function_safe "$pkgfunc"
}
find_libdepends() {
local d sodepends;
sodepends=0;
for d in "${depends[@]}"; do
if [[ $d = *.so ]]; then
sodepends=1;
break;
fi
done
if (( sodepends == 0 )); then
(( ${#depends[@]} )) && printf '%s\n' "${depends[@]}"
return;
fi
local libdeps filename soarch sofile soname soversion;
declare -A libdeps;
while read -r filename; do
# get architecture of the file; if soarch is empty it's not an ELF binary
soarch=$(LC_ALL=C readelf -h "$filename" 2>/dev/null | sed -n 's/.*Class.*ELF\(32\|64\)/\1/p')
[[ -n "$soarch" ]] || continue
# process all libraries needed by the binary
for sofile in $(LC_ALL=C readelf -d "$filename" 2>/dev/null | sed -nr 's/.*Shared library: \[(.*)\].*/\1/p')
do
# extract the library name: libfoo.so
soname="${sofile%.so?(+(.+([0-9])))}".so
# extract the major version: 1
soversion="${sofile##*\.so\.}"
if [[ ${libdeps[$soname]} ]]; then
if [[ ${libdeps[$soname]} != *${soversion}-${soarch}* ]]; then
libdeps[$soname]+=" ${soversion}-${soarch}"
fi
else
libdeps[$soname]="${soversion}-${soarch}"
fi
done
done < <(find "$pkgdir" -type f -perm -u+x)
local libdepends v
for d in "${depends[@]}"; do
case "$d" in
*.so)
if [[ ${libdeps[$d]} ]]; then
for v in ${libdeps[$d]}; do
libdepends+=("$d=$v")
done
else
warning "$(gettext "Library listed in %s is not required by any files: %s")" "'depends'" "$d"
libdepends+=("$d")
fi
;;
*)
libdepends+=("$d")
;;
esac
done
(( ${#libdepends[@]} )) && printf '%s\n' "${libdepends[@]}"
}
find_libprovides() {
local p libprovides missing
for p in "${provides[@]}"; do
missing=0
case "$p" in
*.so)
mapfile -t filename < <(find "$pkgdir" -type f -name $p\*)
if [[ $filename ]]; then
# packages may provide multiple versions of the same library
for fn in "${filename[@]}"; do
# check if we really have a shared object
if LC_ALL=C readelf -h "$fn" 2>/dev/null | grep -q '.*Type:.*DYN (Shared object file).*'; then
# get the string binaries link to (e.g. libfoo.so.1.2 -> libfoo.so.1)
local sofile=$(LC_ALL=C readelf -d "$fn" 2>/dev/null | sed -n 's/.*Library soname: \[\(.*\)\].*/\1/p')
if [[ -z "$sofile" ]]; then
warning "$(gettext "Library listed in %s is not versioned: %s")" "'provides'" "$p"
libprovides+=("$p")
continue
fi
# get the library architecture (32 or 64 bit)
local soarch=$(LC_ALL=C readelf -h "$fn" | sed -n 's/.*Class.*ELF\(32\|64\)/\1/p')
# extract the library major version
local soversion="${sofile##*\.so\.}"
libprovides+=("${p}=${soversion}-${soarch}")
else
warning "$(gettext "Library listed in %s is not a shared object: %s")" "'provides'" "$p"
libprovides+=("$p")
fi
done
else
libprovides+=("$p")
missing=1
fi
;;
*)
libprovides+=("$p")
;;
esac
if (( missing )); then
warning "$(gettext "Cannot find library listed in %s: %s")" "'provides'" "$p"
fi
done
(( ${#libprovides[@]} )) && printf '%s\n' "${libprovides[@]}"
}
write_kv_pair() {
local key="$1"
shift
for val in "$@"; do
if [[ $val = *$'\n'* ]]; then
error "$(gettext "Invalid value for %s: %s")" "$key" "$val"
exit 1
fi
printf "%s = %s\n" "$key" "$val"
done
}
write_pkginfo() {
local builddate=$(date -u "+%s")
if [[ -n $PACKAGER ]]; then
local packager="$PACKAGER"
else
local packager="Unknown Packager"
fi
local size="$(du -sk)"
size="$(( ${size%%[^0-9]*} * 1024 ))"
merge_arch_attrs
msg2 "$(gettext "Generating %s file...")" ".PKGINFO"
printf "# Generated by makepkg %s\n" "$makepkg_version"
printf "# using %s\n" "$(fakeroot -v)"
printf "# %s\n" "$(LC_ALL=C date -u)"
write_kv_pair "pkgname" "$pkgname"
if (( SPLITPKG )) || [[ "$pkgbase" != "$pkgname" ]]; then
write_kv_pair "pkgbase" "$pkgbase"
fi
local fullver=$(get_full_version)
write_kv_pair "pkgver" "$fullver"
if [[ "$fullver" != "$basever" ]]; then
write_kv_pair "basever" "$basever"
fi
# TODO: all fields should have this treatment
local spd="${pkgdesc//+([[:space:]])/ }"
spd=("${spd[@]#[[:space:]]}")
spd=("${spd[@]%[[:space:]]}")
write_kv_pair "pkgdesc" "$spd"
write_kv_pair "url" "$url"
write_kv_pair "builddate" "$builddate"
write_kv_pair "packager" "$packager"
write_kv_pair "size" "$size"
write_kv_pair "arch" "$pkgarch"
mapfile -t provides < <(find_libprovides)
mapfile -t depends < <(find_libdepends)
write_kv_pair "license" "${license[@]}"
write_kv_pair "replaces" "${replaces[@]}"
write_kv_pair "group" "${groups[@]}"
write_kv_pair "conflict" "${conflicts[@]}"
write_kv_pair "provides" "${provides[@]}"
write_kv_pair "backup" "${backup[@]}"
write_kv_pair "depend" "${depends[@]}"
write_kv_pair "optdepend" "${optdepends[@]//+([[:space:]])/ }"
write_kv_pair "makedepend" "${makedepends[@]}"
write_kv_pair "checkdepend" "${checkdepends[@]}"
}
write_buildinfo() {
msg2 "$(gettext "Generating %s file...")" ".BUILDINFO"
write_kv_pair "builddir" "${BUILDDIR}"
local sum="$(sha256sum "${BUILDFILE}")"
sum=${sum%% *}
write_kv_pair "pkgbuild_sha256sum" $sum
write_kv_pair "buildenv" "${BUILDENV[@]}"
write_kv_pair "options" "${OPTIONS[@]}"
local pkglist=($(run_pacman -Q | sed "s# #-#"))
write_kv_pair "installed" "${pkglist[@]}"
}
create_package() {
(( NOARCHIVE )) && return
if [[ ! -d $pkgdir ]]; then
error "$(gettext "Missing %s directory.")" "\$pkgdir/"
plain "$(gettext "Aborting...")"
exit 1 # $E_MISSING_PKGDIR
fi
cd_safe "$pkgdir"
msg "$(gettext "Creating package \"%s\"...")" "$pkgname"
pkgarch=$(get_pkg_arch)
# tar it up
local fullver=$(get_full_version)
local pkg_file="$PKGDEST/${pkgname}-${fullver}-${pkgarch}${PKGEXT}"
local ret=0
[[ -f $pkg_file ]] && rm -f "$pkg_file"
[[ -f $pkg_file.sig ]] && rm -f "$pkg_file.sig"
# when fileglobbing, we want * in an empty directory to expand to
# the null string rather than itself
shopt -s nullglob
msg2 "$(gettext "Compressing package...")"
# TODO: Maybe this can be set globally for robustness
shopt -s -o pipefail
# bsdtar's gzip compression always saves the time stamp, making one
# archive created using the same command line distinct from another.
# Disable bsdtar compression and use gzip -n for now.
cd_safe "./$VITASDK/arm-vita-eabi"
LANG=C bsdtar -hcf - * |
case "$PKGEXT" in
*tar.gz) ${COMPRESSGZ[@]:-gzip -c -f -n} ;;
*tar.bz2) ${COMPRESSBZ2[@]:-bzip2 -c -f} ;;
*tar.xz) ${COMPRESSXZ[@]:-xz -c -z -} ;;
*tar.lrz) ${COMPRESSLRZ[@]:-lrzip -q} ;;
*tar.lzo) ${COMPRESSLZO[@]:-lzop -q} ;;
*tar.Z) ${COMPRESSZ[@]:-compress -c -f} ;;
*tar) cat ;;
*) warning "$(gettext "'%s' is not a valid archive extension.")" \
"$PKGEXT"; cat ;;
esac > "${pkg_file}" || ret=$?
cd_safe "$pkgdir"
shopt -u nullglob
shopt -u -o pipefail
if (( ret )); then
error "$(gettext "Failed to create package file.")"
exit 1 # TODO: error code
fi
create_signature "$pkg_file"
if (( ! ret )) && [[ ! "$PKGDEST" -ef "${startdir}" ]]; then
rm -f "${pkg_file/$PKGDEST/$startdir}"
ln -s "${pkg_file}" "${pkg_file/$PKGDEST/$startdir}"
ret=$?
if [[ -f $pkg_file.sig ]]; then
rm -f "${pkg_file/$PKGDEST/$startdir}.sig"
ln -s "$pkg_file.sig" "${pkg_file/$PKGDEST/$startdir}.sig"
fi
fi
if (( ret )); then
warning "$(gettext "Failed to create symlink to package file.")"
fi
}
create_debug_package() {
# check if a debug package was requested
if ! check_option "debug" "y" || ! check_option "strip" "y"; then
return
fi
pkgdir="${pkgdir}-@DEBUGSUFFIX@"
# check if we have any debug symbols to package
if dir_is_empty "$pkgdir/usr/lib/debug"; then
return
fi
depends=("$pkgname=$(get_full_version)")
pkgdesc="Detached debugging symbols for $pkgname"
pkgname=$pkgname-@DEBUGSUFFIX@
unset groups optdepends provides conflicts replaces backup install changelog
create_package
}
create_srcpackage() {
local ret=0
msg "$(gettext "Creating source package...")"
local srclinks="$(mktemp -d "$startdir"/srclinks.XXXXXXXXX)"
mkdir "${srclinks}"/${pkgbase}
msg2 "$(gettext "Adding %s...")" "$BUILDSCRIPT"
ln -s "${BUILDFILE}" "${srclinks}/${pkgbase}/${BUILDSCRIPT}"
msg2 "$(gettext "Generating %s file...")" .SRCINFO
write_srcinfo > "$srclinks/$pkgbase"/.SRCINFO
local file all_sources
get_all_sources 'all_sources'
for file in "${all_sources[@]}"; do
if [[ "$file" = "$(get_filename "$file")" ]] || (( SOURCEONLY == 2 )); then
local absfile
absfile=$(get_filepath "$file") || missing_source_file "$file"
msg2 "$(gettext "Adding %s...")" "${absfile##*/}"
ln -s "$absfile" "$srclinks/$pkgbase"
fi
done
local i
for i in 'changelog' 'install'; do
local file files
[[ ${!i} ]] && files+=("${!i}")
for name in "${pkgname[@]}"; do
if extract_function_variable "package_$name" "$i" 0 file; then
files+=("$file")
fi
done
for file in "${files[@]}"; do
if [[ $file && ! -f "${srclinks}/${pkgbase}/$file" ]]; then
msg2 "$(gettext "Adding %s file (%s)...")" "$i" "${file}"
ln -s "${startdir}/$file" "${srclinks}/${pkgbase}/"
fi
done
done
local TAR_OPT
case "$SRCEXT" in
*tar.gz) TAR_OPT="-z" ;;
*tar.bz2) TAR_OPT="-j" ;;
*tar.xz) TAR_OPT="-J" ;;
*tar.lrz) TAR_OPT="--lrzip" ;;
*tar.lzo) TAR_OPT="--lzop" ;;
*tar.Z) TAR_OPT="-Z" ;;
*tar) TAR_OPT="" ;;
*) warning "$(gettext "'%s' is not a valid archive extension.")" \
"$SRCEXT" ;;
esac
local fullver=$(get_full_version)
local pkg_file="$SRCPKGDEST/${pkgbase}-${fullver}${SRCEXT}"
# tar it up
msg2 "$(gettext "Compressing source package...")"
cd_safe "${srclinks}"
if ! LANG=C bsdtar -cL ${TAR_OPT} -f "$pkg_file" ${pkgbase}; then
error "$(gettext "Failed to create source package file.")"
exit 1 # TODO: error code
fi
create_signature "$pkg_file"
if [[ ! "$SRCPKGDEST" -ef "${startdir}" ]]; then
rm -f "${pkg_file/$SRCPKGDEST/$startdir}"
ln -s "${pkg_file}" "${pkg_file/$SRCPKGDEST/$startdir}"
ret=$?
if [[ -f $pkg_file.sig ]]; then
rm -f "${pkg_file/$SRCPKGDEST/$startdir}.sig"
ln -s "$pkg_file.sig" "${pkg_file/$SRCPKGDEST/$startdir}.sig"
fi
fi
if (( ret )); then
warning "$(gettext "Failed to create symlink to source package file.")"
fi
cd_safe "${startdir}"
rm -rf "${srclinks}"
}
# this function always returns 0 to make sure clean-up will still occur
install_package() {
(( ! INSTALL )) && return
if (( ! SPLITPKG )); then
msg "$(gettext "Installing package %s with %s...")" "$pkgname" "$PACMAN -U"
else
msg "$(gettext "Installing %s package group with %s...")" "$pkgbase" "$PACMAN -U"
fi
local fullver pkgarch pkg pkglist
(( ASDEPS )) && pkglist+=('--asdeps')
(( NEEDED )) && pkglist+=('--needed')
for pkg in ${pkgname[@]}; do
fullver=$(get_full_version)
pkgarch=$(get_pkg_arch $pkg)
pkglist+=("$PKGDEST/${pkg}-${fullver}-${pkgarch}${PKGEXT}")
if [[ -f "$PKGDEST/${pkg}-@DEBUGSUFFIX@-${fullver}-${pkgarch}${PKGEXT}" ]]; then
pkglist+=("$PKGDEST/${pkg}-@DEBUGSUFFIX@-${fullver}-${pkgarch}${PKGEXT}")
fi
done
if ! run_pacman -U "${pkglist[@]}"; then
warning "$(gettext "Failed to install built package(s).")"
return 0
fi
}
get_vcsclient() {
local proto=${1%%+*}
local i
for i in "${VCSCLIENTS[@]}"; do
local handler="${i%%::*}"
if [[ $proto = "$handler" ]]; then
local client="${i##*::}"
break
fi
done
# if we didn't find an client, return an error
if [[ -z $client ]]; then
error "$(gettext "Unknown download protocol: %s")" "$proto"
plain "$(gettext "Aborting...")"
exit 1 # $E_CONFIG_ERROR
fi
printf "%s\n" "$client"
}
check_vcs_software() {
local all_sources all_deps deps ret=0
if (( SOURCEONLY == 1 )); then
# we will not download VCS sources
return $ret
fi
# we currently only use global depends/makedepends arrays for --syncdeps
for attr in depends makedepends; do
get_pkgbuild_attribute "$pkg" "$attr" 1 'deps'
check_deps "${deps[@]}"
done
get_all_sources_for_arch 'all_sources'
for netfile in ${all_sources[@]}; do
local proto=$(get_protocol "$netfile")
case $proto in
bzr*|git*|hg*|svn*)
if ! type -p ${proto%%+*} > /dev/null; then
local client
client=$(get_vcsclient "$proto") || exit $?
# ensure specified program is installed
local uninstalled
uninstalled=$(check_deps "$client") || exit 1
# if not installed, check presence in depends or makedepends
if [[ -n "$uninstalled" ]] && (( ! NODEPS || ( VERIFYSOURCE && !DEP_BIN ) )); then
if ! in_array "$client" ${all_deps[@]}; then
error "$(gettext "Cannot find the %s package needed to handle %s sources.")" \
"$client" "${proto%%+*}"
ret=1
fi
fi
fi
;;
*)
# non VCS source
;;
esac
done
return $ret
}
check_software() {
# check for needed software
local ret=0
# check for sudo if we will need it during makepkg execution
if (( DEP_BIN || RMDEPS || INSTALL )); then
if ! type -p sudo >/dev/null; then
warning "$(gettext "Cannot find the %s binary. Will use %s to acquire root privileges.")" "sudo" "su"
fi
fi
# fakeroot - correct package file permissions
if check_buildenv "fakeroot" "y" && (( EUID > 0 )); then
if ! type -p fakeroot >/dev/null; then
error "$(gettext "Cannot find the %s binary.")" "fakeroot"
ret=1
fi
fi
# gpg - package signing
if [[ $SIGNPKG == 'y' ]] || { [[ -z $SIGNPKG ]] && check_buildenv "sign" "y"; }; then
if ! type -p gpg >/dev/null; then
error "$(gettext "Cannot find the %s binary required for signing packages.")" "gpg"
ret=1
fi
fi
# gpg - source verification
if (( ! SKIPPGPCHECK )) && source_has_signatures; then
if ! type -p gpg >/dev/null; then
error "$(gettext "Cannot find the %s binary required for verifying source files.")" "gpg"
ret=1
fi
fi
# checksum operations
if (( GENINTEG || ! SKIPCHECKSUMS )); then
local integlist
IFS=$'\n' read -rd '' -a integlist < <(get_integlist)