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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
|
#!/usr/bin/env bash
# Copyright 1999-2023 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
if ___eapi_has_DESTTREE_INSDESTTREE; then
export DESTTREE=/usr
export INSDESTTREE=""
else
export __E_DESTTREE=/usr
export __E_INSDESTTREE=""
fi
export __E_EXEDESTTREE=""
export __E_DOCDESTTREE=""
export INSOPTIONS="-m0644"
export EXEOPTIONS="-m0755"
export LIBOPTIONS="-m0644"
export DIROPTIONS="-m0755"
export MOPREFIX=${PN}
# Do not compress files which are smaller than this (in bytes), bug #169260
export PORTAGE_DOCOMPRESS_SIZE_LIMIT="128"
declare -a PORTAGE_DOCOMPRESS=( /usr/share/{doc,info,man} )
declare -a PORTAGE_DOCOMPRESS_SKIP=( /usr/share/doc/${PF}/html )
declare -a PORTAGE_DOSTRIP=( / )
has strip ${PORTAGE_RESTRICT} && PORTAGE_DOSTRIP=()
declare -a PORTAGE_DOSTRIP_SKIP=()
into() {
if [[ "$1" == "/" ]]; then
export __E_DESTTREE=""
else
export __E_DESTTREE=$1
if ! ___eapi_has_prefix_variables; then
local ED=${D}
fi
if [[ ! -d "${ED%/}/${__E_DESTTREE#/}" ]]; then
install -d "${ED%/}/${__E_DESTTREE#/}"
local ret=$?
if [[ ${ret} -ne 0 ]] ; then
__helpers_die "${FUNCNAME[0]} failed"
return ${ret}
fi
fi
fi
if ___eapi_has_DESTTREE_INSDESTTREE; then
export DESTTREE=${__E_DESTTREE}
fi
}
insinto() {
if [[ "${1}" == "/" ]]; then
export __E_INSDESTTREE=""
else
export __E_INSDESTTREE=${1}
if ! ___eapi_has_prefix_variables; then
local ED=${D}
fi
if [[ ! -d "${ED%/}/${__E_INSDESTTREE#/}" ]]; then
install -d "${ED%/}/${__E_INSDESTTREE#/}"
local ret=$?
if [[ ${ret} -ne 0 ]] ; then
__helpers_die "${FUNCNAME[0]} failed"
return ${ret}
fi
fi
fi
if ___eapi_has_DESTTREE_INSDESTTREE; then
export INSDESTTREE=${__E_INSDESTTREE}
fi
}
exeinto() {
if [[ "${1}" == "/" ]]; then
export __E_EXEDESTTREE=""
else
export __E_EXEDESTTREE="${1}"
if ! ___eapi_has_prefix_variables; then
local ED=${D}
fi
if [[ ! -d "${ED%/}/${__E_EXEDESTTREE#/}" ]]; then
install -d "${ED%/}/${__E_EXEDESTTREE#/}"
local ret=$?
if [[ ${ret} -ne 0 ]] ; then
__helpers_die "${FUNCNAME[0]} failed"
return ${ret}
fi
fi
fi
}
docinto() {
if [[ "${1}" == "/" ]]; then
export __E_DOCDESTTREE=""
else
export __E_DOCDESTTREE="${1}"
if ! ___eapi_has_prefix_variables; then
local ED=${D}
fi
if [[ ! -d "${ED%/}/usr/share/doc/${PF}/${__E_DOCDESTTREE#/}" ]]; then
install -d "${ED%/}/usr/share/doc/${PF}/${__E_DOCDESTTREE#/}"
local ret=$?
if [[ ${ret} -ne 0 ]] ; then
__helpers_die "${FUNCNAME[0]} failed"
return ${ret}
fi
fi
fi
}
insopts() {
export INSOPTIONS="$@"
# `install` should never be called with '-s' ...
has -s ${INSOPTIONS} && die "Never call insopts() with -s"
}
diropts() {
export DIROPTIONS="$@"
}
exeopts() {
export EXEOPTIONS="$@"
# `install` should never be called with '-s' ...
has -s ${EXEOPTIONS} && die "Never call exeopts() with -s"
}
libopts() {
if ! ___eapi_has_dolib_libopts; then
die "'${FUNCNAME}' has been banned for EAPI '${EAPI}'"
fi
export LIBOPTIONS="$@"
# `install` should never be called with '-s' ...
has -s ${LIBOPTIONS} && die "Never call libopts() with -s"
}
docompress() {
___eapi_has_docompress || die "'docompress' not supported in this EAPI"
local f g
if [[ ${1} = "-x" ]]; then
shift
for f; do
f=$(__strip_duplicate_slashes "${f}"); f=${f%/}
[[ ${f:0:1} = / ]] || f="/${f}"
for g in "${PORTAGE_DOCOMPRESS_SKIP[@]}"; do
[[ ${f} = "${g}" ]] && continue 2
done
PORTAGE_DOCOMPRESS_SKIP[${#PORTAGE_DOCOMPRESS_SKIP[@]}]=${f}
done
else
for f; do
f=$(__strip_duplicate_slashes "${f}"); f=${f%/}
[[ ${f:0:1} = / ]] || f="/${f}"
for g in "${PORTAGE_DOCOMPRESS[@]}"; do
[[ ${f} = "${g}" ]] && continue 2
done
PORTAGE_DOCOMPRESS[${#PORTAGE_DOCOMPRESS[@]}]=${f}
done
fi
}
dostrip() {
___eapi_has_dostrip || die "'${FUNCNAME}' not supported in this EAPI"
local f g
if [[ $1 = "-x" ]]; then
shift
for f; do
f=$(__strip_duplicate_slashes "${f}"); f=${f%/}
[[ ${f:0:1} = / ]] || f="/${f}"
for g in "${PORTAGE_DOSTRIP_SKIP[@]}"; do
[[ ${f} = "${g}" ]] && continue 2
done
PORTAGE_DOSTRIP_SKIP+=( "${f}" )
done
else
for f; do
f=$(__strip_duplicate_slashes "${f}"); f=${f%/}
[[ ${f:0:1} = / ]] || f="/${f}"
for g in "${PORTAGE_DOSTRIP[@]}"; do
[[ ${f} = "${g}" ]] && continue 2
done
PORTAGE_DOSTRIP+=( "${f}" )
done
fi
}
useq() {
___eapi_has_useq || die "'${FUNCNAME}' banned in EAPI ${EAPI}"
eqawarn "QA Notice: The 'useq' function is deprecated (replaced by 'use')"
use ${1}
}
usev() {
local nargs=1
___eapi_usev_has_second_arg && nargs=2
[[ ${#} -gt ${nargs} ]] && die "usev takes at most ${nargs} arguments"
if use ${1}; then
echo "${2:-${1#!}}"
return 0
fi
return 1
}
if ___eapi_has_usex; then
usex() {
if use "$1"; then
echo "${2-yes}$4"
else
echo "${3-no}$5"
fi
return 0
}
fi
use() {
local u=$1
local found=0
# If we got something like '!flag', then invert the return value
if [[ ${u:0:1} == "!" ]] ; then
u=${u:1}
found=1
fi
if [[ ${EBUILD_PHASE} = depend ]] ; then
# TODO: Add a registration interface for eclasses to register
# any number of phase hooks, so that global scope eclass
# initialization can by migrated to phase hooks in new EAPIs.
# Example: add_phase_hook before pkg_setup ${ECLASS}_pre_pkg_setup
#if [[ -n ${EAPI} ]] && ! has "${EAPI}" 0 1 2 3 ; then
# die "use() called during invalid phase: ${EBUILD_PHASE}"
#fi
true
# Make sure we have this USE flag in IUSE, but exempt binary
# packages for API consumers like Entropy which do not require
# a full profile with IUSE_IMPLICIT and stuff (see bug #456830).
elif declare -f ___in_portage_iuse >/dev/null &&
[[ -n ${EBUILD_PHASE} && -n ${PORTAGE_INTERNAL_CALLER} ]] ; then
if ! ___in_portage_iuse "${u}"; then
if [[ ${EMERGE_FROM} != binary &&
! ${EAPI} =~ ^(0|1|2|3|4|4-slot-abi)$ ]] ; then
# This is only strict starting with EAPI 5, since implicit IUSE
# is not well defined for earlier EAPIs (see bug #449708).
die "USE Flag '${u}' not in IUSE for ${CATEGORY}/${PF}"
fi
eqawarn "QA Notice: USE Flag '${u}' not" \
"in IUSE for ${CATEGORY}/${PF}"
fi
fi
local IFS=$' \t\n' prev_shopts=$- ret
set -f
if has ${u} ${USE} ; then
ret=${found}
else
ret=$((!found))
fi
[[ ${prev_shopts} == *f* ]] || set +f
return ${ret}
}
use_with() {
if [[ -z "${1}" ]]; then
echo "!!! use_with() called without a parameter." >&2
echo "!!! use_with <USEFLAG> [<flagname> [value]]" >&2
return 1
fi
if ___eapi_use_enable_and_use_with_support_empty_third_argument; then
local UW_SUFFIX=${3+=$3}
else
local UW_SUFFIX=${3:+=$3}
fi
local UWORD=${2:-$1}
if use ${1}; then
echo "--with-${UWORD}${UW_SUFFIX}"
else
echo "--without-${UWORD}"
fi
return 0
}
use_enable() {
if [[ -z "${1}" ]]; then
echo "!!! use_enable() called without a parameter." >&2
echo "!!! use_enable <USEFLAG> [<flagname> [value]]" >&2
return 1
fi
if ___eapi_use_enable_and_use_with_support_empty_third_argument; then
local UE_SUFFIX=${3+=$3}
else
local UE_SUFFIX=${3:+=$3}
fi
local UWORD=${2:-$1}
if use ${1}; then
echo "--enable-${UWORD}${UE_SUFFIX}"
else
echo "--disable-${UWORD}"
fi
return 0
}
unpack() {
local srcdir
local x
local y y_insensitive
local suffix suffix_insensitive
local myfail
local eapi=${EAPI:-0}
[[ -z "$*" ]] && die "Nothing passed to the 'unpack' command"
for x in "$@"; do
__vecho ">>> Unpacking ${x} to ${PWD}"
suffix=${x##*.}
suffix_insensitive=$(LC_ALL=C tr "[:upper:]" "[:lower:]" <<< "${suffix}")
y=${x%.*}
y=${y##*.}
y_insensitive=$(LC_ALL=C tr "[:upper:]" "[:lower:]" <<< "${y}")
# wrt PMS 11.3.3.13 Misc Commands
if [[ ${x} != */* ]]; then
# filename without path of any kind
srcdir=${DISTDIR}/
elif [[ ${x} == ./* ]]; then
# relative path starting with './'
srcdir=
else
# non-'./' filename with path of some kind
if ___eapi_unpack_supports_absolute_paths; then
# EAPI 6 allows absolute and deep relative paths
srcdir=
if [[ ${x} == ${DISTDIR%/}/* ]]; then
eqawarn "QA Notice: unpack called with redundant \${DISTDIR} in path"
fi
elif [[ ${x} == ${DISTDIR%/}/* ]]; then
die "Arguments to unpack() cannot begin with \${DISTDIR} in EAPI ${EAPI}"
elif [[ ${x} == /* ]] ; then
die "Arguments to unpack() cannot be absolute in EAPI ${EAPI}"
else
die "Relative paths to unpack() must be prefixed with './' in EAPI ${EAPI}"
fi
fi
[[ ! -s ${srcdir}${x} ]] && die "unpack: ${x} does not exist"
__unpack_tar() {
if [[ ${y_insensitive} == tar ]] ; then
if ___eapi_unpack_is_case_sensitive && \
[[ tar != ${y} ]] ; then
eqawarn "QA Notice: unpack called with" \
"secondary suffix '${y}' which is unofficially" \
"supported with EAPI '${EAPI}'. Instead use 'tar'."
fi
$1 -c -- "${srcdir}${x}" | tar xof -
__assert_sigpipe_ok "${myfail}"
else
local cwd_dest=${x##*/}
cwd_dest=${cwd_dest%.*}
$1 -c -- "${srcdir}${x}" > "${cwd_dest}" || die "${myfail}"
fi
}
myfail="unpack: failure unpacking ${x}"
case "${suffix_insensitive}" in
tar)
if ___eapi_unpack_is_case_sensitive && \
[[ tar != ${suffix} ]] ; then
eqawarn "QA Notice: unpack called with" \
"suffix '${suffix}' which is unofficially supported" \
"with EAPI '${EAPI}'. Instead use 'tar'."
fi
tar xof "${srcdir}${x}" || die "${myfail}"
;;
tgz)
if ___eapi_unpack_is_case_sensitive && \
[[ tgz != ${suffix} ]] ; then
eqawarn "QA Notice: unpack called with" \
"suffix '${suffix}' which is unofficially supported" \
"with EAPI '${EAPI}'. Instead use 'tgz'."
fi
tar xozf "${srcdir}${x}" || die "${myfail}"
;;
tbz|tbz2)
if ___eapi_unpack_is_case_sensitive && \
[[ " tbz tbz2 " != *" ${suffix} "* ]] ; then
eqawarn "QA Notice: unpack called with" \
"suffix '${suffix}' which is unofficially supported" \
"with EAPI '${EAPI}'. Instead use 'tbz' or 'tbz2'."
fi
${PORTAGE_BUNZIP2_COMMAND:-${PORTAGE_BZIP2_COMMAND} -d} -c -- "${srcdir}${x}" | tar xof -
__assert_sigpipe_ok "${myfail}"
;;
zip|jar)
if ___eapi_unpack_is_case_sensitive && \
[[ " ZIP zip jar " != *" ${suffix} "* ]] ; then
eqawarn "QA Notice: unpack called with" \
"suffix '${suffix}' which is unofficially supported" \
"with EAPI '${EAPI}'." \
"Instead use 'ZIP', 'zip', or 'jar'."
fi
# unzip will interactively prompt under some error conditions,
# as reported in bug #336285
( set +x ; while true ; do echo n || break ; done ) | \
unzip -qo "${srcdir}${x}" || die "${myfail}"
;;
gz|z)
if ___eapi_unpack_is_case_sensitive && \
[[ " gz z Z " != *" ${suffix} "* ]] ; then
eqawarn "QA Notice: unpack called with" \
"suffix '${suffix}' which is unofficially supported" \
"with EAPI '${EAPI}'. Instead use 'gz', 'z', or 'Z'."
fi
__unpack_tar "gzip -d"
;;
bz2|bz)
if ___eapi_unpack_is_case_sensitive && \
[[ " bz bz2 " != *" ${suffix} "* ]] ; then
eqawarn "QA Notice: unpack called with" \
"suffix '${suffix}' which is unofficially supported" \
"with EAPI '${EAPI}'. Instead use 'bz' or 'bz2'."
fi
__unpack_tar "${PORTAGE_BUNZIP2_COMMAND:-${PORTAGE_BZIP2_COMMAND} -d}"
;;
7z)
if ___eapi_unpack_supports_7z; then
local my_output
my_output="$(7z x -y "${srcdir}${x}")"
if [[ $? -ne 0 ]]; then
echo "${my_output}" >&2
die "${myfail}"
fi
else
__vecho "unpack ${x}: file format not recognized. Ignoring."
fi
;;
rar)
if ___eapi_unpack_is_case_sensitive && \
[[ " rar RAR " != *" ${suffix} "* ]] ; then
eqawarn "QA Notice: unpack called with" \
"suffix '${suffix}' which is unofficially supported" \
"with EAPI '${EAPI}'. Instead use 'rar' or 'RAR'."
fi
if ___eapi_unpack_supports_rar; then
unrar x -idq -o+ "${srcdir}${x}" || die "${myfail}"
else
__vecho "unpack ${x}: file format not recognized. Ignoring."
fi
;;
lha|lzh)
if ___eapi_unpack_is_case_sensitive && \
[[ " LHA LHa lha lzh " != *" ${suffix} "* ]] ; then
eqawarn "QA Notice: unpack called with" \
"suffix '${suffix}' which is unofficially supported" \
"with EAPI '${EAPI}'." \
"Instead use 'LHA', 'LHa', 'lha', or 'lzh'."
fi
if ___eapi_unpack_supports_lha; then
lha xfq "${srcdir}${x}" || die "${myfail}"
else
__vecho "unpack ${x}: file format not recognized. Ignoring."
fi
;;
a)
if ___eapi_unpack_is_case_sensitive && \
[[ " a " != *" ${suffix} "* ]] ; then
eqawarn "QA Notice: unpack called with" \
"suffix '${suffix}' which is unofficially supported" \
"with EAPI '${EAPI}'. Instead use 'a'."
fi
ar x "${srcdir}${x}" || die "${myfail}"
;;
deb)
if ___eapi_unpack_is_case_sensitive && \
[[ " deb " != *" ${suffix} "* ]] ; then
eqawarn "QA Notice: unpack called with" \
"suffix '${suffix}' which is unofficially supported" \
"with EAPI '${EAPI}'. Instead use 'deb'."
fi
# Unpacking .deb archives can not always be done with
# `ar`. For instance on AIX this doesn't work out.
# If `ar` is not the GNU binutils version and we have
# `deb2targz` installed, prefer it over `ar` for that
# reason. We just make sure on AIX `deb2targz` is
# installed.
if [[ $(ar --version 2>/dev/null) != "GNU ar"* ]] && \
type -P deb2targz > /dev/null; then
y=${x##*/}
local created_symlink=0
if [[ ! "${srcdir}${x}" -ef "${y}" ]]; then
# deb2targz always extracts into the same directory as
# the source file, so create a symlink in the current
# working directory if necessary.
ln -sf "${srcdir}${x}" "${y}" || die "${myfail}"
created_symlink=1
fi
deb2targz "${y}" || die "${myfail}"
if [[ ${created_symlink} = 1 ]]; then
# Clean up the symlink so the ebuild
# doesn't inadvertently install it.
rm -f "${y}"
fi
mv -f "${y%.deb}".tar.gz data.tar.gz \
|| mv -f "${y%.deb}".tar.xz data.tar.xz \
|| die "${myfail}"
else
ar x "${srcdir}${x}" || die "${myfail}"
fi
;;
lzma)
if ___eapi_unpack_is_case_sensitive && \
[[ " lzma " != *" ${suffix} "* ]] ; then
eqawarn "QA Notice: unpack called with" \
"suffix '${suffix}' which is unofficially supported" \
"with EAPI '${EAPI}'. Instead use 'lzma'."
fi
__unpack_tar "lzma -d"
;;
xz)
if ___eapi_unpack_is_case_sensitive && \
[[ " xz " != *" ${suffix} "* ]] ; then
eqawarn "QA Notice: unpack called with" \
"suffix '${suffix}' which is unofficially supported" \
"with EAPI '${EAPI}'. Instead use 'xz'."
fi
if ___eapi_unpack_supports_xz; then
__unpack_tar "xz -T$(___makeopts_jobs) -d"
else
__vecho "unpack ${x}: file format not recognized. Ignoring."
fi
;;
txz)
if ___eapi_unpack_is_case_sensitive && \
[[ " txz " != *" ${suffix} "* ]] ; then
eqawarn "QA Notice: unpack called with" \
"suffix '${suffix}' which is unofficially supported" \
"with EAPI '${EAPI}'. Instead use 'txz'."
fi
if ___eapi_unpack_supports_txz; then
XZ_OPT="-T$(___makeopts_jobs)" tar xof "${srcdir}${x}" || die "${myfail}"
else
__vecho "unpack ${x}: file format not recognized. Ignoring."
fi
;;
*)
__vecho "unpack ${x}: file format not recognized. Ignoring."
;;
esac
done
# Do not chmod '.' since it's probably ${WORKDIR} and PORTAGE_WORKDIR_MODE
# should be preserved.
find . -mindepth 1 -maxdepth 1 ! -type l -print0 | \
${XARGS} -0 "${PORTAGE_BIN_PATH}/chmod-lite"
}
econf() {
local x
local pid=${BASHPID:-$(__bashpid)}
if ! ___eapi_has_prefix_variables; then
local EPREFIX=
fi
__hasg() {
local x s=$1
shift
for x ; do [[ ${x} == ${s} ]] && echo "${x}" && return 0 ; done
return 1
}
__hasgq() { __hasg "$@" >/dev/null ; }
local phase_func=$(__ebuild_arg_to_phase "${EBUILD_PHASE}")
if [[ -n ${phase_func} ]] ; then
if ! ___eapi_has_src_configure; then
[[ ${phase_func} != src_compile ]] && \
eqawarn "QA Notice: econf called in" \
"${phase_func} instead of src_compile"
else
[[ ${phase_func} != src_configure ]] && \
eqawarn "QA Notice: econf called in" \
"${phase_func} instead of src_configure"
fi
fi
: ${ECONF_SOURCE:=.}
if [[ -x "${ECONF_SOURCE}/configure" ]]; then
if [[ -n ${CONFIG_SHELL} && \
"$(head -n1 "${ECONF_SOURCE}/configure")" =~ ^'#!'[[:space:]]*/bin/sh([[:space:]]|$) ]] ; then
cp -p "${ECONF_SOURCE}/configure" "${ECONF_SOURCE}/configure._portage_tmp_.${pid}" || die
sed -i \
-e "1s:^#![[:space:]]*/bin/sh:#!${CONFIG_SHELL}:" \
"${ECONF_SOURCE}/configure._portage_tmp_.${pid}" \
|| die "Substition of shebang in '${ECONF_SOURCE}/configure' failed"
# Preserve timestamp, see bug #440304
touch -r "${ECONF_SOURCE}/configure" "${ECONF_SOURCE}/configure._portage_tmp_.${pid}" || die
mv -f "${ECONF_SOURCE}/configure._portage_tmp_.${pid}" "${ECONF_SOURCE}/configure" || die
fi
if [[ -e "${EPREFIX}"/usr/share/gnuconfig/ ]]; then
find "${WORKDIR}" -type f '(' \
-name config.guess -o -name config.sub ')' -print0 | \
while read -r -d $'\0' x ; do
__vecho " * econf: updating ${x/${WORKDIR}\/} with ${EPREFIX}/usr/share/gnuconfig/${x##*/}"
# Make sure we do this atomically incase we're run in parallel, bug #487478
cp -f "${EPREFIX}"/usr/share/gnuconfig/"${x##*/}" "${x}.${pid}"
mv -f "${x}.${pid}" "${x}"
done
fi
local conf_args=()
if ___eapi_econf_passes_--disable-dependency-tracking || ___eapi_econf_passes_--disable-silent-rules || ___eapi_econf_passes_--docdir_and_--htmldir || ___eapi_econf_passes_--with-sysroot; then
local conf_help=$("${ECONF_SOURCE}/configure" --help 2>/dev/null)
if ___eapi_econf_passes_--datarootdir; then
if [[ ${conf_help} == *--datarootdir* ]]; then
conf_args+=( --datarootdir="${EPREFIX}"/usr/share )
fi
fi
if ___eapi_econf_passes_--disable-dependency-tracking; then
if [[ ${conf_help} == \
*--disable-dependency-tracking[^A-Za-z0-9+_.-]* ]]; then
conf_args+=( --disable-dependency-tracking )
fi
fi
if ___eapi_econf_passes_--disable-silent-rules; then
if [[ ${conf_help} == \
*--disable-silent-rules[^A-Za-z0-9+_.-]* ]]; then
conf_args+=( --disable-silent-rules )
fi
fi
if ___eapi_econf_passes_--disable-static; then
if [[ ${conf_help} == *--enable-shared[^A-Za-z0-9+_.-]* &&
${conf_help} == *--enable-static[^A-Za-z0-9+_.-]* ]]; then
conf_args+=( --disable-static )
fi
fi
if ___eapi_econf_passes_--docdir_and_--htmldir; then
if [[ ${conf_help} == *--docdir* ]]; then
conf_args+=( --docdir="${EPREFIX}"/usr/share/doc/${PF} )
fi
if [[ ${conf_help} == *--htmldir* ]]; then
conf_args+=( --htmldir="${EPREFIX}"/usr/share/doc/${PF}/html )
fi
fi
if ___eapi_econf_passes_--with-sysroot; then
if [[ ${conf_help} == *--with-sysroot[^A-Za-z0-9+_.-]* ]]; then
conf_args+=( --with-sysroot="${ESYSROOT:-/}" )
fi
fi
fi
# If the profile defines a location to install libs to aside from default, pass it on.
# If the ebuild passes in --libdir, they're responsible for the libdir fun.
local libdir libdir_var="LIBDIR_${ABI}"
if [[ -n ${ABI} && -n ${!libdir_var} ]] ; then
libdir=${!libdir_var}
fi
if [[ -n ${libdir} ]] && ! __hasgq --libdir=\* "$@" ; then
export CONF_PREFIX=$(__hasg --exec-prefix=\* "$@")
[[ -z ${CONF_PREFIX} ]] && CONF_PREFIX=$(__hasg --prefix=\* "$@")
: ${CONF_PREFIX:=${EPREFIX}/usr}
CONF_PREFIX=${CONF_PREFIX#*=}
[[ ${CONF_PREFIX} != /* ]] && CONF_PREFIX="/${CONF_PREFIX}"
[[ ${libdir} != /* ]] && libdir="/${libdir}"
conf_args+=(
--libdir="$(__strip_duplicate_slashes "${CONF_PREFIX}${libdir}")"
)
fi
# Handle arguments containing quoted whitespace (see bug #457136).
eval "local -a EXTRA_ECONF=(${EXTRA_ECONF})"
set -- \
--prefix="${EPREFIX}"/usr \
${CBUILD:+--build=${CBUILD}} \
--host=${CHOST} \
${CTARGET:+--target=${CTARGET}} \
--mandir="${EPREFIX}"/usr/share/man \
--infodir="${EPREFIX}"/usr/share/info \
--datadir="${EPREFIX}"/usr/share \
--sysconfdir="${EPREFIX}"/etc \
--localstatedir="${EPREFIX}"/var/lib \
"${conf_args[@]}" \
"$@" \
"${EXTRA_ECONF[@]}"
__vecho "${ECONF_SOURCE}/configure" "$@"
if ! "${ECONF_SOURCE}/configure" "$@" ; then
if [[ -s config.log ]]; then
echo
echo "!!! Please attach the following file when seeking support:"
echo "!!! ${PWD}/config.log"
fi
# econf dies unconditionally in EAPIs 0 to 3
___eapi_helpers_can_die || die "econf failed"
__helpers_die "econf failed"
return 1
fi
elif [[ -f "${ECONF_SOURCE}/configure" ]]; then
die "configure is not executable"
else
die "no configure script found"
fi
}
einstall() {
if ! ___eapi_has_einstall; then
die "'${FUNCNAME}' has been banned for EAPI '${EAPI}'"
exit 1
fi
# CONF_PREFIX is only set if they didn't pass in libdir above.
local LOCAL_EXTRA_EINSTALL="${EXTRA_EINSTALL}"
if ! ___eapi_has_prefix_variables; then
local ED=${D}
fi
local libdir libdir_var="LIBDIR_${ABI}"
if [[ -n "${ABI}" && -n "${!libdir_var}" ]]; then
libdir="${!libdir_var}"
fi
if [[ -n "${libdir}" && "${CONF_PREFIX:+set}" = set ]]; then
local destlibdir="${D%/}/${CONF_PREFIX}/${libdir}"
destlibdir="$(__strip_duplicate_slashes "${destlibdir}")"
LOCAL_EXTRA_EINSTALL="libdir=${destlibdir} ${LOCAL_EXTRA_EINSTALL}"
fi
if [[ -f Makefile || -f GNUmakefile || -f makefile ]] ; then
if [[ "${PORTAGE_DEBUG}" == "1" ]]; then
${MAKE:-make} -n prefix="${ED%/}/usr" \
datadir="${ED%/}/usr/share" \
infodir="${ED%/}/usr/share/info" \
localstatedir="${ED%/}/var/lib" \
mandir="${ED%/}/usr/share/man" \
sysconfdir="${ED%/}/etc" \
${LOCAL_EXTRA_EINSTALL} \
${MAKEOPTS} -j1 \
"$@" ${EXTRA_EMAKE} install
fi
if ! ${MAKE:-make} prefix="${ED%/}/usr" \
datadir="${ED%/}/usr/share" \
infodir="${ED%/}/usr/share/info" \
localstatedir="${ED%/}/var/lib" \
mandir="${ED%/}/usr/share/man" \
sysconfdir="${ED%/}/etc" \
${LOCAL_EXTRA_EINSTALL} \
${MAKEOPTS} -j1 \
"$@" ${EXTRA_EMAKE} install
then
__helpers_die "einstall failed"
return 1
fi
else
die "no Makefile found"
fi
}
__eapi0_pkg_nofetch() {
[[ -z ${A} ]] && return
elog "The following files cannot be fetched for ${PN}:"
local x
for x in ${A}; do
elog " ${x}"
done
}
__eapi0_src_unpack() {
[[ -n ${A} ]] && unpack ${A}
}
__eapi0_src_compile() {
if [[ -x ./configure ]]; then
econf
fi
__eapi2_src_compile
}
__eapi0_src_test() {
# Since we don't want emake's automatic die
# support (EAPI 4 and later), and we also don't
# want the warning messages that it produces if
# we call it in 'nonfatal' mode, we use emake_cmd
# to emulate the desired parts of emake behavior.
local emake_cmd="${MAKE:-make} ${MAKEOPTS} ${EXTRA_EMAKE}"
local internal_opts=
if ___eapi_default_src_test_disables_parallel_jobs; then
internal_opts+=" -j1"
fi
if ${emake_cmd} ${internal_opts} check -n &> /dev/null; then
__vecho "${emake_cmd} ${internal_opts} check" >&2
${emake_cmd} ${internal_opts} check || \
die "Make check failed. See above for details."
elif ${emake_cmd} ${internal_opts} test -n &> /dev/null; then
__vecho "${emake_cmd} ${internal_opts} test" >&2
${emake_cmd} ${internal_opts} test || \
die "Make test failed. See above for details."
fi
}
__eapi1_src_compile() {
__eapi2_src_configure
__eapi2_src_compile
}
__eapi2_src_prepare() {
:
}
__eapi2_src_configure() {
if [[ -x ${ECONF_SOURCE:-.}/configure ]] ; then
econf
fi
}
__eapi2_src_compile() {
if [[ -f Makefile || -f GNUmakefile || -f makefile ]]; then
emake || die "emake failed"
fi
}
__eapi4_src_install() {
if [[ -f Makefile || -f GNUmakefile || -f makefile ]] ; then
emake DESTDIR="${D}" install
fi
if ! declare -p DOCS &>/dev/null ; then
local d
for d in README* ChangeLog AUTHORS NEWS TODO CHANGES \
THANKS BUGS FAQ CREDITS CHANGELOG ; do
[[ -s "${d}" ]] && dodoc "${d}"
done
elif ___is_indexed_array_var DOCS ; then
dodoc "${DOCS[@]}"
else
dodoc ${DOCS}
fi
}
__eapi6_src_prepare() {
if ___is_indexed_array_var PATCHES ; then
[[ ${#PATCHES[@]} -gt 0 ]] && eapply "${PATCHES[@]}"
elif [[ -n ${PATCHES} ]]; then
eapply ${PATCHES}
fi
eapply_user
}
__eapi6_src_install() {
if [[ -f Makefile || -f GNUmakefile || -f makefile ]] ; then
emake DESTDIR="${D}" install
fi
einstalldocs
}
__eapi8_src_prepare() {
local f
if ___is_indexed_array_var PATCHES ; then
[[ ${#PATCHES[@]} -gt 0 ]] && eapply -- "${PATCHES[@]}"
elif [[ -n ${PATCHES} ]]; then
eapply -- ${PATCHES}
fi
eapply_user
}
___best_version_and_has_version_common() {
local atom root root_arg
# If ROOT is set to / below then SYSROOT cannot point elsewhere. Even if
# ROOT is untouched, setting SYSROOT=/ for this command will always work.
local -a cmd=(env SYSROOT=/)
case $1 in
--host-root|-r|-d|-b)
root_arg=$1
shift ;;
esac
atom=$1
shift
[[ $# -gt 0 ]] && die "${FUNCNAME[1]}: unused argument(s): $*"
case ${root_arg} in
"") if ___eapi_has_prefix_variables; then
root=${ROOT%/}/${EPREFIX#/}
else
root=${ROOT}
fi ;;
--host-root)
if ! ___eapi_best_version_and_has_version_support_--host-root; then
die "${FUNCNAME[1]}: option ${root_arg} is not supported with EAPI ${EAPI}"
fi
if ___eapi_has_prefix_variables; then
# Since portageq requires the root argument be consistent
# with EPREFIX, ensure consistency here (bug #655414).
root=/${PORTAGE_OVERRIDE_EPREFIX#/}
cmd+=(EPREFIX="${PORTAGE_OVERRIDE_EPREFIX}")
else
root=/
fi ;;
-r|-d|-b)
if ! ___eapi_best_version_and_has_version_support_-b_-d_-r; then
die "${FUNCNAME[1]}: option ${root_arg} is not supported with EAPI ${EAPI}"
fi
if ___eapi_has_prefix_variables; then
case ${root_arg} in
-r) root=${ROOT%/}/${EPREFIX#/} ;;
-d) root=${ESYSROOT:-/} ;;
-b)
# Use /${PORTAGE_OVERRIDE_EPREFIX#/} to support older
# EAPIs, as it is equivalent to BROOT.
root=/${PORTAGE_OVERRIDE_EPREFIX#/}
cmd+=(EPREFIX="${PORTAGE_OVERRIDE_EPREFIX}")
;;
esac
else
case ${root_arg} in
-r) root=${ROOT:-/} ;;
-d) root=${SYSROOT:-/} ;;
-b) root=/ ;;
esac
fi ;;
esac
if [[ -n ${PORTAGE_IPC_DAEMON} ]] ; then
cmd+=("${PORTAGE_BIN_PATH}"/ebuild-ipc "${FUNCNAME[1]}" "${root}" "${atom}")
else
cmd+=("${PORTAGE_BIN_PATH}"/portageq-wrapper "${FUNCNAME[1]}" "${root}" "${atom}")
fi
"${cmd[@]}"
local retval=$?
case "${retval}" in
0|1)
return ${retval}
;;
2)
die "${FUNCNAME[1]}: invalid atom: ${atom}"
;;
*)
if [[ -n ${PORTAGE_IPC_DAEMON} ]]; then
die "${FUNCNAME[1]}: unexpected ebuild-ipc exit code: ${retval}"
else
die "${FUNCNAME[1]}: unexpected portageq exit code: ${retval}"
fi
;;
esac
}
# @FUNCTION: has_version
# @USAGE: [--host-root|-r|-d|-b] <DEPEND ATOM>
# @DESCRIPTION:
# Return true if given package is installed. Otherwise return false.
# Callers may override the ROOT variable in order to match packages from an
# alternative ROOT.
has_version() {
___best_version_and_has_version_common "$@"
}
# @FUNCTION: best_version
# @USAGE: [--host-root|-r|-d|-b] <DEPEND ATOM>
# @DESCRIPTION:
# Returns highest installed matching category/package-version (without .ebuild).
# Callers may override the ROOT variable in order to match packages from an
# alternative ROOT.
best_version() {
___best_version_and_has_version_common "$@"
}
portageq() {
die "portageq is not allowed in ebuild scope"
}
if ___eapi_has_get_libdir; then
get_libdir() {
local libdir_var="LIBDIR_${ABI}"
local libdir="lib"
[[ -n ${ABI} && -n ${!libdir_var} ]] && libdir=${!libdir_var}
echo "${libdir}"
}
fi
if ___eapi_has_einstalldocs; then
einstalldocs() {
(
if [[ $(declare -p DOCS 2>/dev/null) != *=* ]]; then
local d
for d in README* ChangeLog AUTHORS NEWS TODO CHANGES \
THANKS BUGS FAQ CREDITS CHANGELOG ; do
[[ -f ${d} && -s ${d} ]] && docinto / && dodoc "${d}"
done
elif ___is_indexed_array_var DOCS ; then
[[ ${#DOCS[@]} -gt 0 ]] && docinto / && dodoc -r "${DOCS[@]}"
else
[[ ${DOCS} ]] && docinto / && dodoc -r ${DOCS}
fi
)
(
if ___is_indexed_array_var HTML_DOCS ; then
[[ ${#HTML_DOCS[@]} -gt 0 ]] && \
docinto html && dodoc -r "${HTML_DOCS[@]}"
else
[[ ${HTML_DOCS} ]] && \
docinto html && dodoc -r ${HTML_DOCS}
fi
)
}
fi
if ___eapi_has_eapply; then
eapply() {
local failed patch_cmd=patch
local -x LC_COLLATE=POSIX
# for bsd userland support, use gpatch if available
type -P gpatch > /dev/null && patch_cmd=gpatch
_eapply_patch() {
local f=${1}
local prefix=${2}
ebegin "${prefix:-Applying }${f##*/}"
# -p1 as a sane default
# -f to avoid interactivity
# -g0 to guarantee no VCS interaction
# --no-backup-if-mismatch not to pollute the sources
local all_opts=(
-p1 -f -g0 --no-backup-if-mismatch
"${patch_options[@]}"
)
# Try applying with -F0 first, output a verbose warning
# if fuzz factor is necessary
if ${patch_cmd} "${all_opts[@]}" --dry-run -s -F0 \
< "${f}" &>/dev/null; then
all_opts+=( -s -F0 )
fi
${patch_cmd} "${all_opts[@]}" < "${f}"
failed=${?}
if ! eend "${failed}"; then
__helpers_die "patch -p1 ${patch_options[*]} failed with ${f}"
fi
}
local patch_options=() files=()
local i found_doublehyphen
# First, try to split on --
for (( i = 1; i <= ${#@}; ++i )); do
if [[ ${@:i:1} == -- ]]; then
patch_options=( "${@:1:i-1}" )
files=( "${@:i+1}" )
found_doublehyphen=1
break
fi
done
# Then, try to split on first non-option
if [[ -z ${found_doublehyphen} ]]; then
for (( i = 1; i <= ${#@}; ++i )); do
if [[ ${@:i:1} != -* ]]; then
patch_options=( "${@:1:i-1}" )
files=( "${@:i}" )
break
fi
done
# Ensure that no options were interspersed with files
for i in "${files[@]}"; do
if [[ ${i} == -* ]]; then
die "eapply: all options must be passed before non-options"
fi
done
fi
if [[ ${#files[@]} -eq 0 ]]; then
die "eapply: no files specified"
fi
local f
for f in "${files[@]}"; do
if [[ -d ${f} ]]; then
_eapply_get_files() {
local LC_ALL=POSIX
local prev_shopt=$(shopt -p nullglob)
shopt -s nullglob
local f
for f in "${1}"/*; do
if [[ ${f} == *.diff || ${f} == *.patch ]]; then
files+=( "${f}" )
fi
done
${prev_shopt}
}
local files=()
_eapply_get_files "${f}"
[[ ${#files[@]} -eq 0 ]] && die "No *.{patch,diff} files in directory ${f}"
einfo "Applying patches from ${f} ..."
local f2
for f2 in "${files[@]}"; do
_eapply_patch "${f2}" ' '
# in case of nonfatal
[[ ${failed} -ne 0 ]] && return "${failed}"
done
else
_eapply_patch "${f}"
# In case of nonfatal
[[ ${failed} -ne 0 ]] && return "${failed}"
fi
done
return 0
}
fi
if ___eapi_has_eapply_user; then
eapply_user() {
[[ ${EBUILD_PHASE} == prepare ]] || \
die "eapply_user() called during invalid phase: ${EBUILD_PHASE}"
# Keep path in __dyn_prepare in sync!
local tagfile=${T}/.portage_user_patches_applied
[[ -f ${tagfile} ]] && return
>> "${tagfile}"
local basedir=${PORTAGE_CONFIGROOT%/}/etc/portage/patches
local columns=${COLUMNS:-0}
[[ ${columns} == 0 ]] && columns=$(set -- $( ( stty size </dev/tty ) 2>/dev/null || echo 24 80 ) ; echo $2)
(( columns > 0 )) || (( columns = 80 ))
local applied d f
local -A _eapply_user_patches
local prev_shopt=$(shopt -p nullglob)
shopt -s nullglob
# Patches from all matched directories are combined into a
# sorted (POSIX order) list of the patch basenames. Patches
# in more-specific directories override patches of the same
# basename found in less-specific directories. An empty patch
# (or /dev/null symlink) negates a patch with the same
# basename found in a less-specific directory.
#
# order of specificity:
# 1. ${CATEGORY}/${P}-${PR} (note: -r0 desired to avoid applying
# ${P} twice)
# 2. ${CATEGORY}/${P}
# 3. ${CATEGORY}/${PN}
# all of the above may be optionally followed by a slot
for d in "${basedir}"/${CATEGORY}/{${P}-${PR},${P},${PN}}{:${SLOT%/*},}; do
for f in "${d}"/*; do
if [[ ( ${f} == *.diff || ${f} == *.patch ) &&
-z ${_eapply_user_patches[${f##*/}]} ]]; then
_eapply_user_patches[${f##*/}]=${f}
fi
done
done
if [[ ${#_eapply_user_patches[@]} -gt 0 ]]; then
while read -r -d '' f; do
f=${_eapply_user_patches[${f}]}
if [[ -s ${f} ]]; then
if [[ -z ${applied} ]]; then
einfo "${PORTAGE_COLOR_INFO}$(for ((column = 0; column < ${columns} - 3; column++)); do echo -n =; done)${PORTAGE_COLOR_NORMAL}"
einfo "Applying user patches from ${basedir} ..."
fi
eapply "${f}"
applied=1
fi
done < <(printf -- '%s\0' "${!_eapply_user_patches[@]}" |
LC_ALL=C sort -z)
fi
${prev_shopt}
if [[ -n ${applied} ]]; then
einfo "User patches applied."
einfo "${PORTAGE_COLOR_INFO}$(for ((column = 0; column < ${columns} - 3; column++)); do echo -n =; done)${PORTAGE_COLOR_NORMAL}"
fi
}
fi
if ___eapi_has_in_iuse; then
in_iuse() {
local use=${1}
if [[ -z "${use}" ]]; then
echo "!!! in_iuse() called without a parameter." >&2
echo "!!! in_iuse <USEFLAG>" >&2
die "in_iuse() called without a parameter"
fi
local liuse=( ${IUSE_EFFECTIVE} )
has "${use}" "${liuse[@]#[+-]}"
}
fi
|