; The build machine needs a working musl C++17 compiler. CXXFLAGS and LDFLAGS ; may point at that compiler's C++ headers and runtime for this first stage. ; A native bootstrap builds the target runtime with the new compiler. A ; cross bootstrap needs an existing build-machine compiler for the target. host-arch := if memq(string->symbol("aarch64"), features()) { "aarch64" } else { "x86_64" } selected := get-environment-variable("VPAC_TARGET_ARCH") arch := if string?(selected) { selected } else { host-arch } triplet := string-append(arch, "-linux-musl") cross := not(string=?(arch, host-arch)) libc := if string=?(arch, "aarch64") { "musl>=1.2.6-4" } else { "musl" } ; Makefiles keep absolute paths. A worker retry can keep the prepared source ; and objects in the same dedicated directory. checkpoint := get-environment-variable("VINIX_GCC_BUILD_DIR") persistent := if string?(checkpoint) { not(string=?("", checkpoint)) } else { #f } checkpoint-recipe := if persistent { string-append(checkpoint, "/recipe.vile") } else { "" } cached := if persistent { file-exists?(checkpoint-recipe) } else { #f } build-dir := fn() { if persistent { checkpoint } else { srcdir() } } local-archive := get-environment-variable("VINIX_GCC_LOCAL_SOURCE") source-archive := if equal?("1", local-archive) { "gcc-14.2.0.tar.xz" } else { "https://distfiles.alpinelinux.org/distfiles/v3.21/gcc-14.2.0.tar.xz" } itm-compiler := fn() { if cross { "CXX_FOR_TARGET=vinix-c++" } else { build := build-dir() cxx := string-append(build, "/", triplet, "/libstdc++-v3") string-append("CXX_FOR_TARGET=", build, "/gcc/xg++ -B", build, "/gcc/ -nostdinc++", " -isystem ", cxx, "/include/", triplet, " -isystem ", cxx, "/include", " -isystem ", build, "/gcc-14.2.0/libstdc++-v3/libsupc++", " -L", cxx, "/src/.libs -L", cxx, "/libsupc++/.libs") } } defpkgbuild(gcc, #:pkgname, "gcc", #:pkgver, "14.2.0", #:pkgrel, 1, #:pkgdesc, "GNU C and C++ compilers, headers and development libraries for Vinix", #:arch, [#:x86-64, #:aarch64], #:url, "https://gcc.gnu.org/", #:license, ["GPL-3.0-or-later", "GPL-3.0-or-later WITH GCC-exception-3.1"], #:depends, list(libc, if string=?(arch, "aarch64") { "gcc-libs=14.2.0-2" } else { "gcc-libs=14.2.0-1" }, "gmp", "mpfr", "mpc", "isl25", "zlib", "binutils"), #:provides, ["g++=14.2.0", "libstdc++-dev=14.2.0"], #:makedepends, ["make", "linux-headers"], #:source, if cached { list() } else { list(source-archive) }, #:sha256sums, if cached { list() } else { ["a7b39bc69cbf9e25826c5a60ab26477001f7c08d85cec04bc0e29cabed6f3cc9"] }, #:prepare, fn() { if cached { run("cmp", string-append(startdir(), "/PKGBUILD.vile"), checkpoint-recipe) run("test", "-x", string-append(build-dir(), "/gcc-14.2.0/configure")) } else { ; Serialize the two memory-intensive instruction-table generators. run("sed", "-i", "$a s-automata: s-attrtab", "gcc-14.2.0/gcc/Makefile.in") ; Match the library directory used by Vinix's musl loader. if string=?(arch, "x86_64") { run("sed", "-i", "s|m64=../lib64|m64=../lib|", "gcc-14.2.0/gcc/config/i386/t-linux64") } else { run("sed", "-i", "s|mabi.lp64=../lib64|mabi.lp64=../lib|", "gcc-14.2.0/gcc/config/aarch64/t-aarch64-linux") ; This default also applies when GCC drives an alternate GNU linker. run("sed", "-i", "s|^#define LINK_SPEC LINUX_TARGET_LINK_SPEC|#define LINK_SPEC \"-z max-page-size=16384 -z common-page-size=16384 \" LINUX_TARGET_LINK_SPEC|", "gcc-14.2.0/gcc/config/aarch64/aarch64-linux.h") } if persistent { run("mkdir", checkpoint) run("mv", "gcc-14.2.0", checkpoint) run("cp", string-append(startdir(), "/PKGBUILD.vile"), checkpoint-recipe) } } }, #:build, fn() { root := get-environment-variable("VPAC_MAKEPKG_ROOT") binutils := if cross { get-environment-variable("VINIX_GCC_BUILD_TOOLS") } else { string-append(root, "/usr/bin") } run("test", "-x", string-append(binutils, "/as")) run("test", "-x", string-append(binutils, "/ld")) target-tools := if cross { list("CC_FOR_BUILD=gcc", "CXX_FOR_BUILD=g++", "CFLAGS_FOR_BUILD=-O2 -g0", "CXXFLAGS_FOR_BUILD=-O2 -g0", "LDFLAGS_FOR_BUILD=", "AR_FOR_BUILD=ar", "RANLIB_FOR_BUILD=ranlib", string-append("AR=", binutils, "/ar"), string-append("AS=", binutils, "/as"), string-append("LD=", binutils, "/ld"), string-append("NM=", binutils, "/nm"), string-append("RANLIB=", binutils, "/ranlib"), string-append("STRIP=", binutils, "/strip"), "CC_FOR_TARGET=vinix-cc", "GCC_FOR_TARGET=vinix-cc", "CXX_FOR_TARGET=vinix-c++", "RAW_CXX_FOR_TARGET=vinix-c++", string-append("AR_FOR_TARGET=", binutils, "/ar"), string-append("AS_FOR_TARGET=", binutils, "/as"), string-append("LD_FOR_TARGET=", binutils, "/ld"), string-append("NM_FOR_TARGET=", binutils, "/nm"), string-append("RANLIB_FOR_TARGET=", binutils, "/ranlib")) } else { list() } build-option := if cross { list() } else { list(string-append("--build=", triplet)) } configured := string-append(build-dir(), "/.vinix-configured") if not(file-exists?(configured)) { apply(run, append(list("sh", "-ec", "cd \"$1\"; shift; exec \"$@\"", "gcc-configure", build-dir(), "env", "CC=vinix-cc", "CXX=vinix-c++", "CC_FOR_BUILD=gcc", "CXX_FOR_BUILD=g++", "CFLAGS=-O1 -g0", "CFLAGS_FOR_TARGET=-O2 -g0", "CXXFLAGS_FOR_TARGET=-O2 -g0"), target-tools, list("gcc-14.2.0/configure", "--prefix=/usr", "--libdir=/usr/lib"), build-option, list(string-append("--host=", triplet), string-append("--target=", triplet), "--enable-languages=c,c++", "--disable-bootstrap", "--with-sysroot=/", string-append("--with-build-sysroot=", root), "--with-native-system-header-dir=/usr/include", string-append("--with-build-time-tools=", binutils), string-append("--with-gmp=", root, "/usr"), string-append("--with-mpfr=", root, "/usr"), string-append("--with-mpc=", root, "/usr"), string-append("--with-isl=", root, "/usr"), "--with-system-zlib", "--without-zstd", "--disable-multilib", "--disable-nls", "--disable-libsanitizer", "--disable-libvtv", "--disable-libquadmath", "--enable-libgomp", "--enable-libatomic", "--enable-libitm", "--disable-libstdcxx-pch", "--enable-libcc1", "--enable-lto", "--enable-plugin", "--enable-threads=posix", "--enable-shared", "--enable-default-pie", "--enable-default-ssp", "--enable-initfini-array"))) run("touch", configured) } apply(run, append(list("make", "-C", build-dir(), "GENERATOR_CFLAGS=-O2 -g0"), target-tools, list("all-gcc", "all-libcc1", "all-lto-plugin", "all-target-libgcc", "all-target-libstdc++-v3", "all-target-libatomic", "all-target-libgomp"))) ; Pass a concrete command to libitm's recursive make. The standard ; CXX_FOR_TARGET recipe expands a shell command to find the C++ headers. apply(run, append(list("make", "-C", build-dir(), itm-compiler()), target-tools, list("all-target-libitm"))) }, #:check, fn() { driver := string-append(build-dir(), "/gcc/xgcc") binaries := string-append("-B", build-dir(), "/gcc/") if cross { runtime := string-append(build-dir(), "/", triplet) libraries := string-append(runtime, "/libstdc++-v3/src/.libs:", runtime, "/libgcc") run("vinix-run", "--library-path", libraries, driver, binaries, "-dumpmachine") } else { run(driver, binaries, "-dumpmachine") } }, #:package, fn() { run("make", "-C", build-dir(), string-append("DESTDIR=", pkgdir()), "install-gcc", "install-libcc1", "install-lto-plugin", "install-target-libgcc", "install-target-libstdc++-v3", "install-target-libatomic", "install-target-libgomp") run("make", "-C", build-dir(), string-append("DESTDIR=", pkgdir()), itm-compiler(), "install-target-libitm") ; The versioned shared objects are owned by gcc-libs. Keep the unversioned ; linker entries, static archives and headers here. for-each(fn(lib) { files := glob(string-append(pkgdir(), "/usr/lib/", lib, ".so.[0-9]*")) run("test", "-f", car(files)) for-each(fn(file) { run("rm", file) }, files) }, list("libgcc_s", "libstdc++", "libatomic", "libgomp")) for-each(fn(la) { run("rm", la) }, glob(string-append(pkgdir(), "/usr/lib/*.la"))) run("ln", "-s", "gcc", string-append(pkgdir(), "/usr/bin/cc")) for-each(fn(standard) { path := string-append(pkgdir(), "/usr/bin/", standard) compatible := if string=?(standard, "c89") { "-ansi|-std=iso9899:1990" } else { "-std=iso9899:1999" } call-with-output-file(path, fn(port) { display(string-append("#!/bin/sh\nfor arg do\n case \"$arg\" in\n -std=", standard, "|", compatible, ") ;;\n -std=*) echo \"", standard, ": incompatible C standard: $arg\" >&2; exit 1 ;;\n esac\ndone\nexec /usr/bin/gcc -std=", standard, " \"$@\"\n"), port) }) run("chmod", "755", path) }, list("c89", "c99")) plugin := string-append("libexec/gcc/", triplet, "/14.2.0/liblto_plugin.so") run("test", "-f", string-append(pkgdir(), "/usr/", plugin)) run("mkdir", "-p", string-append(pkgdir(), "/usr/lib/bfd-plugins")) run("ln", "-s", string-append("../../", plugin), string-append(pkgdir(), "/usr/lib/bfd-plugins/liblto_plugin.so")) run("rm", "-f", string-append(pkgdir(), "/usr/share/info/dir")) run("install", "-Dm644", string-append(build-dir(), "/gcc-14.2.0/COPYING3"), string-append(pkgdir(), "/usr/share/licenses/gcc/COPYING3")) run("install", "-Dm644", string-append(build-dir(), "/gcc-14.2.0/COPYING.RUNTIME"), string-append(pkgdir(), "/usr/share/licenses/gcc/COPYING.RUNTIME")) })