-
Notifications
You must be signed in to change notification settings - Fork 21
/
bootstrap-prefix.sh
executable file
·3265 lines (2931 loc) · 99.4 KB
/
bootstrap-prefix.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
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
#!/usr/bin/env bash
# Copyright 2006-2023 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
trap 'exit 1' TERM INT QUIT ABRT
# RAP (libc) mode is triggered on Linux kernel and glibc.
is-rap() { [[ ${PREFIX_DISABLE_RAP} != "yes" && ${CHOST} = *linux-gnu* ]]; }
rapx() { is-rap && echo $1 || echo $2; }
## Functions Start Here
estatus() {
# this can give some garbage in the logs, but it shouldn't be too
# disturbing -- if it works, it makes it easy to see where we are in
# the bootstrap from the terminal status line (usually the window
# name)
printf '\033]2;'"$*"'\007'
}
eerror() { estatus $*; echo "!!! $*" 1>&2; }
einfo() { echo "* $*"; }
v() { echo "$@"; "$@"; }
econf() {
estatus "stage1: configuring ${PWD##*/}"
v ${CONFIG_SHELL} ./configure \
--host=${CHOST} \
--prefix="${ROOT}"/tmp/usr \
--mandir="${ROOT}"/tmp/usr/share/man \
--infodir="${ROOT}"/tmp/usr/share/info \
--datadir="${ROOT}"/tmp/usr/share \
--sysconfdir="${ROOT}"/tmp/etc \
--localstatedir="${ROOT}"/tmp/var/lib \
--build=${CHOST} \
"$@" || return 1
}
emake() {
[[ $* == *install* ]] \
&& estatus "stage1: installing ${PWD##*/}" \
|| estatus "stage1: building ${PWD##*/}"
v ${MAKE} ${MAKEOPTS} "$@" || return 1
}
efetch() {
if [[ ! -e ${DISTDIR}/${1##*/} ]] ; then
mkdir -p "${DISTDIR}" >& /dev/null
# Try fetching from local mirrors first, as this requires no connection
for loc in ${GENTOO_MIRRORS} ; do
if [[ ${loc} = /* && -e "${loc}/${1##*/}" ]]; then
cp "${loc}/${1##*/}" "${DISTDIR}/${1##*/}" && return 0
fi
done
if [[ ${OFFLINE_MODE} ]] ; then
echo "I need ${1##*/} from $1 in $DISTDIR, can you give it to me?"
read
[[ -e ${DISTDIR}/${1##*/} ]] && return 0
# Give fetch a try
fi
if [[ -z ${FETCH_COMMAND} ]] ; then
# Try to find a download manager, we only deal with wget,
# curl, FreeBSD's fetch and ftp.
if [[ x$(type -t wget) == "xfile" ]] ; then
FETCH_COMMAND="wget"
[[ $(wget -h) == *"--no-check-certificate"* ]] \
&& FETCH_COMMAND+=" --no-check-certificate"
elif [[ x$(type -t curl) == "xfile" ]] ; then
FETCH_COMMAND="curl -f -L -O"
elif [[ x$(type -t fetch) == "xfile" ]] ; then
FETCH_COMMAND="fetch"
elif [[ x$(type -t ftp) == "xfile" ]] ; then
FETCH_COMMAND="ftp"
else
eerror "no suitable download manager found!"
eerror "tried: wget, curl, fetch and ftp"
eerror "could not download ${1##*/}"
exit 1
fi
fi
einfo "Fetching ${1##*/}"
estatus "stage1: fetching ${1##*/}"
pushd "${DISTDIR}" > /dev/null
# Try for mirrors first, fall back to distfiles, then try given location
local locs=( )
local loc
for loc in ${GENTOO_MIRRORS} ${DISTFILES_G_O} ${DISTFILES_PFX}; do
locs=(
"${locs[@]}"
"${loc}/distfiles/${1##*/}"
)
done
locs=( "${locs[@]}" "$1" )
for loc in "${locs[@]}" ; do
v ${FETCH_COMMAND} "${loc}" < /dev/null
[[ -f ${1##*/} ]] && break
done
if [[ ! -f ${1##*/} ]] ; then
eerror "downloading ${1} failed!"
return 1
fi
popd > /dev/null
fi
return 0
}
configure_cflags() {
export CPPFLAGS="-I${ROOT}/tmp/usr/include"
case ${CHOST} in
*-darwin*)
export LDFLAGS="-Wl,-search_paths_first -L${ROOT}/tmp/usr/lib"
;;
*-solaris*)
export LDFLAGS="-L${ROOT}/tmp/usr/lib -R${ROOT}/tmp/usr/lib"
;;
*)
export LDFLAGS="-L${ROOT}/tmp/usr/lib -Wl,-rpath=${ROOT}/tmp/usr/lib"
;;
esac
case ${CHOST} in
# note: we need CXX for binutils-apple which' ld is c++
*64-apple* | sparcv9-*-solaris* | x86_64-*-solaris*)
export CC="${CC-gcc} -m64"
export CXX="${CXX-g++} -m64"
export HOSTCC="${CC}"
;;
i*86-apple-darwin1*)
export CC="${CC-gcc} -m32"
export CXX="${CXX-g++} -m32"
export HOSTCC="${CC}"
;;
i*86-pc-linux-gnu)
if [[ $(${CC} -dumpspecs | grep -A1 multilib_default) != *m32 ]]; then
export CC="${CC-gcc} -m32"
export CXX="${CXX-g++} -m32"
fi
;;
esac
# point possible host pkg-config to stage2 files
export PKG_CONFIG_PATH=${ROOT}/tmp/usr/lib/pkgconfig
}
configure_toolchain() {
linker="sys-devel/binutils"
local gcc_deps="dev-libs/gmp dev-libs/mpfr dev-libs/mpc"
compiler="${gcc_deps} sys-devel/gcc-config sys-devel/gcc"
compiler_stage1="${gcc_deps} sys-devel/gcc-config"
compiler_type="gcc"
case ${CHOST} in
*-darwin*)
# handled below
;;
*-freebsd* | *-openbsd*)
# comes with clang, handled below
;;
*)
# The host may not have a functioning c++ toolchain, so use a
# stage1 compiler that can build with C only.
# But gcc-4.7 fails to build with gcc-5.4, so we check for
# >gcc-4.7, as anything newer provides c++ anyway (#619542).
# gcc-4.7 is the last version not to require a c++ compiler to
# build
eval $( (gcc -E - | grep compiler_stage1) <<-EOP
#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 7))
compiler_stage1+=" sys-devel/gcc"
#elif defined(__GNUC__) && __GNUC__ >= 4
compiler_stage1+=" <sys-devel/gcc-4.8"
#else
compiler_stage1+=" <sys-devel/gcc-4.7"
#endif
EOP
)
esac
CC=gcc
CXX=g++
case ${CHOST}:${DARWIN_USE_GCC} in
*darwin*:1)
einfo "Triggering Darwin with GCC toolchain"
compiler_stage1+=" sys-apps/darwin-miscutils"
local ccvers="$(unset CHOST; /usr/bin/gcc --version 2>/dev/null)"
local isgcc=
case "${ccvers}" in
*"(GCC) 4.2.1 "*)
linker="=sys-devel/binutils-apple-3.2.6"
isgcc=true
;;
*"(GCC) 4.0.1 "*)
linker="=sys-devel/binutils-apple-3.2.6"
# upgrade to 4.2.1 first
compiler_stage1+="
sys-devel/gcc-apple
=sys-devel/binutils-apple-3.2.6"
isgcc=true
;;
*"Apple clang version "*|*"Apple LLVM version "*)
# recent binutils-apple are hard to build (C++11
# features, and cmake build system) so avoid going
# there, the system ld is good enough to bring us to
# stage3, after which the @system set will take care of
# the rest
linker=sys-devel/native-cctools
;;
*)
eerror "unknown compiler: ${ccvers}"
return 1
;;
esac
if [[ ${isgcc} == true ]] ; then
# current compiler (gcc-11) requires C++11, which is
# available since 4.8, so need to bootstrap with <11
compiler_stage1+=" <sys-devel/gcc-11"
compiler="${compiler%sys-devel/gcc} <sys-devel/gcc-11"
else
# assume LLVM/Clang has C++11 support
compiler_stage1+=" sys-devel/gcc"
fi
;;
*-darwin*)
einfo "Triggering Darwin with LLVM/Clang toolchain"
# for compilers choice, see bug:
# https://bugs.gentoo.org/show_bug.cgi?id=538366
compiler_stage1="sys-apps/darwin-miscutils"
compiler_type="clang"
local ccvers="$(unset CHOST; /usr/bin/gcc --version 2>/dev/null)"
local llvm_deps="dev-util/ninja"
case "${ccvers}" in
*"Apple clang version "*|*"Apple LLVM version "*)
# this is Clang, recent enough to compile recent clang
compiler_stage1+="
${llvm_deps}
sys-libs/libcxxabi
sys-libs/libcxx
sys-devel/llvm
sys-devel/clang
"
CC=clang
CXX=clang++
# avoid going through hoops and deps for
# binutils-apple, rely on the host-installed ld to
# build a compiler, we'll pull in binutils-apple
# from system set
linker=sys-devel/native-cctools
;;
*)
eerror "unknown/unsupported compiler"
return 1
;;
esac
compiler="
dev-libs/libffi
${llvm_deps}
sys-libs/libcxxabi
sys-libs/libcxx
sys-devel/llvm
sys-devel/clang"
;;
*-freebsd* | *-openbsd*)
CC=clang
CXX=clang++
# TODO: target clang toolchain someday?
;;
*-solaris*)
local ccvers="$(unset CHOST; gcc --version 2>/dev/null)"
case "${ccvers}" in
*"gcc (GCC) 3.4.3"*)
# host compiler doesn't cope with the asm introduced
# in mpfr-4, so force using an older one during
# bootstrap for this target
compiler_stage1=${compiler_stage1/" dev-libs/mpfr "/" <dev-libs/mpfr-4 "}
;;
esac
;;
*-linux*)
is-rap && einfo "Triggering Linux RAP bootstrap"
;;
esac
return 0
}
bootstrap_setup() {
einfo "Setting up some guessed defaults"
local FS_INSENSITIVE=0
touch "${ROOT}"/FOO.$$
[[ -e ${ROOT}/foo.$$ ]] && FS_INSENSITIVE=1
rm "${ROOT}"/FOO.$$
[[ ! -e "${MAKE_CONF_DIR}" ]] && mkdir -p -- "${MAKE_CONF_DIR}"
if [[ ! -f ${MAKE_CONF_DIR}/0100_bootstrap_prefix_make.conf ]] ; then
{
echo "# Added by bootstrap-prefix.sh for ${CHOST}"
echo 'USE="unicode nls"'
echo 'CFLAGS="${CFLAGS} -O2 -pipe"'
echo 'CXXFLAGS="${CFLAGS}"'
echo "MAKEOPTS=\"${MAKEOPTS}\""
echo "CONFIG_SHELL=\"${ROOT}/bin/bash\""
echo "DISTDIR=\"${DISTDIR:-${ROOT}/var/cache/distfiles}\""
if is-rap ; then
echo "# sandbox does not work well on Prefix, bug #490246"
echo 'FEATURES="${FEATURES} -usersandbox -sandbox"'
# bug #759424
[[ -n ${STABLE_PREFIX} ]] && \
echo 'ACCEPT_KEYWORDS="${ARCH} -~${ARCH}"'
else
echo "# last mirror is for Prefix specific distfiles, you"
echo "# might experience fetch failures if you remove it"
echo "GENTOO_MIRRORS=\"${GENTOO_MIRRORS} ${DISTFILES_PFX}\""
fi
if [[ ${FS_INSENSITIVE} == 1 ]] ; then
echo
echo "# Avoid problems due to case-insensitivity, bug #524236"
echo 'FEATURES="${FEATURES} case-insensitive-fs"'
fi
[[ -n ${PORTDIR_OVERLAY} ]] && \
echo "PORTDIR_OVERLAY=\"\${PORTDIR_OVERLAY} ${PORTDIR_OVERLAY}\""
[[ -n ${MAKE_CONF_ADDITIONAL_USE} ]] &&
echo "USE=\"\${USE} ${MAKE_CONF_ADDITIONAL_USE}\""
[[ ${OFFLINE_MODE} ]] && \
echo 'FETCHCOMMAND="bash -c \"echo I need \${FILE} from \${URI} in \${DISTDIR}; read\""'
} > "${MAKE_CONF_DIR}/0100_bootstrap_prefix_make.conf"
fi
if is-rap ; then
if [[ ! -f ${ROOT}/etc/passwd ]]; then
if grep -q $(id -un) /etc/passwd; then
ln -sf {,"${ROOT}"}/etc/passwd
else
getent passwd > "${ROOT}"/etc/passwd
# add user if it's not in /etc/passwd, bug #766417
getent passwd $(id -un) >> "${ROOT}"/etc/passwd
fi
fi
if [[ ! -f ${ROOT}/etc/group ]]; then
if grep -q $(id -gn) /etc/group; then
ln -sf {,"${ROOT}"}/etc/group
else
getent group > "${ROOT}"/etc/group
# add group if it's not in /etc/group, bug #766417
getent group $(id -gn) >> "${ROOT}"/etc/group
fi
fi
[[ -f ${ROOT}/etc/resolv.conf ]] || ln -s {,"${ROOT}"}/etc/resolv.conf
[[ -f ${ROOT}/etc/hosts ]] || cp {,"${ROOT}"}/etc/hosts
fi
bootstrap_profile
}
bootstrap_profile() {
local profile=""
# 2.6.32.1 -> 2*256^3 + 6*256^2 + 32 * 256 + 1 = 33955841
kver() { uname -r|cut -d\- -f1|awk -F. '{for (i=1; i<=NF; i++){s+=lshift($i,(4-i)*8)};print s}'; }
# >=glibc-2.20 requires >=linux-2.6.32.
profile-kernel() {
if [[ $(kver) -ge 50462720 ]] ; then # 3.2
echo kernel-3.2+
elif [[ $(kver) -ge 33955840 ]] ; then # 2.6.32
echo kernel-2.6.32+
elif [[ $(kver) -ge 33951744 ]] ; then # 2.6.16
echo kernel-2.6.16+
elif [[ $(kver) -ge 33947648 ]] ; then # 2.6
echo kernel-2.6+
fi
}
if is-rap ; then
local profile_linux=default/linux/ARCH/17.0/prefix/$(profile-kernel)
else
local profile_linux=prefix/linux/ARCH
fi
case ${CHOST} in
powerpc-apple-darwin9)
rev=${CHOST##*darwin}
profile="prefix/darwin/macos/10.$((rev - 4))/ppc"
;;
i*86-apple-darwin1[578])
rev=${CHOST##*darwin}
profile="prefix/darwin/macos/10.$((rev - 4))/x86"
;;
x86_64-apple-darwin1[5789])
rev=${CHOST##*darwin}
profile="prefix/darwin/macos/10.$((rev - 4))/x64"
;;
*64-apple-darwin2[0123456789])
# Big Sur is 11.0
# Monterey is 12.0
# Ventura is 13.0
rev=${CHOST##*darwin}
case ${CHOST%%-*} in
x86_64) arch=x64 ;;
arm64) arch=arm64 ;;
*) arch=error ;;
esac
profile="prefix/darwin/macos/$((rev - 9)).0/${arch}"
;;
i*86-pc-linux-gnu)
profile=${profile_linux/ARCH/x86}
;;
riscv64-pc-linux-gnu)
profile=${profile_linux/ARCH/riscv}
profile=${profile/17.0/20.0/rv64gc/lp64d}
;;
x86_64-pc-linux-gnu)
profile=${profile_linux/ARCH/amd64}
profile=${profile/17.0/17.1/no-multilib}
;;
powerpc-unknown-linux-gnu)
profile=${profile_linux/ARCH/ppc}
;;
powerpc64-unknown-linux-gnu)
profile=${profile_linux/ARCH/ppc64}
;;
powerpc64le-unknown-linux-gnu)
profile=${profile_linux/ARCH/ppc64le}
;;
riscv-pc-unknown-linux-gnu)
profile=${profile_linux/ARCH/riscv}
profile=${profile/17.0/20.0/rv64gc/lp64d}
;;
aarch64-unknown-linux-gnu)
profile=${profile_linux/ARCH/arm64}
;;
armv7l-pc-linux-gnu)
profile=${profile_linux/ARCH/arm}
;;
x86_64-pc-solaris2.11)
profile="prefix/sunos/solaris/5.11/x64"
;;
i386-pc-solaris2*|sparc-sun-solaris2*|sparcv9-sun-solaris2*)
eerror "REMOVED ARCH: this Solaris architecture was removed,"
eerror "bootstrapping is impossible"
exit 1
;;
i586-pc-winnt*|x86_64-pc-cygwin*)
eerror "REMOVED ARCH: this Windows architecture was removed,"
eerror "bootstrapping is impossible"
exit 1
;;
*)
eerror "UNKNOWN ARCH: You need to set up a make.profile symlink to a"
eerror "profile in ${PORTDIR} for your CHOST ${CHOST}"
exit 1
;;
esac
if [[ ${CHOST} == *-darwin* ]] ; then
# setup MacOSX.sdk symlink for GCC, this should probably be
# managed using an eselect module in the future
rm -f "${ROOT}"/MacOSX.sdk
local SDKPATH=$(xcrun --show-sdk-path --sdk macosx)
if [[ ! -e ${SDKPATH} ]] ; then
SDKPATH=$(xcodebuild -showsdks | sort -nr \
| grep -o "macosx.*" | head -n1)
SDKPATH=$(xcode-select -print-path)/SDKs/MacOSX${SDKPATH#macosx}.sdk
fi
( cd "${ROOT}" && ln -s "${SDKPATH}" MacOSX.sdk )
einfo "using system sources from ${SDKPATH}"
fi
if [[ ${DARWIN_USE_GCC} == 1 ]] ; then
# amend profile, to use gcc one
profile="${profile}/gcc"
fi
[[ -n ${PROFILE_BASE}${PROFILE_VARIANT} ]] &&
profile=${PROFILE_BASE:-prefix}/${profile#prefix/}${PROFILE_VARIANT:+/${PROFILE_VARIANT}}
if [[ -n ${profile} && ! -e ${ROOT}/etc/portage/make.profile ]] ; then
local fullprofile="${PORTDIR}/profiles/${profile}"
ln -s "${fullprofile}" "${ROOT}"/etc/portage/make.profile
einfo "Your profile is set to ${fullprofile}."
fi
# Use package.use to disable in the portage tree to be shared between
# stage2 and stage3. The hack will be undone during tree sync in stage3.
cat >> "${ROOT}"/etc/portage/make.profile/package.use <<-EOF
# Disable bootstrapping libcxx* with libunwind
sys-libs/libcxxabi -libunwind
sys-libs/libcxx -libunwind
# Most binary Linux distributions seem to fancy toolchains that
# do not do c++ support (need to install a separate package).
sys-libs/ncurses -cxx
sys-devel/binutils -cxx
EOF
# On Darwin we might need this to bootstrap the compiler, since
# bootstrapping the linker (binutils-apple) requires a c++11
# compiler amongst other things
cat >> "${ROOT}"/etc/portage/make.profile/package.unmask <<-EOF
# For Darwin bootstraps
sys-devel/native-cctools
EOF
# Strange enough, -cxx causes wrong libtool config on Cygwin,
# but we require a C++ compiler there anyway - so just use it.
cat >> "${ROOT}"/etc/portage/make.profile/package.use <<-EOF
# gmp has cxx flag enabled by default. When dealing with a host
# compiler without cxx support this causes configure failure.
# In addition, The stage2 g++ is only for compiling stage3 compiler,
# because the host libstdc++.so runtime may be not compatible and
# stage2 libstdc++.so might conflict with that of stage3. The
# trade-off is just not to use cxx.
dev-libs/gmp -cxx
sys-devel/binutils -gold
EOF
}
do_tree() {
local x
for x in etc{,/portage} usr/{{,s}bin,$(rapx "" lib)} var/tmp var/lib/portage var/log/portage var/db;
do
[[ -d ${ROOT}/${x} ]] || mkdir -p "${ROOT}/${x}"
done
# Make symlinks as USE=split-usr is masked in prefix/rpath. This is
# necessary for Cygwin, as there is no such thing like an
# embedded runpath. Instead we put all the dlls next to the
# exes, to get them working even without the PATH environment
# variable being set up.
#
# In prefix/standalone, however, no symlink is desired.
# Because we keep USE=split-usr enabled to align with the
# default of Gentoo vanilla.
if ! is-rap; then
for x in lib sbin bin; do
[[ -e ${ROOT}/${x} ]] || ( cd "${ROOT}" && ln -s usr/${x} )
done
fi
mkdir -p "${PORTDIR}"
if [[ ! -e ${PORTDIR}/.unpacked ]]; then
# latest tree cannot be fetched from mirrors, always have to
# respect the source to get the latest
if [[ -n ${LATEST_TREE_YES} ]] ; then
echo "$1"
( export GENTOO_MIRRORS= DISTFILES_G_O= DISTFILES_PFX= ;
efetch "$1/$2" ) || return 1
else
efetch "$1/$2" || return 1
fi
einfo "Unpacking, this may take a while"
estatus "stage1: unpacking Portage tree"
bzip2 -dc ${DISTDIR}/$2 | tar -xf - -C ${PORTDIR} --strip-components=1
[[ ${PIPESTATUS[*]} == '0 0' ]] || return 1
touch ${PORTDIR}/.unpacked
fi
}
bootstrap_tree() {
# RAP uses the latest gentoo main repo snapshot to bootstrap.
is-rap && LATEST_TREE_YES=1
local PV="20230601"
if [[ -n ${LATEST_TREE_YES} ]]; then
do_tree "${SNAPSHOT_URL}" portage-latest.tar.bz2
else
do_tree http://dev.gentoo.org/~grobian/distfiles prefix-overlay-${PV}.tar.bz2
fi
local ret=$?
if [[ -n ${TREE_FROM_SRC} ]]; then
estatus "stage1: rsyncing Portage tree"
rsync -av --delete \
--exclude=.unpacked \
--exclude=distfiles \
--exclude=snapshots \
"${TREE_FROM_SRC}"/ "${PORTDIR}"/
fi
return $ret
}
bootstrap_startscript() {
local theshell=${SHELL##*/}
if [[ ${theshell} == "sh" ]] ; then
einfo "sh is a generic shell, using bash instead"
theshell="bash"
fi
if [[ ${theshell} == "csh" ]] ; then
einfo "csh is a prehistoric shell not available in Gentoo, switching to tcsh instead"
theshell="tcsh"
fi
einfo "Trying to emerge the shell you use, if necessary by running:"
einfo "emerge -u ${theshell}"
if ! emerge -u ${theshell} ; then
eerror "Your shell is not available in portage, hence we cannot" > /dev/stderr
eerror "automate starting your prefix, set SHELL and rerun this script" > /dev/stderr
return 1
fi
einfo "Finally, emerging prefix-toolkit for your convenience"
emerge -u app-portage/prefix-toolkit || return 1
einfo "To start Gentoo Prefix, run the script ${ROOT}/startprefix"
# see if PATH is kept/respected
local minPATH="preamble:${BASH%/*}:postlude"
local theirPATH="$(echo 'echo "${PATH}"' | env LS_COLORS= PATH="${minPATH}" $SHELL -l 2>/dev/null | grep "preamble:.*:postlude")"
if [[ ${theirPATH} != *"preamble:"*":postlude"* ]] ; then
einfo "WARNING: your shell initialisation (.cshrc, .bashrc, .profile)"
einfo " seems to overwrite your PATH, this effectively kills"
einfo " your Prefix. Change this to only append to your PATH"
elif [[ ${theirPATH} != "preamble:"* ]] ; then
einfo "WARNING: your shell initialisation (.cshrc, .bashrc, .profile)"
einfo " seems to prepend to your PATH, this might kill your"
einfo " Prefix:"
einfo " ${theirPATH%%preamble:*}"
einfo " You better fix this, YOU HAVE BEEN WARNED!"
fi
}
prepare_portage() {
# see bootstrap_portage for explanations.
mkdir -p "${ROOT}"/bin/. "${ROOT}"/var/log
[[ -x ${ROOT}/bin/bash ]] || ln -s "${ROOT}"{/tmp,}/bin/bash || return 1
[[ -x ${ROOT}/bin/sh ]] || ln -s bash "${ROOT}"/bin/sh || return 1
}
bootstrap_portage() {
# Set TESTING_PV in env if you want to test a new portage before bumping the
# STABLE_PV that is known to work. Intended for power users only.
## It is critical that STABLE_PV is the lastest (non-masked) version that is
## included in the snapshot for bootstrap_tree.
STABLE_PV="3.0.30.1"
[[ ${TESTING_PV} == latest ]] && TESTING_PV="3.0.30.1"
PV="${TESTING_PV:-${STABLE_PV}}"
A=prefix-portage-${PV}.tar.bz2
einfo "Bootstrapping ${A%.tar.*}"
efetch ${DISTFILES_URL}/${A} || return 1
einfo "Unpacking ${A%.tar.*}"
export S="${PORTAGE_TMPDIR}"/portage-${PV}
ptmp=${S}
rm -rf "${S}" >& /dev/null
mkdir -p "${S}" >& /dev/null
cd "${S}"
bzip2 -dc "${DISTDIR}/${A}" | tar -xf -
[[ ${PIPESTATUS[*]} == '0 0' ]] || return 1
S="${S}/prefix-portage-${PV}"
cd "${S}"
fix_config_sub
# disable ipc
sed -e "s:_enable_ipc_daemon = True:_enable_ipc_daemon = False:" \
-i lib/_emerge/AbstractEbuildProcess.py || \
return 1
# host-provided wget may lack certificates, stage1 wget is without ssl
[[ $(wget -h) == *"--no-check-certificate"* ]] &&
sed -e '/wget/s/ --passive-ftp /&--no-check-certificate /' -i cnf/make.globals
# Portage checks for valid shebangs. These may (xz-utils) originate
# in CONFIG_SHELL (AIX), which originates in PORTAGE_BASH then.
# So we need to ensure portage's bash is valid as shebang too.
# Solaris mkdir chokes on existing symlink-to-dir, trailing /. helps.
mkdir -p "${ROOT}"/tmp/bin/. || return 1
[[ -x ${ROOT}/tmp/bin/bash ]] || [[ ! -x ${ROOT}/tmp/usr/bin/bash ]] || ln -s ../usr/bin/bash "${ROOT}"/tmp/bin/bash || return 1
[[ -x ${ROOT}/tmp/bin/bash ]] || ln -s "${BASH}" "${ROOT}"/tmp/bin/bash || return 1
[[ -x ${ROOT}/tmp/bin/sh ]] || ln -s bash "${ROOT}"/tmp/bin/sh || return 1
export PORTAGE_BASH="${ROOT}"/tmp/bin/bash
einfo "Compiling ${A%.tar.*}"
econf \
--with-offset-prefix="${ROOT}"/tmp \
--with-portage-user="`id -un`" \
--with-portage-group="`id -gn`" \
--with-extra-path="${PATH}" \
|| return 1
emake || return 1
einfo "Installing ${A%.tar.*}"
emake install || return 1
cd "${ROOT}"
rm -Rf ${ptmp} >& /dev/null
# Some people will skip the tree() step and hence var/log is not created
# As such, portage complains..
mkdir -p "${ROOT}"/tmp/var/log
# in Prefix the sed wrapper is deadly, so kill it
rm -f "${ROOT}"/tmp/usr/lib/portage/bin/ebuild-helpers/sed
local tmpportdir=${ROOT}/tmp/${PORTDIR#${ROOT}}
[[ -e "${tmpportdir}" ]] || ln -s "${PORTDIR}" "${tmpportdir}"
for d in "${ROOT}"/tmp/usr/lib/python$(python_ver); do
[[ -e ${d}/portage ]] || ln -s "${ROOT}"/tmp/usr/lib/portage/lib/portage ${d}/portage
[[ -e ${d}/_emerge ]] || ln -s "${ROOT}"/tmp/usr/lib/portage/lib/_emerge ${d}/_emerge
done
if [[ -s ${PORTDIR}/profiles/repo_name ]]; then
# sync portage's repos.conf with the tree being used
sed -i -e "s,gentoo_prefix,$(<"${PORTDIR}"/profiles/repo_name)," "${ROOT}"/tmp/usr/share/portage/config/repos.conf || return 1
fi
einfo "${A%.tar.*} successfully bootstrapped"
}
fix_config_sub() {
# macOS Big Sur (11.x, darwin20) supports Apple Silicon (arm64),
# which config.sub doesn't understand about. It is, however, Apple
# who seem to use arm64-apple-darwin20 CHOST triplets, so patch that
# for various versions of autoconf
if [[ ${CHOST} == arm64-apple-darwin* ]] ; then
# Apple Silicon doesn't use aarch64, but arm64
find . -name "config.sub" | \
xargs sed -i -e 's/ arm\(-\*\)* / arm\1 | arm64\1 /'
find . -name "config.sub" | \
xargs sed -i -e 's/ aarch64 / aarch64 | arm64 /'
fi
}
bootstrap_simple() {
local PN PV A S myconf
PN=$1
PV=$2
A=${PN}-${PV}.tar.${3:-gz}
einfo "Bootstrapping ${A%.tar.*}"
efetch ${4:-${DISTFILES_G_O}/distfiles}/${A} || return 1
einfo "Unpacking ${A%.tar.*}"
S="${PORTAGE_TMPDIR}/${PN}-${PV}"
rm -rf "${S}"
mkdir -p "${S}"
cd "${S}"
case $3 in
xz) decomp=xz ;;
bz2) decomp=bzip2 ;;
gz|"") decomp=gzip ;;
esac
${decomp} -dc "${DISTDIR}"/${A} | tar -xf -
[[ ${PIPESTATUS[*]} == '0 0' ]] || return 1
S="${S}"/${PN}-${PV}
cd "${S}"
fix_config_sub
# for libressl, only provide static lib, such that wget (above)
# links it in and we don't have to bother about RPATH or something
if [[ ${PN} == "libressl" ]] ; then
myconf="${myconf} --enable-static --disable-shared"
fi
einfo "Compiling ${A%.tar.*}"
if [[ -x configure ]] ; then
econf ${myconf} || return 1
fi
emake || return 1
einfo "Installing ${A%.tar.*}"
emake PREFIX="${ROOT}"/tmp/usr install || return 1
cd "${ROOT}"
rm -Rf "${S}"
einfo "${A%.tar.*} successfully bootstrapped"
}
bootstrap_gnu() {
local PN PV A S
PN=$1
PV=$2
einfo "Bootstrapping ${A%.tar.*}"
for t in tar.xz tar.bz2 tar.gz tar ; do
A=${PN}-${PV}.${t}
# save the user some useless downloading
if [[ ${t} == tar.gz ]] ; then
type -P gzip > /dev/null || continue
fi
if [[ ${t} == tar.xz ]] ; then
type -P xz > /dev/null || continue
fi
if [[ ${t} == tar.bz2 ]] ; then
type -P bzip2 > /dev/null || continue
fi
URL=${GNU_URL}/${PN}/${A}
efetch ${URL} || continue
einfo "Unpacking ${A%.tar.*}"
S="${PORTAGE_TMPDIR}/${PN}-${PV}"
rm -rf "${S}"
mkdir -p "${S}"
cd "${S}"
case ${t} in
tar.xz) decomp=xz ;;
tar.bz2) decomp=bzip2 ;;
tar.gz) decomp=gzip ;;
tar)
tar -xf "${DISTDIR}"/${A} || continue
break
;;
*)
einfo "unhandled extension: $t"
return 1
;;
esac
${decomp} -dc "${DISTDIR}"/${URL##*/} | tar -xf -
[[ ${PIPESTATUS[*]} == '0 0' ]] || continue
break
done
S="${S}"/${PN}-${PV}
[[ -d ${S} ]] || return 1
cd "${S}" || return 1
# Tar upstream bug #59755 for broken build on macOS:
# https://savannah.gnu.org/bugs/index.php?59755
if [[ ${PN}-${PV} == "tar-1.32" ]] ; then
local tar_patch_file="tar-1.32-check-sys-ioctl-header-configure.patch"
local tar_patch_id="file_id=50554"
local tar_patch_url="https://file.savannah.gnu.org/file/${tar_patch_file}?${tar_patch_id}"
efetch "${tar_patch_url}" || return 1
# If fetched from upstream url instead of mirror, filename will
# have a suffix. Remove suffix by copy, not move, to not
# trigger refetch on repeated invocations of this script.
if [[ -f "${DISTDIR}/${tar_patch_file}?${tar_patch_id}" ]]; then
cp ${DISTDIR}/${tar_patch_file}{?${tar_patch_id},} || return 1
fi
patch -p1 < ${DISTDIR}/${tar_patch_file} || return 1
fi
local myconf=""
if [[ ${PN} == "make" && ${PV} == "4.2.1" ]] ; then
if [[ ${CHOST} == *-linux-gnu* ]] ; then
# force this, macros aren't set correctly with newer glibc
export CPPFLAGS="${CPPFLAGS} -D__alloca=alloca -D__stat=stat"
fi
fi
if [[ ${PN} == "m4" ]] ; then
# drop _GL_WARN_ON_USE which gets turned into an error with
# recent GCC 1.4.17 and below only, on 1.4.18 this expression
# doesn't match
sed -i -e '/_GL_WARN_ON_USE (gets/d' lib/stdio.in.h lib/stdio.h
if [[ ${PV} == "1.4.18" ]] ; then
# macOS 10.13 have an issue with %n, which crashes m4
efetch "http://rsync.prefix.bitzolder.nl/sys-devel/m4/files/m4-1.4.18-darwin17-printf-n.patch" || return 1
patch -p1 < "${DISTDIR}"/m4-1.4.18-darwin17-printf-n.patch || return 1
# Bug 715880
efetch http://dev.gentoo.org/~heroxbd/m4-1.4.18-glibc228.patch || return 1
patch -p1 < "${DISTDIR}"/m4-1.4.18-glibc228.patch || return 1
fi
fi
fix_config_sub
if [[ ${PN} == "grep" ]] ; then
# Solaris and OSX don't like it when --disable-nls is set,
# so just don't set it at all.
# Solaris 11 has a messed up prce installation. We don't need
# it anyway, so just disable it
myconf="${myconf} --disable-perl-regexp"
fi
# pod2man may be too old (not understanding --utf8) but we don't
# care about manpages at this stage
export ac_cv_path_POD2MAN=no
# Darwin9 in particular doesn't compile when using system readline,
# but we don't need any groovy input handling at all, so just disable it
[[ ${PN} == "bash" ]] && myconf="${myconf} --disable-readline"
# On e.g. musl systems bash will crash with a malloc error if we use
# bash' internal malloc, so disable it during it this stage
[[ ${PN} == "bash" ]] && \
myconf="${myconf} --without-bash-malloc"
# Ensure we don't read system-wide shell initialisation, it may
# contain cruft, bug #650284
[[ ${PN} == "bash" ]] && \
export CPPFLAGS="${CPPFLAGS} \
-DSYS_BASHRC=\\\"${ROOT}/etc/bash/bashrc\\\" \
-DSYS_BASH_LOGOUT=\\\"${ROOT}/etc/bash/bash_logout\\\" \
"
# Don't do ACL stuff on Darwin, especially Darwin9 will make
# coreutils completely useless (install failing on everything)
# Don't try using gmp either, it may be that just the library is
# there, and if so, the buildsystem assumes the header exists too
# stdbuf is giving many problems, and we don't really care about it
# at this level, so disable it too
if [[ ${PN} == "coreutils" ]] ; then
myconf="${myconf} --disable-acl --without-gmp"
myconf="${myconf} --enable-no-install-program=stdbuf"
fi
# Gentoo Bug 400831, fails on Ubuntu with libssl-dev installed
if [[ ${PN} == "wget" ]] ; then
if [[ -x ${ROOT}/tmp/usr/bin/openssl ]] ; then
myconf="${myconf} --with-ssl=openssl"
myconf="${myconf} --with-libssl-prefix=${ROOT}/tmp/usr"
export CPPFLAGS="${CPPFLAGS} -I${ROOT}/tmp/usr/include"
export LDFLAGS="${LDFLAGS} -L${ROOT}/tmp/usr/lib"
else
myconf="${myconf} --without-ssl"
fi
fi
# SuSE 11.1 has GNU binutils-2.20, choking on crc32_x86
[[ ${PN} == "xz" ]] && myconf="${myconf} --disable-assembler"
if [[ ${PN} == "libffi" ]] ; then
# we do not have pkg-config to find lib/libffi-*/include/ffi.h
sed -i -e '/includesdir =/s/=.*/= $(includedir)/' include/Makefile.in
# force install into libdir
myconf="${myconf} --libdir=${ROOT}/tmp/usr/lib"
sed -i -e '/toolexeclibdir =/s/=.*/= $(libdir)/' Makefile.in
# we have to build the libraries for correct bitwidth
case $CHOST in
(x86_64-*-*|sparcv9-*-*)
export CFLAGS="-m64"
;;
(i?86-*-*)
export CFLAGS="-m32"
;;
(arm64-*-darwin*)
sed -i -e 's/aarch64\*-\*-\*/arm64*-*-*|&/' \
configure configure.host
;;
esac
fi
einfo "Compiling ${A%.tar.*}"
econf ${myconf} || return 1
if [[ ${PN} == "make" && $(type -t $MAKE) != "file" ]]; then
estatus "stage1: building ${A%.tar.*}"
v ./build.sh || return 1
else
emake || return 1
fi
einfo "Installing ${A%.tar.*}"
if [[ ${PN} == "make" && $(type -t $MAKE) != "file" ]]; then
estatus "stage1: installing ${A%.tar.*}"
v ./make install MAKE="${S}/make" || return 1
else
emake install || return 1
fi
cd "${ROOT}"
rm -Rf "${S}"
einfo "${A%.tar.*} successfully bootstrapped"
}
python_ver() {
# keep this number in line with PV below for stage1,2
# also, note that this version must match the Python version in the
# snapshot for stage3, else packages will break with some python
# mismatch error due to Portage using a different version after it
# upgraded itself with a newer Python
echo 3.11 # keep this number in line with PV below for stage1,2
}
bootstrap_python() {
PV=$(python_ver).3-gentoo-prefix-patched
A=Python-${PV}.tar.xz
einfo "Bootstrapping ${A%.tar.*}"
if [[ ${PV} == *-gentoo-prefix-patched ]] ; then
efetch https://dev.gentoo.org/~grobian/distfiles/${A}
else
efetch https://www.python.org/ftp/python/${PV}/${A}
fi
einfo "Unpacking ${A%.tar.*}"
export S="${PORTAGE_TMPDIR}/python-${PV}"
rm -rf "${S}"
mkdir -p "${S}"
cd "${S}"
case ${A} in
*bz2) bzip2 -dc "${DISTDIR}"/${A} | tar -xf - ;;
*xz) xz -dc "${DISTDIR}"/${A} | tar -xf - ;;
*) einfo "Don't know to unpack ${A}" ;;
esac
[[ ${PIPESTATUS[*]} == '0 0' ]] || return 1
S="${S}"/Python-${PV%%-*}
cd "${S}"
rm -rf Modules/_ctypes/libffi* || return 1
rm -rf Modules/zlib || return 1
case ${CHOST} in
(*-solaris*)
# Solaris' host compiler (if old -- 3.4.3) doesn't grok HUGE_VAL,
# and barfs on isnan() so patch it out