1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
# Maintainer: Matt Taylor <64.delta@proton.me>
# https://github.com/64/aur-packages for pull requests and issues.
pkgname=mlibc
pkgver=5.0.0
pkgrel=1
pkgdesc="A portable C standard library"
arch=('x86_64')
url="https://github.com/managarm/mlibc"
license=('MIT')
groups=()
depends=()
makedepends=(
binutils
gcc
git
libisl
libmpc
libxcrypt
meson
ninja
python
zstd
)
checkdepends=('meson' 'ninja')
optdepends=()
provides=()
conflicts=()
replaces=()
backup=()
options=(staticlibs)
install=
changelog=
GCCVER=13.2.3
BINUTILSVER=2.40
LINUXVER=6.8.1
source=("$pkgname-$pkgver.tar.gz::https://github.com/managarm/mlibc/archive/refs/tags/$pkgver.tar.gz"
"gcc-managarm-$GCCVER.tar.gz::https://github.com/managarm/gcc/archive/refs/tags/managarm/gcc-$GCCVER.tar.gz"
"binutils-managarm-$BINUTILSVER.tar.gz::https://github.com/managarm/binutils-gdb/archive/refs/tags/managarm/binutils-2_40_2.tar.gz"
"https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-$LINUXVER.tar.xz"
"config.sub::https://git.savannah.gnu.org/cgit/config.git/plain/config.sub?id=948ae97ca5703224bd3eada06b7a69f40dd15a02")
noextract=()
md5sums=('870d607b8d4c5922a74653af8a5625cd'
'b6d5828e1392c9e84fb86fb2735c5fd8'
'd277da5a45da1e0323f1e4eb571f8f53'
'c4423a42f1e32d9decf17897eaca15ee'
'e14e81807d4870d70f29ec131aed4ab2')
validpgpkeys=()
# We can't use the linux-headers package, because it installs to /usr/include (and including that during the
# mlibc build will include all other system headers). We'll install our own kernel headers instead.
sysroot_install_linux_headers() {
make -C linux-$LINUXVER headers_install INSTALL_HDR_PATH=$SYSROOT/usr
}
sysroot_install_mlibc() {
cd "$pkgname-$pkgver"
# The default flags include -fexceptions which requires libgcc.
CFLAGS=${CFLAGS//"-fexceptions"}
CXXFLAGS=${CXXFLAGS//"-fexceptions"}
# The default LDFLAGS includes -z,now which we don't support.
LDFLAGS=${LDFLAGS//",-z,now"}
# Install mlibc into sysroot
meson --prefix=/usr -Dlinux_kernel_headers=$SYSROOT/usr/include -Dbuildtype=release -Ddefault_library=both build
DESTDIR="$SYSROOT" ninja -C build install
# This mlibc-gcc uses a specs file to wrap the host's one. It's a hack, we don't use it.
rm $SYSROOT/usr/bin/mlibc-gcc $SYSROOT/usr/lib/mlibc-gcc.specs
cd ../
}
build_gcc_and_binutils() {
# Combined tree build!
# https://gcc.gnu.org/wiki/Building_Cross_Toolchains_with_gcc
# Unpacking binutils over gcc works but not the other way around...
SRCDIR="binutils-gdb-managarm-binutils-2_40_2"
# cp -R "binutils-gdb-managarm-binutils-2_40_2"/* "gcc-managarm-gcc-$GCCVER/"
cp -R "gcc-managarm-gcc-$GCCVER/"* $SRCDIR
# Copy a newer config.sub that knows about mlibc
cp ../config.sub "$SRCDIR"
mkdir -p build-mlibc
cd build-mlibc
# Copied from gcc-git AUR package
CFLAGS=${CFLAGS/-Werror=format-security/}
CXXFLAGS=${CXXFLAGS/-Werror=format-security/}
# TODO: relative paths in --with-build-sysroot do not work, this causes warnings since the absolute path references $srcdir.
# --with-build-sysroot=$(realpath --relative-to . $SYSROOT)
../$SRCDIR/configure \
--target=$CARCH-linux-mlibc \
--prefix=/usr \
--with-sysroot=/usr/share/mlibc-sysroot \
--with-build-sysroot=$SYSROOT \
--enable-languages=c,c++,lto \
--enable-initfini-array \
--disable-multilib \
--disable-shared \
--disable-nls \
--disable-libstdcxx-hosted \
--disable-libstdcxx-backtrace \
--disable-wchar_t \
--disable-{libssp,libsanitizer,libquadmath,gdb,gold,gprof,gprofng} \
--disable-{libdecnmumber,readline,sim,libctf,libgomp,libatomic} \
--disable-{libffi,libitm,libvtv} \
--disable-werror
make
DESTDIR="$SYSROOT" make install
cd ../
}
build() {
mkdir -p mlibc-sysroot/usr
SYSROOT=$(realpath mlibc-sysroot)
sysroot_install_linux_headers
sysroot_install_mlibc
build_gcc_and_binutils
}
check() {
important_binaries=("ld" "gcc" "g++")
for bin in "${important_binaries[@]}"; do
file="$SYSROOT/usr/bin/$CARCH-linux-mlibc-$bin"
echo "Checking that $file exists..."
test -f $file
done
}
package() {
SYSROOT=$(realpath mlibc-sysroot)
PREFIX=/usr/share/mlibc-sysroot/usr
mkdir -p "$pkgdir/usr/share"
cp -R "$SYSROOT" "$pkgdir/usr/share/"
mkdir -p "$pkgdir/usr/bin"
ln -s "$PREFIX/bin/$CARCH-linux-mlibc-gcc" "$pkgdir/usr/bin/mlibc-gcc"
ln -s "$PREFIX/bin/$CARCH-linux-mlibc-g++" "$pkgdir/usr/bin/mlibc-g++"
install -Dm644 "./$pkgname-$pkgver/LICENSE" "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}
|