#!/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 # Force deterministic AR output patch -p1 -i ../binutils-2.14-force-deterministic.patch 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 # Force deterministic AR output patch -p1 -i ../binutils-2.14-force-deterministic.patch ./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 # Force deterministic AR output patch -p1 -i ../binutils-2.20.1-force-deterministic.patch ./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 # Fix hardcode of /bin/pwd sed -i -e 's@/bin/pwd@pwd@g' configure # Make build deterministic sed -i -e 's/__DATE__//g' -e 's/__TIME__//g' nscd/nscd_stat.c # 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 -L/gcc2/lib -DBOOTSTRAP_GLIBC=1' ../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 # Build deterministic archives #sed -i -e 's/$AR cru/$AR crD/' mpc/configure #sed -i -e '/^ARFLAGS =/s/cru/crD/' \ # zlib/Makefile.in \ # libcpp/Makefile.in \ # libdecnumber/Makefile.in # 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 # Build deterministic archives #sed -i -e 's/$AR cru/$AR crD/' configure ./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