forked from dilawar/Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gentoo_bootstrap_bash.sh
executable file
·2349 lines (2101 loc) · 71 KB
/
gentoo_bootstrap_bash.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-2014 Gentoo Foundation; Distributed under the GPL v2
# $Id: bootstrap-prefix.sh 61818 2014-01-08 07:28:16Z haubi $
trap 'exit 1' TERM KILL INT QUIT ABRT
# some basic output functions
eerror() { echo "!!! $*" 1>&2; }
einfo() { echo "* $*"; }
# prefer gtar over tar
[[ x$(type -t gtar) == "xfile" ]] \
&& TAR="gtar" \
|| TAR="tar"
## Functions Start Here
econf() {
${CONFIG_SHELL} ./configure \
--host=${CHOST} \
--prefix="${ROOT}"/usr \
--mandir="${ROOT}"/usr/share/man \
--infodir="${ROOT}"/usr/share/info \
--datadir="${ROOT}"/usr/share \
--sysconfdir="${ROOT}"/etc \
--localstatedir="${ROOT}"/var/lib \
--build=${CHOST} \
"$@" || return 1
}
efetch() {
if [[ ! -e ${DISTDIR}/${1##*/} ]] ; then
if [[ ${OFFLINE_MODE} ]]; then
echo "I needed ${1##*/} from $1 or ${GENTOO_MIRRORS}/distfiles/${1##*/} in $DISTDIR"
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"
elif [[ x$(type -t ftp) == "xfile" ]] ; then
FETCH_COMMAND="ftp"
elif [[ x$(type -t curl) == "xfile" ]] ; then
einfo "WARNING: curl doesn't fail when downloading fails, please check its output carefully!"
FETCH_COMMAND="curl -L -O"
elif [[ x$(type -t fetch) == "xfile" ]] ; then
FETCH_COMMAND="fetch"
else
eerror "no suitable download manager found (need wget, curl, fetch or ftp)"
eerror "could not download ${1##*/}"
exit 1
fi
fi
mkdir -p "${DISTDIR}" >& /dev/null
einfo "Fetching ${1##*/}"
pushd "${DISTDIR}" > /dev/null
# try for mirrors first, then try given location
${FETCH_COMMAND} "${GENTOO_MIRRORS}/distfiles/${1##*/}" < /dev/null
[[ ! -f ${1##*/} && ${1} != ${GENTOO_MIRRORS}/distfiles/${1##*/} ]] \
&& ${FETCH_COMMAND} "$1" < /dev/null
if [[ ! -f ${1##*/} ]] ; then
eerror "downloading ${1} failed!"
return 1
fi
popd > /dev/null
fi
return 0
}
# template
# bootstrap_() {
# PV=
# A=
# einfo "Bootstrapping ${A%-*}"
# efetch ${A} || return 1
# einfo "Unpacking ${A%-*}"
# export S="${PORTAGE_TMPDIR}/${PN}"
# rm -rf ${S}
# mkdir -p ${S}
# cd ${S}
# $TAR -zxf ${DISTDIR}/${A} || return 1
# S=${S}/${PN}-${PV}
# cd ${S}
# einfo "Compiling ${A%-*}"
# econf || return 1
# $MAKE ${MAKEOPTS} || return 1
# einfo "Installing ${A%-*}"
# $MAKE install || return 1
# einfo "${A%-*} successfully bootstrapped"
# }
configure_toolchain() {
export CPPFLAGS="-I${ROOT}/usr/include -I${ROOT}/tmp/usr/include"
case ${bootstrapCHOST} in
*-darwin*)
export LDFLAGS="-Wl,-search_paths_first -L${ROOT}/usr/lib -L${ROOT}/lib -L${ROOT}/tmp/usr/lib"
;;
*-solaris* | *-irix*)
export LDFLAGS="-L${ROOT}/usr/lib -R${ROOT}/usr/lib -L${ROOT}/lib -R${ROOT}/lib -L${ROOT}/tmp/usr/lib -R${ROOT}/tmp/usr/lib"
;;
*-hp-hpux*)
export LDFLAGS="-L${ROOT}/usr/lib -R${ROOT}/usr/lib -L${ROOT}/lib -R${ROOT}/lib -L${ROOT}/tmp/usr/lib -R${ROOT}/tmp/usr/lib -L/usr/local/lib -R/usr/local/lib"
;;
*-*-aix*)
# The bootstrap compiler unlikely has runtime linking
# enabled already, but elibtoolize switches to the
# "lib.so(shr.o)" sharedlib variant.
export LDFLAGS="-Wl,-brtl -L${ROOT}/usr/lib -L${ROOT}/lib -L${ROOT}/tmp/usr/lib"
;;
i586-pc-interix* | i586-pc-winnt* | i686-pc-cygwin*)
export LDFLAGS="-L${ROOT}/usr/lib -L${ROOT}/lib -L${ROOT}/tmp/usr/lib"
;;
*)
export LDFLAGS="-L${ROOT}/usr/lib -Wl,-rpath=${ROOT}/usr/lib -L${ROOT}/lib -Wl,-rpath=${ROOT}/lib -L${ROOT}/tmp/usr/lib -Wl,-rpath=${ROOT}/tmp/usr/lib"
;;
esac
case ${bootstrapCHOST} in
# note: we need CXX for binutils-apple which' ld is c++
*64-apple* | sparcv9-*-solaris* | x86_64-*-solaris*)
[[ -z ${CC} ]] && export CC="gcc -m64"
[[ -z ${CXX} ]] && export CXX="g++ -m64"
[[ -z ${HOSTCC} ]] && export HOSTCC="gcc -m64"
;;
i*86-apple-darwin1*)
[[ -z ${CC} ]] && export CC="gcc -m32"
[[ -z ${CXX} ]] && export CXX="g++ -m32"
[[ -z ${HOSTCC} ]] && export HOSTCC="gcc -m32"
;;
*)
;;
esac
pkggcc="sys-devel/gcc"
case ${bootstrapCHOST} in
*-darwin*)
case "$(gcc --version)" in
*"(GCC) 4.2.1 "*|*"Apple LLVM version 5."*)
local linker=sys-devel/binutils-apple
;;
*"(GCC) 4.0.1 "*)
local linker="=sys-devel/binutils-apple-3.2"
;;
*)
eerror "unknown compiler"
return 1
;;
esac
toolchainpackages=(
sys-apps/darwin-miscutils
sys-libs/csu
${linker}
sys-devel/gcc-apple
)
pkggcc="sys-devel/gcc-apple"
;;
i?86-*-solaris*)
# 4.2/x86 can't cope with Sun ld/as
# results in a bootstrap compare mismatch
# Figure out what Solaris we're on. Since Solaris 10u10
# some Solaris 11 changes have been integrated that
# implement some GNU extensions to ELF. This most notably
# is the VERSYM_HIDDEN flag, that GCC 4.1 doesn't know
# about, resulting in a libstdc++.so that cannot find these
# hidden symbols. GCC 4.2 knows about these, so we must
# have it there. Unfortunately, 4.2 doesn't always compile,
# so we need to perform the expensive 4.1 -> 4.2 -> current.
local SOLARIS_RELEASE=$(head -n1 /etc/release)
local needgcc42=
case "${SOLARIS_RELEASE}" in
*"Solaris 10"*)
# figure out major update level
SOLARIS_RELEASE=${SOLARIS_RELEASE##*s10s_u}
SOLARIS_RELEASE=${SOLARIS_RELEASE##*s10x_u}
SOLARIS_RELEASE=${SOLARIS_RELEASE%%wos_*}
if [[ "${SOLARIS_RELEASE}" -ge "10" ]] ; then
needgcc42="=sys-devel/gcc-4.2*"
fi
;;
*)
# assume all the rest is Oracle Solaris 11,
# OpenSolaris, OpenIndiana, SmartOS, whatever,
# thus > Solaris 10u10
needgcc42="=sys-devel/gcc-4.2*"
;;
esac
toolchainpackages=(
sys-devel/binutils
"=sys-devel/gcc-4.1*"
${needgcc42}
)
;;
sparc-*-solaris2.11)
# unknown what the problem is here
toolchainpackages=(
sys-devel/binutils
"=sys-devel/gcc-4.1*"
"=sys-devel/gcc-4.2*"
)
;;
*-*-aix*)
toolchainpackages=(
sys-apps/diffutils # or gcc PR14251
sys-devel/native-cctools
"=sys-devel/gcc-4.2*"
sys-apps/aix-miscutils
sys-apps/texinfo
)
;;
*)
toolchainpackages=(
sys-devel/binutils
"=sys-devel/gcc-4.2*"
)
;;
esac
}
bootstrap_setup() {
local profile=""
einfo "setting up some guessed defaults"
case ${CHOST} in
powerpc-apple-darwin7)
profile="prefix/darwin/macos/10.3"
;;
powerpc-apple-darwin[89])
rev=${CHOST##*darwin}
profile="prefix/darwin/macos/10.$((rev - 4))/ppc"
;;
powerpc64-apple-darwin[89])
rev=${CHOST##*darwin}
profile="prefix/darwin/macos/10.$((rev - 4))/ppc64"
;;
i*86-apple-darwin[89])
rev=${CHOST##*darwin}
profile="prefix/darwin/macos/10.$((rev - 4))/x86"
;;
i*86-apple-darwin1[0123])
rev=${CHOST##*darwin}
profile="prefix/darwin/macos/10.$((rev - 4))/x86"
;;
x86_64-apple-darwin9|x86_64-apple-darwin1[0123])
rev=${CHOST##*darwin}
profile="prefix/darwin/macos/10.$((rev - 4))/x64"
;;
i*86-pc-linux-gnu)
profile="prefix/linux/x86"
;;
x86_64-pc-linux-gnu)
profile="prefix/linux/amd64"
;;
ia64-pc-linux-gnu)
profile="prefix/linux/ia64"
;;
powerpc-unknown-linux-gnu)
profile="prefix/linux/ppc"
;;
powerpc64-unknown-linux-gnu)
profile="prefix/linux/ppc64"
;;
armv7l-pc-linux-gnu)
profile="prefix/linux/arm"
;;
sparc-sun-solaris2.9)
profile="prefix/sunos/solaris/5.9/sparc"
;;
sparcv9-sun-solaris2.9)
profile="prefix/sunos/solaris/5.9/sparc64"
# we need this, or binutils can't link, can't add it to -L,
# since then binutils breaks on finding an old libiberty.a
# from there instead of its own
cp /usr/sfw/lib/64/libgcc_s.so.1 "${ROOT}"/tmp/usr/lib/
;;
i386-pc-solaris2.10)
profile="prefix/sunos/solaris/5.10/x86"
;;
x86_64-pc-solaris2.10)
profile="prefix/sunos/solaris/5.10/x64"
# we need this, or binutils can't link, can't add it to -L,
# since then binutils breaks on finding an old libiberty.a
# from there instead of its own
cp /usr/sfw/lib/64/libgcc_s.so.1 "${ROOT}"/tmp/usr/lib/
;;
sparc-sun-solaris2.10)
profile="prefix/sunos/solaris/5.10/sparc"
;;
sparcv9-sun-solaris2.10)
profile="prefix/sunos/solaris/5.10/sparc64"
# we need this, or binutils can't link, can't add it to -L,
# since then binutils breaks on finding an old libiberty.a
# from there instead of its own
cp /usr/sfw/lib/64/libgcc_s.so.1 "${ROOT}"/tmp/usr/lib/
;;
i386-pc-solaris2.11)
profile="prefix/sunos/solaris/5.11/x86"
;;
x86_64-pc-solaris2.11)
profile="prefix/sunos/solaris/5.11/x64"
# we need this, or binutils can't link, can't add it to -L,
# since then binutils breaks on finding an old libiberty.a
# from there instead of its own
cp /usr/sfw/lib/64/libgcc_s.so.1 "${ROOT}"/tmp/usr/lib/
;;
sparc-sun-solaris2.11)
profile="prefix/sunos/solaris/5.11/sparc"
;;
sparcv9-sun-solaris2.11)
profile="prefix/sunos/solaris/5.11/sparc64"
# we need this, or binutils can't link, can't add it to -L,
# since then binutils breaks on finding an old libiberty.a
# from there instead of its own
cp /usr/sfw/lib/64/libgcc_s.so.1 "${ROOT}"/tmp/usr/lib/
;;
powerpc-ibm-aix*)
profile="prefix/aix/${CHOST#powerpc-ibm-aix}/ppc"
;;
mips-sgi-irix*)
profile="prefix/irix/${CHOST#mips-sgi-irix}/mips"
;;
i586-pc-interix*)
profile="prefix/windows/interix/${CHOST#i586-pc-interix}/x86"
;;
i586-pc-winnt*)
profile="prefix/windows/winnt/${CHOST#i586-pc-winnt}/x86"
;;
i686-pc-cygwin*)
profile="prefix/windows/cygwin/${CHOST#i686-pc-cygwin}/x86"
;;
hppa64*-hp-hpux11*)
profile="prefix/hpux/B.11${CHOST#hppa*-hpux11}/hppa64"
;;
hppa2.0*-hp-hpux11*)
profile="prefix/hpux/B.11${CHOST#hppa*-hpux11}/hppa2.0"
;;
ia64-hp-hpux11*)
profile="prefix/hpux/B.11${CHOST#ia64-hp-hpux11}/ia64"
;;
i386-pc-freebsd*)
profile="prefix/bsd/freebsd/${CHOST#i386-pc-freebsd}/x86"
;;
x86_64-pc-freebsd*)
profile="prefix/bsd/freebsd/${CHOST#x86_64-pc-freebsd}/x64"
;;
i386-pc-netbsd*)
profile="prefix/bsd/netbsd/${CHOST#i386-pc-netbsdelf}/x86"
;;
powerpc-unknown-openbsd*)
profile="prefix/bsd/openbsd/${CHOST#powerpc-unknown-openbsd}/ppc"
;;
i386-pc-openbsd*)
profile="prefix/bsd/openbsd/${CHOST#i386-pc-openbsd}/x86"
;;
x86_64-pc-openbsd*)
profile="prefix/bsd/openbsd/${CHOST#x86_64-pc-openbsd}/x64"
;;
*)
einfo "UNKNOWN ARCH: You need to set up a make.profile symlink to a"
einfo "profile in ${PORTDIR} for your CHOST ${CHOST}"
;;
esac
if [[ -n ${profile} && ! -e ${ROOT}/etc/portage/make.profile ]] ; then
local fullprofile="${PORTDIR}/profiles/${profile}"
for base in ${PORTDIR_OVERLAY} ; do
if [[ -e ${base}/profiles/${profile}/parent ]] ; then
fullprofile="${base}/profiles/${profile}"
break
fi
done
ln -s "${fullprofile}" "${ROOT}"/etc/portage/make.profile
einfo "Your profile is set to ${fullprofile}."
fi
# Disable the STALE warning because the snapshot frequently gets stale.
echo 'PORTAGE_SYNC_STALE=0' >> "${PORTDIR}"/profiles/features/prefix/make.defaults
# Some people will hit bug 262653 with gcc-4.2 and elfutils. Let's skip it
# here and bring it in AFTER the --sync
echo "dev-libs/elfutils-0.153" >> "${PORTDIR}"/profiles/features/prefix/package.provided
}
do_tree() {
local x
for x in etc{,/portage} usr/{{,s}bin,lib} var/tmp var/lib/portage var/log/portage var/db;
do
[[ -d ${ROOT}/${x} ]] || mkdir -p "${ROOT}/${x}"
done
if [[ ${PREFIX_DISABLE_USR_SPLIT} == "yes" ]] ; then
# note to self: don't make bin a symlink to usr/bin for
# coreutils installs symlinks to from usr/bin to bin, which in
# case they are the same boils down to a pointless indirection
# to self
for x in lib sbin ; do
[[ -e ${ROOT}/${x} ]] || ( cd "${ROOT}" && ln -s usr/${x} )
done
else
for x in lib sbin ; do
[[ -d ${ROOT}/${x} ]] || mkdir -p "${ROOT}/${x}"
done
fi
if [[ ! -e ${PORTDIR}/.unpacked ]]; then
efetch "$1/$2" || return 1
[[ -e ${PORTDIR} ]] || mkdir -p ${PORTDIR}
einfo "Unpacking, this may take a while"
bzip2 -dc ${DISTDIR}/$2 | $TAR -xf - -C ${PORTDIR%portage} || return 1
touch ${PORTDIR}/.unpacked
fi
}
bootstrap_tree() {
local PV="20140228"
if [[ -n ${LATEST_TREE_YES} ]]; then
do_tree "${SNAPSHOT_URL}" portage-latest.tar.bz2
else
do_tree http://prefix.gentooexperimental.org/distfiles prefix-overlay-${PV}.tar.bz2
fi
}
bootstrap_latest_tree() {
# kept here for compatibility reasons
einfo "This function 'latest_tree' is deprecated and will be"
einfo "removed in the future, please set LATEST_TREE_YES=1 in the env"
LATEST_TREE_YES=1 bootstrap_tree
}
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 "Creating the Prefix start script (startprefix)"
# currently I think right into the prefix is the best location, as
# putting it in /bin or /usr/bin just hides it some more for the
# user
sed \
-e "s|@GENTOO_PORTAGE_EPREFIX@|${ROOT}|g" \
"${ROOT}"/usr/portage/scripts/startprefix.in \
> "${ROOT}"/startprefix
chmod 755 "${ROOT}"/startprefix
einfo "To start Gentoo Prefix, run the script ${ROOT}/startprefix"
einfo "You can copy this file to a more convenient place if you like."
# 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
}
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="2.2.8"
[[ ${TESTING_PV} == latest ]] && TESTING_PV="2.2.8"
PV="${TESTING_PV:-${STABLE_PV}}"
A=prefix-portage-${PV}.tar.bz2
einfo "Bootstrapping ${A%-*}"
efetch ${DISTFILES_URL}/${A} || return 1
einfo "Unpacking ${A%-*}"
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 - || return 1
S="${S}/prefix-portage-${PV}"
cd "${S}"
# disable ipc
sed -e "s:_enable_ipc_daemon = True:_enable_ipc_daemon = False:" \
-i pym/_emerge/AbstractEbuildProcess.py || \
return 1
# 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.
mkdir -p ${ROOT}/bin || return 1
[[ -x ${ROOT}/bin/bash ]] || [[ ! -x ${ROOT}/tmp/usr/bin/bash ]] || ln -s ${ROOT}/tmp/usr/bin/bash ${ROOT}/bin/bash || return 1
[[ -x ${ROOT}/bin/bash ]] || ln -s ${BASH} ${ROOT}/bin/bash || return 1
export PORTAGE_BASH=${ROOT}/bin/bash
einfo "Compiling ${A%-*}"
econf \
--with-offset-prefix="${ROOT}" \
--with-portage-user="`id -un`" \
--with-portage-group="`id -gn`" \
--mandir="${ROOT}/automatically-removed" \
--with-extra-path="${ROOT}/tmp/usr/bin:/bin:/usr/bin:${PATH}" \
|| return 1
$MAKE ${MAKEOPTS} || return 1
einfo "Installing ${A%-*}"
$MAKE install || return 1
bootstrap_setup
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..
[[ ! -d $ROOT/var/log ]] && mkdir ${ROOT}/var/log
# during bootstrap_portage(), man pages are not compressed. This is
# problematic once you have a working prefix. So, remove them now.
rm -rf "${ROOT}/automatically-removed"
# in Prefix the sed wrapper is deadly, so kill it
rm -f "${ROOT}"/usr/lib/portage/bin/ebuild-helpers/sed
einfo "${A%-*} successfully bootstrapped"
}
prep_gcc-apple() {
GCC_PV=5341
GCC_A="gcc-${GCC_PV}.tar.gz"
TAROPTS="-zxf"
efetch ${GCC_APPLE_URL}/${GCC_A} || return 1
}
prep_gcc-fsf() {
GCC_PV=4.1.2
GCC_A=gcc-${GCC_PV}.tar.bz2
TAROPTS="-jxf"
efetch ${GENTOO_MIRRORS}/distfiles/${GCC_A} || return 1
}
bootstrap_gcc() {
case ${CHOST} in
*-*-darwin*)
prep_gcc-apple
;;
*-*-solaris*)
prep_gcc-fsf
GCC_EXTRA_OPTS="--disable-multilib --with-gnu-ld"
;;
*)
prep_gcc-fsf
;;
esac
GCC_LANG="c,c++"
export S="${PORTAGE_TMPDIR}/gcc-${GCC_PV}"
rm -rf "${S}"
mkdir -p "${S}"
cd "${S}"
einfo "Unpacking ${GCC_A}"
$TAR ${TAROPTS} "${DISTDIR}"/${GCC_A} || return 1
rm -rf "${S}"/build
mkdir -p "${S}"/build
cd "${S}"/build
${CONFIG_SHELL} ${S}/gcc-${GCC_PV}/configure \
--prefix="${ROOT}"/usr \
--mandir="${ROOT}"/usr/share/man \
--infodir="${ROOT}"/usr/share/info \
--datadir="${ROOT}"/usr/share \
--disable-checking \
--disable-werror \
--disable-nls \
--with-system-zlib \
--enable-languages=${GCC_LANG} \
${GCC_EXTRA_OPTS} \
|| return 1
$MAKE ${MAKEOPTS} bootstrap-lean || return 1
$MAKE install || return 1
cd "${ROOT}"
rm -Rf "${S}"
einfo "${GCC_A%-*} successfully bootstrapped"
}
bootstrap_gnu() {
local PN PV A S
PN=$1
PV=$2
einfo "Bootstrapping ${PN}"
for t in tar.gz tar.xz tar.bz2 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%-*}"
S="${PORTAGE_TMPDIR}/${PN}-${PV}"
rm -rf "${S}"
mkdir -p "${S}"
cd "${S}"
if [[ ${t} == "tar.gz" ]] ; then
gzip -dc "${DISTDIR}"/${URL##*/} | $TAR -xf - || continue
elif [[ ${t} == "tar.xz" ]] ; then
xz -dc "${DISTDIR}"/${URL##*/} | $TAR -xf - || continue
elif [[ ${t} == "tar.bz2" ]] ; then
bzip2 -dc "${DISTDIR}"/${URL##*/} | $TAR -xf - || continue
elif [[ ${t} == "tar" ]] ; then
$TAR -xf "${DISTDIR}"/${A} || continue
else
einfo "unhandled extension: $t"
return 1
fi
break
done
S="${S}"/${PN}-${PV}
[[ -d ${S} ]] || return 1
cd "${S}" || return 1
local myconf=""
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"
# Except interix really needs it for grep.
[[ $CHOST == *interix* ]] && myconf="${myconf} --disable-nls"
fi
# AIX doesn't like --enable-nls in general during bootstrap
[[ $CHOST == *-aix* ]] && myconf="${myconf} --disable-nls"
# AIX 7.1 has fstatat(), but broken without APAR IV23716:
[[ $CHOST == *-aix7* ]] && export ac_cv_func_fstatat=no
# AIX lacks /dev/fd/*, bash uses (blocking) named pipes instead
[[ ${PN} == "bash" ]] && sed -i -e 's/|O_NONBLOCK//' subst.c
# NetBSD has strange openssl headers, which make wget fail.
[[ $CHOST == *-netbsd* ]] && myconf="${myconf} --disable-ntlm"
# Darwin9 in particular doesn't compile when using system readline,
# but we don't need any groovy input at all, so just disable it
[[ ${PN} == "bash" ]] && myconf="${myconf} --disable-readline"
# 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
[[ ${PN} == "coreutils" ]] && \
myconf="${myconf} --disable-acl --without-gmp"
if [[ ${PN} == "coreutils" && ${CHOST} == *-interix* ]] ; then
# Interix doesn't have filesystem listing stuff, but that means all
# other utilities but df aren't useless at all, so don't die
sed -i -e '/^if test -z "$ac_list_mounted_fs"; then$/c\if test 1 = 0; then' configure
# try to make id() not poll the entire domain before returning
export CFLAGS="${CFLAGS} -Dgetgrgid=getgrgid_nomembers -Dgetgrent=getgrent_nomembers -Dgetgrnam=getgrnam_nomembers"
# Fix a compilation error due to a missing definition
sed -i -e '/^#include "fcntl-safer.h"$/a\#define ESTALE -1' lib/savewd.c
fi
if [[ ${PN} == "tar" && ${CHOST} == *-hpux* ]] ; then
# Fix a compilation error due to a missing definition
export CPPFLAGS="${CPPFLAGS} -DCHAR_BIT=8"
fi
# Gentoo Bug 400831, fails on Ubuntu with libssl-dev installed
[[ ${PN} == "wget" ]] && myconf="${myconf} --without-ssl"
einfo "Compiling ${PN}"
econf ${myconf} || return 1
if [[ ${PN} == "make" && $(type -t $MAKE) != "file" ]]; then
./build.sh || return 1
else
$MAKE ${MAKEOPTS} || return 1
fi
einfo "Installing ${PN}"
if [[ ${PN} == "make" && $(type -t $MAKE) != "file" ]]; then
./make install MAKE="${S}/make" || return 1
else
$MAKE install || return 1
fi
cd "${ROOT}"
rm -Rf "${S}"
einfo "${PN}-${PV} successfully bootstrapped"
}
bootstrap_python() {
PV=2.7.3
case $CHOST in
*-*-aix*)
# TODO: freebsd 10 also seems to need this
A=Python-${PV}.tar.bz2 # patched one breaks
patch=true
;;
*)
A=python-${PV}-patched.tar.bz2
patch=false
;;
esac
einfo "Bootstrapping ${A%-*}"
# don't really want to put this on the mirror, since they are
# non-vanilla sources, bit specific for us
efetch ${DISTFILES_URL}/${A} || return 1
einfo "Unpacking ${A%%-*}"
export S="${PORTAGE_TMPDIR}/python-${PV}"
rm -rf "${S}"
mkdir -p "${S}"
cd "${S}"
bzip2 -dc "${DISTDIR}"/${A} | $TAR -xf - || return 1
S="${S}"/Python-${PV}
cd "${S}"
if ${patch}; then
# This patch is critical and needs to be applied even
# when using the otherwise unpatched sources.
efetch "http://dev.gentoo.org/~redlizard/distfiles/02_all_disable_modules_and_ssl.patch"
patch -p0 < "${DISTDIR}"/02_all_disable_modules_and_ssl.patch
fi
local myconf=""
case $CHOST in
*-*-aix*)
# Python stubbornly insists on using cc_r to compile. We
# know better, so force it to listen to us
myconf="${myconf} --with-gcc=yes"
;;
*-openbsd*)
CFLAGS="${CFLAGS} -D_BSD_SOURCE=1"
;;
*-linux*)
# Bug 382263: make sure Python will know about the libdir in use for
# the current arch
libdir="-L/usr/lib/$(gcc -print-multi-os-directory)"
;;
x86_64-*-solaris*|sparcv9-*-solaris*)
# Like above, make Python know where GCC's 64-bits
# libgcc_s.so is on Solaris
libdir="-L/usr/sfw/lib/64"
;;
esac
# python refuses to find the zlib headers that are built in the
# offset
export CPPFLAGS="-I$EPREFIX/tmp/usr/include"
export LDFLAGS="-L$EPREFIX/tmp/usr/lib"
# set correct flags for runtime for ELF platforms
case $CHOST in
*-*bsd*|*-linux*)
# GNU ld
export LDFLAGS="${LDFLAGS} -Wl,-rpath,$EPREFIX/tmp/usr/lib ${libdir}"
;;
*-solaris*)
# Sun ld
export LDFLAGS="${LDFLAGS} -R$EPREFIX/tmp/usr/lib ${libdir}"
;;
esac
# if the user has a $HOME/.pydistutils.cfg file, the python
# installation is going to be screwed up, as reported by users, so
# just make sure Python won't find it
export HOME="${S}"
export PYTHON_DISABLE_MODULES="_bsddb bsddb bsddb185 bz2 crypt _ctypes_test _curses _curses_panel dbm _elementtree gdbm _locale nis pyexpat readline _sqlite3 _tkinter"
export PYTHON_DISABLE_SSL=1
export OPT="${CFLAGS}"
einfo "Compiling ${A%-*}"
#some ancient versions of hg fail with "hg id -i", so help configure to not find them
HAS_HG=no \
econf \
--disable-toolbox-glue \
--disable-ipv6 \
--disable-shared \
${myconf} || return 1
$MAKE ${MAKEOPTS} || return 1
einfo "Installing ${A%-*}"
$MAKE -k install || echo "??? Python failed to install *sigh* continuing anyway"
cd "${ROOT}"/usr/bin
ln -sf python${PV%.*} python
cd "${ROOT}"/usr/lib
# messes up python emerges, and shouldn't be necessary for anything
# http://forums.gentoo.org/viewtopic-p-6890526.html
rm -f libpython${PV%.*}.a
einfo "${A%-*} bootstrapped"
}
bootstrap_zlib_core() {
# use 1.2.5 by default, current bootstrap guides
PV="${1:-1.2.5}"
A=zlib-${PV}.tar.gz
einfo "Bootstrapping ${A%-*}"
if ! efetch ${GENTOO_MIRRORS}/distfiles/${A} ; then
A=zlib-${PV}.tar.bz2
efetch ${GENTOO_MIRRORS}/distfiles/${A} || return 1
fi
einfo "Unpacking ${A%%-*}"
export S="${PORTAGE_TMPDIR}/zlib-${PV}"
rm -rf "${S}"
mkdir -p "${S}"
cd "${S}"
if [[ ${A} == *.tar.gz ]] ; then
gzip -dc "${DISTDIR}"/${A} | $TAR -xf - || return 1
else
bzip2 -dc "${DISTDIR}"/${A} | $TAR -xf - || return 1
fi
S="${S}"/zlib-${PV}
cd "${S}"
if [[ ${CHOST} == x86_64-*-* || ${CHOST} == sparcv9-*-* ]] ; then
# 64-bits targets need zlib as library (not just to unpack),
# hence we need to make sure that we really bootstrap this
# 64-bits (in contrast to the tools which we don't care if they
# are 32-bits)
export CC="gcc -m64"
elif [[ ${CHOST} == i?86-*-* ]] ; then
# This is important for bootstraps which are 64-native, but we
# want 32-bits, such as most Linuxes, and more recent OSX.
# OS X Lion and up default to a 64-bits userland, so force the
# compiler to 32-bits code generation if requested here
export CC="gcc -m32"
fi
# 1.2.5 suffers from a concurrency problem
[[ ${PV} == 1.2.5 ]] && MAKEOPTS=
einfo "Compiling ${A%-*}"
CHOST= ${CONFIG_SHELL} ./configure --prefix="${ROOT}"/usr || return 1
$MAKE ${MAKEOPTS} || return 1
einfo "Installing ${A%-*}"
$MAKE install || return 1
# this lib causes issues when emerging python again on Solaris
# because the tmp lib path is in the library search path there
rm -Rf "${ROOT}"/usr/lib/libz*.a
if [[ ${CHOST} == *-aix* ]]; then
# No aix-soname support, but symlinks when built with gcc. This breaks
# later on when aix-soname is added within Prefix, where the lib.so.1
# is an archive then, while finding this one first due to possible
# rpath ordering issues.
rm -f "${ROOT}"/usr/lib/libz.so.1
fi
einfo "${A%-*} bootstrapped"
}
bootstrap_zlib() {
bootstrap_zlib_core 1.2.8 || bootstrap_zlib_core 1.2.7 || \
bootstrap_zlib_core 1.2.6 || bootstrap_zlib_core 1.2.5
}
bootstrap_sed() {
bootstrap_gnu sed 4.2.1
}
bootstrap_findutils() {
bootstrap_gnu findutils 4.5.10 || bootstrap_gnu findutils 4.2.33
}
bootstrap_wget() {
bootstrap_gnu wget 1.13.4
}
bootstrap_grep() {
# don't use 2.13, it contains a bug that bites, bug #425668
# 2.9 is the last version provided as tar.gz (platforms without xz)
# 2.7 is necessary for Solaris/OpenIndiana (2.8, 2.9 fail to configure)
bootstrap_gnu grep 2.14 || bootstrap_gnu grep 2.12 || \
bootstrap_gnu grep 2.9 || bootstrap_gnu grep 2.7
}
bootstrap_coreutils() {
# 8.12 for FreeBSD 9.1, bug #415439
# 8.16 is the last version released as tar.gz
bootstrap_gnu coreutils 8.17 || bootstrap_gnu coreutils 8.16 || \
bootstrap_gnu coreutils 8.12
}
bootstrap_tar() {
bootstrap_gnu tar 1.26
}
bootstrap_make() {
MAKEOPTS= # no GNU make yet
bootstrap_gnu make 3.82
}
bootstrap_patch() {
# 2.5.9 needed for OSX 10.6.x
bootstrap_gnu patch 2.6.1 || bootstrap_gnu patch 2.5.9 || \
bootstrap_gnu patch 2.5.4
}
bootstrap_gawk() {
bootstrap_gnu gawk 4.0.1 || bootstrap_gnu gawk 4.0.0 || \
bootstrap_gnu gawk 3.1.8
}
bootstrap_binutils() {
bootstrap_gnu binutils 2.17
}
bootstrap_texinfo() {
bootstrap_gnu texinfo 4.8
}
bootstrap_bash() {
bootstrap_gnu bash 4.2
}
bootstrap_bison() {
bootstrap_gnu bison 2.6.2 || bootstrap_gnu bison 2.6.1 || \
bootstrap_gnu bison 2.6 || bootstrap_gnu bison 2.5.1 || \
bootstrap_gnu bison 2.4
}
bootstrap_m4() {
bootstrap_gnu m4 1.4.16 || bootstrap_gnu m4 1.4.15
}
bootstrap_gzip() {
bootstrap_gnu gzip 1.4
}
bootstrap_bzip2() {
local PN PV A S
PN=bzip2
PV=1.0.6
A=${PN}-${PV}.tar.gz
einfo "Bootstrapping ${A%-*}"
efetch ${GENTOO_MIRRORS}/distfiles/${A} || return 1
einfo "Unpacking ${A%-*}"
S="${PORTAGE_TMPDIR}/${PN}-${PV}"