# Maintainer: Marian Buschsieweke # Based upon Alpine's avr-gcc and Arch Linux's arm-none-eabi-gcc, to which # the following people contributed: # Contributor: Pedro Filipe # Contributor: Stefan Wagner # Contributor: Anatol Pomozov # Contributor: Martin Schmölzer pkgname=gcc-cross-embedded pkgver=13.1.0 pkgrel=0 pkgdesc="C compilers from the GNU Compiler Collection for embedded targets" url="https://gcc.gnu.org/" depends="gcc" makedepends="bash linux-headers gmp-dev mpfr-dev mpc1-dev zlib-dev isl-dev python3" arch="aarch64 armv7 ppc64le x86_64 x86" license="GPL-3.0-or-later" source="https://mirrors.kernel.org/gnu/gcc/gcc-$pkgver/gcc-$pkgver.tar.xz newlib-getentropy.patch" options="!check" builddir="$srcdir/gcc-$pkgver" # classify targets as exotic or mainstream. Only build support for # exotic targets on typical developer / CI hardware (x86_86, aarach64). _targets_mainstream=" arm-none-eabi riscv-none-elf " _targets_exotic=" msp430-elf or1k-elf aarch64-none-elf " # This specifies the supported RISC-V multilib ISA extensions. # For more information on the syntax, see the comment in gcc/config/riscv/multilib-generator. # # The selected ISA extensions are modeled after the Debian package. # See: https://salsa.debian.org/debian/gcc-riscv64-unknown-elf/-/blob/4a1de76060cb8721c06bcfb4c846bc82ee6b3fc3/debian/patches/0002-Add-more-multi-lib-for-rv32-and-rv64.patch _riscv_multilib="rv32e-ilp32e--c;rv32ea-ilp32e--m;\ rv32em-ilp32e--c;rv32eac-ilp32e--;rv32emac-ilp32e--;\ rv32i-ilp32--c;rv32ia-ilp32--m;rv32im-ilp32--c;\ rv32if-ilp32f-rv32ifd-c;rv32iaf-ilp32f-rv32imaf,rv32iafc-d;\ rv32imf-ilp32f-rv32imfd-c;rv32iac-ilp32--;rv32imac-ilp32--;\ rv32imafc-ilp32f-rv32imafdc-;rv32ifd-ilp32d--c;rv32imfd-ilp32d--c;\ rv32iafd-ilp32d-rv32imafd,rv32iafdc-;rv32imafdc-ilp32d--;rv64i-lp64--c;\ rv64ia-lp64--m;rv64im-lp64--c;rv64if-lp64f-rv64ifd-c;\ rv64iaf-lp64f-rv64imaf,rv64iafc-d;rv64imf-lp64f-rv64imfd-c;\ rv64iac-lp64--;rv64imac-lp64--;rv64imafc-lp64f-rv64imafdc-;\ rv64ifd-lp64d--m,c;rv64iafd-lp64d-rv64imafd,rv64iafdc-;rv64imafdc-lp64d--" case "$CARCH" in x86_64|aarch64) # support all targets on typical workstation / notebook / CI servers _targets="$_targets_mainstream $_targets_exotic" ;; *) # support only mainstream targets on exotic hosts _targets="$_targets_mainstream" ;; esac for target in $_targets; do targetnorm="${target//-/_}" subpackages="gcc-$target:$targetnorm $subpackages" makedepends="$makedepends binutils-$target" done prepare() { default_prepare # hack! - some configure tests for header files using "$CPP $CPPFLAGS" for dir in libiberty gcc; do sed -i "/ac_cpp=/s/\$CPPFLAGS/\$CPPFLAGS -O2/" $dir/configure done } _build_gcc() { case "$target" in # Support M and R architecture profiles for ARM arm-none-eabi) _target_specific_flags="--with-multilib-list=rmprofile" ;; riscv-none-elf) _target_specific_flags="--with-multilib-generator=$_riscv_multilib" ;; *) _target_specific_flags="" ;; esac # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100431 export CFLAGS="$CFLAGS -Wno-error=format-security" export CXXFLAGS="$CXXFLAGS -Wno-error=format-security" export CPPFLAGS="$CPPFLAGS -Wno-error=format-security" msg "Running ./configure for $target" "$builddir"/configure \ --target=$target \ --prefix=/usr \ --with-sysroot=/usr/$target \ --with-native-system-header-dir=/include \ --with-headers=/usr/$target/include \ --with-python-dir=share/gcc-$target \ --libexecdir=/usr/lib \ --infodir=/deleteme/info \ --htmldir=/deleteme/html \ --pdfdir=/deleteme/pdf \ --mandir=/deleteme/man \ --enable-languages=c \ --enable-lto \ --enable-plugins \ --enable-gnu-indirect-function \ --disable-decimal-float \ --disable-libffi \ --disable-libgomp \ --disable-libmudflap \ --disable-libquadmath \ --disable-libssp \ --disable-libstdcxx-pch \ --disable-nls \ --disable-shared \ --disable-threads \ --disable-werror \ --with-gmp \ --with-gnu-as \ --with-gnu-ld \ --with-host-libstdcxx='-static-libgcc -Wl,-Bstatic,-lstdc++,-Bdynamic -lm' \ --with-isl \ --with-libelf \ --with-mpc \ --with-mpfr \ --with-newlib \ --with-system-zlib \ --with-pkgversion='Alpine Linux' \ $_target_specific_flags msg "Running make for $target" make INHIBIT_LIBC_CFLAGS='-DUSE_TM_CLONE_REGISTRY=0' } build() { for target in $_targets; do # Build "regular" variant workingdir="$srcdir/build-$target" mkdir "$workingdir" cd "$workingdir" export CFLAGS_FOR_TARGET='-pipe -Os -ffunction-sections -fdata-sections' export CXXFLAGS_FOR_TARGET='-pipe -Os -ffunction-sections -fdata-sections -fno-use-cxa-atexit' _build_gcc done } package() { for target in $_targets; do depends="$depends gcc-$target" done mkdir -p "$pkgdir" } _install_subpkg() { target="${subpkgname#gcc-}" pkgdesc="C compiler of the GNU Compiler Collection for $target targets" depends="$depends binutils-$target" workingdir="$srcdir/build-$target" cd "$workingdir" make install DESTDIR="$subpkgdir" -j1 # Delete documentation. (The user can use the host GCC doc instead) rm -rf "$subpkgdir"/deleteme # Delete libcc1.so*, which is already part of the host's gcc rm -f "$subpkgdir"/usr/lib/libcc1.so* # Strip libs using target binutils find "$subpkgdir"/usr/lib -type f -name "*.a" -exec /usr/bin/$target-strip --strip-debug '{}' \; # Strip executables using host binutils find "$subpkgdir"/usr/bin -type f -executable -exec strip '{}' \; } arm_none_eabi() { _install_subpkg } mips_mti_elf() { _install_subpkg } msp430_elf() { _install_subpkg } or1k_elf() { _install_subpkg } riscv_none_elf() { _install_subpkg } aarch64_none_elf() { _install_subpkg } sha512sums=" 6cf06dfc48f57f5e67f7efe3248019329a14d690c728d9f2f7ef5fa0d58f1816f309586ba7ea2eac20d0b60a2d1b701f68392e9067dd46f827ba0efd7192db33 gcc-13.1.0.tar.xz 52e45ba12be74ce6f740eff3a79e3da87c80b06275fd00b2a1193b052fd0891e7c4c09fd6a9c204a82178c135318d69db3e250f12c37eca72edb1e3c0b0be2db newlib-getentropy.patch "