vinix-ports / gcc-libs / PKGBUILD.vile
104 lines · 103 sloc · 7.67 KB · 9dc6de9af9e346da27b593c74109e3eb040897cd
Raw
1; Build the target runtimes from GCC sources using the external bootstrap
2; compiler. Only the versioned shared objects belong to this package.
3host-arch := if memq(string->symbol("aarch64"), features()) { "aarch64" } else { "x86_64" }
4selected := get-environment-variable("VPAC_TARGET_ARCH")
5arch := if string?(selected) { selected } else { host-arch }
6arm := string=?(arch, "aarch64")
7libc := if arm { "musl>=1.2.6-4" } else { "musl" }
8triplet := string-append(arch, "-linux-musl")
9libs := list("libgcc_s.so.1", "libstdc++.so.6", "libatomic.so.1", "libgomp.so.1")
10
11defpkgbuild(gcc-libs,
12 #:pkgname, "gcc-libs",
13 #:pkgver, "14.2.0",
14 #:pkgrel, if arm { 2 } else { 1 },
15 #:pkgdesc, "GNU C and C++ shared runtime libraries for Vinix",
16 #:arch, [#:x86-64, #:aarch64],
17 #:url, "https://gcc.gnu.org/",
18 #:license, ["GPL-3.0-or-later WITH GCC-exception-3.1"],
19 #:depends, list(libc),
20 #:provides, ["libgcc=14.2.0", "libstdc++=14.2.0", "libatomic=14.2.0", "libgomp=14.2.0"],
21 #:makedepends, ["linux-headers", "gmp", "mpfr", "mpc", "zlib", "make"],
22 #:source, ["https://distfiles.alpinelinux.org/distfiles/v3.21/gcc-14.2.0.tar.xz"],
23 #:sha256sums, ["a7b39bc69cbf9e25826c5a60ab26477001f7c08d85cec04bc0e29cabed6f3cc9"],
24 #:build, fn() {
25 root := get-environment-variable("VPAC_MAKEPKG_ROOT")
26 native := string=?(host-arch, arch)
27 prefix := if native { "" } else { get-environment-variable("CROSS_COMPILE") }
28 driver := string-append(srcdir(), "/driver-support")
29 ; Alpine's bootstrap GCC unconditionally links -lssp_nonshared. Older
30 ; Vinix SDKs lack the archive. Build its GCC implementation for the
31 ; selected target without adding any external library search directory.
32 driver-flags := if file-exists?(string-append(root, "/usr/lib/libssp_nonshared.a")) { "" } else {
33 run("mkdir", "-p", driver)
34 call-with-output-file(string-append(driver, "/config.h"), fn(port) { display("#define HAVE_HIDDEN_VISIBILITY 1\n", port) })
35 object := string-append(driver, "/ssp-local.o")
36 run("vinix-cc", "-O2", "-fPIC", "-fno-stack-protector", string-append("-I", driver), "-c", "gcc-14.2.0/libssp/ssp-local.c", "-o", object)
37 run(string-append(prefix, "ar"), "rcs", string-append(driver, "/libssp_nonshared.a"), object)
38 string-append("-L", driver)
39 }
40 build-option := if native { list(string-append("--build=", triplet)) } else { list() }
41 target-flags := if arm { "-O2 -g0 -mno-outline-atomics" } else { "-O2 -g0" }
42 target-tools := if native { list() } else {
43 list("CC_FOR_BUILD=gcc", "CXX_FOR_BUILD=g++", "CFLAGS_FOR_BUILD=-O2 -g0", "CXXFLAGS_FOR_BUILD=-O2 -g0", "LDFLAGS_FOR_BUILD=",
44 "AR_FOR_BUILD=ar", "RANLIB_FOR_BUILD=ranlib",
45 string-append("AR=", prefix, "ar"), string-append("AS=", prefix, "as"),
46 string-append("LD=", prefix, "ld"), string-append("NM=", prefix, "nm"),
47 string-append("RANLIB=", prefix, "ranlib"), string-append("STRIP=", prefix, "strip"),
48 string-append("AR_FOR_TARGET=", prefix, "ar"), string-append("AS_FOR_TARGET=", prefix, "as"),
49 string-append("LD_FOR_TARGET=", prefix, "ld"), string-append("NM_FOR_TARGET=", prefix, "nm"),
50 string-append("RANLIB_FOR_TARGET=", prefix, "ranlib"), string-append("STRIP_FOR_TARGET=", prefix, "strip"))
51 }
52 apply(run, append(list("env", "CC=vinix-cc", "CXX=vinix-c++", "CC_FOR_BUILD=gcc", "CXX_FOR_BUILD=g++",
53 "CFLAGS=-O1 -g0", string-append("CFLAGS_FOR_TARGET=", target-flags), string-append("CXXFLAGS_FOR_TARGET=", target-flags)), target-tools,
54 list("gcc-14.2.0/configure", "--prefix=/usr", "--libdir=/usr/lib"), build-option,
55 list(string-append("--host=", triplet), string-append("--target=", triplet), "--enable-languages=c,c++",
56 "--disable-bootstrap", "--with-sysroot=/", string-append("--with-build-sysroot=", root), "--with-native-system-header-dir=/usr/include",
57 string-append("--with-gmp=", root, "/usr"), string-append("--with-mpfr=", root, "/usr"), string-append("--with-mpc=", root, "/usr"),
58 "--with-system-zlib", "--without-isl", "--disable-multilib", "--disable-nls", "--disable-libstdcxx-pch", "--disable-libsanitizer",
59 "--disable-libquadmath", "--disable-libcc1", "--enable-libatomic", "--enable-libgomp", "--enable-shared", "--enable-threads=posix")))
60 apply(run, append(list("make"), target-tools, list("configure-gcc", "all-build-libiberty", "all-build-fixincludes",
61 "all-libiberty", "all-libcpp", "all-libdecnumber", "all-libbacktrace")))
62 ; GCC's fixed-header rules query the compiler's predefined macros and
63 ; multilib list. The bootstrap driver can answer both for the target.
64 apply(run, append(list("make", "-C", "gcc", "-o", "xgcc", "-o", "specs", "-o", "cc1", "GCC_FOR_TARGET=vinix-cc"),
65 target-tools, list("GENERATOR_CFLAGS=-O2 -g0", "libgcc-support", "tm.h", "options.h", "insn-constants.h", "insn-modes.h", "insn-modes-inline.h")))
66 target-make := append(list("make", "-o", "maybe-all-gcc", "-o", "all-gcc", "CC_FOR_TARGET=vinix-cc", "GCC_FOR_TARGET=vinix-cc",
67 "CXX_FOR_TARGET=vinix-c++", "RAW_CXX_FOR_TARGET=vinix-c++"), target-tools)
68 apply(run, append(target-make, list(string-append("LDFLAGS_FOR_TARGET=", driver-flags), "all-target-libgcc")))
69 ; The stage-one musl specs normally select static compiler support.
70 ; Link libstdc++ to the shared unwinder built in the preceding step.
71 support := string-append(srcdir(), "/", triplet, "/libgcc")
72 run("test", "-f", string-append(support, "/libgcc_s.so.1"))
73 ; Libtool filters a bare shared-object argument from LDFLAGS. Passing it
74 ; explicitly to ld keeps the new runtime's SONAME in libstdc++.so.6.
75 link-flags := string-append("LDFLAGS_FOR_TARGET=", driver-flags, " -Wl,--no-as-needed,", support, "/libgcc_s.so.1,--as-needed -Wl,-rpath-link,",
76 root, "/lib -Wl,-rpath-link,", root, "/usr/lib")
77 ; Preserve the completed unwinder. Recursing into libgcc with its own
78 ; shared object on the link line produces a self-dependent library.
79 libraries := append(target-make, list("-o", "maybe-all-target-libgcc", "-o", "all-target-libgcc"))
80 apply(run, append(libraries, list(link-flags, "all-target-libstdc++-v3")))
81 apply(run, append(libraries, list(string-append("LDFLAGS_FOR_TARGET=", driver-flags), "all-target-libatomic", "all-target-libgomp")))
82 },
83 #:package, fn() {
84 dest := string-append(pkgdir(), "/usr/lib")
85 run("mkdir", "-p", dest)
86 ; Copy only files linked by these four target build directories. The
87 ; archive contains the versioned ELF and its SONAME, not seed libraries.
88 for-each(fn(pattern) {
89 for-each(fn(file) { run("cp", "-P", file, dest) }, glob(pattern))
90 }, list(string-append(triplet, "/libgcc/libgcc_s.so.*"), string-append(triplet, "/libstdc++-v3/src/.libs/libstdc++.so.*"),
91 string-append(triplet, "/libatomic/.libs/libatomic.so.*"), string-append(triplet, "/libgomp/.libs/libgomp.so.*")))
92 for-each(fn(lib) { run("test", "-f", string-append(dest, "/", lib)) }, libs)
93 run("sh", "-ec", "readelf -d \"$1\" | grep '(NEEDED)' | grep -F '[libgcc_s.so.1]'", "check-unwinder",
94 string-append(dest, "/libstdc++.so.6"))
95 if arm {
96 for-each(fn(lib) {
97 file := string-append(dest, "/", lib)
98 run("vinix-elf-pages", arch, file)
99 run("sh", "-ec", "readelf --wide --dyn-syms \"$1\" | awk '$7 == \"UND\" && $8 ~ /^__aarch64_(cas|swp|ldadd|ldclr|ldeor|ldset)/ { print $8; bad=1 } END { exit bad }'", "check-outlined-atomics", file)
100 }, libs)
101 }
102 run("install", "-Dm644", "gcc-14.2.0/COPYING.RUNTIME", string-append(pkgdir(), "/usr/share/licenses/gcc-libs/COPYING.RUNTIME"))
103 run("install", "-Dm644", "gcc-14.2.0/COPYING3", string-append(pkgdir(), "/usr/share/licenses/gcc-libs/COPYING3"))
104 })
105