projects/aports·blob master · refs

213 lines · 4.4 KiB

1# Contributor: Olliver Schinagl <[email protected]>
2# Maintainer: Olliver Schinagl <[email protected]>
3pkgname=klibc
4pkgver=2.0.14
5pkgrel=1
6pkgdesc="A minimalistic libc subset for use with initramfs"
7url="https://git.kernel.org/pub/scm/libs/klibc/klibc.git/"
8arch="all"
9license="GPL-2.0-or-later"
10makedepends="linux-headers perl"
11install="
12 lib$pkgname.post-deinstall
13 lib$pkgname.post-install
14"
15subpackages="
16 $pkgname-dash
17 $pkgname-dev
18 $pkgname-doc
19 $pkgname-static:static
20 $pkgname-fstype:bins
21 $pkgname-ipconfig:bins
22 $pkgname-kinit::noarch
23 $pkgname-klcc::noarch
24 $pkgname-nfsmount:bins
25 $pkgname-resume:bins
26 $pkgname-run-init:bins
27 $pkgname-utils
28 lib$pkgname:libs
29"
30source="
31 https://git.kernel.org/pub/scm/libs/klibc/klibc.git/snapshot/klibc-$pkgver.tar.gz
32"
33_installdir="/usr/lib/$pkgname-$CARCH/"
34
35# secfixes:
36# 2.0.9-r0:
37# - CVE-2021-31870
38# - CVE-2021-31871
39# - CVE-2021-31872
40# - CVE-2021-31873
41
42build() {
43 # klibc's header misses the struct declaration, Linux's misses
44 # the function declaration. Combine them here.
45 if [ ! -e "$builddir/usr/include/sys/sysinfo.h.orig" ]; then
46 mv "$builddir/usr/include/sys/sysinfo.h" \
47 "$builddir/usr/include/sys/sysinfo.h.orig"
48 fi
49 cat \
50 "/usr/include/linux/sysinfo.h" \
51 "$builddir/usr/include/sys/sysinfo.h.orig" > \
52 "$builddir/usr/include/sys/sysinfo.h"
53
54 make \
55 KBUILD_REPRODUCIBLE=1 \
56 KLIBCKERNELSRC="/usr/"
57}
58
59check() {
60 make \
61 KBUILD_REPRODUCIBLE=1 \
62 KLIBCKERNELSRC="/usr/" \
63 test
64}
65
66package() {
67 depends="
68 lib$pkgname
69 $pkgname-dash
70 $pkgname-kinit
71 $pkgname-utils
72 "
73
74case "$CARCH" in
75 aarch64)
76 _klibcarch="arm64"
77 ;;
78 armhf)
79 _klibcarch="arm"
80 CPU_ARCH="armv6zk"
81 CPU_TUNE="arm1176jzf-s"
82 ;;
83 armv7)
84 _klibcarch="arm"
85 CPU_ARCH="armv7"
86 CPU_TUNE="generic-armv7-a"
87 ;;
88 ppc)
89 _klibcarch="ppc"
90 ;;
91 ppc64|ppc64le)
92 _klibcarch="ppc64"
93 ;;
94 riscv64)
95 _klibcarch="riscv64"
96 ;;
97 s390x)
98 _klibcarch="s390"
99 ;;
100 x86)
101 _klibcarch="i386"
102 ;;
103 x86_64)
104 _klibcarch="x86_64"
105 ;;
106 *)
107 echo 'Unsupported architecture'
108 ;;
109 esac
110 export CPU_ARCH
111 export CPU_TUNE
112 make \
113 INSTALLDIR="$_installdir" \
114 INSTALLROOT="$pkgdir" \
115 KBUILD_REPRODUCIBLE=1 \
116 KLIBCKERNELSRC="/usr/" \
117 mandir="/usr/share/man" \
118 install
119
120 # Duplicated in INSTALLDIR/lib and replaced with post.install
121 rm -r "${pkgdir:?}/lib"
122
123 for _arch in "$pkgdir/$_installdir/include/arch/"*; do
124 if [ "${_arch##*/}" != "$_klibcarch" ]; then
125 rm -r "${_arch:?}"
126 fi
127 done
128
129 # Replace hardlinks with symlinks
130 unlink "$pkgdir/$_installdir/bin/gunzip"
131 unlink "$pkgdir/$_installdir/bin/poweroff"
132 unlink "$pkgdir/$_installdir/bin/reboot"
133 unlink "$pkgdir/$_installdir/bin/zcat"
134
135 ln -s "gzip" "$pkgdir/$_installdir/bin/gunzip"
136 ln -s "gzip" "$pkgdir/$_installdir/bin/zcat"
137
138 ln -s "halt" "$pkgdir/$_installdir/bin/poweroff"
139 ln -s "halt" "$pkgdir/$_installdir/bin/reboot"
140}
141
142klcc() {
143 depends="perl"
144
145 mkdir -p "$subpkgdir/usr/bin"
146 mv "$pkgdir/usr/bin/klcc" "$subpkgdir/usr/bin/"
147}
148
149libs() {
150 mkdir -p "$subpkgdir/$_installdir"
151 mv "$pkgdir/$_installdir/lib" "$subpkgdir/$_installdir/"
152}
153
154bins() {
155 depends="lib$pkgname"
156
157 mkdir -p "$subpkgdir/$_installdir/bin"
158 mv "$pkgdir/$_installdir/bin/${subpkgname#"$pkgname"-}" "$subpkgdir/$_installdir/bin/"
159}
160
161dash() {
162 depends="lib$pkgname"
163
164 mkdir -p "$subpkgdir/$_installdir/bin"
165 mv "$pkgdir/$_installdir/bin/sh" "$subpkgdir/$_installdir/bin/"
166}
167
168kinit() {
169 depends="
170 $pkgname-fstype
171 $pkgname-ipconfig
172 $pkgname-nfsmount
173 $pkgname-resume
174 $pkgname-run-init
175 "
176
177 mkdir -p "$subpkgdir"
178}
179
180utils() {
181 depends="lib$pkgname"
182
183 mkdir -p "$subpkgdir/$_installdir/"
184 mv "$pkgdir/$_installdir/bin" "$subpkgdir/$_installdir/"
185}
186
187static() {
188 mkdir -p "$subpkgdir/$_installdir/bin"
189
190 find "$builddir" -type d -name 'static' | while read -r _staticbins; do
191 for _bin in "$_staticbins/"*; do
192 if [ -z "${_bin%%*.g}" ]; then
193 continue
194 fi
195
196 install -D -m 755 "${_bin}" \
197 "$subpkgdir/$_installdir/bin/${_bin##*/}.static"
198 done
199 done
200
201 mv "$pkgdir/$_installdir/bin/gunzip" \
202 "$subpkgdir/$_installdir/bin/gunzip.static"
203
204 mv "$pkgdir/$_installdir/bin/gzip" \
205 "$subpkgdir/$_installdir/bin/gzip.static"
206
207 mv "$pkgdir/$_installdir/bin/zcat" \
208 "$subpkgdir/$_installdir/bin/zcat.static"
209}
210
211sha512sums="
2124a0a1a1fb7c1e52519a1e403f3c5050ca311394aebe09f131baec2204bb3ff46198f18ea84c0eff5a22e94ffb776dea3b16f9ca0db1a4a3ac850b6038edef866 klibc-2.0.14.tar.gz
213"