Browse Source
			
			
			
			
				
		Based on guix' gnu/packages/commencement.scm, revision b85863f7ce99d05205e57358b36ff50656cca08bmaster
				 21 changed files with 3837 additions and 0 deletions
			
			
		| @ -0,0 +1,5 @@ | |||
| 81189d0d0095c044b3113dd38f0e8e195627cd06  bin/busybox | |||
| 34b500b18659b9331d4225eb6734be2ce8990589  mes/bin/blood-elf | |||
| 7ebbf5dcf1d66966d0609fc09d4279c3d247c16b  mes/bin/hex2 | |||
| 2cc482ca6cbafc33cbc856384ed5685887c27120  mes/bin/M1 | |||
| de1e6f6cffcf5660b4b2586c2e5031fd82fa0646  mes/bin/mes | |||
| @ -0,0 +1,37 @@ | |||
| #!/bin/sh | |||
| set -e | |||
| 
 | |||
| # Use qemu if necessary | |||
| #qemu=qemu-i386 | |||
| qemu= | |||
| 
 | |||
| rm -rf system | |||
| mkdir -p builds | |||
| 
 | |||
| # Stage 1: Build matching mes and busybox binaries | |||
| ./build_binaries.sh | |||
| mv system/binaries.tar.gz builds/  # Will be regenerated later, to match. | |||
| 
 | |||
| # Stage 2: Bootstrap system from these | |||
| mkdir -p system/sources/ | |||
| cp -av sources/* system/sources/ | |||
| cp build_bootstrap.sh system/sources/ | |||
| mkdir system/dev system/tmp | |||
| mknod system/dev/null c 1 3 | |||
| mknod system/dev/tty c 5 0 | |||
| $qemu system/bin/busybox chroot system /bin/busybox env -i NPROC="$(nproc)" /bin/busybox sh /sources/build_bootstrap.sh | |||
| mv system/bootstrap.tar.gz builds/ | |||
| 
 | |||
| # Stage 2.5 (optional): Rebuild bootstrap binaries to have a "clean" archive | |||
| if [ "$1" = double_bootstrap ]; then | |||
| cp build_binaries.sh binaries.sha1 busybox-config system/ | |||
| $qemu system/bootstrap/bin/chroot system /bootstrap/bin/env -i NPROC="$(nproc)" PATH=/bootstrap/bin /bootstrap/bin/sh /build_binaries.sh | |||
| mv system/system/binaries.tar.gz builds/ | |||
| rm system/build_binaries.sh system/binaries.sha1 system/busybox-config | |||
| rm -rf system/system/ | |||
| fi | |||
| 
 | |||
| # Stage 3: Cross-compile system for x86_64 | |||
| cp build_cross.sh system/sources | |||
| $qemu system/bootstrap/bin/chroot system /bootstrap/bin/env -i NPROC="$(nproc)" /bootstrap/bin/sh /sources/build_cross.sh | |||
| mv system/system/cross.tar.gz builds/ | |||
| @ -0,0 +1,181 @@ | |||
| #!/bin/sh | |||
| set -eu | |||
| 
 | |||
| version_mes=0.22 | |||
| version_mescc_tools=1.0.1 | |||
| version_nyacc=0.99.3 | |||
| 
 | |||
| version_linux=4.14 | |||
| version_binutils=2.20.1 | |||
| version_gcc=4.9.4 | |||
| version_gmp=4.3.2 | |||
| version_mpfr=2.4.2 | |||
| version_mpc=1.0.3 | |||
| version_musl=1.2.1 | |||
| version_busybox=1.31.1 | |||
| 
 | |||
| export MAKEFLAGS="-j${NPROC:-$(getconf _NPROCESSORS_ONLN)}" | |||
| 
 | |||
| system=system | |||
| dir_root="$PWD" | |||
| dir_sources="$dir_root/sources" | |||
| dir_install="$dir_root/$system" | |||
| 
 | |||
| mkdir -p build && cd build | |||
| 
 | |||
| rm -rf "mes-$version_mes" | |||
| tar xf "$dir_sources/mes-$version_mes.tar.gz" | |||
| ( cd "mes-$version_mes" | |||
|     tar xf "$dir_sources/mescc-tools-Release_$version_mescc_tools.tar.gz" | |||
|     tar xf "$dir_sources/nyacc-$version_nyacc.tar.gz" | |||
|     mv "mescc-tools-Release_$version_mescc_tools" mescc-tools | |||
|     mv "nyacc-$version_nyacc" nyacc | |||
|     cp -a mescc-tools mescc-tools-target | |||
| 
 | |||
|     make -C mescc-tools M1 hex2 blood-elf COMMIT= | |||
|     export PATH="$PWD/mescc-tools/bin:$PATH" | |||
| 
 | |||
|     # First, we build a native mes, "mes-gcc". | |||
|     # This allows us to cross-build everything on systems that mes doesn't support. | |||
|     gcc -O2 -std=gnu99 -w -lrt -o mes-gcc -DMES_VERSION='""' -DSYSTEM_LIBC=1 -Iinclude \ | |||
|         lib/mes/eputs.c \ | |||
|         lib/mes/fdgetc.c \ | |||
|         lib/mes/fdputc.c \ | |||
|         lib/mes/fdputs.c \ | |||
|         lib/mes/fdungetc.c \ | |||
|         lib/mes/itoa.c \ | |||
|         lib/mes/mes_open.c \ | |||
|         lib/mes/ntoab.c \ | |||
|         src/gc.c \ | |||
|         src/hash.c \ | |||
|         src/lib.c \ | |||
|         src/math.c \ | |||
|         src/mes.c \ | |||
|         src/module.c \ | |||
|         src/posix.c \ | |||
|         src/reader.c \ | |||
|         src/string.c \ | |||
|         src/struct.c \ | |||
|         src/vector.c | |||
| 
 | |||
|     # This version of mes messes doesn't have a proper getopt... | |||
|     # TODO: Fix this (somehow) and make the patch unnecessary. | |||
|     sed -i -e 's/ -nostdlib/ --nostdlib/' \ | |||
|            -e 's/ -lc/ -l c/' \ | |||
|         build-aux/bootstrap.sh.in | |||
| 
 | |||
|     # Use this to build mes and its libc for the target | |||
|     CC=true guile_site_dir="$PWD/nyacc/module" sh configure.sh --host=x86-linux-mes | |||
|     CC="$PWD/scripts/mescc" MES="$PWD/mes-gcc" sh bootstrap.sh | |||
| 
 | |||
|     # Install mes | |||
|     install -Dm755 bin/mes "$dir_install/mes/bin/mes" | |||
| 
 | |||
|     # Build tools with mes to obtain reproducible outputs | |||
|     make -C mescc-tools-target M1 hex2 blood-elf COMMIT= \ | |||
|         CC="$PWD/scripts/mescc" MES="$PWD/mes-gcc" MES_PREFIX="../" \ | |||
|         GUILE_LOAD_PATH="../module" CFLAGS='-L ../lib -L ../mescc-lib -l c+tcc' | |||
|     install -Dm755 mescc-tools-target/bin/M1 "$dir_install/mes/bin/M1" | |||
|     install -Dm755 mescc-tools-target/bin/hex2 "$dir_install/mes/bin/hex2" | |||
|     install -Dm755 mescc-tools-target/bin/blood-elf "$dir_install/mes/bin/blood-elf" | |||
| ) | |||
| 
 | |||
| rm -rf "linux-$version_linux" | |||
| tar xf "$dir_sources/linux-$version_linux.tar.gz" | |||
| ( cd "linux-$version_linux" | |||
|     make mrproper | |||
|     make ARCH=x86 INSTALL_HDR_PATH="$dir_install/sources/linux-headers" headers_install | |||
|     find "$dir_install/sources/linux-headers" -type f ! -name "*.h" -exec rm {} + | |||
| ) | |||
| 
 | |||
| # Build static busybox with musl | |||
| rm -rf "busybox-$version_busybox" | |||
| tar xf "$dir_sources/busybox-$version_busybox.tar.bz2" | |||
| ( cd "busybox-$version_busybox" | |||
|     tar xf "$dir_sources/binutils-${version_binutils}a.tar.bz2" | |||
|     mv "binutils-$version_binutils" binutils | |||
|     tar xf "$dir_sources/gcc-$version_gcc.tar.bz2" | |||
|     mv "gcc-$version_gcc" gcc | |||
|     tar xf "$dir_sources/gmp-$version_gmp.tar.bz2" | |||
|     mv "gmp-$version_gmp" gcc/gmp | |||
|     tar xf "$dir_sources/mpfr-$version_mpfr.tar.bz2" | |||
|     mv "mpfr-$version_mpfr" gcc/mpfr | |||
|     tar xf "$dir_sources/mpc-$version_mpc.tar.gz" | |||
|     mv "mpc-$version_mpc" gcc/mpc | |||
|     tar xf "$dir_sources/musl-$version_musl.tar.gz" | |||
|     mv "musl-$version_musl" musl | |||
| 
 | |||
|     prefix="$PWD/prefix" | |||
|     export PATH="$prefix/bin:$PATH" | |||
| 
 | |||
|     # Fix requirement for mktemp, so it works with coreutils-5.0 | |||
|     if ! command -v mktemp 2> /dev/null; then | |||
|         sed -i -e 's@$(mktemp tmp.XXXXXXXXXX)@/tmp/tmp.trylink@' scripts/trylink | |||
|     fi | |||
| 
 | |||
|     # Building a specific version of binutils+GCC, to make the results reproducible... | |||
|     # GCC-4.6.4's results aren't reproducible across machines for some reason, | |||
|     #   so this bootstrap uses GCC-4.9.4. This increases the build time a little. | |||
|     ( cd binutils | |||
|         CFLAGS='-O2 -w' ./configure \ | |||
|             --target=i686-bootstrap-linux-gnu \ | |||
|             --prefix="$prefix" \ | |||
|             --with-sysroot="$prefix" \ | |||
|             --disable-nls \ | |||
|             --disable-werror | |||
|         make | |||
|         make install | |||
|     ) | |||
|     ( cd gcc | |||
|         mkdir build && cd build  # Build breaks without a build directory | |||
| 
 | |||
|         # Using --with-local-prefix=/ puts /include in the search path before | |||
|         #   /lib/gcc/.../include-fixed, avoiding some issues. | |||
|         CFLAGS='-O2 -w' CXXFLAGS='-O2 -w' MAKEINFO=true ../configure \ | |||
|             --target=i686-bootstrap-linux-gnu \ | |||
|             --prefix="$prefix" \ | |||
|             --with-sysroot="$prefix" \ | |||
|             --with-local-prefix=/ \ | |||
|             --with-host-libstdcxx=-lsupc++ \ | |||
|             --with-newlib \ | |||
|             --without-headers \ | |||
|             --disable-shared \ | |||
|             --disable-threads \ | |||
|             --disable-nls \ | |||
|             --enable-languages=c | |||
|         make all-gcc all-target-libgcc | |||
|         make install-gcc install-target-libgcc | |||
|     ) | |||
| 
 | |||
|     # Musl provides a very small libc, that can be linked statically. | |||
|     # It might be worthwhile to switch to uClibc in the future, as that's | |||
|     #   what's usually used for busybox. Might yield "cleaner" results. | |||
|     cp -a "$dir_install/sources/linux-headers" prefix | |||
|     ( cd musl | |||
|         ./configure \ | |||
|             --host=i686-bootstrap-linux-gnu \ | |||
|             --prefix="$PWD/../prefix" \ | |||
|             --disable-shared | |||
|         make | |||
|         make install | |||
|     ) | |||
| 
 | |||
|     cp "$dir_root/busybox-config" .config | |||
|     make CROSS_COMPILE=i686-bootstrap-linux-gnu- CONFIG_STATIC=y busybox | |||
| 
 | |||
|     install -Dm755 busybox "$dir_install/bin/busybox" | |||
|     install -Dm755 busybox_unstripped "$dir_install/bin/busybox_unstripped" | |||
| ) | |||
| 
 | |||
| cd "$dir_install" | |||
| 
 | |||
| # Verify the built binaries | |||
| sha1sum -c "$dir_root/binaries.sha1" | |||
| 
 | |||
| # Pack it up | |||
| find bin mes sources \( -type f -o -type l \) ! -path bin/busybox_unstripped | LC_ALL=C sort | xargs tar --mtime=@0 --numeric-owner --owner=0 --group=0 -cf binaries.tar | |||
| gzip -nv binaries.tar | |||
| 
 | |||
| # Clean up | |||
| cd "$dir_root" | |||
| rm -rf build | |||
| @ -0,0 +1,873 @@ | |||
| #!/bin/sh | |||
| set -e | |||
| 
 | |||
| # To initialize/enter chroot: | |||
| # mkdir dev tmp | |||
| # mknod dev/null c 1 3 | |||
| # mknod dev/tty c 5 0 | |||
| # ./bin/busybox chroot . /bin/busybox env -i NPROC="$(nproc)" /bin/busybox sh /sources/build_bootstrap.sh | |||
| 
 | |||
| # Amount of make threads, configure this to your liking. | |||
| # This can be obtained using `getconf _NPROCESSORS_ONLN`, but requires /proc | |||
| #   to be mounted, which we avoid. | |||
| NPROC="${NPROC:-4}" | |||
| 
 | |||
| # Creates a busybox symlink, useful to keep track of what bootstrap binaries | |||
| #   are necessary at what stages. | |||
| link() { | |||
|     for x in "$@"; do  | |||
|         if [ ! -e /bin/$x ]; then | |||
|             busybox ln -s busybox /bin/$x | |||
|         fi | |||
|     done | |||
| } | |||
| link sh | |||
| 
 | |||
| # TODO: Either start using tar-1.14 in the bootstrap or implement the | |||
| #         -j/--bzip2 option into tar-1.12, to avoid the awkward tar commands. | |||
| # TODO: Figure out what causes the timestamps to go bad with tar-1.12 (maybe use 1.13?) | |||
| 
 | |||
| cd /sources | |||
| 
 | |||
| 
 | |||
| #### Build Mes and its libc from the 4 necessary bootstrap bins | |||
| export PATH=/mes/bin:/bin | |||
| 
 | |||
| link cp mkdir rm tar zcat | |||
| 
 | |||
| # nyacc (0.99.3): | |||
| rm -rf nyacc-0.99.3 | |||
| zcat nyacc-0.99.3.tar.gz | tar x | |||
| mkdir -p /mes/share/guile/site/2.2 | |||
| cp -a nyacc-0.99.3/module/nyacc /mes/share/guile/site/2.2 | |||
| rm -rf nyacc-0.99.3 | |||
| 
 | |||
| link basename cat chmod cmp dirname echo ln sed | |||
| 
 | |||
| # mes-boot (0.22): | |||
| rm -rf mes-0.22 | |||
| zcat mes-0.22.tar.gz | tar x | |||
| ( cd mes-0.22 | |||
|     # "grep: command not found" is harmless here, as the results are identical. | |||
|     CC=true ./configure.sh --host=x86-linux-mes --prefix=/mes | |||
|     CC="$PWD/scripts/mescc" ./bootstrap.sh | |||
| 
 | |||
|     # Optional, make sure the rebuilt mes still matches. | |||
|     cmp bin/mes /mes/bin/mes | |||
| 
 | |||
|     # Installing manually to avoid reliance on "tar --create" | |||
|     #BASHOPTS= ./install.sh | |||
|     set -x | |||
|     mkdir -p /mes/bin/ | |||
|     cp -a bin/mes scripts/mesar scripts/mescc.scm scripts/mescc scripts/diff.scm /mes/bin/ | |||
|     cp -a include /mes/ | |||
|     mkdir -p /mes/lib/linux/ | |||
|     cp -a lib/x86-mes /mes/lib/ | |||
|     cp -a lib/linux/x86-mes /mes/lib/linux/ | |||
|     cp -a gcc-lib/x86-mes/* /mes/lib/ | |||
|     cp -a mescc-lib/x86-mes /mes/lib/ | |||
|     mkdir -p /mes/share/mes/ | |||
|     cp -a mes/module /mes/share/mes/ | |||
|     mkdir -p /mes/share/guile/site/2.2 | |||
|     cp -a module/* /mes/share/guile/site/2.2 | |||
| ) | |||
| rm -rf mes-0.22 | |||
| 
 | |||
| link install | |||
| 
 | |||
| # mescc-tools (1.0.1): | |||
| # This step is completely optional, as identical tools are already installed. | |||
| # However, as a sanity check it's done anyway. | |||
| rm -rf mescc-tools-Release_1.0.1 | |||
| zcat mescc-tools-Release_1.0.1.tar.gz | tar x | |||
| ( cd mescc-tools-Release_1.0.1 | |||
|     #make -Bn M1 hex2 blood-elf COMMIT= CC=mescc CFLAGS='-lc+tcc' | |||
|     set -x | |||
| 
 | |||
|     mkdir -p bin | |||
|     mescc -lc+tcc M1-macro.c functions/file_print.c functions/match.c functions/numerate_number.c functions/string.c functions/require.c functions/in_set.c -o bin/M1 | |||
|     mescc -lc+tcc hex2_linker.c functions/file_print.c functions/match.c functions/numerate_number.c functions/require.c functions/in_set.c -o bin/hex2 | |||
|     mescc -lc+tcc blood-elf.c functions/file_print.c functions/match.c functions/require.c functions/in_set.c functions/numerate_number.c -o bin/blood-elf | |||
| 
 | |||
|     # Optional, make sure the tools built with the new mes still match. | |||
|     cmp bin/M1 /mes/bin/M1 | |||
|     cmp bin/hex2 /mes/bin/hex2 | |||
|     cmp bin/blood-elf /mes/bin/blood-elf | |||
| 
 | |||
|     install -Dm755 bin/M1 /mes/bin/M1 | |||
|     install -Dm755 bin/hex2 /mes/bin/hex2 | |||
|     install -Dm755 bin/blood-elf /mes/bin/blood-elf | |||
| ) | |||
| rm -rf mescc-tools-Release_1.0.1 | |||
| 
 | |||
| 
 | |||
| #### Bootstrap TCC, with mes-libc | |||
| # Using the C library provided by Mes, we build the Tiny C Compiler to use it, | |||
| #   to later be able to build a bunch of tools from this combination. | |||
| export PATH=/tcc/bin:/mes/bin:/bin | |||
| rm -rf /tcc | |||
| 
 | |||
| # tcc-boot0 (0.9.26): | |||
| # This step will take a _long_ time, because mescc is a slow compiler, as a | |||
| #   result of how minimal its core is designed. | |||
| # Thankfully, things will speed up considerably once TCC is bootstrapped. | |||
| rm -rf tcc-0.9.26-1103-g6e62e0e | |||
| zcat tcc-0.9.26-1103-g6e62e0e.tar.gz | tar x | |||
| ( cd tcc-0.9.26-1103-g6e62e0e | |||
|     echo '#define TCC_VERSION "0.9.27"' > config.h | |||
|     MES_PREFIX=/mes prefix=/tcc ./bootstrap.sh  # Slow! | |||
| 
 | |||
|     # Installing manually to avoid reliance on "tar --create" | |||
|     #MES_PREFIX=/mes prefix=/tcc ./install.sh | |||
|     mkdir -p /tcc/bin/ | |||
|     cp tcc /tcc/bin/ | |||
|     cp -a /mes/include /tcc/ | |||
|     mkdir -p /tcc/lib/tcc/ | |||
|     cp -a crt1.o crti.o crtn.o libc.a libgetopt.a /tcc/lib/ | |||
|     cp -a libtcc1.a /tcc/lib/tcc/ | |||
| ) | |||
| rm -rf tcc-0.9.26-1103-g6e62e0e | |||
| 
 | |||
| # This binary was only necessary for the optional checks in mes-boot, | |||
| #   mescc-tools, as well as tcc-boot0's bootstrap.sh | |||
| # Possible future removal/implementation in mes? | |||
| rm /bin/cmp | |||
| 
 | |||
| 
 | |||
| #### Build compression tools, upgrade TCC to 0.9.27. | |||
| # Upgrading TCC is probably not truly necessary, but it hardly hurts. | |||
| # Some tools are required to achieve this, but these tools will be necessary | |||
| #   later on, regardless. | |||
| export PATH=/tcc/bin:/bin | |||
| 
 | |||
| # sed-mesboot (1.18): | |||
| # Used by nearly every configure script, and in this script to patch sources. | |||
| # It's only used for the mes-boot configure.sh before this point. | |||
| # May be possible to move out of the bootstrap bins in the future. | |||
| rm -rf sed-1.18 | |||
| zcat sed-1.18.tar.gz | tar x | |||
| ( cd sed-1.18 | |||
|     set -x | |||
|     tcc -DREGEX_MALLOC=1 -DSTDC_HEADERS=1 -DHAVE_MEMCPY=1 -o sed sed.c utils.c regex.c getopt.c getopt1.c | |||
|     install -Dm755 sed /bin/sed | |||
| ) | |||
| rm -rf sed-1.18 | |||
| 
 | |||
| link mv | |||
| 
 | |||
| # gzip-mesboot (1.2.4): | |||
| # Reduces the reliance on the bootstrap binary for gzip, as that only has to be | |||
| #   used to decompress archives. Glibc requires it to compress. | |||
| # This, along with `tar` should be rebuilt as soon as possible due to how many | |||
| #   packages rely on these, but `tar` unfortunately has a few more dependencies. | |||
| rm -rf gzip-1.2.4 | |||
| zcat gzip-1.2.4.tar.gz | tar x | |||
| ( cd gzip-1.2.4 | |||
|     sed -e 's/^char [*]strlwr/&_/' util.c > /tmp/sed; mv /tmp/sed util.c | |||
| 
 | |||
|     set -x | |||
|     tcc -DNO_UTIME_H -DHAVE_UNISTD_H -o gzip gzip.c zip.c deflate.c trees.c bits.c unzip.c inflate.c util.c crypt.c lzw.c unlzw.c unpack.c unlzh.c getopt.c | |||
|     install -Dm755 gzip /bin/gzip | |||
|     ln -sf gzip /bin/gunzip | |||
|     ln -sf gzip /bin/zcat | |||
| ) | |||
| rm -rf gzip-1.2.4 | |||
| 
 | |||
| # bzip2-mesboot (1.0.8): | |||
| # This compressor isn't part of the bootstrap binaries, but is necessary for | |||
| #   unpacking certain archives, including tcc-0.9.27.tar.bz2... | |||
| rm -rf bzip2-1.0.8 | |||
| zcat bzip2-1.0.8.tar.gz | tar x | |||
| ( cd bzip2-1.0.8 | |||
|     # mes-libc-0.22 uses the value 0 for stdin, which trips up a check. | |||
|     # This breaks decompressing data from stdin, through for example "tar jxf". | |||
|     # Patching it out is "fine", since enough checks cover other failure states. | |||
|     sed -e 's/if (f == NULL /if (0 /' bzlib.c > /tmp/sed; mv /tmp/sed bzlib.c | |||
| 
 | |||
|     echo '#define fchown(filedes, owner, group) 0' > utime.h | |||
|     echo '#define fchmod(filedes, mode) 0' >> utime.h | |||
|     echo 'struct utimbuf { int actime; int modtime; };' >> utime.h | |||
|     echo '#define utime(filename, buf) 0' >> utime.h | |||
| 
 | |||
|     set -x | |||
|     tcc -I. -o bzip2 blocksort.c huffman.c crctable.c randtable.c compress.c decompress.c bzlib.c bzip2.c | |||
|     install -Dm755 bzip2 /bin/bzip2 | |||
|     ln -sf bzip2 /bin/bunzip2 | |||
|     ln -sf bzip2 /bin/bzcat | |||
| ) | |||
| rm -rf bzip2-1.0.8 | |||
| 
 | |||
| # tcc-boot (0.9.27): | |||
| rm -rf tcc-0.9.27 | |||
| bzcat tcc-0.9.27.tar.bz2 | tar x | |||
| ( cd tcc-0.9.27 | |||
|     sed -e 's/s->alacarte_link = 1;/s->static_link = 1;/' \ | |||
|         libtcc.c > /tmp/sed; mv /tmp/sed libtcc.c | |||
|     echo '#define TCC_VERSION "0.9.27"' > config.h | |||
| 
 | |||
|     # Build tcc twice, as avoiding bootstrapping here breaks programs later | |||
|     set -x | |||
|     for x in a b; do | |||
|         tcc -vvv -DONE_SOURCE=1 \ | |||
|             -DTCC_TARGET_I386 \ | |||
|             -DCONFIG_TCC_STATIC \ | |||
|             -DCONFIG_TCCDIR=\"/tcc/lib/tcc\" \ | |||
|             -DCONFIG_TCC_CRTPREFIX=\"/tcc/lib\" \ | |||
|             -DCONFIG_TCC_SYSINCLUDEPATHS=\"/tcc/include\" \ | |||
|             -DCONFIG_TCC_LIBPATHS=\"/tcc/lib\" \ | |||
|             -o tcc tcc.c | |||
|         ./tcc -vvv -c -o libtcc1.o lib/libtcc1.c | |||
|         ./tcc -ar rc libtcc1.a libtcc1.o | |||
|         install -Dm755 tcc /tcc/bin/tcc | |||
|         install -Dm644 libtcc1.a /tcc/lib/tcc/libtcc1.a | |||
|     done | |||
| ) | |||
| rm -rf tcc-0.9.27 | |||
| 
 | |||
| 
 | |||
| #### Build tools, round 1 | |||
| # At this point we try to rebuild the bootstrap tools, to reduce the reliance | |||
| #   on them and their (minimal) featureset, and build some additional tools | |||
| #   required to build GCC2. | |||
| # Rebuilding the bootstrap tools as early as possible allows for simplification | |||
| #   of the bootstrap tools, which should lead to smaller binaries. | |||
| # Unfortunately, the following packages can not be built with TCC yet: | |||
| # - coreutils | |||
| # These are required to build GCC2, and the bootstrap binaries will be used. | |||
| 
 | |||
| # grep-mesboot (2.0): | |||
| # Required by most configure scripts, but we've been able to avoid it thus far. | |||
| rm -rf grep-2.0 | |||
| zcat grep-2.0.tar.gz | tar x | |||
| ( cd grep-2.0 | |||
|     set -x | |||
|     tcc -DSTDC_HEADERS=1 -DHAVE_ALLOCA_H=1 -DHAVE_MEMCHR=1 -o grep grep.c getopt.c regex.c dfa.c kwset.c obstack.c search.c | |||
|     install -Dm755 grep /bin/grep | |||
|     ln -sf grep /bin/egrep | |||
|     ln -sf grep /bin/fgrep | |||
| ) | |||
| rm -rf grep-2.0 | |||
| 
 | |||
| link expr ls uniq sleep sort | |||
| 
 | |||
| # gnu-make-mesboot0 (3.80): | |||
| # Make is required to build nearly everything, so it has to be built as soon as | |||
| #   possible. | |||
| rm -rf make-3.80 | |||
| bzcat make-3.80.tar.bz2 | tar x | |||
| ( cd make-3.80 | |||
|     sed -e 's/@REMOTE@/stub/' \ | |||
|         -e 's/@LIBOBJS@/getloadavg.o/' \ | |||
|         build.sh.in > /tmp/sed; mv /tmp/sed build.sh.in | |||
|     sed -e 's/^extern long int lseek.*/\/\/ &/' \ | |||
|         make.h > /tmp/sed; mv /tmp/sed make.h | |||
|     CC=tcc LD=tcc ./configure \ | |||
|         --build=i686-pc-linux-gnu \ | |||
|         --disable-nls | |||
|     sh build.sh | |||
|     install -Dm755 make /bin/make | |||
| ) | |||
| rm -rf make-3.80 | |||
| 
 | |||
