diff --git a/gcc-bootstrap.scm b/gcc-bootstrap.scm new file mode 100644 index 0000000..3b4cfed --- /dev/null +++ b/gcc-bootstrap.scm @@ -0,0 +1,1704 @@ +;;; GNU Guix --- Functional package management for GNU +;;; +;;; Copyright © 2024 Stefan +;;; +;;; This file is not part of GNU Guix. +;;; +;;; GNU Guix is free software; you can redistribute it and/or modify it +;;; under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 3 of the License, or (at +;;; your option) any later version. +;;; +;;; GNU Guix is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with GNU Guix. If not, see . + +(define-module (gcc-bootstrap) + #:use-module (gnu packages) + #:use-module (gnu packages bootstrap) + #:use-module (gnu packages commencement) + #:use-module ((guix build utils) + #:select (modify-phases)) + #:use-module (guix build-system gnu) + #:use-module (guix build-system copy) + #:use-module (guix download) + #:use-module (guix gexp) + #:use-module (guix git-download) + #:use-module ((guix licenses) + #:prefix license:) + #:use-module (guix packages) + #:use-module (guix utils) + #:use-module (ice-9 optargs) + #:use-module ((srfi srfi-1) + #:select (first second))) + +(define*-public (with-shell shell . inputs) + "Return an alist of labeled inputs for a package definition. This alist will +contain the SHELL package labeled \"bash\" and all packages in INPUTS labeled +with their package names. + +The gnu-build-system relies on a package labeled \"bash\" and it is troublesome +to provide a different shell without resorting to labeled inputs." + (let ((bash (package + (name "bash") + (version #f) + (source #f) + (build-system #f) + (synopsis "Empty bash package") + (description + "A replacable \"bash\" package for the gnu-build-system.") + (home-page #f) + (license #f)))) + (modify-inputs (package-inputs (package + (inherit bash) + (inputs (append inputs (list bash))))) + (replace "bash" shell)))) + +;; This package offers the commands bash, gash, sh. +(define-public gash-boot + (@@ (gnu packages commencement) gash-boot)) + +;; This package offers the commands bzip2, gzip, tar, xz. +(define-public bootar + (@@ (gnu packages commencement) bootar)) + +;; This package offers many usual commands including tar and compress. Its tar +;; command depends on other packages offering bzip2, gziz, xz. It has to come +;; before bootar in input lists, to overwrite its tar. +(define-public gash-utils-boot + (@@ (gnu packages commencement) gash-utils-boot)) + +(define-public tcc-boot0 + (@@ (gnu packages commencement) tcc-boot0)) + +(define-public gnu-make-mesboot0 + (@@ (gnu packages commencement) gnu-make-mesboot0)) + +(define*-public (make-TCC-bootstrap name + libc + tcc + #:key + (cflags '()) + (make-flags '()) + patch-source-for-mes?) + "Make a tcc package named NAME using LIBC as its C library, built with the TCC +compiler using the additional CONFIGURE-FLAGS and MAKE-FLAGS. + +Set PATCH-SOURCE-FOR-MES?, if the compiling TCC relies on Mes." + (let ((revision "2024.08.20") + (commit "12acbf3e92e4067155da2e6242cf4cd72b1e291e")) + (package + (name name) + (version (git-version "0.9.28rc" revision commit)) + (source + (origin + (method git-fetch) + (uri (git-reference + (url "git://repo.or.cz/tinycc.git") + (commit commit))) + (file-name (git-file-name "tcc" version)) + (sha256 + (base32 "1yynfbqpbg1901hnrp9fswqm1w4wx23bvr7wdx4psysw83xgwynz")))) + (native-inputs (with-shell gash-boot + gnu-make-mesboot0 + gash-utils-boot)) + (build-system gnu-build-system) + (arguments + (list + #:guile %bootstrap-guile + #:implicit-inputs? #f + #:test-target "test" + #:tests? (not patch-source-for-mes?) + #:strip-binaries? #f + #:configure-flags + #~(let* ((cc (string-append #$tcc "/bin/tcc")) + (ar (string-append cc " -ar")) + (tcc/lib/tcc (string-append #$tcc "/lib/tcc")) + (libc/lib (string-append #$libc "/lib")) + (libc/include (string-append #$libc "/include")) + (cflags (string-join '#$cflags " " 'prefix))) + (list + (string-append "--ar=" ar) + (string-append "--cc=" cc) + (string-append "--crtprefix=" libc/lib) + (string-append "--elfinterp=" libc/lib "/ld-musl-missing.so.1") + (string-append "--libpaths={B}:" libc/lib) + (string-append "--sysincludepaths=" libc/include ":{B}/include") + ;; Ensure that executables are built with the new libc to get a + ;; switch from i386 to x86_64. This also halves the number of + ;; iterations until both musl and tcc become stable. + (string-append "--extra-cflags=-nostdinc -I" libc/include cflags) + (string-append "--extra-ldflags=-nostdlib -L" libc/lib + " -L" tcc/lib/tcc " " + libc/lib "/crt1.o " + libc/lib "/crti.o " + libc/lib "/crtn.o " + "-lc -ltcc1 -lc") + ;; Ensure static builds and the presence of __SIZEOF_LONG_LONG__, + ;; which Mes requries to define 64 bit types like uint64_t. It is + ;; defined by GCC and mescc but not TCC. It is not needed by musl, + ;; but increases the compatibility to other compilers. + "--tcc-switches=-static -D__SIZEOF_LONG_LONG__=8" + ;; The built tcc does not need backtrace or bound-checking + ;; functionality. + "--config-backtrace=no" + "--config-bcheck=no" + ;; Only built the static libraries libtcc1.a and libtcc.a. + "--enable-static")) + #:make-flags + #~(cons (string-append "SHELL=" #$gash-boot "/bin/sh") + '#$make-flags) + #:phases + #~(modify-phases %standard-phases + (delete 'install-locale) + (add-after 'unpack 'patch-source + (lambda _ + (substitute* "configure" + ;; Gash does not support local variables. Luckily the + ;; configure script works without. + (("^([ \t]*)local[ \t]*([^=]+)(=.*)?" _ space var value) + (if value + (string-append space var value) + "")) + ;; The cut from gash-utils does not support ranges on fields. + ;; Ranges are used to separate configure flag values after the + ;; equal-sign. + (("-f 2-") + "-f 2,3,4,5,6,7,8,9") + ;; The ln from gash-utils does not support the -n option. + (("ln -sfn") + "ln -sf")) + (substitute* (find-files "." "^Makefile$") + ;; Emulate the or-function from make 3.81 in make 3.80. + (("# Tiny C Compiler Makefile.*" line) + (string-append line "or=$(if $1,$1,$2)\n")) + (("\\$\\(or ") + "$(call or,")) + (substitute* "Makefile" + ;; Substitute install by chmod and cp. + (("install -m([0-7]+)" _ flags) + (string-append "chmod " flags " $1 && cp")) + ;; Ensure that c2str is built with our --extra-cflags and + ;; --extra-ldflags. + (("-o c2str") + "$(CFLAGS) $(LDFLAGS) -o c2str")) + (substitute* "lib/Makefile" + ;; Although we use --enable-static, the file runmain.o would + ;; still be built and installed. As we don't need it but + ;; install some other object files, we remove it. + (("runmain.o ") + "")) + (substitute* "tests/Makefile" + ;; Split 'else if', which is not supported by Make 3.80, into + ;; a nested 'if … endif'. + (("^else (if.*)$" _ if-clause) + (string-append + "else\n" + if-clause)) + ;; Add an endif afer the nested 'if' body. + (("^ TESTS \\+= btest test1b tccb\n$" line) + (string-append + line + "endif\n")) + ;; Avoid use of ldd from unavailable GNU C Library. + ((" ldd \\$\\(TOP\\)/tcc;") + "") + ;; For testing avoid the use of the TCC, which was used for + ;; compilation. It is not a reference GCC, which some tests + ;; assume, and it is worse than the newly built TCC, as it may + ;; leak problems from Mes. + (("\\$\\(CC\\)") + "$(TCC)") + ;; Remove tests, which require support for diff or a dynamic + ;; linker. + ((" cross-test") + "") + ((" *(hello-run|libtest|test3|memtest|dlltest|abitest|tests2-dir|pp-dir) *\\\\\n") + "")) + #$@(if patch-source-for-mes? + '((substitute* "lib/tcov.c" + ;; Mes is missing struct flock. There are checks for + ;; _WIN32 only to avoid file locking. + (("^#ifndef _WIN32\n$") + (string-append + "#ifndef CONFIG_TCC_FILELOCK\n" + "#elif !defined _WIN32\n"))) + (substitute* "Makefile" + ;; Mes has no libm.a. + (("LIBS\\+=-lm") + "LIBS+="))) + '()) + (substitute* "i386-asm.c" + ;; Fix a bug with "call *%%gs:16", which sets the two flags + ;; OP_INDIR and OP_SEG in pop->type. + (("pop->type != OP_SEG") + "!(pop->type & OP_SEG)") + ;; For x86_64 there are more than just 8 registers. + (("reg = 0; reg < 8;") + "reg = 0; reg < NB_ASM_REGS;") + ;; Handle 'register long r10 __asm__("%r10")' without %, too. + ;; Using GCC the % is optional. The musl source code does not + ;; use the % prefix. The GCC source code uses both variants. + ;; Instead of returning an error code without the proper % + ;; prefix, we decrease s and avoid the return. This pretends + ;; a % prefix, which is afterwards skipped by increasing s. + (("^( *)if \\(s\\[0\\] != '%'\\)\n$" _ indent) + (string-append + indent "if (s[0] != '%')\n" + indent " --s;\n" + ;; Avoid to ever call the return -1 in the following line. + indent "else if (0)\n"))) + (substitute* "tccelf.c" + ;; As va_list.o in libtcc1.a referes to abort, the libc.a must + ;; be linked again after linking libtcc1.a. There may be + ;; similar problems with other functions like memcpy. With + ;; this we have a match to the --extra-ldflags containing + ;; -lc -ltcc1 -lc. Usually this is not an issue because of + ;; dynamic linking and abort as a builtin-function in GCC. + (("^( *)(tcc_add_support\\(s1, TCC_LIBTCC1\\);\n)$" + _ indent libtcc1) + (string-append + indent "{\n" + indent " " libtcc1 + indent " tcc_add_library_err(s1, \"c\");\n" + indent "}\n"))))) + (add-after 'install 'install-libtcc1-object-files + (lambda _ + ;; As musl will be used by GCC, the musl package must not retain + ;; dependencies to libtcc1.a, which are not provided by libgcc.a + ;; as well. Such dependencies must be gathered as object files. + (let ((tcc/lib/tcc (string-append #$output "/lib/tcc"))) + ;; For x86_64 we need va_list.o for __va_arg as implementation + ;; of va_arg, which is a builtin-function in GCC. + (install-file "lib/va_list.o" tcc/lib/tcc) + ;; The __math_xflow of musl uses __mzerodf from libtcc1.o. + (install-file "lib/libtcc1.o" tcc/lib/tcc))))))) + (native-search-paths + (list (search-path-specification + (variable "C_INCLUDE_PATH") + (files '("include"))) + (search-path-specification + (variable "LIBRARY_PATH") + (files '("lib"))))) + (synopsis "Tiny and fast C compiler") + (description + "TinyCC (aka TCC) is a small but hyper fast C compiler. Unlike other C +compilers, it is meant to be self-relying: you do not need an external assembler +or linker because TCC does that for you. TCC not only supports ANSI C, but also +most of the new ISO C99 standard and many GNU GCC extensions including inline +assembly.") + (home-page "https://bellard.org/tcc/") + (license license:lgpl2.1+)))) + +(define*-public (make-MUSL-bootstrap name tcc) + "Make a static musl C library package named NAME. Build it using TCC." + (package + (name name) + (version "1.2.5") + (source + (origin + (method url-fetch) + (uri (string-append "https://www.musl-libc.org/releases/musl-" version + ".tar.gz")) + (sha256 + (base32 "1r3mgky9d19b2285s274qxzlgs7sncx8plm01vd691sdx2xii8d9")))) + (native-inputs (with-shell gash-boot + gnu-make-mesboot0 + gash-utils-boot + bootar)) + (build-system gnu-build-system) + (arguments + (list + #:guile %bootstrap-guile + #:implicit-inputs? #f + ;; There are no tests for musl. + #:tests? #f + #:strip-binaries? #f + #:configure-flags + #~(let* ((cc (string-append #$tcc "/bin/tcc")) + (ar (string-append cc " -ar"))) + (list + (string-append "CC=" cc) + (string-append "AR=" ar) + "LIBCC=-ltcc1" + "RANLIB=true" + "--disable-shared" + "--syslibdir=$(libdir)")) + #:make-flags + #~(list + (string-append "SHELL=" #$gash-boot "/bin/sh") + ;; TCC has a bug linking syscall functions using the assembler + ;; instruction "call *%%gs:16" from arch/i386/syscall_arch.h. This + ;; leads to an error "Invalid relocation entry [ 7] '.rel.text' @ 00…". + ;; Setting the define SYSCALL_NO_TLS switches to the assembler + ;; instruction "int $128" instead. + "CPPFLAGS=-DSYSCALL_NO_TLS=1") + #:phases + #~(modify-phases %standard-phases + (delete 'install-locale) + (add-after 'unpack 'patch-source + (lambda _ + (substitute* "Makefile" + ;; As musl will be used by GCC, the musl package must not retain + ;; dependencies to libtcc1.a, which are not provided by libgcc.a + ;; as well. Therefore we add all installed TCC object files + ;; into the libc.a. + (("^AOBJS =( .*)$" _ o-files) + (string-append + "AOBJS = $(sort $(wildcard " #$tcc "/lib/tcc/*.o))" o-files))) + (substitute* (find-files "src" "\\.s$") + ;; TCC does not support the procedure linkage table hint in + ;; assembly code. Removing @PLT is possible, as we link musl + ;; statically. + (("@PLT") + "")) + (substitute* "src/signal/i386/sigsetjmp.s" + ;; TCC has a bug with forward referencing numeric labels. We + ;; move the label and its code to the top. + (("^1:[\t ]*jmp ___setjmp") + "") + (("^sigsetjmp:") + "1:\tjmp ___setjmp\nsigsetjmp:") + ;; And we turn the forward into a backward reference. + (("jecxz 1f") + "jecxz 1b")) + ;; TCC does not support the complex type. + (delete-file-recursively "src/complex") + ;; TCC does not support the extended asm for float registers. + ;; All src/math/{i386,x86_64}/*.c files make use of it. Luckily + ;; musl has an automatic fallback to generic C implementations in + ;; src/math. Therefore we can simply delete these files. + (for-each (lambda (path) + (for-each delete-file (find-files path "\\.c$"))) + '("src/math/i386" "src/math/x86_64")) + (substitute* "tools/install.sh" + ;; Gash does not support getopts, replace its use. + (("^while getopts Dlm: name ; do\n$") + (string-append + "for name in \"$@\" ; do\n" + " if [ \"$mode\" == \"yes\" ] ; then\n" + " mode=\"$name\" ; shift ; continue\n" + " fi\n")) + (("^(D|l|m|\\?)\\) ([^ =]+).*;;\n$" _ option var) + (string-append "-" option ") " var (if (string=? option "?") + " ;;\n" + "=yes ; shift ;;\n"))) + (("^shift \\$\\(\\(\\$OPTIND - 1\\)\\)\n$") + ""))))))) + (synopsis "C standard library") + (description + "The musl is an implementation of the C standard library built on top of +the Linux system call API, including interfaces defined in the base language +standard, POSIX, and widely agreed-upon extensions. It strives to be correct in +the sense of standards-conformance and safety.") + (home-page "https://musl.libc.org") + (license (list license:expat (license:non-copyleft "file://COPYRIGHT"))))) + +(define MUSL-TCC-bootstrap + ;; A musl package and a TCC package using it. They are both built with the + ;; help of multible intermediate TCC and musl packages. The floating point + ;; capablities of tcc-boot0 and Mes are broken. This chain of intermediate + ;; packages is needed to get working floating point capabilities in both, musl + ;; and TCC. With each step the problems get less. It is unclear why exactly + ;; three iterations are needed before they generate identical packages, if + ;; iteratingfurther. + (let* ((tcc-mes-cflags + (list + ;; Mes misses pthread and therefore semaphore.h as well. + "-DCONFIG_TCC_SEMLOCK=0" + ;; Mes misses dlopen, dlsym, dlclose, avoid their use. + "-DCONFIG_TCC_STATIC=1" + ;; Mes misses realpath, which is used for "#pragma once". + "-Drealpath\\(path,resoved_path\\)=NULL")) + (tcc-mes-make-flags + (list + ;; Mes has no libdl.a. + "CONFIG_ldl=no" + ;; Mes has no libpthread.a. + "CONFIG_pthread=no")) + (tcc-mes-bootstrap + (make-TCC-bootstrap "TCC-MES-bootstrap" + tcc-boot0 + tcc-boot0 + #:cflags tcc-mes-cflags + #:make-flags tcc-mes-make-flags + #:patch-source-for-mes? #t))) + ;; Mes specific cflags and make-flags are not needed for TCC after + ;; tcc-mes-bootstrap. We need three iterations to get properly working + ;; floating point capabilities. After that a musl and a TCC package from + ;; yet another iteration would have no differences any more. + (let loop ((tcc tcc-mes-bootstrap) + (number 1)) + (let* ((final-number 3) + ;; The last iteration of the packages omitts a number. + (iteration (if (>= number final-number) + "" + (number->string (- number)))) + (name (string-append "MUSL" iteration "-bootstrap")) + (musl (make-MUSL-bootstrap name tcc)) + (name (string-append "TCC" iteration "-bootstrap")) + (tcc (make-TCC-bootstrap name musl tcc))) + (if (not (string-null? iteration)) + ;; The packages are not stable yet, we need another iteration. + (loop tcc (1+ number)) + ;; The packages are stable now. Return them. + (list musl tcc)))))) + +(define-public MUSL-bootstrap + ;; The stable MUSL-boostrap package. + (first MUSL-TCC-bootstrap)) + +(define-public TCC-bootstrap + ;; The stable TCC-boostrap package using MUSL-bootstrap. + (second MUSL-TCC-bootstrap)) + +;; Neither make 3.80 nor 4.4.1 built with TCC-bootstrap runs reliably with the +;; -j flag. Make 4.4.1 does not compile with tcc-boot0, actually Mes. The +;; compiler complains about missing prototypes for fileno, lstat, pipe, strdup, +;; about missing implementations of at least getpwnam, putenv after defining +;; POSIX and about undefined O_CLOEXEC and ENOTSUP defines. +;; Probably gash or %bootstrap-guile causes make to hang when using -j. +;; To avoid problems with missing functionality in make 3.80, like for TCC with +;; the or-function, we switch to the newer make version. +(define-public MAKE-bootstrap + (package + (name "MAKE-bootstrap") + (version "4.4.1") + (source + (origin + (method url-fetch) + (uri (string-append "mirror://gnu/make/make-" version ".tar.gz")) + (sha256 + (base32 "1cwgcmwdn7gqn5da2ia91gkyiqs9birr10sy5ykpkaxzcwfzn5nx")))) + (native-inputs (with-shell gash-boot + gnu-make-mesboot0 + gash-utils-boot + bootar)) + (build-system gnu-build-system) + (arguments + (list + #:guile %bootstrap-guile + #:implicit-inputs? #f + #:tests? #f + #:strip-binaries? #f + #:configure-flags + #~(let* ((cc (string-append #$TCC-bootstrap "/bin/tcc")) + (ar (string-append cc " -ar"))) + (list + (string-append "CC=" cc) + (string-append "AR=" ar) + (string-append "LD=" cc) + ;; Prevent the generation of useless dependency files. + "--disable-dependency-tracking")) + #:phases + #~(modify-phases %standard-phases + (delete 'install-locale) + (replace 'build + (lambda _ + (invoke "sh" "./build.sh"))) + (replace 'install + (lambda _ + (install-file "make" (string-append #$output "/bin"))))))) + (synopsis "GNU Make") + (description + "GNU Make is a tool which controls the generation of executables and other +non-source files of a program from the program's source files.") + (home-page "https://www.gnu.org/software/make/") + (license license:gpl3+))) + +#! +(define-public TCL-bootstrap + (package + (name "TCL-bootstrap") + (version "8.6.14") + (source + (origin + (method url-fetch) + (uri (string-append "mirror://sourceforge/tcl/Tcl/" version "/tcl" + version "-src.tar.gz")) + (sha256 + (base32 "0rnyqkhl099jlvlp36xasqfcw14i4zv5q3zvsic4r5gpmddj502q")))) + (native-inputs (with-shell gash-boot + MAKE-bootstrap + gash-utils-boot + bootar)) + (build-system gnu-build-system) + (arguments + (list + #:guile %bootstrap-guile + #:implicit-inputs? #f + ;#:parallel-build? #f + ;; Floating point tests show a mismatch in the least significant bit. + ;; Dynamic loading is not possible, tests fail due to this. Some tests + ;; fail because of a lack of functionality in gash-utils. Others fail + ;; because of ~/ or the root user-id. The effort to remove this amount of + ;; failing tests is too high. + #:tests? #f + #:strip-binaries? #f + #:configure-flags + #~(let* ((cc (string-append #$TCC-bootstrap "/bin/tcc")) + (ar (string-append cc " -ar"))) + (list + (string-append "AR=" ar) + (string-append "CC=" cc) + "EXTRA_INSTALL=install-private-headers" + "--disable-shared" + ;"--disable-threads" + (string-append "--infodir=" #$output "/share/info") + (string-append "--mandir=" #$output "/share/man"))) + #:make-flags + #~(list (string-append "SHELL=" #$gash-boot "/bin/sh")) + #:phases + #~(modify-phases %standard-phases + (delete 'install-locale) + (delete 'compress-documentation) + (add-before 'configure 'patch-/bin/sh + (lambda _ + (with-directory-excursion "tests" + (substitute* '("io.test" "exec.test" "chanio.test") + (("/bin/sh") + (string-append #$gash-boot "/bin/sh")))))) + (add-before 'configure 'chdir-unix + (lambda _ (chdir "unix"))) + (add-after 'install 'tclsh + (lambda _ + (let* ((bin (string-append #$output "/bin")) + (tclsh (string-append bin "/tclsh"))) + (symlink (car (find-files bin "^tclsh[0-9.]+")) tclsh))))))) + (home-page "https://www.tcl.tk/") + (synopsis "Tool Command Language") + (description + "Tcl is a powerful, easy to use, embeddable, cross-platform interpreted +scripting language.") + (license license:tcl/tk))) + +(define-public EXPECT-bootstrap + (package + (name "EXPECT-bootstrap") + (version "5.45.4") + (source + (origin + (method url-fetch) + (uri (string-append "mirror://sourceforge/expect/Expect/" version + "/expect" version ".tar.gz")) + (sha256 + (base32 "0d1cp5hggjl93xwc8h1y6adbnrvpkk0ywkd00inz9ndxn21xm9s9")))) + (build-system gnu-build-system) + (native-inputs (with-shell gash-boot + TCL-bootstrap + MAKE-bootstrap + gash-utils-boot + bootar)) + (arguments + (list + #:guile %bootstrap-guile + #:implicit-inputs? #f + #:strip-binaries? #f + ;; The tests need dynamic loading, which is not available. + #:tests? #f + #:configure-flags + #~(let* ((cc (string-append #$TCC-bootstrap "/bin/tcc")) + (ar (string-append cc " -ar"))) + (list + (string-append "AR=" ar) + (string-append "CC=" cc) + "--disable-shared" + (string-append "--with-tcl=" #$TCL-bootstrap "/lib") + (string-append "--with-tclinclude=" #$TCL-bootstrap "/include"))) + #:phases + #~(modify-phases %standard-phases + (delete 'install-locale) + (delete 'compress-documentation) + (add-after 'unpack 'patch-source + (lambda _ + (substitute* "Makefile.in" + ;; When linking statically -ltclstub8.6 is missing. + (("@TCL_LIB_SPEC@") + "@TCL_LIB_SPEC@ @TCL_STUB_LIB_FLAG@"))))) + #;(modify-phases %standard-phases + (add-before 'configure 'set-path-to-stty + (lambda _ + (substitute* "configure" + (("STTY_BIN=/bin/stty") + (string-append "STTY_BIN=" (which "stty"))))))))) + (home-page "https://core.tcl-lang.org/expect/") + (synopsis "Tool for automating interactive applications") + (description + "Expect is a tool for automating interactive applications such as telnet, +ftp, passwd, fsck, rlogin, tip, etc. Expect really makes this stuff trivial. +Expect is also useful for testing these same applications.") + (license (list license:public-domain + (license:non-copyleft "file://license.terms"))))) + +(define-public DEJAGNU-bootstrap + (package + (name "DEJAGNU-bootstrap") + (version "1.6.3") + #;(source + (origin + (method url-fetch) + (uri (string-append "mirror://gnu/dejagnu/dejagnu-" version ".tar.gz")) + (sha256 + (base32 "1qx2cv6qkxbiqg87jh217jb62hk3s7dmcs4cz1llm2wmsynfznl7")))) + (source + (origin + (method git-fetch) + (uri (git-reference + (url "https://git.savannah.gnu.org/git/dejagnu.git") + (commit "417b59616a5ce4c5e752c34e11fe5ddc0f41b80c"))) + (file-name (git-file-name "dejagnu" version)) + (sha256 + (base32 "0bv7dr0r346bk04s0fd1l8r6r05bcdhz09jbjbad7ikjp8d8vj11")))) + (build-system gnu-build-system) + (native-inputs (with-shell gash-boot + EXPECT-bootstrap + MAKE-bootstrap + gash-utils-boot + bootar)) + (propagated-inputs EXPECT-bootstrap + TCL-bootstrap + gash-utils-boot + bootar + gash-boot) + (arguments + (list + #:guile %bootstrap-guile + #:implicit-inputs? #f + ;; The tests require a C++ compiler, which is not available. + #:tests? #f + #:configure-flags + #~(list + (string-append "CC=" #$TCC-bootstrap "/bin/tcc") + ;; Prevent the generation of useless dependency files. + "--disable-dependency-tracking") + #:phases + #~(modify-phases %standard-phases + (delete 'install-locale) + (delete 'compress-documentation) + (add-after 'unpack 'patch-source + (lambda _ + (invoke "touch" "doc/dejagnu.info") + (substitute* '("config/adb.exp" "lib/remote.exp" "lib/rsh.exp") + ;; Avoid pipelining through cat, just as a speedup. + (("\\|& cat") + "2>@1")) + (substitute* "lib/remote.exp" + ;; Avoid pipelining through tee, which is not available. + (("^proc local_exec .*$" line) + ;; Move the scope of outf and use_tee to the procedure level. + (string-append + line + " set outpf {}\n" + " set use_tee 0\n")) + ;; Avoid pipelining through tee. + (("\\|& tee \\$outpf") + "2>@1") + ;; Write the captured output into the file to mimic tee. + (("^([ \t]+)verbose \"output is \\$output status \\$status\"\n$" + line indent) + (string-append + indent "if {$use_tee} {\n" + indent " set id [open $outpf w]\n" + indent " try {puts $id $output} finally {close $id}\n" + indent "}\n" + line))) + (substitute* "dejagnu" + ((" exec /bin/sh ") + " exec sh ")) + (substitute* "runtest.exp" + ;; See . + (("^([\t ]+)catch \"(set logname \\[exec .*\\])\" tmp\n" _ i s) + (string-append i "if [catch {" s "} tmp] {\n")) + (("^[\t ]+if \\{\\[string match .* \\$tmp\\]\\} \\{\n") + ""))))))) + (home-page "https://www.gnu.org/software/dejagnu/") + (synopsis "GNU software testing framework") + (description + "DejaGnu is a framework for testing software. In effect, it serves as a +front-end for all tests written for a program. Thus, each program can have +multiple test suites, which are then all managed by a single harness.") + (license license:gpl3+))) +!# + +;; With tcc -ar rc … it is not possible to append to an existing archive. The +;; configure scripts have a check for the maximum command line length, which +;; evaluates to only 512 characters. The libtool scripts generate multiple +;; invocations of tcc -ar rc … from a long list of arguments to respect this +;; limit, if necessary. They query the getconf tool for the limit. So we can +;; provide a getconf stub to return an unproblematic command line length to only +;; have a single invocation of tcc -ar rc …. +(define-public GETCONF-bootstrap + (package + (name "GETCONF-bootstrap") + (version "0.1") + (source + (program-file "getconf" + #~(let* ((argv (cdr (program-arguments))) + (argc (length argv))) + (if (= argc 1) + (case (string->symbol (car argv)) + ((ARG_MAX) + ;; ARG_MAX is set to 131072 in limits.h of musl. + (display 131072) + (newline) + (exit 0)))) + (exit 1)) + #:guile %bootstrap-guile)) + (build-system copy-build-system) + (arguments + (list + #:guile %bootstrap-guile + #:install-plan #~'(("getconf" "bin/")) + #:phases + #~(list + (assq 'unpack %standard-phases) + (assq 'install %standard-phases)))) + (synopsis "getconf ARG_MAX") + (description + "A stub of the getconf tool of the GNU C Library supporting: +@itemize +@item ARG_MAX +@end itemize") + (license license:gpl3+) + (home-page #f))) + +(define-public BINUTILS-bootstrap + (package + (name "BINUTILS-bootstrap") + ;; The ld of Binutils 2.43 crashes using object files compiled by GCC 4.6.4. + (version "2.42") + (source + (origin + (method url-fetch) + (uri (string-append "mirror://gnu/binutils/binutils-" version + ".tar.bz2")) + (sha256 + (base32 "04mgvzgsdcksm7cm0qs8j4ljb562asqdkhjfrmr4q1m5pl78am5a")))) + (native-inputs (with-shell gash-boot + GETCONF-bootstrap + MAKE-bootstrap + gash-utils-boot + bootar)) + (build-system gnu-build-system) + (arguments + (list + #:guile %bootstrap-guile + #:implicit-inputs? #f + ;; Without makeinfo there are troubles building out-of-source. For some + ;; reason at least the bfd Makefile wants to rebuild the bfd.info file. + ;; If building in-source, then this does not happen. + #:out-of-source? #f + ;; The testsuite of Binutils heavily depends on a not yet available GCC. + #:tests? #f + #:strip-binaries? #f + #:configure-flags + #~(let* ((cc (string-append #$TCC-bootstrap "/bin/tcc")) + (ar (string-append cc " -ar"))) + (list + (string-append "AR=" ar) + (string-append "CC=" cc) + ;; TODO Remove --build. + ;"--build=i686-unknown-linux-gnu" + ;; Prevent the generation of useless dependency files. + "--disable-dependency-tracking" + ;; Avoid building the faster gold linker. + "--disable-gold" + ;; Avoid building gprofng. + "--disable-gprofng" + ;; Avoid building lto support, as it requires dynamic loading. + "--disable-lto" + ;; Avoid building shared libraries. + "--disable-shared" + ;; Disable separate-code as the testsuite unveils Arm bugs in ld: + ;; FAIL: R_ARM_THM_JUMP24 Relocation veneers: Short 1 + ;; FAIL: Cortex-A8 erratum fix, headers + ;; FAIL: Cortex-A8 erratum fix, relocate bl.w to PLT + ;; FAIL: Thumb only PLT and GOT + ;; FAIL: Thumb only PLT and GOT LSB Symbol + "--disable-separate-code" + ;; Build a 64-bit bfd lib also on 32-bit hosts. + "--enable-64-bit-bfd" + ;; Enable compressed debug sections with all supported formats. + "--enable-compressed-debug-sections=all" + ;; Ensure that generated archives will be reproducable. + "--enable-deterministic-archives" + ;; Install the built libraries and headers. + "--enable-install-libbfd" + ;; Enable the use of DT_RUNPATH by default for elf targets. + "--enable-new-dtags" + ;; Enforce an empty LIB_PATH, a colon is the documented method, + ;; to avoid the usual default of /lib:/usr/lib:/usr/local/lib. + "--with-lib-path=:" + ;; All paths to --with-… options are relative to the sysroot. As + ;; store paths are absolute, the sysroot needs to be /. This is + ;; also needed to make cross ld find absolute DT_RUNPATH entries + ;; when searching for needed libraries, which are only searched + ;; relative to the configured sysroot directory or not at all. + ;; See . + ;; This is also documented in the ld manual for the -rpath option: + ;; "Searching -rpath in this way is only supported by native + ;; linkers and cross linkers which have been configured with the + ;; --with-sysroot option." + "--with-sysroot=/" + ;; There is no zlib yet. + "--without-system-zlib" + ;; There is no zstd yet + "--without-zstd")) + #:phases + #~(modify-phases %standard-phases + (delete 'install-locale) + (delete 'compress-documentation) + (add-after 'unpack 'patch-source + (lambda _ + (substitute* "bfd/bfd.c" + ;; Although configure will detect that thread local storage is + ;; not supported by tcc, there are still some static functions + ;; trying to use the undefined name TLS. + (("^static TLS ") + "static ")) + (substitute* '("gas/Makefile.in" "gas/doc/local.mk") + ;; The touch command of gash-utils misses the -m option and + ;; ignores the -r option. Because of this gas/doc/asconfig.texi + ;; seems to be modified and rebuilding gas/doc/as.info fails, as + ;; makeinfo is missing. Providing makeinfo instead is not an + ;; option during bootstrap. It is possible to use cp -p and + ;; prevent calling touch -m -r. + (("cp (.*) && touch -m -r .*" _ cp-arguments) + (string-append "cp -p " cp-arguments "\n"))))) + (add-after 'configure 'create-empty-files-for-sed + (lambda _ + ;; The sed from gash-utils throws an error for the r command if + ;; its file-argument is not existing. Instead GNU sed treats this + ;; situation just like an empty file. As a mitigation we create + ;; some empty files. This has to be done after the configure + ;; phase, as configure otherwise terminates when creating the + ;; same directories with just mkdir, and because afterwards the + ;; build directory will already be present and entered. + (for-each (lambda (file) + (mkdir-p (dirname file)) + (with-output-to-file file (const #t))) + '("bfd/po/BLD-POTFILES" + "bfd/po/SRC-POTFILES" + "ld/po/BLD-POTFILES" + "ld/po/SRC-POTFILES"))))))) + (synopsis "The GNU binary utilities ld, as, gold and others") + (description + "The GNU Binutils are a collection of binary tools. The main ones are +@itemize +@item ld - the GNU linker +@item as - the GNU assempler +@item gold - a new, faster, elf only linker. +@end itemize +But they also include: +@itemize +@item addr2line - Converts addresses into filenames and line numbers. +@item ar - A utility for creating, modifying and extracting from archives. +@item c++filt - Filter to demangle encoded C++ symbols. +@item dlltool - Creates files for building and using DLLs. +@item elfedit - Allows alteration of ELF format files. +@item gprof - Displays profiling information. +@item gprofng - Collects and displays application performance data. +@item nlmconv - Converts object code into an NLM. +@item nm - Lists symbols from object files. +@item objcopy - Copies and translates object files. +@item objdump - Displays information from object files. +@item ranlib - Generates an index to the contents of an archive. +@item readelf - Displays information from any ELF format object file. +@item size - Lists the section sizes of an object or archive file. +@item strings - Lists printable strings from files. +@item strip - Discards symbols. +@item windmc - A Windows compatible message compiler. +@item windres - A compiler for Windows resource files. +@end itemize +As well as some libraries: +@itemize +@item libbfd - A library for manipulating binary files in a variety of different +formats. +@item libctf - A library for manipulating the CTF debug format. +@item libopcodes - A library for assembling and disassembling a variety of +different assembler languages. +@item libsframe - A library for manipulating the SFRAME debug format. +@end itemize +Most of these programs use BFD, the Binary File Descriptor library, to do +low-level manipulation. Many of them also use the opcodes library to assemble +and disassemble machine instructions.") + (license license:gpl3+) + (home-page "https://www.gnu.org/software/binutils/"))) + +(define-public FINDUTILS-bootstrap + (package + (name "FINDUTILS-bootstrap") + (version "4.10.0") + (source + (origin + (method url-fetch) + (uri (string-append "mirror://gnu/findutils/findutils-" version + ".tar.xz")) + (sha256 + (base32 "1xd4y24qfsdfp3ndz7d5j49lkhbhpzgr13wrvsmx4izjgyvf11qk")))) + (native-inputs (with-shell gash-boot + MAKE-bootstrap + gash-utils-boot + bootar)) + (build-system gnu-build-system) + (arguments + (list + #:guile %bootstrap-guile + #:implicit-inputs? #f + #:tests? #f + #:strip-binaries? #f + #:configure-flags + #~(let* ((cc (string-append #$TCC-bootstrap "/bin/tcc")) + (ar (string-append cc " -ar"))) + (list + (string-append "AR=" ar) + (string-append "CC=" cc) + (string-append "LD=" cc) + "MAKEINFO=true" + "--localstatedir=/var" + ;; Prevent the generation of useless dependency files. + "--disable-dependency-tracking")) + #:make-flags #~(list "V=1") + #:phases + #~(modify-phases %standard-phases + (delete 'install-locale) + (delete 'compress-documentation) + (add-after 'unpack 'patch-source + (lambda _ + (substitute* "configure" + ;; Gash has some issues with character classes. + (("\\[:space:\\]") + "\\ \\f\\n\\r\\t\\v")) + (substitute* "gl/lib/Makefile.in" + ;; The sed of gash-utils misses the w command. + (("-n -e 'w \\$@-t'") + "> $@-t")) + (substitute* "locate/Makefile.in" + ;; Prevent the creation of /var, which fails. + (("^\t.*mkinstalldirs .*\\$\\(localstatedir\\)\n$") + ""))))))) + (synopsis "Directory searching utilities") + (description + "The GNU Find Utilities are the basic directory searching utilities of the +GNU operating system. These programs are typically used in conjunction with +other programs to provide modular and powerful directory search and file +locating capabilities to other commands. + +The tools supplied with this package are: +@itemize +@item find - search for files in a directory hierarchy +@item locate - list files in databases that match a pattern +@item updatedb - update a file name database +@item xargs - build and execute command lines from standard input +@end itemize +The find program searches a directory tree to find a file or group of files. +It traverses the directory tree and reports all occurrences of a file matching +the user's specifications. The find program includes very powerful searching +capability. + +The locate program scans one or more databases of filenames and displays any +matches. This can be used as a very fast find command if the file was present +during the last file name database update. + +The updatedb program updates the file name database used by the locate program. +The file name database contains lists of files that were in particular directory +trees when the databases were last updated. This is usually run nightly by the +cron system daemon. + +The xargs program builds and executes command lines by gathering together +arguments it reads on the standard input. Most often, these arguments are lists +of file names generated by find.") + (home-page "https://www.gnu.org/software/findutils/") + (license license:gpl3+))) + +(define gmp-boot + (@@ (gnu packages commencement) gmp-boot)) + +(define mpfr-boot + (@@ (gnu packages commencement) mpfr-boot)) + +(define mpc-boot + (@@ (gnu packages commencement) mpc-boot)) + +;; GCC 4.6.4 is used to bootstrap RISC-V. Therefore we start with this version. +;; There is a small core release, which only contains the C language. GCC 4.7.4 +;; is the last version buildable with some ISO C89 compiler, but has no smaller +;; core release anymore. However, we need C++ to build a newer GCC version, +;; therefore the core release is of no use. +(define-public GCC-4-bootstrap + (package + (name "GCC-4-bootstrap") + (version "4.6.4") + (source + (origin + (method url-fetch) + (uri (string-append "mirror://gnu/gcc/gcc-" version "/gcc-" version + ".tar.bz2")) + (sha256 + (base32 "1s3pv52xv21cvksj49am822mcpxws9vgpjhmxfwgjymnl2pidbrm")))) + (native-inputs (with-shell gash-boot + FINDUTILS-bootstrap + BINUTILS-bootstrap + GETCONF-bootstrap + MAKE-bootstrap + gash-utils-boot + bootar)) + (build-system gnu-build-system) + (outputs '("out" "lib")) + (arguments + (list + #:guile %bootstrap-guile + #:implicit-inputs? #f + #:out-of-source? #t + #:tests? #f + #:configure-flags + #~(list + ;; Define the tcc with proper flags as replacement for needed tools. + (string-append "CC=" #$TCC-bootstrap "/bin/tcc") + ;; Prevent support for the C decimal floating point extension. + "--disable-decimal-float" + ;; Prevent the generation of useless dependency files. + "--disable-dependency-tracking" + ;; Prevent run-time libraries for OpenMP. + "--disable-libgomp" + ;; Prevent quad-precision math library. + "--disable-libquadmath" + ;; Prevent run-time libraries for stack smashing protection. + "--disable-libssp" + ;; Prevent link-time-optimization, as there is nodynamic loader yet. + "--disable-lto" + ;; As musl is limited, gcc will only be usable for 32 bit builds. + "--disable-multilib" + ;; Without a dynamic loader shared libraries are still not usable and + ;; we won't use this GCC version to build the GNU C library. + "--disable-shared" + ;; Only build the C and C++ front-ends. + "--enable-languages=c,c++" + ;; Avoid the use of /usr/include, the default of oldincudedir. + (string-append "--oldincludedir=" #$output) + ;; Prevent the C++ headers in #$output:lib, put them in #$output:out + ;; instead. Use an unconventional path to prevent it from being + ;; added to the environment variables C_INCLUDE_PATH and + ;; CPLUS_INCLUDE_PATH. + "--with-gxx-include-dir=$(prefix)/include-c++" + ;; The first set of include paths consists of #$output/include-c++/… + ;; and #$output:lib/lib/…/include. Second is usually + ;; /usr/local/include, which is documented to be avoided, if the same + ;; value is used for both --prefix and --with-local-prefix. + (string-append "--with-local-prefix=" #$output) + ;; Third set is #$output:lib/…/include-fixed, which expects + ;; #$MUSL-bootstrap/include to follow. Kernel-headers are obsolete + ;; with musl. Fourth and usually the last include path is + ;; /usr/include containing all system headers. It is only possible to + ;; specify one path for this. The #$MUSL-bootstrap/include path must + ;; be patched to prevent the use of /usr/include, as configure is + ;; missing the future --with-native-system-header-dir option. + (string-append + "--with-specs=" + ;; Ensure that the built GCC will find the right executables from + ;; #$BINUTILS-bootstrap. + "-B" #$BINUTILS-bootstrap "/bin " + ;; Embed the link-time search path to #$MUSL-bootstrap/lib. + "-B" #$MUSL-bootstrap "/lib") + ;; There is no PPL library to use. + "--without-ppl") + #:phases + #~(modify-phases %standard-phases + (delete 'install-locale) + (delete 'compress-documentation) + (add-after 'unpack 'patch-source + (lambda _ + (substitute* "Makefile.in" + ;; Don't store configure arguments, to avoid a cyclic reference + ;; in #$output:lib/lib/gcc/…/include/configargs.h back to + ;; #$output and retaining references to build-time dependencies + ;; like gash-boot. + (("@TOPLEVEL_CONFIGURE_ARGUMENTS@") + "")) + ;; The configure script is missing the important future option + ;; --with-native-system-header-dir, which got introduced with GCC + ;; 4.7 (). + ;; Therefore we need two patches to use the path to the musl + ;; headers instead of /usr/include. + (substitute* "gcc/Makefile.in" + ;; Ensure to use the proper path during build and for fixinc.sh. + (("^(NATIVE_SYSTEM_HEADER_DIR *= *)/usr/include" _ head) + (string-append head #$MUSL-bootstrap "/include"))) + (substitute* "libstdc++-v3/python/Makefile.in" + ;; Change pythondir from #$output:out to #$output:lib to prevent + ;; #$output:lib/lib/libstdc++.*-gdb.py to create a cyclic + ;; dependency to #$output:out/share/…/python. This moves all + ;; python files to #$output:lib. + (("pythondir = \\$\\(datadir\\)") + "pythondir = $(libdir)/share")) + (substitute* "gcc/genmultilib" + ;; Enforce proper invokations of sh. + (("#! */bin/sh") + (string-append "#!" (which "sh")))) + (substitute* "gcc/cppdefault.c" + ;; Ensure that the built pre-processor will use the proper path. + (("(#define +STANDARD_INCLUDE_DIR +)\"/usr/include\"" _ head) + (string-append head "\"" #$MUSL-bootstrap "/include\""))) + (substitute* "libstdc++-v3/configure.host" + ;; The configure scripts of GCC 4.6.4 do not know musl. They + ;; basically assume the presence of the GNU C Library. This + ;; leads to issues when building libstdc++-v3. For musl files + ;; from libstdc++-v3/config/os/generic have to be used instead + ;; of files from libstdc++-v3/config/os/gnu-linux. + (("os_include_dir=\"os/gnu-linux\"") + "os_include_dir=\"os/generic\"")) + (substitute* "libmudflap/mf-runtime.c" + ;; Both musl and GCC define an __assert_fail function. Rename + ;; the one of GCC. There are more occurences in gcc/testsuite, + ;; which we don't care about. + (("__assert_fail") + "__gcc_assert_fail")))) + (add-after 'patch-source 'unpack-gmp-mpc-mpfr + (lambda _ + ;; Older versions of GMP, MPC and MPFR are compilable with the + ;; assembler from TCC, at least for i386. However, newer versions + ;; require the GNU assembler (TCC misses at least the .value + ;; directive), called through the gcc driver, because the + ;; preprocessor is needed. When Unpacking the sources of GMP, MPC + ;; and MPFR inside the GCC source tree, they get compiled with the + ;; GNU assembler in every build-stage, which avoids problems but + ;; takes a lot more time. + (for-each (lambda (package) + (invoke "tar" "xvf" package)) + '#$(list gmp-boot mpc-boot mpfr-boot)) + ;; Rename gmp-x.y.z to gmp etc. + (for-each rename-file + (find-files "." + "^(gmp|mpc|mpfr)-[0-9.]+[a-z]?$" + #:directories? #t) + '("gmp" "mpc" "mpfr")))) + (add-after 'install 'remove-install-tools + (lambda _ + ;; The programs in install-tools try to modify the store and have + ;; retaining references to sed and bash-minimal. They are useless + ;; in Guix and can be deleted to reduce references. + (for-each (lambda (directory) + (delete-file-recursively + (car (find-files directory + "^install-tools$" + #:directories? #t)))) + (list #$output #$output:lib))))))) + (native-search-paths + (list (search-path-specification + (variable "C_INCLUDE_PATH") + (files (list "include"))) + (search-path-specification + (variable "CPLUS_INCLUDE_PATH") + (files (list "include"))) + (search-path-specification + (variable "LIBRARY_PATH") + (files (list "lib"))))) + (synopsis "GNU Compiler Collection for C and C++") + (description + "This GNU Compiler Collection includes a front end for C and C++.") + (home-page "https://gcc.gnu.org/") + (license license:gpl3+))) + +(define-public M4-bootstrap + (package + (name "M4-bootstrap") + (version "1.4.19") + (source + (origin + (method url-fetch) + (uri (string-append "mirror://gnu/m4/m4-" version ".tar.xz")) + (sha256 + (base32 "15mghcksh11saylpm86h1zkz4in0rbi0pk8i6nqxkdikdmfdxbk3")))) + (native-inputs (with-shell gash-boot + GCC-4-bootstrap + BINUTILS-bootstrap + GETCONF-bootstrap + MAKE-bootstrap + gash-utils-boot + bootar)) + (build-system gnu-build-system) + (arguments + (list + #:guile %bootstrap-guile + #:implicit-inputs? #f + #:out-of-source? #t + #:tests? #f + #:configure-flags + #~(list + ;; Prevent the generation of useless dependency files. + "--disable-dependency-tracking") + #:phases + #~(modify-phases %standard-phases + (delete 'install-locale) + (delete 'compress-documentation)))) + (synopsis "Macro processor") + (description + "GNU M4 is an implementation of the traditional Unix macro processor. It +is mostly SVR4 compatible although it has some extensions. GNU M4 also has +built-in functions for including files, running shell commands, doing +arithmetic, etc. + +GNU M4 is a macro processor in the sense that it copies its input to the output +expanding macros as it goes. Macros are either builtin or user-defined and can +take any number of arguments. Besides just doing macro expansion, m4 has +builtin functions for including named files, running UNIX commands, doing +integer arithmetic, manipulating text in various ways, recursion etc.") + (home-page "https://www.gnu.org/software/m4/") + (license license:gpl3+))) + +;; Building GMP, MPC and MPFR as separate package has the advatage to build them +;; only once and no three times in each GCC build stage. + +(define-public GMP-bootstrap + (package + (name "GMP-bootstrap") + (version "6.3.0") + (source + (origin + (method url-fetch) + (uri (string-append "mirror://gnu/gmp/gmp-" version ".tar.xz")) + (sha256 + (base32 "1648ad1mr7c1r8lkkqshrv1jfjgfdb30plsadxhni7mq041bihm3")))) + (native-inputs (with-shell gash-boot + M4-bootstrap + GCC-4-bootstrap + BINUTILS-bootstrap + GETCONF-bootstrap + MAKE-bootstrap + gash-utils-boot + bootar)) + (build-system gnu-build-system) + (arguments + (list + #:guile %bootstrap-guile + #:implicit-inputs? #f + #:out-of-source? #t + #:tests? #f + #:configure-flags + #~(list + ;; Prevent the generation of useless dependency files. + "--disable-dependency-tracking" + ;; Prevent building shared libraries. + "--disable-shared") + #:phases + #~(modify-phases %standard-phases + (delete 'install-locale) + (delete 'compress-documentation)))) + (synopsis "GNU Multiple Precision Arithmetic Library") + (description + "@acronym{GMP, the GNU Multiple Precision Arithmetic Library} is a free +library for arbitrary precision arithmetic, operating on signed integers, +rational numbers, and floating-point numbers. There is no practical limit to +the precision except the ones implied by the available memory in the machine GMP +runs on. GMP has a rich set of functions, and the functions have a regular +interface. + +The main target applications for GMP are cryptography applications and research, +Internet security applications, algebra systems, computational algebra research, +etc.") + (home-page "https://gmplib.org/") + (license license:lgpl3+))) + +(define-public MPFR-bootstrap + (package + (name "MPFR-bootstrap") + (version "4.2.1") + (source + (origin + (method url-fetch) + (uri (string-append "mirror://gnu/mpfr/mpfr-" version ".tar.xz")) + (sha256 + (base32 "1cnb3y7y351qg6r7ynwsgaykm7l2a8zg2nlljs4rf9k778shfy17")))) + (native-inputs (with-shell gash-boot + GMP-bootstrap + GCC-4-bootstrap + BINUTILS-bootstrap + GETCONF-bootstrap + MAKE-bootstrap + gash-utils-boot + bootar)) + (build-system gnu-build-system) + (arguments + (list + #:guile %bootstrap-guile + #:implicit-inputs? #f + #:out-of-source? #t + #:tests? #f + #:configure-flags + #~(list + ;; Prevent the generation of useless dependency files. + "--disable-dependency-tracking" + ;; Prevent the maintainer mode with more checks. + "--disable-maintainer-mode" + ;; Prevent building shared libraries. + "--disable-shared") + #:phases + #~(modify-phases %standard-phases + (delete 'install-locale) + (delete 'compress-documentation)))) + (synopsis "C library for multiple-precision floating-point computations") + (description + "The GNU@tie{}@acronym{MPFR, Multiple Precision Floating-Point Reliable +Library} is a C library for multiple-precision floating-point computations with +correct rounding. MPFR is based on the GMP multiple precision library. + +The main goal of MPFR is to provide a library for multiple-precision +floating-point computation which is both efficient and has a well-defined +semantic. It copies the good ideas from the ANSI/IEEE-754 standard for +double-precision floating-point arithmetic (53-bit significand).") + (home-page "https://www.mpfr.org/") + (license license:lgpl3+))) + +(define-public MPC-bootstrap + (package + (name "MPC-bootstrap") + (version "1.3.1") + (source + (origin + (method url-fetch) + (uri (string-append "mirror://gnu/mpc/mpc-" version ".tar.gz")) + (sha256 + (base32 "1f2rqz0hdrrhx4y1i5f8pv6yv08a876k1dqcm9s2p26gyn928r5b")))) + (native-inputs (with-shell gash-boot + MPFR-bootstrap + GMP-bootstrap + GCC-4-bootstrap + BINUTILS-bootstrap + GETCONF-bootstrap + MAKE-bootstrap + gash-utils-boot + bootar)) + (build-system gnu-build-system) + (arguments + (list + #:guile %bootstrap-guile + #:implicit-inputs? #f + #:out-of-source? #t + #:tests? #f + #:configure-flags + #~(list + ;; Prevent the generation of useless dependency files. + "--disable-dependency-tracking" + ;; Prevent building shared libraries. + "--disable-shared") + #:phases + #~(modify-phases %standard-phases + (delete 'install-locale) + (delete 'compress-documentation)))) + (synopsis "C library for arbitrary precision arithmetic on complex numbers") + (description + "GNU@tie{}@acronym{MPC, Multiple Precision Complex Library} is a C library +for the arithmetic of complex numbers with arbitrarily high precision and +correct rounding of the result. It extends the principles of the IEEE-754 +standard for fixed precision real floating point numbers to complex numbers, +providing well-defined semantics for every operation.") + (home-page "https://www.multiprecision.org/mpc/") + (license license:lgpl3+))) + +;; GCC 10.5.0 is the latest version compilable with an ISC C++98 comiler and +;; therefore buildable with GCC 4.6.4. +;; Unfortunately the GCC 10.5.0 archive can't be extracted with bootar nor +;; gash-utils. Both tools fail probably because of pax Extended Headers used +;; in the tar file. +;; See +;; and . +;; Therefore we fallback to GCC 10.4.0 instead. +(define-public GCC-10-bootstrap + (package + (name "GCC-10-bootstrap") + (version "10.4.0") + (source + (origin + (method url-fetch) + (uri (string-append "mirror://gnu/gcc/gcc-" version "/gcc-" version + ".tar.xz")) + (sha256 + (base32 "1wg4xdizkksmwi66mvv2v4pk3ja8x64m7v9gzhykzd3wrmdpsaf9")))) + (native-inputs (with-shell gash-boot + MPC-bootstrap + MPFR-bootstrap + GMP-bootstrap + GCC-4-bootstrap + FINDUTILS-bootstrap + BINUTILS-bootstrap + GETCONF-bootstrap + MAKE-bootstrap + gash-utils-boot + bootar)) + (build-system gnu-build-system) + (outputs '("out" "lib")) + (arguments + (list + #:guile %bootstrap-guile + #:implicit-inputs? #f + #:out-of-source? #t + #:tests? #f + #:configure-flags + #~(list + ;; Prevent the built gcc to build itself again to save time. + #;"--disable-bootstrap" + ;; Prevent support for the C decimal floating point extension. + "--disable-decimal-float" + ;; Prevent the generation of useless dependency files. + "--disable-dependency-tracking" + ;; Prevent run-time libraries for atomic operations. + "--disable-libatomic" + ;; Prevent run-time libraries for OpenMP. + "--disable-libgomp" + ;; Prevent quad-precision math library. + "--disable-libquadmath" + ;; Prevent the run-time libraries for sanitizers, they requrie linux + ;; headers + "--disable-libsanitizer" + ;; Prevent run-time libraries for stack smashing protection. + "--disable-libssp" + ;; Save space by disabling pre-compiled libstdc++ headers. + "--disable-libstdcxx-pch" + ;; Prevent run-time libraries for vtable verification. + "--disable-libvtv" + ;; Disable link-time-optimization, which requires a dynamic linker. + "--disable-lto" + ;; Multiarch support is not a topic for Guix. + "--disable-multiarch" + ;; As musl is limited, gcc will not be usable for 32 and 64 bit builds. + "--disable-multilib" + ;; Without a dynamic loader shared libraries are still not usable and + ;; we won't use this GCC version to build the GNU C library. + "--disable-shared" + ;; Disable all language frontends except for C and C++. + "--enable-languages=c,c++" + ;; Avoid parallel linking to not crash on systems with limited memory. + "--enable-link-serialization" + ;; Prevent the C++ headers in #$output:lib, put them in #$output:out + ;; instead. Use an unconventional path to prevent it from being added + ;; to the environment variables C_INCLUDE_PATH, CPLUS_INCLUDE_PATH. + "--with-gxx-include-dir=$(prefix)/include-c++" + ;; The first set of include paths consists of #$output/include-c++/… + ;; and #$output:lib/lib/…/include. Second is usually + ;; /usr/local/include, which is documented to be avoided, if the same + ;; value is used for both --prefix and --with-local-prefix. + (string-append "--with-local-prefix=" #$output) + ;; Third set is #$output:lib/…/include-fixed, which expects + ;; #$MUSL-bootstrap/include to follow. Kernel-headers are obsolete + ;; with musl. Fourth and usually the last include path is /usr/include + ;; containing all system headers. It is only possible to specify one + ;; path for this. Set the #$MUSL-bootstrap/include path and prevent + ;; the use of /usr/include. + (string-append "--with-native-system-header-dir=" + #$MUSL-bootstrap "/include") + (string-append + "--with-specs=" + ;; Ensure that the built GCC will find the right executables from + ;; #$BINUTILS-bootstrap. + "-B" #$BINUTILS-bootstrap "/bin " + ;; Embed the link-time search path to #$MUSL-bootstrap/lib. + "-B" #$MUSL-bootstrap "/lib")) + #:phases + #~(modify-phases %standard-phases + (delete 'install-locale) + (delete 'compress-documentation) + (add-after 'unpack 'patch-source + (lambda _ + (substitute* "Makefile.in" + ;; Don't store configure arguments, to avoid a cyclic reference + ;; in #$output:lib/lib/gcc/…/include/configargs.h back to + ;; #$output and retaining references to build-time dependencies + ;; like gash-boot. + (("@TOPLEVEL_CONFIGURE_ARGUMENTS@") + "")) + (substitute* "libstdc++-v3/configure.host" + ;; The configure scripts of GCC 10.5.0 do not know musl. Using + ;; a configure option --build=i686-unknown-linux-gnu or omitting + ;; it, they basically assume the presence of the GNU C Library. + ;; This leads to issues when building libstdc++-v3. For musl + ;; files from libstdc++-v3/config/os/generic have to be used + ;; instead of files from libstdc++-v3/config/os/gnu-linux. + (("os_include_dir=\"os/gnu-linux\"") + "os_include_dir=\"os/generic\"")) + (substitute* "libstdc++-v3/python/Makefile.in" + ;; Change pythondir from #$output:out to #$output:lib to prevent + ;; #$output:lib/lib/libstdc++.*-gdb.py to create a cyclic + ;; dependency to #$output:out/share/…/python. This moves all + ;; python files to #$output:lib. The configure option + ;; --with-python-dir stays usable. + (("pythondir = \\$\\(datadir\\)") + "pythondir = $(libdir)/share") + (("pythondir = \\$\\(prefix\\)") + "pythondir = $(libdir)")) + (substitute* "gcc/gen-pass-instances.awk" + ;; In commands/awk/parser.scm of gash-utils the function + ;; parameter list gramma is missing newline-opt around COMMA: + ;; (param-list + ;; (name) : `(,$1) + ;; (param-list COMMA name) : `(,@$1 ,$3)) + ;; Due to this the parsing of the parameters of the function + ;; parse_line in gcc/gen-pass-instances.awk fails. Removing the + ;; newlines is a possible workaround. + (("^([^#]*,)\n" _ line) + line) + ;; In gash/commands/awk.scm of gash-utils the function + ;; eval-awke/number does not strip leading whitespace from a + ;; string before converting it into a number, as the C function + ;; atof does, which awk is probably using. + (("^([ \t]*)pass_num = args\\[2\\] \\+ 0;\n$" line indent) + (string-append + indent "sub(/^[ \\t]*/, \"\", args[2]);\n" + line))) + (substitute* "gcc/opt-functions.awk" + ;; In ash/commands/awk.scm of gash-utils the function + ;; string-split/regex returns a list with an empty string when + ;; trying to split an empty string, leading to the wrong result + ;; of 1 intstead of 0 for the awk split command. + (("^([ \t]*)n_enabledby_array = split\\(enabledby_name,.*$" + line indent) + (string-append + line + indent "if (enabledby_name == \"\") {\n" + indent " n_enabledby_array = 0\n" + indent "}\n"))))) + (add-after 'install 'remove-install-tools + (lambda _ + ;; The programs in install-tools try to modify the store and have + ;; retaining references to sed and bash-minimal. They are useless + ;; in Guix and can be deleted to reduce references. + (for-each (lambda (directory) + (delete-file-recursively + (car (find-files directory + "^install-tools$" + #:directories? #t)))) + (list #$output #$output:lib))))))) + (native-search-paths + (list (search-path-specification + (variable "C_INCLUDE_PATH") + (files (list "include"))) + (search-path-specification + (variable "CPLUS_INCLUDE_PATH") + (files (list "include"))) + (search-path-specification + (variable "LIBRARY_PATH") + (files (list "lib"))))) + (synopsis "GNU Compiler Collection for C and C++") + (description + "This GNU Compiler Collection includes a front end for C and C++.") + (home-page "https://gcc.gnu.org/") + (license license:gpl3+))) + +(define-public GLIBC-bootstrap + (package + (name "GLIBC-bootstrap") + (version "2.22") + (source + (origin + (method url-fetch) + (uri (string-append "mirror://gnu/glibc/glibc-" version ".tar.gz")) + (sha256 + (base32 "1rcby0cqgswgqaxyqz0yqc4zizb1kvpi5vlfqp7dh3sa132109m6")))) + (native-inputs (with-shell gash-boot + GCC-10-bootstrap + BINUTILS-bootstrap + GETCONF-bootstrap + MAKE-bootstrap + gash-utils-boot + bootar)) + (build-system gnu-build-system) + (arguments + (list + #:guile %bootstrap-guile + #:implicit-inputs? #f + #:out-of-source? #t + #:tests? #f + #:configure-flags + #~(list + "--disable-sanity-checks" + "--disable-shared" + "--enable-static-nss" + (string-append "--with-headers=" + #$%bootstrap-linux-libre-headers + "/include")))) +#! + #:phases + #~(modify-phases %standard-phases + (add-after 'unpack 'patch-source + (lambda _ + #;(substitute* "configure" + ;; Ignore all arguments, which are not options. The + ;; gnu-build-system passes CONFIG_SHELL=… and SHELL=… which + ;; get otherwise interpreted as multiple host arguments. + (("nonopt=\"\\$ac_option\"") "") + ;; Disable checks for program versions. + (("ac_prog_version, bad\"; ac_verc_fail=yes;;") + "ac_prog_version, ok\"; ac_verc_fail=no;;") + ;; Don't insist to combile with GCC only. + (("error: GNU libc must(.+) exit 1;" _ message) + (string-append "warning: GNU libc should" message)) + ;; Map x86_64 to i386. + (("i\\[3456\\]86.+" ix86) + (string-append + ix86 "\n" + "x86_64)\tbase_machine=i386 machine=i386/i686 ;;")) + ;; Do not use the result of $CC -print-file-name=include. + (("-isystem \\$ccheaders ") "")) + #;(substitute* "Rules" + ;; TCC does not know SUNPRO_DEPENDENCIES and needs two separate + ;; commands to output defines and dependencies. + (("(.+)-E -dM -xc -.+)" cc prefix) + (string-append cc "\n" + prefix "-M -MF $(@:st=dT) -xc - -o $@")) + #;(substitute* "sysdeps/i386/elf/start.S" + (("\\.globl _start") "")) + #;(substitute* "sysdeps/unix/sysv/linux/i386/sysdep.S" + (("ENTRY \\(__syscall_error\\)") "__syscall_error:")) + #;(substitute* "csu/version.c" + (("Compiled by GNU CC version \"__VERSION__\"") + "Compiled by Tiny C Compiler")) + #;(substitute* "sysdeps/generic/check_fds.c" + (("\\|\\| st\\.st_rdev != makedev \\(DEV_NULL_MAJOR, DEV_NULL_MINOR\\)") + (string-append + "|| st.st_rdev.__val[0] != DEV_NULL_MAJOR\n" + "|| st.st_rdev.__val[1] != DEV_NULL_MINOR"))))) +!# + (synopsis "The GNU C Library") + (description + "The GNU C Library is the standard system C library for all GNU systems, +and is an important part of what makes up a GNU system. It provides the system +API for all programs written in C and C-compatible languages such as C++ and +Objective C; the runtime facilities of other programming languages use the C +library to access the underlying operating system.") + (home-page "https://sourceware.org/glibc/") + (license license:lgpl2.0+))) + +;; The GNU C library version 2.23 requires GCC 4.7, the version 2.22 is the +;; latest version buildable with GCC 4.6.4. +;; GCC 4.8.0 is the oldest version known to have been built with Glibc 2.22. +;; See . +#;(define glibc-bootstrap-2.22-native-inputs + (fold alist-cons + (alist-delete "tcc" GCC-bootstrap-native-inputs) + '("gcc" "headers") + '(GCC-bootstrap ,((@@ (gnu packages commencement) mesboot-headers))))) + +;; TCC 0.9.27 from December 2017 is able to build GCC 4.7.4. +;; See . + +;; GCC 4.8.3 is the first ISO C++11 compiler able to build all versions up to +;; GCC 14.1.0 (latest release at 2024-06) or maybe newer. +;; GCC 10.5.0 is the latest version compilable with an ISC C++98 comiler. +;; GCC 10.5.0 is not extractable, fallback to GCC 10.4.0. + +;; Plan: +;; Use GCC 4.6.4 to build GCC 10.4.0, latest extractable and buildable version. +;; Use GCC 10.5.0 to build GCC 14.2.0, the latest GCC version as of 2024-10. + +;; Obstacles: +;; GCC 10.4.0 has some prerequisites which need to be build as well. They may +;; not be compilable with GCC 4.6.4. + + +; Fertiger GCC! +; /gnu/store/0jdihrzpbakrmsb7b8ck9l82mypr11am-GCC-4-bootstrap-4.6.4-lib +; /gnu/store/1dv1gda31w16wlvy15p1qkzyw02m4nqq-GCC-4-bootstrap-4.6.4 +