projects/aports·blob master · refs

284 lines · 8.2 KiB

1# Based upon Alpine's avr-gcc and Arch Linux's arm-none-eabi-gcc, to which
2# the following people contributed:
3# Contributor: Pedro Filipe <[email protected]>
4# Contributor: Stefan Wagner <[email protected]>
5# Contributor: Anatol Pomozov <[email protected]>
6# Contributor: Martin Schmölzer <[email protected]>
7# Maintainer: Marian Buschsieweke <[email protected]>
8pkgname=gcc-cross-embedded
9pkgver=16.2.0
10pkgrel=0
11pkgdesc="C compilers from the GNU Compiler Collection for embedded targets"
12url="https://gcc.gnu.org/"
13depends="gcc"
14makedepends="
15 bash
16 gmp-dev
17 isl-dev
18 linux-headers
19 mpc1-dev
20 mpfr-dev
21 python3
22 zlib-dev
23 "
24# riscv64: CI is still too slow
25arch="all !riscv64"
26license="GPL-3.0-or-later"
27source="
28 https://mirrors.kernel.org/gnu/gcc/gcc-$pkgver/gcc-$pkgver.tar.xz
29
30 newlib-getentropy.patch
31 xtensa-fix-specs.patch
32 "
33options="!check"
34builddir="$srcdir/gcc-$pkgver"
35
36# classify targets as exotic or mainstream. Only build support for
37# exotic targets on typical developer / CI hardware (x86_86, aarach64).
38_targets_mainstream="
39 arm-none-eabi
40 riscv-none-elf
41 "
42
43_targets_exotic="
44 msp430-elf
45 or1k-elf
46 aarch64-none-elf
47 xtensa-none-elf
48 xtensa-esp32-elf
49 xtensa-esp32s2-elf
50 xtensa-esp32s3-elf
51 xtensa-esp8266-elf
52 i386-elf
53 x86_64-elf
54 "
55
56# This specifies the supported RISC-V multilib ISA extensions.
57# For more information on the syntax, see the comment in gcc/config/riscv/multilib-generator.
58#
59# The selected ISA extensions are modeled after the Debian package.
60# See: https://salsa.debian.org/debian/gcc-riscv64-unknown-elf/-/blob/4a1de76060cb8721c06bcfb4c846bc82ee6b3fc3/debian/patches/0002-Add-more-multi-lib-for-rv32-and-rv64.patch
61_riscv_multilib="rv32e-ilp32e--c;rv32ea-ilp32e--m;\
62rv32em-ilp32e--c;rv32eac-ilp32e--;rv32emac-ilp32e--;\
63rv32i-ilp32--c;rv32ia-ilp32--m;rv32im-ilp32--c;\
64rv32if-ilp32f-rv32ifd-c;rv32iaf-ilp32f-rv32imaf,rv32iafc-d;\
65rv32imf-ilp32f-rv32imfd-c;rv32iac-ilp32--;rv32imac-ilp32--;\
66rv32imafc-ilp32f-rv32imafdc-;rv32ifd-ilp32d--c;rv32imfd-ilp32d--c;\
67rv32iafd-ilp32d-rv32imafd,rv32iafdc-;rv32imafdc-ilp32d--;rv64i-lp64--c;\
68rv64ia-lp64--m;rv64im-lp64--c;rv64if-lp64f-rv64ifd-c;\
69rv64iaf-lp64f-rv64imaf,rv64iafc-d;rv64imf-lp64f-rv64imfd-c;\
70rv64iac-lp64--;rv64imac-lp64--;rv64imafc-lp64f-rv64imafdc-;\
71rv64ifd-lp64d--m,c;rv64iafd-lp64d-rv64imafd,rv64iafdc-;rv64imafdc-lp64d--"
72
73case "$CARCH" in
74x86_64|aarch64|loongarch64)
75 # support all targets on typical workstation / notebook / CI servers
76 _targets="$_targets_mainstream $_targets_exotic"
77 makedepends="$makedepends xtensa-dynconfig"
78 ;;
79*)
80 # support only mainstream targets on exotic hosts
81 _targets="$_targets_mainstream"
82 ;;
83esac
84
85for target in $_targets; do
86 case "$target" in
87 xtensa-esp*-elf)
88 subpackages="gcc-$target:_install_esp $subpackages"
89 ;;
90 *)
91 subpackages="gcc-$target:_install_subpkg $subpackages"
92 ;;
93 esac
94 makedepends="$makedepends binutils-$target"
95done
96
97prepare() {
98 default_prepare
99
100 # hack! - some configure tests for header files using "$CPP $CPPFLAGS"
101 for dir in libiberty gcc; do
102 sed -i "/ac_cpp=/s/\$CPPFLAGS/\$CPPFLAGS -O2/" $dir/configure
103 done
104}
105
106_configure_gcc() {
107 local target_specific_flags
108 case "$target" in
109 # Support M and R architecture profiles for ARM
110 arm-none-eabi) target_specific_flags="--with-multilib-list=rmprofile" ;;
111 riscv-none-elf) target_specific_flags="--with-multilib-generator=$_riscv_multilib" ;;
112 *) target_specific_flags="" ;;
113 esac
114
115 # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100431
116 export CFLAGS="$CFLAGS -Wno-error=format-security"
117 export CXXFLAGS="$CXXFLAGS -Wno-error=format-security"
118 export CPPFLAGS="$CPPFLAGS -Wno-error=format-security"
119
120 msg "Running ./configure for $target"
121 "$builddir"/configure \
122 --target=$target \
123 --prefix=/usr \
124 --with-sysroot=/usr/$target \
125 --with-native-system-header-dir=/include \
126 --with-headers=/usr/$target/include \
127 --with-python-dir=share/gcc-$target \
128 --libexecdir=/usr/lib \
129 --infodir=/deleteme/info \
130 --htmldir=/deleteme/html \
131 --pdfdir=/deleteme/pdf \
132 --mandir=/deleteme/man \
133 --enable-languages=c \
134 --enable-lto \
135 --enable-plugins \
136 --enable-gnu-indirect-function \
137 --disable-decimal-float \
138 --disable-libffi \
139 --disable-libgomp \
140 --disable-libmudflap \
141 --disable-libquadmath \
142 --disable-libssp \
143 --disable-libstdcxx-pch \
144 --disable-nls \
145 --disable-shared \
146 --disable-threads \
147 --disable-werror \
148 --with-gmp \
149 --with-gnu-as \
150 --with-gnu-ld \
151 --with-host-libstdcxx='-static-libgcc -Wl,-Bstatic,-lstdc++,-Bdynamic -lm' \
152 --with-isl \
153 --with-libelf \
154 --with-mpc \
155 --with-mpfr \
156 --with-newlib \
157 --with-system-zlib \
158 --with-pkgversion='Alpine Linux' \
159 $target_specific_flags
160}
161
162build() {
163 local target
164 for target in $_targets; do
165 local workingdir
166 workingdir="$srcdir/build-$target"
167 mkdir "$workingdir"
168 cd "$workingdir"
169 export CFLAGS_FOR_TARGET='-pipe -Os -ffunction-sections -fdata-sections'
170 export CXXFLAGS_FOR_TARGET='-pipe -Os -ffunction-sections -fdata-sections -fno-use-cxa-atexit'
171 case "$target" in
172 xtensa-esp*-elf)
173 local mcu
174 mcu="${target#xtensa-}"
175 mcu="${mcu%-elf}"
176 export XTENSA_GNU_CONFIG="/usr/lib/xtensa-dynconfig/xtensa_$mcu.so"
177 target=xtensa-none-elf
178 _configure_gcc
179 msg "Running make for xtensa-$mcu-elf"
180 make INHIBIT_LIBC_CFLAGS='-DUSE_TM_CLONE_REGISTRY=0' all-target-libgcc
181 ;;
182 *)
183 unset XTENSA_GNU_CONFIG
184 _configure_gcc
185 msg "Running make for $target"
186 make INHIBIT_LIBC_CFLAGS='-DUSE_TM_CLONE_REGISTRY=0'
187 esac
188 done
189}
190
191package() {
192 local target
193 for target in $_targets; do
194 depends="$depends gcc-$target"
195 done
196 mkdir -p "$pkgdir"
197}
198
199_install_subpkg() {
200 target="${subpkgname#gcc-}"
201 pkgdesc="C compiler of the GNU Compiler Collection for $target targets"
202 depends="$depends binutils-$target"
203 local workingdir
204 workingdir="$srcdir/build-$target"
205 cd "$workingdir"
206 make install DESTDIR="$subpkgdir" -j1
207
208 # Delete documentation. (The user can use the host GCC doc instead)
209 rm -rf "$subpkgdir"/deleteme
210 # Delete libcc1.so*, which is already part of the host's gcc
211 rm -f "$subpkgdir"/usr/lib/libcc1.so*
212
213 # Strip libs using target binutils
214 find "$subpkgdir"/usr/lib -type f -name "*.a" -exec /usr/bin/$target-strip --strip-debug '{}' \;
215
216 # Strip executables using host binutils
217 find "$subpkgdir"/usr/bin -type f -executable -exec strip '{}' \;
218
219 case "$target" in
220 xtensa-none-elf)
221 # We don't want libgcc and crt* for generic xtensa (which does not exist
222 # in hardware), but only for concrete xtensa CPUs
223 find "$subpkgdir/usr/lib/gcc/xtensa-none-elf/$pkgver" \
224 \( -name '*.o' -o -name '*.a' \) \
225 -exec rm {} \;
226 ;;
227 esac
228}
229
230_install_esp() {
231 target="${subpkgname#gcc-}"
232 local mcu
233 mcu="${target#xtensa-}"
234 mcu="${mcu%-elf}"
235 pkgdesc="C compiler of the GNU Compiler Collection for $target targets"
236 depends="binutils-$target gcc-xtensa-none-elf=$pkgver-r$pkgrel xtensa-dynconfig-$mcu"
237 local workingdir
238 workingdir="$srcdir/build-$target"
239 cd "$workingdir"
240 make install-target-libgcc DESTDIR="$subpkgdir"/tmp -j1
241 mkdir -p "$subpkgdir/usr/$target/lib/xtensa-none-elf/$pkgver"
242 find "$subpkgdir/tmp/usr/lib/gcc/xtensa-none-elf/$pkgver" \
243 \( -name '*.o' -o -name '*.a' \) \
244 -exec mv {} "$subpkgdir/usr/$target/lib/xtensa-none-elf/$pkgver" \;
245 rm -rf "$subpkgdir"/tmp
246
247 local cmds
248 cmds="
249 gcc-ar
250 gcc-nm
251 gcc-ranlib
252 gcov
253 gcov-dump
254 gcov-tool
255 lto-dump
256 "
257 mkdir -p "$subpkgdir/usr/bin"
258 for cmd in $cmds; do
259 cat > "$subpkgdir/usr/bin/$target-$cmd" << EOF
260#!/bin/sh
261exec env XTENSA_GNU_CONFIG=/usr/lib/xtensa-dynconfig/xtensa_$mcu.so xtensa-none-elf-$cmd "\$@"
262EOF
263 chmod +x "$subpkgdir/usr/bin/$target-$cmd"
264 done
265
266 cmds="
267 cpp
268 gcc
269 "
270 mkdir -p "$subpkgdir/usr/bin"
271 for cmd in $cmds; do
272 cat > "$subpkgdir/usr/bin/$target-$cmd" << EOF
273#!/bin/sh
274exec env XTENSA_GNU_CONFIG=/usr/lib/xtensa-dynconfig/xtensa_$mcu.so xtensa-none-elf-$cmd --sysroot=/usr/$target "\$@"
275EOF
276 chmod +x "$subpkgdir/usr/bin/$target-$cmd"
277 done
278}
279
280sha512sums="
281c51c30ca7422d0cbecf504b2e0f33c3aca31e0f90a76b65217f465163fa6fa17b3f5de39e145c47e5bab90ac0ce7fff3b03c8d553ae36e01faaea5a50f8648d1 gcc-16.2.0.tar.xz
28252e45ba12be74ce6f740eff3a79e3da87c80b06275fd00b2a1193b052fd0891e7c4c09fd6a9c204a82178c135318d69db3e250f12c37eca72edb1e3c0b0be2db newlib-getentropy.patch
283ce9873d26ea4ab6fd9a50b8d5ac55c88abbad18fb16a79a9f6ac3d1ae3a1c7a9b876bfa9fcba11bec16672ef7a10ffaf3923ce361fc530f0f811858dcc9da9eb xtensa-fix-specs.patch
284"