| # Multi-threaded make is broken at this stage | |||
| export MAKEFLAGS=-j1 | |||
| 
 | |||
| link tr | |||
| 
 | |||
| # bash-mesboot0 (2.05b): | |||
| # A lot of shell scripts are ran during the build process. | |||
| # Bootstrapping it here allows the initial shell to remain simple. | |||
| # This shell is non-interactive, so the bootstrap shell might be used by the | |||
| #   user, instead, while this one just runs most scripts. | |||
| rm -rf bash-2.05b | |||
| zcat bash-2.05b.tar.gz | tar x | |||
| ( cd bash-2.05b | |||
|     sed -e 's/mksyntax\.c$/& -lgetopt/' \ | |||
|         -e 's/buildversion\.o$/& -lgetopt/' \ | |||
|         Makefile.in > /tmp/sed; mv /tmp/sed Makefile.in | |||
|     sed -e 's/int name, namelen;/char *name; int namelen;/' \ | |||
|         lib/sh/oslib.c > /tmp/sed; mv /tmp/sed lib/sh/oslib.c | |||
|     sed -e 's/defined (HAVE_LOCALE_H)/0/' \ | |||
|         lib/sh/snprintf.c > /tmp/sed; mv /tmp/sed lib/sh/snprintf.c | |||
| 
 | |||
|     # Progcomp is disabled, so this file shouldn't be built... | |||
|     # TODO: --disable-progcomp should take care of this, figure out what's | |||
|     #         up with that. | |||
|     sed -e 's/ complete\.o$//' \ | |||
|         builtins/Makefile.in > /tmp/sed; mv /tmp/sed builtins/Makefile.in | |||
| 
 | |||
|     # Delete unnecessary commands at end of build | |||
|     sed -e '/ls -l $(Program)$/d' \ | |||
|         -e '/size $(Program)$/d' \ | |||
|         Makefile.in > /tmp/sed; mv /tmp/sed Makefile.in | |||
| 
 | |||
|     CC='tcc -D_POSIX_VERSION=1' AR='tcc -ar' ./configure \ | |||
|         --build=i686-pc-linux-gnu \ | |||
|         --without-bash-malloc \ | |||
|         --disable-readline \ | |||
|         --disable-history \ | |||
|         --disable-bang-history \ | |||
|         --disable-progcomp \ | |||
|         --disable-nls \ | |||
|         bash_cv_getcwd_calls_popen=no \ | |||
|         bash_cv_signal_vintage=posix \ | |||
|         ac_cv_func_working_mktime=yes | |||
|     echo '#define endpwent(x) 0' >> config.h | |||
|     make bash | |||
|     install -Dm755 bash /bin/bash | |||
|     ln -sf bash /bin/sh | |||
| ) | |||
| rm -rf bash-2.05b | |||
| 
 | |||
| # diffutils-mesboot (2.7): | |||
| # `cmp` is only absolutely required by tcc-boot0 thus far (though it should be | |||
| #   possible to patch out), and not strictly required until gcc-4.6.4's install | |||
| #   procedure. | |||
| # However, a lot of configure scripts do use it, and `diff` from time to time, | |||
| #   so it's a good thing to have as soon as possible, regardless. | |||
| rm -rf diffutils-2.7 | |||
| zcat diffutils-2.7.tar.gz | tar x | |||
| ( cd diffutils-2.7 | |||
|     CC=tcc ./configure | |||
|     make cmp diff | |||
|     install -Dm755 cmp /bin/cmp | |||
|     install -Dm755 diff /bin/diff | |||
| ) | |||
| rm -rf diffutils-2.7 | |||
| 
 | |||
| # tar-mesboot0 (1.12), not in guix: | |||
| # Self explanatory, required to unpack archives. Might be possible to moved | |||
| #   earlier in the chain by avoiding the configure script/makefile. | |||
| # Softens the dependency on tar, since up until now it was only necessary to | |||
| #   unpack archives, while the install procedure of e.g. gcc, requires it to | |||
| #   also create archives. | |||
| rm -rf tar-1.12 | |||
| zcat tar-1.12.tar.gz | tar x | |||
| ( cd tar-1.12 | |||
|     # Remove need for ls -L | |||
|     sed -e 's/ls -Lt /ls -t /' configure > /tmp/sed; mv /tmp/sed configure | |||
|     chmod +x configure | |||
| 
 | |||
|     CC=tcc ./configure --disable-nls | |||
|     make -C lib AR='tcc -ar' | |||
|     make -C src | |||
|     install -Dm755 src/tar /bin/tar | |||
| ) | |||
| rm -rf tar-1.12 | |||
| 
 | |||
| # gawk-mesboot0 (3.0.0): | |||
| # AWK is required to build glibc. | |||
| rm -rf gawk-3.0.0 | |||
| zcat gawk-3.0.0.tar.gz | tar x | |||
| ( cd gawk-3.0.0 | |||
|     sed -e 's/date /echo today /' \ | |||
|         configure > /tmp/sed; mv /tmp/sed configure | |||
|     sed -e 's/date /echo today /' \ | |||
|         -e 's/ autoheader/ true/' \ | |||
|         -e 's/ -lm//' \ | |||
|         Makefile.in > /tmp/sed; mv /tmp/sed Makefile.in | |||
|     chmod +x configure | |||
| 
 | |||
|     ac_cv_func_getpgrp_void=yes ac_cv_func_tzset=yes \ | |||
|     CC=tcc LD=tcc ./configure \ | |||
|         --build=i686-pc-linux-gnu \ | |||
|         --disable-nls | |||
|     make gawk | |||
|     install -Dm755 gawk /bin/gawk | |||
|     ln -sf gawk /bin/awk | |||
| ) | |||
| rm -rf gawk-3.0.0 | |||
| 
 | |||
| # patch-mesboot (2.5.9): | |||
| # Used to patch certain packages to fix bootstrap-specific build failures. | |||
| rm -rf patch-2.5.9 | |||
| zcat patch-2.5.9.tar.gz | tar x | |||
| ( cd patch-2.5.9 | |||
|     CC=tcc ./configure | |||
|     make patch | |||
|     install -Dm755 patch /bin/patch | |||
| ) | |||
| rm -rf patch-2.5.9 | |||
| 
 | |||
| #coreutils? (fileutils, textutils, sh-utils)? | |||
| 
 | |||
| 
 | |||
| #### Bootstrap gcc2 toolchain, consisting of gcc-2.95.2, binutils-2.14, glibc-2.2.5 | |||
| # Also rebuild it against itself to remove tcc and mes-libc from the picture. | |||
| # This will become the GNU toolchain that's the basis for the remaining set of tools. | |||
| export PATH=/gcc2/bin:/tcc/bin:/bin | |||
| rm -rf /gcc2 | |||
| 
 | |||
| link touch true | |||
| 
 | |||
| # binutils-mesboot0 (2.14): | |||
| rm -rf binutils-2.14 | |||
| bzcat binutils-2.14.tar.bz2 | tar x | |||
| ( cd binutils-2.14 | |||
|     # Fix some sed-related issues... | |||
|     sed -e 's/_frag=${srcdir}\//_frag=/' \ | |||
|         configure > /tmp/sed; mv /tmp/sed configure | |||
|     sed -e "s@^sed -e '/SRC-POTFILES.*\$@echo -e 'all:\\\\n\\\\ttrue\\\\n\\\\ninstall:\\\\n\\\\ttrue\\\\n' > po/Makefile@" \ | |||
|         bfd/configure > /tmp/sed; mv /tmp/sed bfd/configure | |||
|     chmod +x configure bfd/configure | |||
| 
 | |||
|     CC='tcc -D__GLIBC_MINOR__=6' AR='tcc -ar' ./configure \ | |||
|         --host=i686-pc-linux-gnu \ | |||
|         --prefix=/gcc2 \ | |||
|         --with-sysroot \ | |||
|         --with-lib-path=/gcc2/lib \ | |||
|         --disable-shared \ | |||
|         --disable-nls | |||
|     make | |||
|     make install | |||
| ) | |||
| rm -rf binutils-2.14 | |||
| 
 | |||
| # gcc-core-mesboot0 (2.95.3): | |||
| rm -rf gcc-2.95.3 | |||
| zcat gcc-core-2.95.3.tar.gz | tar x | |||
| ( cd gcc-2.95.3 | |||
|     patch -p1 -i ../gcc-boot-2.95.3.patch | |||
| 
 | |||
|     CC='tcc -D__GLIBC_MINOR__=6' ./configure \ | |||
|         --host=i686-pc-linux-gnu \ | |||
|         --prefix=/gcc2 \ | |||
|         --disable-shared | |||
|     rm -rf texinfo && touch gcc/cpp.info gcc/gcc.info | |||
|     make LIBGCC2_INCLUDES=-I/tcc/include | |||
|     make install | |||
| 
 | |||
|     set -x | |||
|     mkdir tmp | |||
|     cd tmp | |||
|     ar x ../gcc/libgcc2.a | |||
|     ar x /tcc/lib/tcc/libtcc1.a | |||
|     ar r /gcc2/lib/gcc-lib/i686-pc-linux-gnu/2.95.3/libgcc.a *.o | |||
|     cp ../gcc/libgcc2.a /gcc2/lib/libgcc2.a | |||
| ) | |||
| rm -rf gcc-2.95.3 | |||
| 
 | |||
| export PATH=/gcc2/bin:/bin | |||
| 
 | |||
| link pwd | |||
| 
 | |||
| # glibc-mesboot0 (2.2.5): | |||
| cp -ar linux-headers/include /gcc2/ | |||
| rm -rf glibc-2.2.5 | |||
| zcat glibc-2.2.5.tar.gz | tar x | |||
| ( cd glibc-2.2.5 | |||
|     patch -p1 -i ../glibc-boot-2.2.5.patch | |||
| 
 | |||
|     CC='gcc -DMES_BOOTSTRAP=1 -DBOOTSTRAP_GLIBC=1'" -L $PWD" ./configure \ | |||
|         --host=i686-pc-linux-gnu \ | |||
|         --prefix=/gcc2 \ | |||
|         --with-headers=/gcc2/include \ | |||
|         --disable-shared \ | |||
|         --disable-sanity-checks \ | |||
|         --enable-static-nss \ | |||
|         --without-__thread \ | |||
|         --without-cvs \ | |||
|         --without-gd \ | |||
|         --without-tls | |||
|     make | |||
|     make install | |||
| ) | |||
| rm -rf glibc-2.2.5 | |||
| 
 | |||
| # gcc-mesboot0 (2.95.3): | |||
| rm -rf gcc-2.95.3 | |||
| zcat gcc-core-2.95.3.tar.gz | tar x | |||
| ( cd gcc-2.95.3 | |||
|     patch -p1 -i ../gcc-boot-2.95.3.patch | |||
| 
 | |||
|     ./configure \ | |||
|         --host=i686-pc-linux-gnu \ | |||
|         --prefix=/gcc2 \ | |||
|         --disable-shared | |||
|     rm -r texinfo && touch gcc/cpp.info gcc/gcc.info | |||
|     make LIBGCC2_INCLUDES=-I/gcc2/include | |||
|     make install | |||
| 
 | |||
|     set -x | |||
|     mkdir tmp | |||
|     cd tmp | |||
|     ar x ../gcc/libgcc2.a | |||
|     ar r /gcc2/lib/gcc-lib/i686-pc-linux-gnu/2.95.3/libgcc.a *.o | |||
|     cp ../gcc/libgcc2.a /gcc2/lib/libgcc2.a | |||
| ) | |||
| rm -rf gcc-2.95.3 | |||
| 
 | |||
| # binutils-mesboot1 (2.14): | |||
| rm -rf binutils-2.14 | |||
| bzcat binutils-2.14.tar.bz2 | tar x | |||
| ( cd binutils-2.14 | |||
|     # Fix some sed-related issues... | |||
|     sed -e 's/_frag=${srcdir}\//_frag=/' \ | |||
|         configure > /tmp/sed; mv /tmp/sed configure | |||
|     sed -e "s@^sed -e '/SRC-POTFILES.*\$@echo -e 'all:\\\\n\\\\ttrue\\\\n\\\\ninstall:\\\\n\\\\ttrue\\\\n' > po/Makefile@" \ | |||
|         bfd/configure > /tmp/sed; mv /tmp/sed bfd/configure | |||
|     chmod +x configure bfd/configure | |||
| 
 | |||
|     ./configure \ | |||
|         --host=i686-pc-linux-gnu \ | |||
|         --prefix=/gcc2 \ | |||
|         --with-sysroot \ | |||
|         --with-lib-path=/gcc2/lib \ | |||
|         --disable-shared \ | |||
|         --disable-nls | |||
|     make | |||
|     make install | |||
| ) | |||
| rm -rf binutils-2.14 | |||
| 
 | |||
| 
 | |||
| #### Build tools, round 2, now with less TCC | |||
| # At this stage we upgrade some tools that need an upgrade to build later parts, | |||
| #   as well as build some new tools we need. | |||
| # The remaining bootstrap binaries are rebuilt here, too. | |||
| 
 | |||
| # gnu-make-mesboot (3.82): | |||
| # This version can use multiple threads, greatly speeding up further builds. | |||
| # TODO: Can this be upgraded to 4.0 to support building modern glibc-2.31? | |||
| # Make 4.2/4.3 works flawlessly | |||
| rm -rf make-3.82 | |||
| bzcat make-3.82.tar.bz2 | tar x | |||
| ( cd make-3.82 | |||
|     LIBS='-lc -lnss_files -lnss_dns -lresolv' ./configure \ | |||
|         --build=i686-pc-linux-gnu | |||
|     make make | |||
|     install -Dm755 make /bin/make | |||
| ) | |||
| rm -rf make-3.82 | |||
| 
 | |||
| # From this point, multi-threaded make can be used. | |||
| export MAKEFLAGS="-j$NPROC" | |||
| 
 | |||
| # coreutils-mesboot0 (5.0): | |||
| # This is the oldest available version of coreutils, and it can't be built any | |||
| #   sooner... | |||
| rm -rf coreutils-5.0 | |||
| bzcat coreutils-5.0.tar.bz2 | tar x | |||
| ( cd coreutils-5.0 | |||
|     # Tar-1.12 doesn't set the timestamps correctly... | |||
|     # Not fixing them causes erratic build results. | |||
|     touch aclocal.m4 | |||
|     touch Makefile.in | |||
|     touch lib/Makefile.in | |||
|     touch lib/getdate.c | |||
|     touch src/Makefile.in | |||
|     touch src/dircolors.h | |||
|     touch src/wheel.h | |||
|     touch config.hin | |||
|     touch configure | |||
| 
 | |||
|     LIBS='-lc -lnss_files -lnss_dns -lresolv' ./configure \ | |||
|         --build=i686-pc-linux-gnu \ | |||
|         --prefix=/ \ | |||
|         --disable-nls | |||
|     make -C lib | |||
|     make -C src | |||
|     make DESTDIR="$PWD/install" -C src install-exec | |||
|     install -v -Dm755 install/bin/* /bin/ | |||
| ) | |||
| rm -rf coreutils-5.0 | |||
| 
 | |||
| # bash-mesboot (4.4): | |||
| # Finally an interactive shell! | |||
| rm -rf bash-4.4 | |||
| zcat bash-4.4.tar.gz | tar x | |||
| ( cd bash-4.4 | |||
|     sed -e 's/;;$/;/' shell.c > /tmp/sed; mv /tmp/sed shell.c | |||
| 
 | |||
|     LIBS='-lc -lnss_files -lnss_dns -lresolv' ./configure \ | |||
|         --disable-nls | |||
|     make bash | |||
|     install -Dm755 bash /bin/bash | |||
|     ln -sf bash /bin/sh | |||
| ) | |||
| rm -rf bash-4.4 | |||
| 
 | |||
| # (optional) At this point we can get rid of the remaining bootstrap binary... | |||
| #rm /bin/busybox /bin/busybox_unstripped | |||
| # Continue with bash (has tab completion :D): | |||
| # exec /bin/sh -l | |||
| # Entering the chroot after this point: | |||
| # ./bin/chroot . /bin/env -i PATH=/gcc2/bin:/bin /bin/sh -l | |||
| 
 | |||
| # tar-mesboot (1.22): | |||
| # Anything before tar 1.14 truncates the filenames when unpacking gcc-4.6.4 | |||
| #   and gcc-4.9.4 for some odd reason. | |||
| # Tar-1.12 is also known to mess with the timestamps of several packages such | |||
| #   as coreutils and gawk. | |||
| # This may be removed if 1.14 can be built with TCC. | |||
| rm -rf tar-1.22 | |||
| bzcat tar-1.22.tar.bz2 | tar x | |||
| ( cd tar-1.22 | |||
|     LIBS='-lc -lnss_files -lnss_dns -lresolv' ./configure \ | |||
|         --disable-nls | |||
|     make -C lib | |||
|     make -C src | |||
|     install -Dm755 src/tar /bin/tar | |||
| ) | |||
| rm -rf tar-1.22 | |||
| 
 | |||
| # sed-mesboot (4.0.6): | |||
| # Required to build binutils-2.20.1a | |||
| # TODO: Can this be upgraded to 4.3 to support the -E option? | |||
| rm -rf sed-4.0.6 | |||
| tar zxf sed-4.0.6.tar.gz | |||
| ( cd sed-4.0.6 | |||
|     ./configure --disable-nls | |||
|     make -C lib | |||
|     make -C sed | |||
|     install -Dm755 sed/sed /bin/sed | |||
| ) | |||
| rm -rf sed-4.0.6 | |||
| 
 | |||
| # gawk-mesboot (3.1.8): | |||
| # Upgrade required to build glibc-2.16.0 | |||
| rm -rf gawk-3.1.8 | |||
| tar jxf gawk-3.1.8.tar.bz2 | |||
| ( cd gawk-3.1.8 | |||
|     ./configure \ | |||
|         --build=i686-pc-linux-gnu \ | |||
|         ac_cv_func_connect=no | |||
|     make gawk | |||
|     install -Dm755 gawk /bin/gawk | |||
|     ln -sf gawk /bin/awk | |||
| ) | |||
| rm -rf gawk-3.1.8 | |||
| 
 | |||
| 
 | |||
| #### Bootstrap C++, using gcc-4.6.4 | |||
| export PATH=/gcc46/bin:/gcc2/bin:/bin | |||
| rm -rf /gcc46 | |||
| 
 | |||
| # TODO: Reduce the amount of configure flags by only building specific targets | |||
| # gcc-mesboot1 (4.6.4): | |||
| rm -rf gcc-4.6.4 | |||
| tar jxf gcc-core-4.6.4.tar.bz2 | |||
| tar jxf gcc-g++-4.6.4.tar.bz2 | |||
| ( cd gcc-4.6.4 | |||
|     tar jxf ../gmp-4.3.2.tar.bz2 | |||
|     mv gmp-4.3.2 gmp | |||
|     tar jxf ../mpfr-2.4.2.tar.bz2 | |||
|     mv mpfr-2.4.2 mpfr | |||
|     tar zxf ../mpc-1.0.3.tar.gz | |||
|     mv mpc-1.0.3 mpc | |||
| 
 | |||
|     # Build a compiler with /gcc2 as its sysroot, so it picks up the libraries | |||
|     #   from there without having to manually set environment variables, or | |||
|     #   patch the sources. | |||
|     # This just barely works because we're statically linking at this stage. | |||
|     sed -i -e '/^NATIVE_SYSTEM_HEADER_DIR =/s@/usr/include@/include@' \ | |||
|         gcc/Makefile.in | |||
| 
 | |||
|     # Using --enable-bootstrap to avoid segfaulting later... | |||
|     # This causes the build to be the longest in the bootstrap, oh well. | |||
|     ./configure \ | |||
|         --build=i686-pc-linux-gnu \ | |||
|         --prefix=/gcc46 \ | |||
|         --with-sysroot=/gcc2 \ | |||
|         --with-local-prefix=/ \ | |||
|         --with-stage1-libs=-lm \ | |||
|         --disable-shared \ | |||
|         \ | |||
|         --disable-nls \ | |||
|         --disable-decimal-float \ | |||
|         --disable-libatomic \ | |||
|         --disable-libcilkrts \ | |||
|         --disable-libgomp \ | |||
|         --disable-libitm \ | |||
|         --disable-libmudflap \ | |||
|         --disable-libquadmath \ | |||
|         --disable-libsanitizer \ | |||
|         --disable-libssp \ | |||
|         --disable-libvtv \ | |||
|         --disable-lto \ | |||
|         --disable-lto-plugin \ | |||
|         --disable-multilib \ | |||
|         --disable-plugin \ | |||
|         --disable-threads \ | |||
|         --enable-threads=single \ | |||
|         --disable-libstdcxx-pch \ | |||
|         --disable-build-with-cxx | |||
|     make | |||
|     make install | |||
| ) | |||
| rm -rf gcc-4.6.4 | |||
| 
 | |||
| 
 | |||
| #### Create "final" bootstrap toolchain, gcc-4.9.4, binutils-2.20.1a, glibc-2.16.0 | |||
| # This toolchain is the minimum requirement to build a current GCC, as it | |||
| #   fully supports C11 and C++11. | |||
| # Additionally, this toolchain is built with support for dynamic linking. | |||
| 
 | |||
| export PATH=/bootstrap/bin:/gcc46/bin:/gcc2/bin:/bin | |||
| rm -rf /bootstrap | |||
| 
 | |||
| # binutils-mesboot (2.20.1a): | |||
| rm -rf binutils-2.20.1 | |||
| tar jxf binutils-2.20.1a.tar.bz2 | |||
| ( cd binutils-2.20.1 | |||
|     ./configure \ | |||
|         --build=i686-pc-linux-gnu \ | |||
|         --prefix=/bootstrap \ | |||
|         --with-sysroot \ | |||
|         --with-lib-path=/bootstrap/lib \ | |||
|         --disable-shared \ | |||
|         --disable-nls \ | |||
|         --disable-werror | |||
|     make | |||
|     make install | |||
| ) | |||
| rm -rf binutils-2.20.1 | |||
| 
 | |||
| export PATH=/bootstrap/bin:/gcc46/bin:/bin | |||
| 
 | |||
| # glibc-mesboot (2.16.0): | |||
| cp -ar linux-headers/include /bootstrap/ | |||
| rm -rf glibc-2.16.0 | |||
| tar jxf glibc-2.16.0.tar.bz2 | |||
| ( cd glibc-2.16.0 | |||
|     patch -p1 -i ../glibc-boot-2.16.0.patch | |||
| 
 | |||
|     # This can't be rebuilt with the final gcc and glibc, for some reason | |||
|     # Possibly the configure flags aren't suitable? | |||
|     mkdir build && cd build | |||
|     CC='/gcc46/bin/gcc -DBOOTSTRAP_GLIBC=1 -L/gcc2/lib' ../configure \ | |||
|         --build=i686-pc-linux-gnu \ | |||
|         --prefix=/bootstrap \ | |||
|         --with-headers=/bootstrap/include \ | |||
|         --disable-multi-arch \ | |||
|         --enable-static-nss \ | |||
|         --with-pthread \ | |||
|         --without-cvs \ | |||
|         --without-gd \ | |||
|         --enable-add-ons=nptl \ | |||
|         libc_cv_predef_stack_protector=no \ | |||
|         libc_cv_ssp=no \ | |||
|         libc_cv_friendly_stddef=yes | |||
|     make "$PWD/sysd-sorted" | |||
|     sed -i -e 's/ sunrpc//' -e 's/ nis//' sysd-sorted | |||
|     make | |||
| 
 | |||
|     # `sbindir` isn't picked up by config.make.in, so the configure flag is useless | |||
|     mkdir -p /bootstrap/etc | |||
|     make install | |||
| ) | |||
| rm -rf glibc-2.16.0 | |||
| 
 | |||
| # gcc-mesboot (4.9.4): | |||
| rm -rf gcc-4.9.4 | |||
| tar jxf gcc-4.9.4.tar.bz2 | |||
| ( cd gcc-4.9.4 | |||
|     tar jxf ../gmp-4.3.2.tar.bz2 | |||
|     mv gmp-4.3.2 gmp | |||
|     tar jxf ../mpfr-2.4.2.tar.bz2 | |||
|     mv mpfr-2.4.2 mpfr | |||
|     tar zxf ../mpc-1.0.3.tar.gz | |||
|     mv mpc-1.0.3 mpc | |||
| 
 | |||
|     # The previous setup to set the library/include path with --with-sysroot | |||
|     #   doesn't work when you throw dynamic linking into the mix and you're not | |||
|     #   purely cross-compiling (we want to run resulting binaries as-is). | |||
|     # So, instead, we patch the sources. | |||
|     # Thankfully, --with-native-system-header-dir was introduced, so we don't | |||
|     #   need to patch STANDARD_INCLUDE_DIR to do this. | |||
| cat >> gcc/config/i386/linux.h << 'EOF' | |||
| #undef GLIBC_DYNAMIC_LINKER | |||
| #define GLIBC_DYNAMIC_LINKER "/bootstrap/lib/ld-linux.so.2" | |||
| #define STANDARD_STARTFILE_PREFIX_1 "/bootstrap/lib/" | |||
| #define STANDARD_STARTFILE_PREFIX_2 "" | |||
| EOF | |||
| 
 | |||
|     ./configure \ | |||
|         --build=i686-pc-linux-gnu \ | |||
|         --prefix=/bootstrap \ | |||
|         --with-native-system-header-dir=/bootstrap/include \ | |||
|         --with-local-prefix=/bootstrap \ | |||
|         --with-host-libstdcxx=-lsupc++ \ | |||
|         --enable-languages=c,c++ \ | |||
|         --disable-bootstrap \ | |||
|         \ | |||
|         --disable-nls \ | |||
|         --disable-decimal-float \ | |||
|         --disable-libatomic \ | |||
|         --disable-libcilkrts \ | |||
|         --disable-libgomp \ | |||
|         --disable-libitm \ | |||
|         --disable-libmudflap \ | |||
|         --disable-libquadmath \ | |||
|         --disable-libsanitizer \ | |||
|         --disable-libssp \ | |||
|         --disable-libvtv \ | |||
|         --disable-lto \ | |||
|         --disable-lto-plugin \ | |||
|         --disable-multilib \ | |||
|         --disable-plugin \ | |||
|         --disable-threads \ | |||
|         --enable-threads=single \ | |||
|         --disable-libstdcxx-pch \ | |||
|         --disable-build-with-cxx | |||
|     make | |||
|     make install | |||
| ) | |||
| rm -rf gcc-4.9.4 | |||
| 
 | |||
| 
 | |||
| #### The end | |||
| # With the bootstrap toolchain fully built, apply some finishing touches by | |||
| #   cleaning stuff up. | |||
| export PATH=/bootstrap/bin:/bin | |||
| 
 | |||
| # findutils (4.6.0): | |||
| # This one is completely optional, as it's not required for a bootstrap. | |||
| # However, a ton of scripts you'll probably use to further bootstrap will | |||
| #   probably need it. | |||
| # Busybox/linux requiring this to build is a good enough reason to put it here. | |||
| rm -rf findutils-4.6.0 | |||
| tar zxf findutils-4.6.0.tar.gz | |||
| ( cd findutils-4.6.0 | |||
|     ./configure \ | |||
|         --build=i686-pc-linux-gnu \ | |||
|         --disable-nls | |||
|     make -C gl | |||
|     make -C lib | |||
|     make -C find | |||
|     make -C xargs | |||
|     install -Dm755 find/find /bin/find | |||
|     install -Dm755 xargs/xargs /bin/xargs | |||
| ) | |||
| rm -rf findutils-4.6.0 | |||
| 
 | |||
| # Entering chroot before cleanup: | |||
| # ./bin/chroot . /bin/env -i PATH=/bootstrap/bin:/bin /bin/sh -l | |||
| 
 | |||
| # Move binaries | |||
| rm -f /bin/busybox /bin/busybox_unstripped | |||
| mv /bin/* /bootstrap/bin/ | |||
| hash -r  # a ton of binaries just moved | |||
| ln -sf ../bootstrap/bin/bash /bin/bash | |||
| ln -sf bash /bin/sh | |||
| 
 | |||
| # Strip everything (saves hundreds of MB) | |||
| find /bootstrap/lib -type f -name '*.a' | xargs strip --strip-debug || true | |||
| find /bootstrap/lib -type f -name '*.so*' | xargs strip --strip-unneeded || true | |||
| find /bootstrap/bin /bootstrap/sbin /bootstrap/libexec -type f | xargs strip --strip-all || true | |||
| cp /bootstrap/bin/strip /strip | |||
| strip -s /strip | |||
| mv /strip /bootstrap/bin/strip | |||
| 
 | |||
| # Clean up | |||
| #rm -rf /gcc46 /gcc2 /tcc /mes | |||
| rm -rf /bootstrap/share /bootstrap/var /bootstrap/etc | |||
| rm -f /bootstrap/lib/*.la /bootstrap/lib/libstdc++.so.*-gdb.py | |||
| 
 | |||
| # Back it up | |||
| cd / | |||
| find bootstrap bin/sh bin/bash -type f -o -type l | LC_ALL=C sort | xargs tar --mtime=@0 --numeric-owner --owner=0 --group=0 -cf bootstrap.tar | |||
| gzip -nv bootstrap.tar | |||
| 
 | |||
| # Entering chroot after cleanup: | |||
| # ./bootstrap/bin/chroot . /bootstrap/bin/env -i PATH=/bootstrap/bin /bootstrap/bin/sh -l | |||
| @ -0,0 +1,431 @@ | |||
| #!/bin/sh | |||
| set -e | |||
| 
 | |||
| # Example cross compile for x86_64, multilib-enabled | |||
| # This can be adapted for different architectures, but do note that some | |||
| #   architectures will need more recent versions of gcc/glibc/tools. | |||
| # The version of gcc in /bootstrap should be able to build any such newer | |||
| #   versions, at least as of right now (GCC 10.2). | |||
| 
 | |||
| # To homogenize build instructions across both multilib and non-multilib | |||
| #   installs, and because some applications require heavy patches to install  | |||
| #   in alternate libdirs (cough cough python), the lib directory will contain | |||
| #   native libraries, while lib32 whill contain 32-bit libraries. | |||
| # GCC will be patched slightly, and configured to achieve this, as by default | |||
| #   it uses lib64 and lib. | |||
| 
 | |||
| # To initialize/enter chroot: | |||
| # mkdir dev tmp | |||
| # mknod dev/null c 1 3 | |||
| # ./bootstrap/bin/chroot . /bootstrap/bin/env -i NPROC="$(nproc)" /bootstrap/bin/sh /sources/build_cross.sh | |||
| 
 | |||
| # Amount of make threads, configure this to your liking. | |||
| # This can be obtained using `getconf _NPROCESSORS_ONLN`, but requires /proc | |||
| #   to be mounted, which we avoid. | |||
| export MAKEFLAGS="-j${NPROC:-4}" | |||
| 
 | |||
| cd /sources | |||
| 
 | |||
| 
 | |||
| #### Make a cross-compiler | |||
| export PATH=/cross/bin:/bootstrap/bin | |||
| rm -rf /cross /system | |||
| 
 | |||
| # kernel headers | |||
| rm -rf linux-4.14 | |||
| tar zxf linux-4.14.tar.gz | |||
| ( cd linux-4.14 | |||
|     make mrproper | |||
|     make ARCH=x86_64 INSTALL_HDR_PATH="$PWD/install" headers_install | |||
|     find install -type f ! -name "*.h" -exec rm {} + | |||
|     mkdir -p /system/bootstrap/ | |||
|     cp -a install/include /system/bootstrap/ | |||
| ) | |||
| rm -rf linux-4.14 | |||
| 
 | |||
| # Install cross binutils | |||
| rm -rf binutils-2.20.1 | |||
| tar jxf binutils-2.20.1a.tar.bz2 | |||
| ( cd binutils-2.20.1 | |||
|     ./configure \ | |||
|         --build=i686-pc-linux-gnu \ | |||
|         --target=x86_64-pc-linux-gnu \ | |||
|         --prefix=/cross \ | |||
|         --with-sysroot=/system \ | |||
|         --disable-shared \ | |||
|         --disable-nls \ | |||
|         --disable-werror | |||
|     make | |||
|     make install | |||
| ) | |||
| rm -rf binutils-2.20.1 | |||
| 
 | |||
| # Configure the gcc source | |||
| rm -rf gcc-4.9.4 | |||
| tar jxf gcc-4.9.4.tar.bz2 | |||
| ( cd gcc-4.9.4 | |||
|     tar jxf ../gmp-4.3.2.tar.bz2 | |||
|     mv gmp-4.3.2 gmp | |||
|     tar jxf ../mpfr-2.4.2.tar.bz2 | |||
|     mv mpfr-2.4.2 mpfr | |||
|     tar zxf ../mpc-1.0.3.tar.gz | |||
|     mv mpc-1.0.3 mpc | |||
| 
 | |||
|     # Set up the location of target glibc | |||
| cat >> gcc/config/i386/t-linux64 << 'EOF' | |||
| MULTILIB_OSDIRNAMES = m64=../lib | |||
| MULTILIB_OSDIRNAMES+= m32=../lib32 | |||
| EOF | |||
| cat >> gcc/config/i386/linux64.h << 'EOF' | |||
| #undef GLIBC_DYNAMIC_LINKER32 | |||
| #undef GLIBC_DYNAMIC_LINKER64 | |||
| #undef STANDARD_STARTFILE_PREFIX_1 | |||
| #undef STANDARD_STARTFILE_PREFIX_2 | |||
| #define GLIBC_DYNAMIC_LINKER32 "/bootstrap/lib32/ld-linux.so.2" | |||
| #define GLIBC_DYNAMIC_LINKER64 "/bootstrap/lib/ld-linux-x86-64.so.2" | |||
| #define STANDARD_STARTFILE_PREFIX_1 "/bootstrap/lib/" | |||
| #define STANDARD_STARTFILE_PREFIX_2 "" | |||
| EOF | |||
| 
 | |||
|     mkdir build && cd build  # Build breaks without a build directory | |||
|     ../configure \ | |||
|         --build=i686-pc-linux-gnu \ | |||
|         --target=x86_64-pc-linux-gnu \ | |||
|         --prefix=/cross \ | |||
|         --with-sysroot=/system \ | |||
|         --with-native-system-header-dir=/bootstrap/include \ | |||
|         --with-local-prefix=/bootstrap \ | |||
|         --with-host-libstdcxx=-lsupc++ \ | |||
|         --enable-multilib \ | |||
|         --enable-languages=c,c++ \ | |||
|         --disable-nls | |||
| ) | |||
| 
 | |||
| # Install the compiler | |||
| make -C gcc-4.9.4/build all-gcc | |||
| make -C gcc-4.9.4/build install-gcc | |||
| 
 | |||
| # Configure the glibc source | |||
| rm -rf glibc-2.16.0 | |||
| tar jxf glibc-2.16.0.tar.bz2 | |||
| ( cd glibc-2.16.0 | |||
|     # Fix hardcode of /bin/pwd | |||
|     sed -i -e 's@/bin/pwd@pwd@g' configure | |||
| 
 | |||
|     # Fix building cross-rpcgen without host rpc headers | |||
|     sed -i -e 's/$(ALL_BUILD_CFLAGS)/-I. &/' sunrpc/Makefile | |||
| 
 | |||
|     mkdir build && cd build | |||
|     ../configure \ | |||
|         --build=i686-pc-linux-gnu \ | |||
|         --host=x86_64-pc-linux-gnu \ | |||
|         --prefix=/bootstrap \ | |||
|         libc_cv_ssp=no \ | |||
|         libc_cv_forced_unwind=yes | |||
| 
 | |||
|     cd .. | |||
|     mkdir build32 && cd build32 | |||
|     ../configure \ | |||
|         CC='x86_64-pc-linux-gnu-gcc -m32' \ | |||
|         CXX='x86_64-pc-linux-gnu-g++ -m32' \ | |||
|         --build=i686-bootstrap-linux-gnu \ | |||
|         --host=i686-pc-linux-gnu \ | |||
|         --prefix=/bootstrap \ | |||
|         --libdir=/bootstrap/lib32 \ | |||
|         libc_cv_slibdir=/bootstrap/lib32 \ | |||
|         libc_cv_ssp=no \ | |||
|         libc_cv_forced_unwind=yes | |||
| ) | |||
| 
 | |||
| # Installing libgcc by using --without-headers --with-newlib in the gcc config | |||
| #   would avoid having to install csu+headers before building libgcc, | |||
| #   thereby simplifying the instructions slightly. | |||
| # I don't think that simplification is particularly worth it, however. | |||
| 
 | |||
| # Do the whole gcc/glibc song and dance... | |||
| # DESTDIR set to a different dir since glibc makefile breaks otherwise... | |||
| make -C glibc-2.16.0/build DESTDIR=/system csu/subdir_install | |||
| make -C glibc-2.16.0/build32 DESTDIR=/system csu/subdir_install | |||
| make -C glibc-2.16.0/build DESTDIR=/system install-bootstrap-headers=yes install-headers | |||
| touch /system/bootstrap/include/gnu/stubs.h | |||
| x86_64-pc-linux-gnu-gcc -nostdlib -nostartfiles -shared -x c /dev/null -o /system/bootstrap/lib/libc.so | |||
| x86_64-pc-linux-gnu-gcc -m32 -nostdlib -nostartfiles -shared -x c /dev/null -o /system/bootstrap/lib32/libc.so | |||
| make -C gcc-4.9.4/build all-target-libgcc | |||
| make -C gcc-4.9.4/build install-target-libgcc | |||
| make -C glibc-2.16.0/build all | |||
| make -C glibc-2.16.0/build32 all | |||
| make -C glibc-2.16.0/build32 DESTDIR="$PWD/glibc_install" install | |||
| make -C glibc-2.16.0/build DESTDIR="$PWD/glibc_install" install | |||
| # TODO: Would running force-install instead work? | |||
| cp -a glibc_install/bootstrap /system/ | |||
| rm -rf glibc_install | |||
| make -C gcc-4.9.4/build all-target-libstdc++-v3 | |||
| make -C gcc-4.9.4/build install-target-libstdc++-v3 | |||
| 
 | |||
| rm -rf glibc-2.16.0 | |||
| rm -rf gcc-4.9.4/build | |||
| 
 | |||
| 
 | |||
| #### Cross-compile the compiler for the target | |||
| 
 | |||
| # Binutils | |||
| rm -rf binutils-2.20.1 | |||
| tar jxf binutils-2.20.1a.tar.bz2 | |||
| ( cd binutils-2.20.1 | |||
|     ./configure \ | |||
|         --build=i686-pc-linux-gnu \ | |||
|         --host=x86_64-pc-linux-gnu \ | |||
|         --prefix=/bootstrap \ | |||
|         --with-lib-path=/bootstrap/lib \ | |||
|         --with-sysroot \ | |||
|         --disable-shared \ | |||
|         --disable-nls \ | |||
|         --disable-werror | |||
|     make | |||
|     make DESTDIR=/system install | |||
| ) | |||
| rm -rf binutils-2.20.1 | |||
| 
 | |||
| # GCC (using the unpacked+patched archive from before) | |||
| rm -rf gcc-4.9.4/build | |||
| ( cd gcc-4.9.4 | |||
|     mkdir build && cd build | |||
|     ../configure \ | |||
|         CC_FOR_TARGET=x86_64-pc-linux-gnu-gcc \ | |||
|         CXX_FOR_TARGET=x86_64-pc-linux-gnu-g++ \ | |||
|         --build=i686-pc-linux-gnu \ | |||
|         --host=x86_64-pc-linux-gnu \ | |||
|         --prefix=/bootstrap \ | |||
|         --with-native-system-header-dir=/bootstrap/include \ | |||
|         --with-local-prefix=/bootstrap \ | |||
|         --enable-multilib \ | |||
|         --enable-languages=c,c++ \ | |||
|         --disable-nls | |||
|     make all-gcc all-target-libgcc all-target-libstdc++-v3 | |||
|     make DESTDIR=/system install-gcc install-target-libgcc install-target-libstdc++-v3 | |||
| ) | |||
| rm -rf gcc-4.9.4 | |||
| 
 | |||
| 
 | |||
| #### Install a bunch of tools for the target | |||
| rm -rf coreutils-5.0 | |||
| tar jxf coreutils-5.0.tar.bz2 | |||
| ( cd coreutils-5.0 | |||
|     # Fix conflicting type errors | |||
|     sed -i -e '/^char \*malloc/d' lib/putenv.c | |||
|     sed -i -e 's/tee /tee_files /g' src/tee.c | |||
|     sed -i -e 's/eaccess/_&/g' src/test.c | |||
| 
 | |||
|     ./configure \ | |||
|         --prefix=/bootstrap \ | |||
|         --build=i686-pc-linux-gnu \ | |||
|         --host=x86_64-pc-linux-gnu \ | |||
|         --disable-nls \ | |||
|         ac_cv_func_malloc_0_nonnull=yes \ | |||
|         am_cv_func_working_getline=yes \ | |||
|         utils_cv_sys_open_max=1019 | |||
|     make -C lib | |||
|     make -C src | |||
|     make -C src DESTDIR=/system install-exec | |||
| 
 | |||
|     # Link chroot statically (optional if you can use the host's chroot) | |||
|     x86_64-pc-linux-gnu-gcc -static -O2 -o /system/bootstrap/bin/chroot src/chroot.o lib/libfetish.a | |||
| ) | |||
| rm -rf coreutils-5.0 | |||
| 
 | |||
| rm -rf bash-4.4 | |||
| tar zxf bash-4.4.tar.gz | |||
| ( cd bash-4.4 | |||
|     # The configure script can't run a lot of tests when cross-compiling, | |||
|     #   so a lot of the tests are specified manually to match a native build. | |||
|     # This fixes some otherwise-broken scripts when building Gentoo for example. | |||
|     # It uses the following test: [[ $(< <(echo foo) ) == foo ]] | |||
|     #   to check for a sane bash. | |||
|     # Xz also has issues building with a cross-compiled bash. | |||
|     # I encourage you to compare the config.h with a native build! | |||
|     ./configure \ | |||
|         --build=i686-pc-linux-gnu \ | |||
|         --host=x86_64-pc-linux-gnu \ | |||
|         --disable-nls \ | |||
|         ac_cv_func_chown_works=yes \ | |||
|         ac_cv_func_mmap_fixed_mapped=yes \ | |||
|         ac_cv_func_strcoll_works=yes \ | |||
|         bash_cv_func_sigsetjmp=present \ | |||
|         bash_cv_getcwd_malloc=yes \ | |||
|         bash_cv_job_control_missing=no \ | |||
|         bash_cv_printf_a_format=yes \ | |||
|         bash_cv_sys_named_pipes=yes \ | |||
|         bash_cv_sys_siglist=yes \ | |||
|         bash_cv_ulimit_maxfds=yes \ | |||
|         bash_cv_under_sys_siglist=yes \ | |||
|         bash_cv_unusable_rtsigs=no \ | |||
|         bash_cv_wcwidth_broken=yes \ | |||
|         bash_cv_wexitstatus_offset=8 | |||
|     make bash | |||
|     install -Dm755 bash /system/bootstrap/bin/bash | |||
|     ln -sf bash /system/bootstrap/bin/sh | |||
| ) | |||
| rm -rf bash-4.4 | |||
| 
 | |||
| rm -rf gzip-1.2.4 | |||
| tar zxf gzip-1.2.4.tar.gz | |||
| ( cd gzip-1.2.4 | |||
|     # -DSTDC_HEADERS=1 -DHAVE_UNISTD_H=1 -DDIRENT=1 | |||
|     # Such an old configure script doesn't support cross-compiling... | |||
|     set -x | |||
|     x86_64-pc-linux-gnu-gcc -DSTDC_HEADERS=1 -w -O2 -o gzip gzip.c zip.c deflate.c trees.c bits.c unzip.c inflate.c util.c crypt.c lzw.c unlzw.c unpack.c unlzh.c getopt.c | |||
|     CC=x86_64-pc-linux-gnu-gcc ./configure | |||
|     make gzip | |||
|     install -Dm755 gzip /system/bootstrap/bin/gzip | |||
|     ln -sf gzip /system/bootstrap/bin/gunzip | |||
|     ln -sf gzip /system/bootstrap/bin/zcat | |||
| ) | |||
| rm -rf gzip-1.2.4 | |||
| 
 | |||
| rm -rf bzip2-1.0.8 | |||
| tar zxf bzip2-1.0.8.tar.gz | |||
| ( cd bzip2-1.0.8 | |||
|     make \ | |||
|         CC=x86_64-pc-linux-gnu-gcc \ | |||
|         AR=x86_64-pc-linux-gnu-ar \ | |||
|         bzip2 | |||
|     install -Dm755 bzip2 /system/bootstrap/bin/bzip2 | |||
|     ln -sf bzip2 /system/bootstrap/bin/bunzip2 | |||
|     ln -sf bzip2 /system/bootstrap/bin/bzcat | |||
| ) | |||
| rm -rf bzip2-1.0.8 | |||
| 
 | |||
| rm -rf tar-1.22 | |||
| tar jxf tar-1.22.tar.bz2 | |||
| ( cd tar-1.22 | |||
|     ./configure \ | |||
|         --build=i686-pc-linux-gnu \ | |||
|         --host=x86_64-pc-linux-gnu \ | |||
|         --disable-nls | |||
|     make -C lib | |||
|     make -C src | |||
|     install -Dm755 src/tar /system/bootstrap/bin/tar | |||
| ) | |||
| rm -rf tar-1.22 | |||
| 
 | |||
| rm -rf grep-2.0 | |||
| tar zxf grep-2.0.tar.gz | |||
| ( cd grep-2.0 | |||
|     # -DGREP  -DSTDC_HEADERS=1 -DHAVE_STRING_H=1 -DHAVE_SYS_PARAM_H=1 -DHAVE_UNISTD_H=1 -DHAVE_ALLOCA_H=1 -DHAVE_GETPAGESIZE=1 -DHAVE_MEMCHR=1 -DHAVE_STRERROR=1 -DHAVE_VALLOC=1 -DHAVE_WORKING_MMAP=1 | |||
|     # Such an old configure script doesn't support cross-compiling... | |||
|     set -x | |||
|     x86_64-pc-linux-gnu-gcc -DSTDC_HEADERS=1 -DHAVE_MEMCHR=1 -DHAVE_STRERROR=1 -w -O2 -o grep grep.c getopt.c regex.c dfa.c kwset.c obstack.c search.c | |||
|     install -Dm755 grep /system/bootstrap/bin/grep | |||
|     ln -sf grep /system/bootstrap/bin/egrep | |||
|     ln -sf grep /system/bootstrap/bin/fgrep | |||
| ) | |||
| rm -rf grep-2.0 | |||
| 
 | |||
| # Optional, rationale for inclusion same as in build_bootstrap.sh | |||
| rm -rf findutils-4.6.0 | |||
| tar zxf findutils-4.6.0.tar.gz | |||
| ( cd findutils-4.6.0 | |||
|     ./configure \ | |||
|         --build=i686-pc-linux-gnu \ | |||
|         --host=x86_64-pc-linux-gnu \ | |||
|         --disable-nls | |||
|     make -C gl | |||
|     make -C lib | |||
|     make -C find | |||
|     make -C xargs | |||
|     install -Dm755 find/find /system/bootstrap/bin/find | |||
|     install -Dm755 xargs/xargs /system/bootstrap/bin/xargs | |||
| ) | |||
| rm -rf findutils-4.6.0 | |||
| 
 | |||
| rm -rf diffutils-2.7 | |||
| tar zxf diffutils-2.7.tar.gz | |||
| ( cd diffutils-2.7 | |||
|     CC=x86_64-pc-linux-gnu-gcc \ | |||
|     ac_cv_func_closedir_void=no \ | |||
|     ac_cv_header_stdc=yes \ | |||
|     ./configure \ | |||
|         --build=i686-pc-linux-gnu \ | |||
|         --host=x86_64-pc-linux-gnu | |||
|     make cmp diff | |||
|     install -Dm755 cmp /system/bootstrap/bin/cmp | |||
|     install -Dm755 diff /system/bootstrap/bin/diff | |||
| ) | |||
| rm -rf diffutils-2.7 | |||
| 
 | |||
| rm -rf sed-4.0.6 | |||
| tar zxf sed-4.0.6.tar.gz | |||
| ( cd sed-4.0.6 | |||
|     ./configure \ | |||
|         --build=i686-pc-linux-gnu \ | |||
|         --host=x86_64-pc-linux-gnu \ | |||
|         --disable-nls \ | |||
|         am_cv_func_working_getline=yes | |||
|     make -C lib | |||
|     make -C sed | |||
|     install -Dm755 sed/sed /system/bootstrap/bin/sed | |||
| ) | |||
| rm -rf sed-4.0.6 | |||
| 
 | |||
| rm -rf patch-2.5.9 | |||
| tar zxf patch-2.5.9.tar.gz | |||
| ( cd patch-2.5.9 | |||
|     ./configure \ | |||
|         --build=i686-pc-linux-gnu \ | |||
|         --host=x86_64-pc-linux-gnu | |||
|     make patch | |||
|     install -Dm755 patch /system/bootstrap/bin/patch | |||
| ) | |||
| rm -rf patch-2.5.9 | |||
| 
 | |||
| rm -rf gawk-3.1.8 | |||
| tar jxf gawk-3.1.8.tar.bz2 | |||
| ( cd gawk-3.1.8 | |||
|     ./configure \ | |||
|         --build=i686-pc-linux-gnu \ | |||
|         --host=x86_64-pc-linux-gnu \ | |||
|         --disable-nls | |||
|     make gawk | |||
|     install -Dm755 gawk /system/bootstrap/bin/gawk | |||
|     ln -sf gawk /system/bootstrap/bin/awk | |||
| ) | |||
| rm -rf gawk-3.1.8 | |||
| 
 | |||
| rm -rf make-3.82 | |||
| tar jxf make-3.82.tar.bz2 | |||
| ( cd make-3.82 | |||
|     ./configure \ | |||
|         --build=i686-pc-linux-gnu \ | |||
|         --host=x86_64-pc-linux-gnu \ | |||
|         --disable-nls | |||
|     make make | |||
|     install -Dm755 make /system/bootstrap/bin/make | |||
| ) | |||
| rm -rf make-3.82 | |||
| 
 | |||
| # Add /bin/sh symlink | |||
| mkdir -p /system/bin | |||
| ln -sf ../bootstrap/bin/bash /system/bin/bash | |||
| ln -sf bash /system/bin/sh | |||
| 
 | |||
| # Strip everything (saves hundreds of MB) | |||
| find /system/bootstrap/lib /system/bootstrap/lib32 -type f -name '*.a' | xargs x86_64-pc-linux-gnu-strip --strip-debug || true | |||
| find /system/bootstrap/lib /system/bootstrap/lib32 -type f -name '*.so*' | xargs x86_64-pc-linux-gnu-strip --strip-unneeded || true | |||
| find /system/bootstrap/bin /system/bootstrap/sbin /system/bootstrap/libexec -type f | xargs x86_64-pc-linux-gnu-strip --strip-all || true | |||
| 
 | |||
| # Clean up | |||
| #rm -rf /cross | |||
| rm -rf /system/bootstrap/share /system/bootstrap/var /system/bootstrap/etc | |||
| rm -f /system/bootstrap/lib/*.la /system/bootstrap/lib32/*.la /system/bootstrap/lib/libstdc++.so.*-gdb.py /system/bootstrap/lib32/libstdc++.so.*-gdb.py | |||
| 
 | |||
| # Back it up | |||
| cd /system | |||
| # Too many files to fit on single xargs command... | |||
| rm -f cross.tar | |||
| find bootstrap bin/sh bin/bash -type f -o -type l | LC_ALL=C sort | xargs tar --mtime=@0 --numeric-owner --owner=0 --group=0 -rf cross.tar | |||
| gzip -nv cross.tar | |||
| 
 | |||
| # Now you should reboot into a system with a kernel supporting the target architecture. | |||
| # Building a kernel+utilities for such a system is outside the scope of this script. | |||
| # Enter cross-chroot: | |||
| # ./bootstrap/bin/chroot . /bootstrap/bin/env -i PATH=/bootstrap/bin /bootstrap/bin/sh -l | |||
| @ -0,0 +1,3 @@ | |||
| 427a4257055af6d35ee389e211300604b4e5edbb  builds/binaries.tar.gz | |||
| be27f8f4dd7eb36033afaedb08746d3bf9b9284d  builds/bootstrap.tar.gz | |||
| 7df8133faddb1cdb8531e40f0db16e6e1270a4fe  builds/cross.tar.gz | |||
								
									
										File diff suppressed because it is too large
									
								
							
						
					| @ -0,0 +1,13 @@ | |||
| #!/bin/sh | |||
| set -eu | |||
| 
 | |||
| mkdir -p sources | |||
| cd sources | |||
| 
 | |||
| wget -c -i ../sources.wget-list | |||
| 
 | |||
| mv gcc-boot-2.95.3.patch\?id=* gcc-boot-2.95.3.patch | |||
| mv glibc-boot-2.16.0.patch\?id=* glibc-boot-2.16.0.patch | |||
| mv glibc-boot-2.2.5.patch\?id=* glibc-boot-2.2.5.patch | |||
| 
 | |||
| sha1sum -c ../sources.sha1 | |||
| @ -0,0 +1,33 @@ | |||
| Required bootstrap binaries (sorted as in busybox menuconfig) | |||
| 
 | |||
| Archival Utilities: | |||
| - zcat | |||
| - tar | |||
| Coreutils: | |||
| - basename | |||
| - cat | |||
| - chmod | |||
| - chroot (self dep) | |||
| - cp | |||
| - dirname | |||
| - echo | |||
| - env (self dep) | |||
| - expr | |||
| - install | |||
| - ln | |||
| - ls | |||
| - mkdir | |||
| - mv | |||
| - pwd | |||
| - rm | |||
| - sleep | |||
| - sort | |||
| - touch | |||
| - tr | |||
| - true | |||
| - uniq | |||
| Editors: | |||
| - cmp | |||
| - sed | |||
| Shells: | |||
| - ash | |||
| @ -0,0 +1,15 @@ | |||
| 534c7ee46331ff1f1fc96a378fd6a9f6b322a242  bison-3.7.1.tar.xz | |||
| f17235bc9c3aec538065a655681815c242a6d7d5  ca-certificates_20200601.tar.xz | |||
| 8df6cb570c8d6596a67d1c0773bf00650154f7aa  libffi-3.3.tar.gz | |||
| 228604686ca23f42e48b98930babeb5d217f1899  m4-1.4.18.tar.xz | |||
| 7d9d11eb36cfb752da1fb11bb3e521d2a3cc8830  make-4.2.1.tar.bz2 | |||
| 6a4098623cd65b9037b301b8f71c62454ccab2d9  mktemp-1.7.tar.gz | |||
| b213a293f2127ec3e323fb3cfc0c9807664fd997  openssl-1.1.1g.tar.gz | |||
| 1003c6aa71d8966501038178459a9fa4e9aba747  perl-5.30.3.tar.xz | |||
| 2ef586fd14af9c99a8c01d9ff75ec656c5f9a175  portage-3.0.8.tar.bz2 | |||
| e1de02779a89a94000c0ed340ec126de25825f2f  Python-3.7.9.tar.xz | |||
| 00823f43901e7da39f3f0daf20ec9efae47e959e  rsync-3.2.3.tar.gz | |||
| 61bd770062d49cdab3f0f45df473e2bf950ba266  sed-4.8.tar.xz | |||
| 2b886eab5b97267cc358ab35e42d14d33d6dfc95  wget-1.20.3.tar.gz | |||
| fa2ae4db119f639a01b02f99f1ba671ece2828eb  xz-5.2.5.tar.gz | |||
| e6d119755acdf9104d7ba236b1242696940ed6dd  zlib-1.2.11.tar.gz | |||
| @ -0,0 +1,15 @@ | |||
| https://tukaani.org/xz/xz-5.2.5.tar.gz | |||
| https://zlib.net/zlib-1.2.11.tar.gz | |||
| https://github.com/libffi/libffi/releases/download/v3.3/libffi-3.3.tar.gz | |||
| https://www.python.org/ftp/python/3.7.9/Python-3.7.9.tar.xz | |||
| https://www.cpan.org/src/5.0/perl-5.30.3.tar.xz | |||
| https://www.openssl.org/source/old/1.1.1/openssl-1.1.1g.tar.gz | |||
| https://ftp.gnu.org/gnu/wget/wget-1.20.3.tar.gz | |||
| https://rsync.samba.org/ftp/rsync/src/rsync-3.2.3.tar.gz | |||
| https://www.mktemp.org/dist/mktemp-1.7.tar.gz | |||
| http://deb.debian.org/debian/pool/main/c/ca-certificates/ca-certificates_20200601.tar.xz | |||
| https://dev.gentoo.org/~zmedico/portage/archives/portage-3.0.8.tar.bz2 | |||
| https://ftp.gnu.org/gnu/m4/m4-1.4.18.tar.xz | |||
| https://ftp.gnu.org/gnu/bison/bison-3.7.1.tar.xz | |||
| https://ftp.gnu.org/gnu/make/make-4.2.1.tar.bz2 | |||
| https://ftp.gnu.org/gnu/sed/sed-4.8.tar.xz | |||
| @ -0,0 +1,30 @@ | |||
| #!/bin/sh | |||
| set -e | |||
| 
 | |||
| # Run this script in a recent stage3 tarball to grab all required software versions and URLs. | |||
| 
 | |||
| root="${1:-/}" | |||
| 
 | |||
| pkgs=" | |||
| app-arch/xz-utils | |||
| sys-libs/zlib | |||
| dev-libs/libffi | |||
| dev-lang/python | |||
| dev-lang/perl | |||
| dev-libs/openssl | |||
| net-misc/wget | |||
| net-misc/rsync | |||
| app-misc/ca-certificates | |||
| sys-apps/portage | |||
| sys-devel/m4 | |||
| sys-devel/bison | |||
| sys-devel/make | |||
| sys-apps/sed | |||
| " | |||
| 
 | |||
| for x in $pkgs; do | |||
|     ver="$(portageq best_visible "$root" ebuild "$x")" | |||
|     echo "$ver" | |||
|     portageq metadata "$root" ebuild "$ver" SRC_URI | |||
|     echo | |||
| done | |||
| @ -0,0 +1,187 @@ | |||
| Based on portage-3.0.8 and gentoo-20201031 snapshot | |||
| 
 | |||
| The specifics of this document (software versions and whatnot) are subject to | |||
| change as gentoo evolves, but I hope the big lines of it won't change too | |||
| much. | |||
| 
 | |||
| This guide starts off with a system built from build_cross.sh, built for | |||
| x86_64 with i686 multilib. | |||
| It might be possible to adapt both that script, and this guide for other | |||
| architectures, but this guide won't go into detail. | |||
| 
 | |||
| You should be running a system with a x86_64 kernel (with i686 support). | |||
| Install the required sources (listed in gentoo.wget-list) into /sources. | |||
| 
 | |||
| To enter the bootstrap system as a chroot, use the following commands to set | |||
| up the filesystems and entering: | |||
| mkdir -p proc sys dev tmp | |||
| mount -t proc proc proc | |||
| mount -t sysfs sysfs sys | |||
| mount -t devtmpfs devtmpfs dev | |||
| mount -t devpts devpts dev/pts | |||
| mount -t tmpfs tmpfs dev/shm | |||
| mkdir -p etc | |||
| touch etc/resolv.conf | |||
| mount --bind /etc/resolv.conf etc/resolv.conf | |||
| ./bootstrap/bin/chroot . /bootstrap/bin/env -i PATH=/bin:/sbin:/usr/bin:/usr/sbin:/bootstrap/bin:/bootstrap/sbin HOME=/root /bootstrap/bin/sh -l | |||
| 
 | |||
| To install all the prerequisite tools, place the sources (listed in | |||
| gentoo.wget-list) under /sources, then run the gentoo_tools.sh script. | |||
| 
 | |||
| Configure portage: | |||
| echo "root:x:0:0:root:/root:/bin/bash" > /etc/passwd | |||
| echo "root:x:0:root" > /etc/group | |||
| echo "portage:x:250:250:portage:/var/tmp/portage:/bin/false" >> /etc/passwd | |||
| echo "portage::250:portage" >> /etc/group | |||
| echo "C UTF-8" > /etc/locale.gen | |||
| mkdir -p /tmp /root | |||
| chown root.root /tmp /root | |||
| chmod 1777 /tmp | |||
| chmod 0700 /root | |||
| cat > /etc/portage/make.conf << 'EOF' | |||
| FEATURES='-pid-sandbox -news' | |||
| ROOTPATH=/bootstrap/bin:/bootstrap/sbin | |||
| EOF | |||
| ln -sf ../../var/db/repos/gentoo/profiles/default/linux/amd64/17.1/ /etc/portage/make.profile | |||
| 
 | |||
| Install ebuild repository (pick appropriate date, see distfiles.gentoo.org/snapshots): | |||
| emerge-webrsync -v --revert=20201031 | |||
| 
 | |||
| Install some ebuild prerequisites: | |||
| emerge -O1 sys-apps/gentoo-functions  # Used by elt-patches and a ton of other things | |||
| emerge -O1 app-portage/elt-patches  # required by elibtoolize(libtool.eclass), used to install any library | |||
| emerge -O1 sys-devel/gnuconfig  # required by gnuconfig_update(gnuconfig.eclass), used by toolchain(-glibc).eclass, doesn't hurt to have | |||
| emerge -O1 sys-devel/binutils-config sys-devel/gcc-config | |||
| 
 | |||
| First, we will build an updated binutils+gcc combo that targets /usr instead | |||
| of /bootstrap. This makes it easier to bootstrap glibc and everything else. We | |||
| will use portage for this, even though it's a mess. | |||
| 
 | |||
| NOTE: Doing this is (probably) *BAAAAD*, since we're linking the compiler | |||
| support libraries with a potentially incompatible version of glibc in | |||
| /bootstrap, and upgrading it afterwards. Glibc should always be installed | |||
| first into a new prefix! However, due to the complex relationship between | |||
| glibc, gcc, libgcc and libstdc++, this is rather hard to do while wrangling | |||
| the change from /bootstrap to /usr, as well as the multilib libdir changes, so | |||
| for simplicity's sake, I won't bother. This just works™. | |||
| 
 | |||
| Install temporary libc files for target compiler: | |||
| mkdir -p /lib64 /lib | |||
| ln -sf /bootstrap/lib/ld-linux-x86-64.so.2 /lib64/ld-linux-x86-64.so.2 | |||
| ln -sf /bootstrap/lib32/ld-linux.so.2 /lib/ld-linux.so.2 | |||
| mkdir -p /usr/include | |||
| ln -sf /bootstrap/include/limits.h /usr/include/limits.h | |||
| mkdir -p /usr/lib64 /usr/lib | |||
| ln -sf /bootstrap/lib/{crti,crtn,Scrt1}.o \ | |||
|        /bootstrap/lib/{libc,libm,libpthread}.so /usr/lib64/ | |||
| ln -sf /bootstrap/lib32/{crti,crtn,Scrt1}.o \ | |||
|        /bootstrap/lib32/{libc,libm,libpthread}.so /usr/lib/ | |||
| 
 | |||
| Install binutils+GCC (linked against /bootstrap): | |||
| USE='-*' emerge -O1 sys-devel/binutils | |||
| USE='-* static-libs' EXTRA_ECONF=--disable-shared \ | |||
|     CPPFLAGS='-isystem/usr/include' LDFLAGS='-L/usr/lib64 -L/usr/lib' \ | |||
|     emerge -O1 dev-libs/gmp dev-libs/mpfr dev-libs/mpc | |||
| USE='-*' EXTRA_ECONF=--disable-bootstrap GCC_MAKE_TARGET=all \ | |||
|     CPPFLAGS='-isystem/usr/include' LDFLAGS='-L/usr/lib64 -L/usr/lib' \ | |||
|     CPATH=/bootstrap/include \ | |||
|     emerge -O1 sys-devel/gcc | |||
| emerge --rage-clean dev-libs/gmp dev-libs/mpfr dev-libs/mpc | |||
| gcc-config 1  # Not automatic unlike binutils-config... | |||
| 
 | |||
| NOTE: The Glibc ebuild downloads a file called gcc-multilib-bootstrap, which | |||
| contains prebuilt binaries to bootstrap multilib gcc. This is _only_ used when | |||
| the command "echo 'int main(){}' | $CC -m32 -xc -" fails, and shouldn't be | |||
| being used in this bootstrap, but you can make sure of that by patching the | |||
| ebuild to `die` instead of running the `sed` command to enable its use. | |||
| 
 | |||
| NOTE: BOOTSTRAP_RAP=1 is only used in the Glibc ebuild, to avoid a pre-install | |||
| check that might pick up programs from /bootstrap to test against the | |||
| installed glibc, as well as picking up python from $PATH instead of | |||
| eselect-python. I'm not aware of how the support status is for this variable, | |||
| and as such it might disappear in the future, or be used in more packages. | |||
| 
 | |||
| Install initial glibc: | |||
| CC=/bootstrap/bin/gcc emerge -O1 sys-kernel/linux-headers | |||
| USE='-*' BOOTSTRAP_RAP=1 emerge -O1 sys-libs/glibc | |||
| 
 | |||
| NOTE: `sandbox` outputs a failure message to stderr for every program still | |||
| built against /bootstrap, which includes the compiler. Some autoconf scripts | |||
| check stderr to determine a failure, so this causes builds to fail. This is | |||
| why it's (partially) disabled for this stage. | |||
| 
 | |||
| Bootstrap the rest of the system: | |||
| USE=-seccomp emerge -O1 app-misc/pax-utils | |||
| cd /var/db/repos/gentoo/scripts | |||
| mkdir -p /var/run | |||
| ln -s /bootstrap/bin/python3 /usr/bin/python | |||
| rm -f /etc/profile.env | |||
| USE=-nls FEATURES=-usersandbox BOOTSTRAP_RAP=1 ./bootstrap.sh | |||
| 
 | |||
| Reinitialize the environment: | |||
| env-update | |||
| exec bash -l | |||
| export PATH=$PATH:/bootstrap/bin:/bootstrap/sbin | |||
| 
 | |||
| In the following stages, you'll get tons of LD_PRELOAD libsandbox.so errors | |||
| from programs still linked against /bootstrap. This is safe to ignore, and | |||
| will gradually disappear as programs are rebuilt. | |||
| 
 | |||
| It'd be nice to remove the bootstrap tools now, but among wget/openssl, gawk, | |||
| gzip, grep, and other tools, they're still required for some reason. | |||
| 
 | |||
| From this point onward, you're pretty much on your own to beat portage into | |||
| performing an `emerge -e @system` and fixing any unspecified dependencies you | |||
| encounter along the way. This can be done in a whole number of ways, and will | |||
| differ on any given day, since this is painfully unsupported by gentoo devs. | |||
| Because the order in which you install everything can differ wildly, and | |||
| consequently affect the output of your build, it is advised to do a second | |||
| `emerge -e @system` afterwards, for sanity. Below I detail my most recent | |||
| procedure, which, I can't stress enough, may or may not work at the time | |||
| you're reading this. | |||
| 
 | |||
| Fix circular dependencies: | |||
| USE=-filecaps emerge -O1 sys-libs/pam | |||
| USE='-acl -xattr' emerge -O1 sys-apps/shadow  # required by acct-group/acct-user | |||
| 
 | |||
| Verify there's no circular deps left, for sanity: | |||
| emerge -fe @system | |||
| 
 | |||
| Build everything: | |||
| emerge -e @system | |||
| 
 | |||
| Clean up bootstrap tools/configs: | |||
| rm -rf /bootstrap /sources | |||
| rm -f /etc/portage/make.conf | |||
| 
 | |||
| Reinitialize environment: | |||
| env-update | |||
| exec bash -l | |||
| 
 | |||
| Consider rebuilding everything again without /bootstrap, since a lot of | |||
| packages couldn't be properly stripped, and a bunch of other tools have been | |||
| upgraded, during the first emerge -e @system: | |||
| emerge -be @system | |||
| 
 | |||
| To install everything into a clean root: | |||
| ROOT=/final emerge -K @system | |||
| 
 | |||
| Prepare files for catalyst: | |||
| mkdir -p /var/tmp/catalyst/snapshots | |||
| wget -O gentoo-latest.tar.xz http://distfiles.gentoo.org/snapshots/gentoo-latest.tar.xz | |||
| mkdir -p /var/tmp/catalyst/builds/default | |||
| cd /var/tmp/catalyst/builds/default | |||
| tar -C /final -cf stage3-amd64-latest.tar . | |||
| xz -9v stage3-amd64-latest.tar | |||
| rm -rf /final | |||
| wget -O stage1.spec "https://gitweb.gentoo.org/proj/releng.git/plain/releases/specs/amd64/stage1.spec" | |||
| wget -O stage2.spec "https://gitweb.gentoo.org/proj/releng.git/plain/releases/specs/amd64/stage2.spec" | |||
| wget -O stage3.spec "https://gitweb.gentoo.org/proj/releng.git/plain/releases/specs/amd64/stage3.spec" | |||
| sed -i -e 's/@TIMESTAMP@/latest/' -e '/^portage_confdir: /d' *.spec | |||
| 
 | |||
| Build the stage3: | |||
| emerge catalyst | |||
| catalyst -f stage1.spec | |||
| 
 | |||
| Clean up chroot: | |||
| umount -R proc sys dev etc/resolv.conf | |||
| @ -0,0 +1,116 @@ | |||
| This is done in a chroot, from a 10.0 chapter 7 system. To do this on a live | |||
| system, you'll need a kernel, initscripts, and some way to connect to the | |||
| internet, such as iproute+dhcpcd. | |||
| 
 | |||
| Make sure you bind-mount your host's /etc/resolv.conf to the chroot, such as: | |||
| touch $LFS/etc/resolv.conf | |||
| mount -v --bind /etc/resolv.conf $LFS/etc/resolv.conf | |||
| This will allow programs to resolve DNS names, which is necessary to download things. | |||
| 
 | |||
| Also mount /dev/shm, in addition to the mounts in chapter 7.3: | |||
| mount -t tmpfs tmpfs $LFS/dev/shm | |||
| 
 | |||
| Run the following chapters (avoid tests and docs): | |||
| - 8.9. Zlib-1.2.11 | |||
| - 8.10. Bzip2-1.0.8 | |||
| - 8.34. Bash-5.0 | |||
| - 8.47. Libffi-3.3 | |||
| - 8.48. OpenSSL-1.1.1g | |||
| - 8.49. Python-3.8.5 (!--with-system-expat --without-ensurepip) | |||
| 
 | |||
| Symlink python3: | |||
| ln -sf python3 /usr/bin/python | |||
| 
 | |||
| Install ca-certificates: | |||
| make | |||
| mkdir -p /usr/share/ca-certificates | |||
| make install | |||
| ( cd /usr/share/ca-certificates | |||
|   find . -name '*.crt' | LC_ALL=C sort | cut -b3- | |||
| ) > /etc/ca-certificates.conf | |||
| mkdir -p /etc/ssl/certs | |||
| update-ca-certificates | |||
| 
 | |||
| Install wget: | |||
| ./configure --prefix=/usr --sysconfdir=/etc --with-ssl=openssl --with-libssl-prefix=/usr | |||
| make | |||
| make install | |||
| 
 | |||
| Install portage (https://wiki.gentoo.org/wiki/Portage#Tarball): | |||
| python setup.py install | |||
| echo "portage:x:250:250:portage:/var/tmp/portage:/bin/false" >> /etc/passwd | |||
| echo "portage::250:portage" >> /etc/group | |||
| 
 | |||
| Install repository (https://bouncer.gentoo.org/fetch/root/all/snapshots/, grab gentoo-*.tar.xz): | |||
| rm -rf /var/db/repos | |||
| mkdir -p /var/db/repos | |||
| mv gentoo-*/ /var/db/repos/gentoo | |||
| 
 | |||
| Configure portage: | |||
| mkdir -p /etc/portage | |||
| ln -sf ../../var/db/repos/gentoo/profiles/default/linux/amd64/17.1/ /etc/portage/make.profile | |||
| 
 | |||
| emerge -O1 sys-apps/baselayout | |||
| . /etc/profile | |||
| cat /var/lib/gentoo/news/news-gentoo.unread >> /var/lib/gentoo/news/news-gentoo.read | |||
| rm /var/lib/gentoo/news/news-gentoo.unread | |||
| touch /var/lib/gentoo/news/news-gentoo.unread | |||
| dispatch-conf | |||
| 
 | |||
| Bootstrap multilib compiler: | |||
| emerge -O1 sys-apps/gentoo-functions sys-devel/binutils-config sys-devel/gcc-config app-portage/elt-patches sys-devel/binutils dev-libs/gmp dev-libs/mpfr dev-libs/mpc | |||
| 
 | |||
| emerge -Of sys-devel/gcc | |||
| tar xf /var/cache/distfiles/gcc-*.tar.* && cd gcc-*/ && mkdir build && cd build | |||
| mkdir -p /tmp/gcc/include | |||
| touch /tmp/gcc/include/limits.h | |||
| ../configure --prefix=/usr --with-local-prefix=/tmp/gcc --with-newlib --without-headers --disable-shared --disable-threads --disable-bootstrap --enable-multilib --enable-languages=c,c++ | |||
| make all-gcc all-target-libgcc | |||
| make install-gcc install-target-libgcc | |||
| rm -rf /tmp/gcc | |||
| cd ../.. && rm -rf gcc-*/ | |||
| 
 | |||
| Remove use of gcc-multilib-bootstrap, since that defeats the point of building | |||
| everything from source, and we don't need it with this hack: | |||
| cd /var/db/repos/gentoo/sys-libs/glibc | |||
| cp -u glibc-2.31-r6.ebuild{,.orig} | |||
| sed -e '/gcc-multilib-bootstrap/d' glibc-2.31-r6.ebuild.orig > glibc-2.31-r6.ebuild | |||
| ebuild glibc-2.31-r6.ebuild manifest | |||
| PYTHON_COMPAT_OVERRIDE=python3 emerge -O1 sys-libs/glibc | |||
| 
 | |||
| ...in case of downgrade, reinstall any LFS programs that broke (using the | |||
| /tools toolchain?) until portage works again, and reinstall glibc, run | |||
| ldconfig and fix all warnings. | |||
| Alternatively, build LFS with an older glibc or unmask the same glibc version | |||
| that LFS has... | |||
| 
 | |||
| Clean up glibc modifications: | |||
| cd /var/db/repos/gentoo/sys-libs/glibc | |||
| mv glibc-2.31-r6.ebuild.orig glibc-2.31-r6.ebuild | |||
| ebuild glibc-2.31-r6.ebuild manifest | |||
| 
 | |||
| Not sure if this is necessary if not downgrading, but for good measure: | |||
| tar xf /var/cache/distfiles/gcc-*.tar.* && cd gcc-*/ && mkdir build && cd build | |||
| ../libstdc++-v3/configure --prefix=/usr --enable-multilib | |||
| make | |||
| make install | |||
| cd ../.. && rm -rf gcc-*/ | |||
| 
 | |||
| emerge -O1 sys-devel/gcc | |||
| PYTHON_COMPAT_OVERRIDE=python3 emerge -O1 sys-libs/glibc # might be necessary to merge _after_ pax-utils? | |||
| 
 | |||
| Bootstrap rest of system: | |||
| emerge -O1 sys-libs/libseccomp app-misc/pax-utils # required by at least ncurses and sandbox | |||
| emerge -O1 sys-apps/sandbox | |||
| USE=-acl emerge -O1 sys-devel/gettext # circular dep, bundles libxml2, abusing this fact... | |||
| USE=-acl emerge -O1 net-misc/rsync # required by linux-headers | |||
| emerge -O1 dev-util/pkgconf # required by pax-utils | |||
| cd /var/db/repos/gentoo/scripts | |||
| ./bootstrap.sh | |||
| 
 | |||
| USE=-pam emerge -O1 sys-libs/libcap # circular dep | |||
| USE='-acl -xattr -pam' emerge -O1 sys-apps/shadow # required by acct-group | |||
| emerge -abe @system | |||
| 
 | |||
| Unpollute the system by installing it somewhere else: | |||
| ROOT=/final emerge -K @system | |||
| @ -0,0 +1,182 @@ | |||
| Based on portage-3.0.8 and gentoo-20201029 | |||
| 
 | |||
| The specifics of this document (software versions and whatnot) are subject to | |||
| change as gentoo evolves, but I hope the big lines of it won't change too | |||
| much. | |||
| 
 | |||
| This guide starts off with a system built from build_cross.sh, built for | |||
| x86_64 with i686 multilib. | |||
| It might be possible to adapt both that script, and this guide for other | |||
| architectures, but this guide won't go into detail. | |||
| 
 | |||
| You should be running a system with a x86_64 kernel (with i686 support). | |||
| Install the required sources (outlined in gentoo.wget-list) into /sources. | |||
| 
 | |||
| To enter the bootstrap system as a chroot, use the following commands to set | |||
| up the filesystems and entering: | |||
| mkdir -p proc sys dev tmp | |||
| mount -t proc proc proc | |||
| mount -t sysfs sysfs sys | |||
| mount -t devtmpfs devtmpfs dev | |||
| mount -t devpts devpts dev/pts | |||
| mount -t tmpfs tmpfs dev/shm | |||
| mkdir -p etc | |||
| touch etc/resolv.conf | |||
| mount --bind /etc/resolv.conf etc/resolv.conf | |||
| ./bootstrap/bin/chroot . /bootstrap/bin/env -i PATH=/bin:/sbin:/usr/bin:/usr/sbin:/bootstrap/bin:/bootstrap/sbin HOME=/root /bootstrap/bin/sh -l | |||
| 
 | |||
| To install all the prerequisite tools, place the sources (listed in | |||
| gentoo.wget-list) under /sources, then run the gentoo_tools.sh script. | |||
| 
 | |||
| Install ebuild repository: | |||
| tar xf gentoo-*.tar.xz | |||
| mkdir -p /var/db/repos/ | |||
| mv gentoo-*/ /var/db/repos/gentoo | |||
| 
 | |||
| Configure portage: | |||
| echo "root:x:0:0:root:/root:/bin/bash" > /etc/passwd | |||
| echo "root:x:0:root" > /etc/group | |||
| echo "portage:x:250:250:portage:/var/tmp/portage:/bin/false" >> /etc/passwd | |||
| echo "portage::250:portage" >> /etc/group | |||
| mkdir -p /tmp /root | |||
| chown root.root /tmp /root | |||
| chmod 1777 /tmp | |||
| chmod 0700 /root | |||
| ln -sf ../../var/db/repos/gentoo/profiles/default/linux/amd64/17.1/ /etc/portage/make.profile | |||
| cat > /etc/portage/make.conf << 'EOF' | |||
| FEATURES=-pid-sandbox | |||
| ROOTPATH=/bootstrap/bin:/bootstrap/sbin | |||
| EOF | |||
| 
 | |||
| Install some prerequisites: | |||
| emerge -O1 sys-apps/gentoo-functions  # Used by elt-patches and a ton of other things | |||
| emerge -O1 app-portage/elt-patches  # required by elibtoolize(libtool.eclass), used to install any library | |||
| 
 | |||
| TODO: Doing this is *BAAAAD*, since we're linking the compiler and libraries | |||
| with a potentially incompatible version of glibc in /tools, and upgrading it | |||
| afterwards. Glibc should always be installed first into a new prefix! | |||
| I just can't be assed to discuss the manual upgrade of binutils+gcc and their | |||
| dependency tools. | |||
| 
 | |||
| TODO: Consider installing sys-devel/gnuconfig for the config.sub and | |||
| config.guess scripts. | |||
| 
 | |||
| Bootstrap GCC: | |||
| # Install linker at final location, | |||
| #  so programs built with the new compiler can run... | |||
| mkdir -p /lib64 /lib | |||
| ln -sf /bootstrap/lib/ld-linux-x86-64.so.2 /lib64/ld-linux-x86-64.so.2 | |||
| ln -sf /bootstrap/lib32/ld-linux.so.2 /lib/ld-linux.so.2 | |||
| # Target compiler expects target limits.h to be available in target prefix... | |||
| mkdir -p /usr/include | |||
| ln -sf /bootstrap/include/limits.h /usr/include/limits.h | |||
| # GCC errors out at the first incompatible startfile in LIBRARY_PATH, | |||
| #   so multilib paths need to be fixed to match the final compiler... | |||
| mkdir -p /usr/lib64 /usr/lib | |||
| ln -sf /bootstrap/lib/crti.o /bootstrap/lib/crtn.o /bootstrap/lib/Scrt1.o /usr/lib64/ | |||
| ln -sf /bootstrap/lib32/crti.o /bootstrap/lib32/crtn.o /bootstrap/lib32/Scrt1.o /usr/lib/ | |||
| # Reconfigure GCC to match the config of the final compiler as much as possible. | |||
| cat > /etc/portage/gcc.specs << 'EOF' | |||
| *multilib: | |||
| . !m64 !m32;64:../lib64 m64 !m32;32:../lib !m64 m32; | |||
| 
 | |||
| *startfile_prefix_spec: | |||
| /usr/lib/ | |||
| 
 | |||
| *link: | |||
| + %{!shared:%{!static:-dynamic-linker %{m32:/lib/ld-linux.so.2;:/lib64/ld-linux-x86-64.so.2}}} | |||
| 
 | |||
| *cpp: | |||
| + -isystem /usr/include | |||
| EOF | |||
| cat > /etc/portage/bashrc << 'EOF' | |||
| export C_INCLUDE_PATH=/usr/include:/bootstrap/include | |||
| export CPLUS_INCLUDE_PATH=/usr/include:/bootstrap/include | |||
| export LIBRARY_PATH=/usr/lib64:/usr/lib:/bootstrap/lib:/bootstrap/lib32 | |||
| export LD_LIBRARY_PATH=/usr/lib64:/usr/lib:/bootstrap/lib:/bootstrap/lib32 | |||
| export CC='gcc -specs=/etc/portage/gcc.specs' | |||
| export CXX='g++ -specs=/etc/portage/gcc.specs' | |||
| EOF | |||
| emerge -O1 sys-libs/zlib dev-libs/gmp dev-libs/mpfr dev-libs/mpc | |||
| emerge -O1 sys-devel/binutils-config sys-devel/binutils | |||
| emerge -O1 sys-devel/gcc-config sys-devel/gcc | |||
| /usr/bin/gcc-config 1  # Not automatic unlike binutils-config | |||
| 
 | |||
| Make portage forget about everything it's just installed, so it's all rebuilt | |||
| first thing when running bootstrap.sh/emerge later: | |||
| rm -rf /var/db/pkg | |||
| 
 | |||
| Install initial glibc: | |||
| CC=gcc emerge -O1 sys-kernel/linux-headers | |||
| mkdir -p /usr/bin/ | |||
| ln -sf /bootstrap/bin/python3 /usr/bin/python3tmp | |||
| PYTHON_COMPAT_OVERRIDE=python3tmp emerge -O1 sys-libs/glibc | |||
| rm -f /usr/bin/python3tmp | |||
| 
 | |||
| This compiler and dynamic linker will now pick up everything correctly under | |||
| /usr instead of /bootstrap: | |||
| rm -f /etc/portage/bashrc /etc/portage/gcc.specs | |||
| 
 | |||
| Build the remainder of bootstrap utilities: | |||
| cd /var/db/repos/gentoo/scripts | |||
| rm -f /etc/profile.env | |||
| mkdir -p /var/run | |||
| USE=-nls ./bootstrap.sh | |||
| 
 | |||
| You'll get tons of LD_PRELOAD libsandbox.so errors from programs still linked | |||
| against /bootstrap. This is fine to ignore, and will gradually disappear as | |||
| programs are rebuilt. | |||
| 
 | |||
| It'd be nice to remove the bootstrap tools now, but among wget/openssl, gawk, | |||
| gzip, grep, and other tools, they're still required for some reason. | |||
| 
 | |||
| From this point onward, you're pretty much on your own to beat portage into | |||
| performing an `emerge -e @system` and fixing any unspecified dependencies you | |||
| encounter along the way. This can be done in a whole number of ways, and will | |||
| differ on any given day, since this is painfully unsupported by gentoo devs. | |||
| Because the order in which you install everything can differ wildly, and | |||
| consequently affect the output of your build, it is advised to do a second | |||
| `emerge -e @system` afterwards, for sanity. Below I detail my most recent | |||
| procedure, which, I can't stress enough, may or may not work at the time | |||
| you're reading this. | |||
| 
 | |||
| Fix circular dependencies: | |||
| USE=-filecaps emerge -O1 sys-libs/pam | |||
| USE='-acl -xattr' emerge -O1 sys-apps/shadow  # required by acct-group/acct-user | |||
| 
 | |||
| Verify there's no circular deps left, for sanity: | |||
| emerge -fe @system | |||
| 
 | |||
| Build everything: | |||
| emerge -be @system | |||
| 
 | |||
| Clean up bootstrap tools/configs: | |||
| rm -rf /bootstrap /sources | |||
| rm -f /etc/portage/make.conf | |||
| 
 | |||
| Reinitialize environment: | |||
| env-update | |||
| exec bash -l | |||
| 
 | |||
| Consider rebuilding everything again without /bootstrap, as surely a lot | |||
| errors popped up during the first emerge -be @system, can't be sure enough. | |||
| 
 | |||
| To install everything into a clean root: | |||
| ROOT=/final emerge -K @system | |||
| 
 | |||
| Prepare files for catalyst: | |||
| mkdir -p /var/tmp/catalyst/snapshots | |||
| wget -O gentoo-latest.tar.xz http://distfiles.gentoo.org/snapshots/gentoo-latest.tar.xz | |||
| mkdir -p /var/tmp/catalyst/builds/default | |||
| cd /var/tmp/catalyst/builds/default | |||
| tar -C /final -cf stage3-amd64-latest.tar . | |||
| xz -9v stage3-amd64-latest.tar | |||
| rm -rf /final | |||
| wget -O stage1.spec "https://gitweb.gentoo.org/proj/releng.git/plain/releases/specs/amd64/stage1.spec" | |||
| wget -O stage2.spec "https://gitweb.gentoo.org/proj/releng.git/plain/releases/specs/amd64/stage2.spec" | |||
| wget -O stage3.spec "https://gitweb.gentoo.org/proj/releng.git/plain/releases/specs/amd64/stage3.spec" | |||
| sed -i -e 's/@TIMESTAMP@/latest/' -e '/^portage_confdir: /d' *.spec | |||
| 
 | |||
| Build the stage3: | |||
| emerge catalyst | |||
| catalyst -f stage1.spec | |||
| @ -0,0 +1,218 @@ | |||
| #!/bin/sh | |||
| set -e | |||
| 
 | |||
| # This script builds and upgrades a bunch of prerequisite tools for gentoo | |||
| # There's just too many small details about these to cover properly in a text file... | |||
| 
 | |||
| # Maintenance note: Run gentoo_gen.sh in a fully-updated stable system to get | |||
| #   the appropriate package versions and URLs. | |||
| version_xz=5.2.5 | |||
| version_zlib=1.2.11 | |||
| version_libffi=3.3 | |||
| version_python=3.7.9 | |||
| version_perl=5.30.3 | |||
| version_openssl=1.1.1g | |||
| version_wget=1.20.3 | |||
| version_rsync=3.2.3 | |||
| version_mktemp=1.7 | |||
| version_ca_certificates=20200601 | |||
| version_portage=3.0.8 | |||
| version_m4=1.4.18 | |||
| version_bison=3.7.1 | |||
| version_make=4.2.1 | |||
| version_sed=4.8 | |||
| 
 | |||
| export MAKEFLAGS="-j${NPROC:-$(getconf _NPROCESSORS_ONLN)}" | |||
| 
 | |||
| # This symlink isn't provided by the bootstrap, but is necessary for a ton of tools | |||
| mkdir -p /usr/bin | |||
| ln -sf ../../bootstrap/bin/env /usr/bin/env | |||
| 
 | |||
| cd /sources | |||
| export PATH=/bootstrap/bin | |||
| 
 | |||
| # Xz is required to unpack a lot of tarballs, including the Portage tree. | |||
| # app-arch/xz-utils: | |||
| rm -rf xz-$version_xz | |||
| tar zxf xz-$version_xz.tar.gz | |||
| ( cd xz-$version_xz | |||
|     ./configure --prefix=/bootstrap | |||
|     make | |||
|     make install | |||
| ) | |||
| rm -rf xz-$version_xz | |||
| 
 | |||
| # Zlib is required for the zlib Python module, used by Portage. | |||
| # sys-libs/zlib: | |||
| rm -rf zlib-$version_zlib | |||
| tar zxf zlib-$version_zlib.tar.gz | |||
| ( cd zlib-$version_zlib | |||
|     ./configure --prefix=/bootstrap | |||
|     make | |||
|     make install | |||
| ) | |||
| rm -rf zlib-$version_zlib | |||
| 
 | |||
| # Libffi is required for the _ctypes Python module, used by Portage. | |||
| # dev-libs/libffi: | |||
| rm -rf libffi-$version_libffi | |||
| tar zxf libffi-$version_libffi.tar.gz | |||
| ( cd libffi-$version_libffi | |||
|     # Fix an error that crops up due to using coreutils-5.0 | |||
|     sed -i -e 's/tail -1/tail -n 1/g' configure | |||
|     ./configure --prefix=/bootstrap | |||
|     make | |||
|     make install | |||
| ) | |||
| rm -rf libffi-$version_libffi | |||
| 
 | |||
| # Portage is written in Python. Modern glibc also needs it to build. | |||
| # dev-lang/python: | |||
| rm -rf Python-$version_python | |||
| tar Jxf Python-$version_python.tar.xz | |||
| ( cd Python-$version_python | |||
|     ./configure --prefix=/bootstrap --without-ensurepip | |||
|     make | |||
|     make install | |||
|     ln -sf python3 /bootstrap/bin/python | |||
| ) | |||
| rm -rf Python-$version_python | |||
| 
 | |||
| # Perl is required to build OpenSSL as well as some other things. | |||
| # dev-lang/perl: | |||
| rm -rf perl-$version_perl | |||
| tar Jxf perl-$version_perl.tar.xz | |||
| ( cd perl-$version_perl | |||
|     # Fix pwd hardcode | |||
|     sed -i -e "s@'/bin/pwd'@'/bootstrap/bin/pwd'@" dist/PathTools/Cwd.pm | |||
|     ./Configure -des -Dprefix=/bootstrap -Dcc=gcc -Dinstallusrbinperl=n | |||
|     make | |||
|     make install | |||
| ) | |||
| rm -rf perl-$version_perl | |||
| 
 | |||
| # OpenSSL is required for https support in wget. | |||
| # dev-libs/openssl: | |||
| rm -rf openssl-$version_openssl | |||
| tar zxf openssl-$version_openssl.tar.gz | |||
| ( cd openssl-$version_openssl | |||
|     ./config --prefix=/bootstrap --openssldir=/bootstrap/etc/ssl | |||
|     make | |||
|     make install | |||
| ) | |||
| rm -rf openssl-$version_openssl | |||
| 
 | |||
| # Wget is required to download the portage tree and packages. | |||
| # net-misc/wget: | |||
| rm -rf wget-$version_wget | |||
| tar zxf wget-$version_wget.tar.gz | |||
| ( cd wget-$version_wget | |||
|     ./configure --prefix=/bootstrap --with-ssl=openssl --with-libssl-prefix=/bootstrap | |||
|     make | |||
|     make install | |||
| ) | |||
| rm -rf wget-$version_wget | |||
| 
 | |||
| # Rsync is optional to run emerge-webrsync or emerge --sync, | |||
| #   and required for linux-headers. | |||
| # net-misc/rsync: | |||
| rm -rf rsync-$version_rsync | |||
| tar zxf rsync-$version_rsync.tar.gz | |||
| ( cd rsync-$version_rsync | |||
|     ./configure --prefix=/bootstrap --disable-simd --disable-xxhash --disable-zstd --disable-lz4 | |||
|     make | |||
|     make install | |||
| ) | |||
| rm -rf rsync-$version_rsync | |||
| 
 | |||
| # Mktemp is required by ca-certificates as well as Portage for installing packages. | |||
| #   To avoid upgrading all coreutils, this standalone version is used. | |||
| # custom/mktemp: | |||
| rm -rf mktemp-$version_mktemp | |||
| tar zxf mktemp-$version_mktemp.tar.gz | |||
| ( cd mktemp-$version_mktemp | |||
|     ./configure --prefix=/bootstrap | |||
|     make | |||
|     make install | |||
| ) | |||
| rm -rf mktemp-$version_mktemp | |||
| 
 | |||
| # To verify https connections, wget/openssl need some certificates. | |||
| #   They're installed directly here, instead of properly installing | |||
| #   update-ca-certificates. | |||
| # app-misc/ca-certificates: | |||
| rm -rf ca-certificates_$version_ca_certificates | |||
| tar Jxf ca-certificates_$version_ca_certificates.tar.xz | |||
| mv work ca-certificates_$version_ca_certificates | |||
| ( cd ca-certificates_$version_ca_certificates | |||
|     make -C mozilla | |||
|     mkdir -p /bootstrap/share/ca-certificates/mozilla | |||
|     make -C mozilla CERTSDIR=/bootstrap/share/ca-certificates/mozilla install | |||
|     find mozilla -name '*.crt' | LC_ALL=C sort > ca-certificates.conf | |||
|     ./sbin/update-ca-certificates \ | |||
|         --certsconf "$PWD/ca-certificates.conf" \ | |||
|         --certsdir /bootstrap/share/ca-certificates \ | |||
|         --etccertsdir /bootstrap/etc/ssl/certs | |||
| ) | |||
| rm -rf ca-certificates_$version_ca_certificates | |||
| 
 | |||
| # Finally, install the package manager. | |||
| # sys-apps/portage: | |||
| rm -rf portage-$version_portage | |||
| tar jxf portage-$version_portage.tar.bz2 | |||
| ( cd portage-$version_portage | |||
|     python3 setup.py install --system-prefix=/bootstrap | |||
| 
 | |||
|     # This path is hardcoded... | |||
|     # Symlinking the individual files so installing the final package will replace them properly. | |||
|     mkdir -p /usr/share/portage/config/sets | |||
|     ln -sf ../../../../bootstrap/share/portage/config/make.globals /usr/share/portage/config/make.globals | |||
|     ln -sf ../../../../bootstrap/share/portage/config/repos.conf /usr/share/portage/config/repos.conf | |||
|     ln -sf ../../../../../bootstrap/share/portage/config/sets/portage.conf /usr/share/portage/config/sets/portage.conf | |||
| ) | |||
| rm -rf portage-$version_portage | |||
| 
 | |||
| 
 | |||
| ## ...but that's not all! | |||
| ## Here come the dependencies to build the initial gcc/glibc! | |||
| ## These can be installed directly with portage but it's significantly cleaner not to... | |||
| 
 | |||
| # sys-devel/m4 (required by glibc-2.31): | |||
| rm -rf m4-$version_m4 | |||
| tar Jxf m4-$version_m4.tar.xz | |||
| ( cd m4-$version_m4 | |||
|     ./configure --prefix=/bootstrap | |||
|     make | |||
|     make install | |||
| ) | |||
| rm -rf m4-$version_m4 | |||
| 
 | |||
| # sys-devel/bison (required by glibc-2.31): | |||
| rm -rf bison-$version_bison | |||
| tar Jxf bison-$version_bison.tar.xz | |||
| ( cd bison-$version_bison | |||
|     ./configure --prefix=/bootstrap | |||
|     make | |||
|     make install | |||
| ) | |||
| rm -rf bison-$version_bison | |||
| 
 | |||
| # sys-devel/make (>=4.0 required by glibc-2.31): | |||
| rm -rf make-$version_make | |||
| tar jxf make-$version_make.tar.bz2 | |||
| ( cd make-$version_make | |||
|     ./configure --prefix=/bootstrap | |||
|     make | |||
|     make install | |||
| ) | |||
| rm -rf make-$version_make | |||
| 
 | |||
| # sys-apps/sed (>=4.3 required by glibc-2.31 for -E option): | |||
| rm -rf sed-$version_sed | |||
| tar Jxf sed-$version_sed.tar.xz | |||
| ( cd sed-$version_sed | |||
|     ./configure --prefix=/bootstrap | |||
|     make | |||
|     make install | |||
| ) | |||
| rm -rf sed-$version_sed | |||
| @ -0,0 +1,131 @@ | |||
| Current LFS version: 10.0 | |||
| 
 | |||
| Substantial changes were introduced in LFS 10.0, so these notes will probably | |||
| not apply to anything below this version. This version should be easier to | |||
| bootstrap like this, anyway. | |||
| 
 | |||
| Ignore the Host System Requirements, a lot of these either don't apply or will | |||
| be procured as we go through this guide. | |||
| Ignore, as well, the creation of a new partition or user, as the necessary | |||
| tools to achieve this aren't available in the bootstrap toolset. We will be | |||
| building everything on whatever partition the bootstrap toolset was installed. | |||
| 
 | |||
| Install the sources under /sources right next to the /bootstrap directory. | |||
| This can't be done when inside the bootstrap system as no networking utilities | |||
| are yet installed. For the "xz" package, download a .tar.gz or .tar.bz2 | |||
| package, as the xz utilities aren't included with the bootstrap utilities. | |||
| 
 | |||
| To enter the bootstrap system as a chroot, use the following commands to set | |||
| up the filesystems and entering: | |||
| mkdir -p sys proc dev tmp | |||
| mount -o ro -t devtmpfs devtmpfs dev | |||
| mount -o ro -t devpts devpts dev/pts | |||
| mount -o ro -t sysfs sysfs sys | |||
| mount -o ro -t proc proc proc | |||
| ./bootstrap/bin/chroot . /bootstrap/bin/env -i PATH=/bootstrap/bin HOME=/root /bin/sh -l | |||
| 
 | |||
| Set the LFS variable to either / or keep it blank, as the bootstrap tools are | |||
| self-contained in /bootstrap, and can be removed afterwards, keeping a clean | |||
| system anyway. | |||
| 
 | |||
| The bootstrap tools are all x86, if you're going to be cross-compiling for | |||
| x86_64, make sure the command `uname -m` returns `x86_64`, or manually | |||
| substitute it throughout the LFS commands you execute. | |||
| 
 | |||
| In chapter 4.4 Setting Up the Environment, make sure LFS is set according to | |||
| what's been explained, and PATH=$LFS/tools/bin:/bootstrap/bin. We don't want | |||
| to use /usr/bin and /bin until chapter 7. Also define LFS_TGT after setting PATH. | |||
| Also `mkdir /root` before creating the files. If you don't want the "I have no | |||
| name!" prompt, you shouldn't use '\u' in the PS1 variable. | |||
| A finished bashrc/bash_profile looks like: | |||
| mkdir -p /root | |||
| cat > ~/.bash_profile << "EOF" | |||
| exec env -i HOME=$HOME TERM=$TERM PS1='\w\$ ' /bin/bash | |||
| EOF | |||
| cat > ~/.bashrc << "EOF" | |||
| set +h | |||
| umask 022 | |||
| LFS= | |||
| LC_ALL=POSIX | |||
| PATH=$LFS/tools/bin:/bootstrap/bin | |||
| LFS_TGT=$(uname -m)-lfs-linux-gnu | |||
| export LFS LC_ALL LFS_TGT PATH | |||
| EOF | |||
| source ~/.bash_profile | |||
| 
 | |||
| Once you get to chapter 5, you will need to add a couple of tools to the | |||
| /bootstrap toolset, by building them from the sources you've downloaded for LFS. | |||
| 
 | |||
| You'll need to build the following packages: | |||
| - xz-5.2.5 (required to unpack .tar.xz archives) | |||
| - sed-4.8 (required by linux-headers for -E option) | |||
| - m4-1.4.18 (required by bison) | |||
| - bison-3.7.1 (required by glibc) | |||
| - grep-3.4 (required by glibc for -o option) | |||
| - make-4.3 (required by glibc) | |||
| - Python-3.8.5 (required by glibc) | |||
| 
 | |||
| Install them by unpacking them (see "General Compilation Instructions" chapter), | |||
| and running: | |||
| ./configure --prefix=/bootstrap --build=i686-pc-linux-gnu | |||
| make | |||
| make install | |||
| 
 | |||
| Python with: | |||
| ./configure --prefix=/bootstrap --build=i686-pc-linux-gnu --without-ensurepip | |||
| 
 | |||
| Now, you can run chapter 5 and 6, with the following exceptions: | |||
| 
 | |||
| 5.3. GCC-10.2.0 - Pass 1: | |||
|     Add --with-stage1-libs='-lstdc++ -lsupc++' CC='gcc -std=c11' | |||
|     to the ../configure command. | |||
| 
 | |||
| 6.3. Ncurses-6.2: | |||
|     Use --disable-stripping during "main" ./configure | |||
| 
 | |||
| 6.4. Bash-5.0: | |||
|     Do not move bash to /bin or replace the /bin/sh symlink. We'll do this | |||
|     later. | |||
| 
 | |||
| Once you reach chapter 7, run the finishing bash install commands we skipped earlier: | |||
| mv $LFS/usr/bin/bash $LFS/bin/bash | |||
| ln -sfv bash $LFS/bin/sh | |||
| 
 | |||
| Now, if you're cross-building for x86_64, this is the point where you should | |||
| make sure you're either already running a compatible kernel, or you reboot | |||
| into one. You might be able to build one with the tools in /bootstrap and | |||
| /tools, but this guide won't cover this. Booting into this system instead of | |||
| chrooting will also require extra steps, not covered here. | |||
| 
 | |||
| You may skip chapters 7.1 and 7.2, since we've built everything as root, and | |||
| 7.3 may be skipped as well as we've already set up the chroot. However, you | |||
| should set up the PATH variable as described in chapter 7.4, by for example | |||
| modifying your bashrc: | |||
| cat > ~/.bash_profile << "EOF" | |||
| exec env -i HOME=$HOME TERM=$TERM PS1='\u:\w\$ ' /bin/bash | |||
| EOF | |||
| cat > ~/.bashrc << "EOF" | |||
| set +h | |||
| umask 022 | |||
| PATH=/bin:/usr/bin:/sbin:/usr/sbin | |||
| export PATH | |||
| EOF | |||
| source ~/.bash_profile | |||
| 
 | |||
| Chapter 7.5 onwards can be followed without any modifications. This is all | |||
| standard LFS stuff from here on. | |||
| 
 | |||
| It's probably not related to this specific bootstrap, but I had to run the | |||
| following extra commands during the remaining chapters: | |||
| 
 | |||
| 7.10. Perl-5.32.0: | |||
|     Run the following command after sh Configure: | |||
|     echo '#define MB_LEN_MAX 16' >> config.h | |||
| 
 | |||
| 7.13. Util-linux-2.36: | |||
|     Run the following command after ./configure: | |||
|     echo '#define SSIZE_MAX LONG_MAX' >> config.h | |||
| 
 | |||
| 8.15. M4-1.4.18: | |||
|     Run the following command after ./configure: | |||
|     echo '#define MB_LEN_MAX 16' >> lib/config.h | |||
| @ -0,0 +1,24 @@ | |||
| mktemp is a peculiar phenomenon in the linux world. | |||
| Well, I'm sure things like this happen more often, but, | |||
| 
 | |||
| Turns out, there once was an mktemp.c written for OpenBSD. | |||
| Distributions started including it, writing their own version, the usual. | |||
| Apparently, popularity of this tool became big enough, and incompatibilities | |||
| between versions arose significantly, that it was split off into its own | |||
| package and website, https://www.mktemp.org, around 2000. Written by Todd C. | |||
| Miller, the author of sudo! | |||
| This version was included in Debian under the package name "debianutils", with | |||
| the last known version being debianutils-2.8.4, where it was split into its | |||
| own "mktemp" package, both reflecting the state of version 1.5. | |||
| 
 | |||
| https://lists.gnu.org/archive/html/bug-coreutils/2007-10/msg00051.html | |||
| In 2007, GNU coreutils adds its own, slightly incompatible version of mktemp | |||
| with coreutils version 6.10. | |||
| I can only assume most linux distributions switched to it, because come 2008, | |||
| mktemp-1.6 releases, featuring GNU compatibility. | |||
| Debian switches to coreutils inmediately, while Slackware keeps it for another | |||
| decade, citing the incompatibilities, and installing the GNU version as | |||
| mktemp-gnu, only reverting this decision in 2018. | |||
| 
 | |||
| I could've sworn one of my scripts ran into the differences between mktemp-1.5 | |||
| and GNU mktemp, but I can't figure out what it was, and check for it, now. | |||
| @ -0,0 +1,98 @@ | |||
| # Contains a bunch of scrapped build procedures, for different purposes, | |||
| #   so the research may be reused at a later date... | |||
| 
 | |||
| # tar (1.13), not in guix: | |||
| # Builds and works correctly, but has the same bug with extracting gcc-4.6 | |||
| #   as tar-1.12 does, and that one doesn't require patches... | |||
| rm -rf tar-1.13 | |||
| gzip -cd tar-1.13.tar.gz | tar x | |||
| ( cd tar-1.13 | |||
|     sed -e 's/if (case_sensitive$/if (1/' \ | |||
|         lib/argmatch.c > /tmp/sed; mv /tmp/sed lib/argmatch.c | |||
| 
 | |||
|     CC=tcc ./configure --host=i686-pc-linux-gnu --disable-nls | |||
| 
 | |||
|     echo '#define __MES_MODE_T' >> config.h | |||
|     echo '#define S_ISLNK(Mode) (((Mode) & S_IFMT) == S_IFLNK)' >> config.h | |||
| 
 | |||
|     make AR='tcc -ar' | |||
|     install -Dm755 src/tar /bin/tar | |||
| ) | |||
| rm -rf tar-1.13 | |||
| 
 | |||
| # tar (1.14), not in guix: | |||
| # If this can be got to work, the build of tar-1.22 with gcc2 can be dropped. | |||
| # Builds, but extracting anything fails... | |||
| rm -rf tar-1.14 | |||
| bzip2 -cd tar-1.14.tar.bz2 | tar x | |||
| ( cd tar-1.14 | |||
|     # asctime doesn't exist in mes-libc and isn't used anyway... | |||
|     sed -e 's/asctime (tm)/NULL/' \ | |||
|         lib/time_r.c > /tmp/sed; mv /tmp/sed lib/time_r.c | |||
| 
 | |||
|     # mode_t and friends are in sys/stat.h... | |||
|     sed -e 's@<sys/types.h>@<sys/stat.h>@' \ | |||
|         lib/modechange.h > /tmp/sed; mv /tmp/sed lib/modechange.h | |||
| 
 | |||
|     # rewrite src/xheader.c:xheader_set_option to not use strtok: | |||
|     #  char *token = string; | |||
|     #  for (;;) | |||
|     #    { | |||
|     #      char *t = strchr (token, ','); | |||
|     #      if (t) *t = '\0'; | |||
|     # | |||
|     #      char *p = strchr (token, '='); | |||
|     #      if (!p) | |||
|     #        xheader_set_single_keyword (token); | |||
|     #      else | |||
|     #        xheader_set_keyword_equal (token, p); | |||
|     # | |||
|     #      if (!t) break; | |||
|     #      token = t + 1; | |||
|     #    } | |||
| 
 | |||
|     CC=tcc LD=tcc ./configure --disable-nls | |||
| 
 | |||
|     # Add linux kernel defines that are missing from mes-libc | |||
|     echo '#define MB_LEN_MAX 16' >> config.h | |||
|     echo '#define CLOCK_REALTIME 0' >> config.h | |||
|     echo '#define EPERM 1' >> config.h | |||
| 
 | |||
|     make AR='tcc -ar' | |||
|     install -Dm755 src/tar /bin/tar | |||
| ) | |||
| rm -rf tar-1.14 | |||
| 
 | |||
| # Options for a "minimal" bash-2.05b build | |||
| # Left out because even though it holds up just fine, no patches can be avoided | |||
| #   with the minimal config. | |||
| # It might however be interesting to use a minimal config as a bootstrap bin? | |||
|     CC='tcc -D_POSIX_VERSION=1' AR='tcc -ar' ./configure \ | |||
|         --build=i686-pc-linux-gnu \ | |||
|         --without-bash-malloc \ | |||
|         --enable-minimal-config \ | |||
|         --enable-cond-command \ | |||
|         --enable-dparen-arithmetic \ | |||
|         --enable-arith-for-command \ | |||
|         --enable-alias \ | |||
|         --disable-nls \ | |||
|         bash_cv_getcwd_calls_popen=no \ | |||
|         bash_cv_signal_vintage=posix \ | |||
|         ac_cv_func_working_mktime=yes | |||
| 
 | |||
| # gcc-4.6.4 build for build_binaries.sh | |||
|         mkdir build; cd build  # Build breaks without a build directory | |||
|         CFLAGS='-O2 -w' CXXFLAGS='-O2 -w' MAKEINFO=true ../configure \ | |||
|             --target=i686-bootstrap-linux-gnu \ | |||
|             --prefix="$prefix" \ | |||
|             --with-sysroot="$prefix" \ | |||
|             --with-local-prefix=/ \ | |||
|             --with-newlib \ | |||
|             --without-headers \ | |||
|             --disable-shared \ | |||
|             --disable-decimal-float \ | |||
|             --disable-threads \ | |||
|             --disable-nls \ | |||
|             --enable-languages=c | |||
|         make all-gcc all-target-libgcc | |||
|         make install-gcc install-target-libgcc | |||
| @ -0,0 +1,39 @@ | |||
| b3e158877f94e66ec1c8ef604e994851ee388b09  bash-2.05b.tar.gz | |||
| 8de012df1e4f3e91f571c3eb8ec45b43d7c747eb  bash-4.4.tar.gz | |||
| 66b4f057bf687126d7cc11d0a68ed89182541ae7  binutils-2.14.tar.bz2 | |||
| 3f0e3746a15f806a95dd079be2a7f43c17b18818  binutils-2.20.1a.tar.bz2 | |||
| d5514f5cf8eb89a3b20ac3b965f4463f14a5709a  busybox-1.31.1.tar.bz2 | |||
| bf7badf7e248e0ecf465d33c2f5aeec774209227  bzip2-1.0.8.tar.gz | |||
| ce67aacedfc917a92b5be62dd32095393c2f220c  coreutils-5.0.tar.bz2 | |||
| 1638f4ee4a7bd269411c57874f9e761ddee6d5ae  diffutils-2.7.tar.gz | |||
| f18e8aaee3f3d4173a1f598001003be8706d28b0  findutils-4.6.0.tar.gz | |||
| b9120c49429c309529a0af96203cec45a65790de  gawk-3.0.0.tar.gz | |||
| da1091cc39089c320f53d21fd2112bd7ce407de5  gawk-3.1.8.tar.bz2 | |||
| 5bb0b783a57a62b11f1f9bd2aa37145da221d3d0  gcc-4.9.4.tar.bz2 | |||
| b3e26d73b88c9606779a5ca277e3468e5ab163a1  gcc-boot-2.95.3.patch | |||
| 705f2e5f854e12e56ac2f8351c36385a4426127e  gcc-core-2.95.3.tar.gz | |||
| 9b2f25ac248d81c97bbe46690dc2c350e51996a5  gcc-core-4.6.4.tar.bz2 | |||
| e9a47df1bc5e39a9ef995484c315f5d47114daeb  gcc-g++-4.6.4.tar.bz2 | |||
| 3bebc5a3120eafde2144ced6ee151e6c4934c781  glibc-2.16.0.tar.bz2 | |||
| a2254adbc3486d24b56571cb464f77657579f6f1  glibc-2.2.5.tar.gz | |||
| ae3fb503e081f01d31eca5ebca8f2a1071f98414  glibc-boot-2.16.0.patch | |||
| 594fccd05081469bacf73fcdfa8e0ec49fb1f7d3  glibc-boot-2.2.5.patch | |||
| c011e8feaf1bb89158bd55eaabd7ef8fdd101a2c  gmp-4.3.2.tar.bz2 | |||
| 99e8f917557f1496cd3786e6c13f3900b8de24d8  grep-2.0.tar.gz | |||
| ca6794f49f3d838dab8add5d7895e90bd2479542  gzip-1.2.4.tar.gz | |||
| 1631a93d870d11efc7ecaa1450c39ad0a7ad7408  linux-4.14.tar.gz | |||
| d2085842f08e57d58d3e1cd75a5f0342a60e5f45  make-3.80.tar.bz2 | |||
| b8a8a99e4cb636a213aad3816dda827a92b9bbed  make-3.82.tar.bz2 | |||
| a318150059a2bcff6b58e765e203c05d0dfaccee  mes-0.22.tar.gz | |||
| 0d816fc6f2fea4e50f3ec75c644a6bd222294481  mescc-tools-Release_1.0.1.tar.gz | |||
| b8be66396c726fdc36ebb0f692ed8a8cca3bcc66  mpc-1.0.3.tar.gz | |||
| 7ca93006e38ae6e53a995af836173cf10ee7c18c  mpfr-2.4.2.tar.bz2 | |||
| 031062cf1a3c3e81e3dbae5ad2edbeff02ca198f  musl-1.2.1.tar.gz | |||
| 1b513b0615d6d273e0f1ec83e57f71e137c22d03  nyacc-0.99.3.tar.gz | |||
| 9a69f7191576549255f046487da420989d2834a6  patch-2.5.9.tar.gz | |||
| d37e775c2b72864e8c27b8bedcbf6dddf81598af  sed-1.18.tar.gz | |||
| 3a841f31e3ed38c684c2ca9249ae42e1e7bdd438  sed-4.0.6.tar.gz | |||
| a426b8551a4b61289a1bb6d677ada162f8bbc51a  tar-1.12.tar.gz | |||
| ca99a6ade7308f9293bdb04048cb335e52c63215  tar-1.22.tar.bz2 | |||
| cfe72731b87047a0085e8a4b3487e208ea488224  tcc-0.9.26-1103-g6e62e0e.tar.gz | |||
| 3bab3acd404ea92ba18e0c261d9d8cb2f366a8a5  tcc-0.9.27.tar.bz2 | |||
| @ -0,0 +1,39 @@ | |||
| https://ftp.gnu.org/gnu/bash/bash-2.05b.tar.gz | |||
| https://ftp.gnu.org/gnu/bash/bash-4.4.tar.gz | |||
| https://ftp.gnu.org/gnu/binutils/binutils-2.14.tar.bz2 | |||
| https://ftp.gnu.org/gnu/binutils/binutils-2.20.1a.tar.bz2 | |||
| https://ftp.gnu.org/gnu/coreutils/coreutils-5.0.tar.bz2 | |||
| https://ftp.gnu.org/gnu/diffutils/diffutils-2.7.tar.gz | |||
| https://ftp.gnu.org/gnu/findutils/findutils-4.6.0.tar.gz | |||
| https://ftp.gnu.org/gnu/gawk/gawk-3.0.0.tar.gz | |||
| https://ftp.gnu.org/gnu/gawk/gawk-3.1.8.tar.bz2 | |||
| https://ftp.gnu.org/gnu/gcc/gcc-2.95.3/gcc-core-2.95.3.tar.gz | |||
| https://ftp.gnu.org/gnu/gcc/gcc-4.6.4/gcc-core-4.6.4.tar.bz2 | |||
| https://ftp.gnu.org/gnu/gcc/gcc-4.6.4/gcc-g++-4.6.4.tar.bz2 | |||
| https://ftp.gnu.org/gnu/gcc/gcc-4.9.4/gcc-4.9.4.tar.bz2 | |||
| https://ftp.gnu.org/gnu/glibc/glibc-2.16.0.tar.bz2 | |||
| https://ftp.gnu.org/gnu/glibc/glibc-2.2.5.tar.gz | |||
| https://ftp.gnu.org/gnu/gmp/gmp-4.3.2.tar.bz2 | |||
| https://ftp.gnu.org/gnu/grep/grep-2.0.tar.gz | |||
| https://ftp.gnu.org/gnu/gzip/gzip-1.2.4.tar.gz | |||
| https://ftp.gnu.org/gnu/make/make-3.80.tar.bz2 | |||
| https://ftp.gnu.org/gnu/make/make-3.82.tar.bz2 | |||
| https://ftp.gnu.org/gnu/mes/mes-0.22.tar.gz | |||
| https://ftp.gnu.org/gnu/mpc/mpc-1.0.3.tar.gz | |||
| https://ftp.gnu.org/gnu/mpfr/mpfr-2.4.2.tar.bz2 | |||
| https://ftp.gnu.org/gnu/patch/patch-2.5.9.tar.gz | |||
| https://ftp.gnu.org/gnu/sed/sed-1.18.tar.gz | |||
| https://ftp.gnu.org/gnu/sed/sed-4.0.6.tar.gz | |||
| https://ftp.gnu.org/gnu/tar/tar-1.12.tar.gz | |||
| https://ftp.gnu.org/gnu/tar/tar-1.22.tar.bz2 | |||
| https://sourceware.org/pub/bzip2/bzip2-1.0.8.tar.gz | |||
| http://lilypond.org/janneke/mes/20191117/tcc-0.9.26-1103-g6e62e0e.tar.gz | |||
| https://download.savannah.gnu.org/releases/tinycc/tcc-0.9.27.tar.bz2 | |||
| https://download.savannah.gnu.org/releases/nyacc/nyacc-0.99.3.tar.gz | |||
| https://github.com/oriansj/mescc-tools/archive/Release_1.0.1/mescc-tools-Release_1.0.1.tar.gz | |||
| https://busybox.net/downloads/busybox-1.31.1.tar.bz2 | |||
| https://musl.libc.org/releases/musl-1.2.1.tar.gz | |||
| https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.14.tar.gz | |||
| https://git.savannah.gnu.org/cgit/guix.git/plain/gnu/packages/patches/gcc-boot-2.95.3.patch?id=0b652851b187dd0451c221f6dc173afbd7a555f4 | |||
| https://git.savannah.gnu.org/cgit/guix.git/plain/gnu/packages/patches/glibc-boot-2.2.5.patch?id=0b652851b187dd0451c221f6dc173afbd7a555f4 | |||
| https://git.savannah.gnu.org/cgit/guix.git/plain/gnu/packages/patches/glibc-boot-2.16.0.patch?id=0b652851b187dd0451c221f6dc173afbd7a555f4 | |||
					Loading…
					
					
				
		Reference in new issue