2021-06-08 13:14:45 +00:00
2021-12-01 15:36:11 +04:00
# %%define target_arch aarch64
2021-12-01 14:24:25 +04:00
# %%define target_arch arm
# %%define target_arch mipsel
# %%define target_arch riscv64
2022-06-05 15:22:38 +00:00
%define target_arch @targetarch@
2021-12-01 14:24:25 +04:00
%if "%target_arch" == "aarch64"
2021-06-08 13:14:45 +00:00
%define target_kernel arm64
2021-06-09 17:09:54 +00:00
%define target_qemu_arch aarch64
2021-12-01 14:24:25 +04:00
%define target_ld_linux /lib64/ld-linux-aarch64.so.1
%define target_libdir lib64
%define target_has_itm 1
%endif
%if "%target_arch" == "arm"
%define target_kernel arm
%define target_qemu_arch arm
%define target_ld_linux /lib/ld-linux-armhf.so.3
%define target_libdir lib
%define target_has_itm 1
# armhf: use the same arch/fp instruction set as the native compiler
%define arm_arch armv7-a
%define arm_fp_isa vfpv3-d16
%define arm_fp_abi hard
%endif
%if "%target_arch" == "mipsel"
%define target_kernel mips
%define target_qemu_arch mipsel
%define target_ld_linux /lib/ld.so.1
%define target_libdir lib
%endif
%if "%target_arch" == "riscv64"
%define target_kernel riscv
%define target_qemu_arch riscv64
%define target_ld_linux /lib64/ld-linux-riscv64-lp64d.so.1
%define target_libdir lib64
%endif
2022-11-21 16:20:56 +04:00
%if "%target_arch" == "loongarch64"
%define target_kernel loongarch
%define target_qemu_arch loongarch64
%define target_ld_linux /lib64/ld-linux-loongarch-lp64d.so.1
%define target_libdir lib64
%endif
2021-12-01 14:24:25 +04:00
%if "%target_arch" != "arm"
2021-06-15 14:55:40 +00:00
%define target %target_arch-linux-gnu
2021-12-01 14:24:25 +04:00
%else
%define target %target_arch-linux-gnueabihf
%endif
%define sysroot %prefix/lib/%target/sys-root
2021-06-15 14:55:40 +00:00
2021-12-01 14:24:25 +04:00
# don't strip debuginfo from binaries for other platform, it does not work
%brp_strip_none %sysroot/* %prefix/lib/gcc/*.a %prefix/lib/gcc/*.o
2021-06-08 13:14:45 +00:00
2021-08-04 19:18:39 +04:00
Name : cross-toolchain-%target
2022-06-05 15:33:17 +00:00
Version : 20220605
2021-07-29 21:21:13 +04:00
Release : alt1
2021-08-04 19:18:39 +04:00
Summary : GCC cross-toolchain for %target
License : LGPL-2.1-or-later and LGPL-3.0-or-later and GPL-2.0-or-later and GPL-3.0-or-later and GPL-3.0-or-later with GCC-exception-3.1
Group : Development/C
2021-06-08 13:14:45 +00:00
2021-06-10 10:04:47 +00:00
ExclusiveArch : x86_64
2021-08-04 19:18:39 +04:00
%define gcc_version %{get_version gcc-source}
%define gcc_branch %(v=%gcc_version; v=${v%%%%.*}; echo $v)
%define binutils_version %{get_version binutils-source}
%define glibc_version %{get_version glibc-source}
2022-11-21 16:20:56 +04:00
%if "%target_arch" == "loongarch64"
%define kernel_version 6.0
%else
2021-07-29 21:21:13 +04:00
%define kernel_version 5.10
2022-11-21 16:20:56 +04:00
%endif
2021-06-08 13:14:45 +00:00
BuildPreReq : gcc-c++
BuildPreReq : libmpc-devel libmpfr-devel libgmp-devel zlib-devel
2021-12-01 14:24:25 +04:00
BuildPreReq : coreutils flex bison makeinfo perl-Pod-Parser findutils
2021-06-10 13:30:29 +00:00
# Linux' headers_install uses rsync
BuildPreReq : rsync
2021-08-04 19:18:39 +04:00
BuildRequires(pre): gcc-source
BuildRequires(pre): binutils-source
BuildRequires(pre): glibc-source
BuildPreReq : kernel-source-%kernel_version
2021-12-01 14:24:25 +04:00
BuildRequires : /usr/bin/qemu-%target_qemu_arch-static
2021-07-29 21:21:13 +04:00
BuildRequires : python3
2021-06-08 13:14:45 +00:00
2021-08-04 19:18:39 +04:00
%description
GCC cross-toolchain for %target
%define _libexecdir /usr/libexec
%package -n gcc-%target
Version : %gcc_version
Summary : %target_arch-targeted GCC cross-compiler
Group : Development/C
2021-07-30 12:05:31 +04:00
Requires : gcc-%target-static = %gcc_version
2021-07-29 21:21:13 +04:00
Requires : binutils-%target = %binutils_version
2021-07-30 12:05:31 +04:00
Requires : cross-glibc-%target_arch = %glibc_version
2021-06-15 14:55:40 +00:00
2021-08-04 19:18:39 +04:00
%description -n gcc-%target
2021-06-15 14:55:40 +00:00
%target_arch-targeted GCC cross-compiler
2021-08-04 19:18:39 +04:00
%package -n gcc-%target-static
Version : %gcc_version
2021-07-30 12:05:31 +04:00
Summary : %target_arch-targeted GCC cross-compiler, static libraries
Group : Development/C
2021-08-04 19:18:39 +04:00
%description -n gcc-%target-static
2021-07-30 12:05:31 +04:00
%target_arch-targeted GCC cross-compiler, static libraries
2021-07-29 21:21:13 +04:00
%package -n binutils-%target
2021-06-15 14:55:40 +00:00
Version : %binutils_version
Summary : %target_arch-targeted binutils (linker, assembler, etc)
Group : Development/C
2021-07-29 21:21:13 +04:00
%description -n binutils-%target
2021-06-15 14:55:40 +00:00
%target_arch-targeted binutils (linker, assembler, objdump, etc)
2021-07-30 12:05:31 +04:00
%package -n cross-glibc-%target_arch
2021-06-15 14:55:40 +00:00
Version : %glibc_version
Summary : %target_arch-targeted cross-glibc
Group : Development/C
2021-07-30 12:05:31 +04:00
Requires : cross-glibc-static-%target_arch
2021-07-29 21:21:13 +04:00
BuildArch : noarch
2021-06-15 14:55:40 +00:00
2021-07-30 12:05:31 +04:00
%description -n cross-glibc-%target_arch
2021-06-15 14:55:40 +00:00
glibc for %target_arch. Should be used for cross-compilation only
2021-06-08 13:14:45 +00:00
2021-07-30 12:05:31 +04:00
%package -n cross-glibc-static-%target_arch
Version : %glibc_version
Summary : %target_arch-targeted cross-glibc, static libraries
Group : Development/C
BuildArch : noarch
%description -n cross-glibc-static-%target_arch
static glibc for %target_arch. Should be used for cross-compilation only
2021-06-08 13:14:45 +00:00
%prep
%setup -cT
2021-07-29 21:21:13 +04:00
mkdir -p -m755 linux binutils gcc glibc
find /usr/src/gcc-source -type f -name 'gcc-*.tar' | xargs -I {} -n1 tar -x --strip-components=1 -f {} -C gcc
find /usr/src/binutils-source -type f -name 'binutils-*.tar' | xargs -I {} -n1 tar -x --strip-components=1 -f {} -C binutils
find /usr/src/kernel/sources -type f -name 'kernel-source-*.tar' | xargs -I {} -n1 tar -x --strip-components=1 -f {} -C linux
find /usr/src/glibc-source -type f -name 'glibc-*.tar' | xargs -I {} -n1 tar -x --strip-components=1 -f {} -C glibc
2021-06-09 05:57:48 +00:00
rm -rf stage
2021-06-08 13:14:45 +00:00
%build
mkdir -p obj_binutils
mkdir -p obj_gcc
2022-06-05 19:04:43 +04:00
mkdir -p obj_gcc_bootstrap
2021-06-08 13:14:45 +00:00
mkdir -p obj_kheaders
mkdir -p obj_glibc
2021-06-09 05:57:48 +00:00
mkdir -p -m755 stage%prefix/bin
2022-06-05 19:04:43 +04:00
mkdir -p -m755 stage1%prefix/bin
save_PATH=" $ P A T H "
export PATH=`pwd`/stage1%prefix/bin:$PATH
2021-06-09 05:57:48 +00:00
stagedir=`pwd`/stage
2022-06-05 19:04:43 +04:00
stage1dir=`pwd`/stage1
2021-06-08 13:14:45 +00:00
# kernel headers
%_make_bin -j%__nprocs \
2021-07-29 21:21:13 +04:00
-C linux \
2021-06-08 13:14:45 +00:00
O=`pwd`/obj_kheaders \
ARCH=%target_kernel \
2021-06-09 05:57:48 +00:00
INSTALL_HDR_PATH=${stagedir}%sysroot/usr \
2021-06-08 13:14:45 +00:00
headers_install
# XXX: avoid %%configure for it puts $target libraries into /usr/lib64
cd obj_binutils
2021-07-29 21:21:13 +04:00
../binutils/configure \
2021-06-08 13:14:45 +00:00
--target=%target \
--host=%{_configure_platform} \
--build=%{_configure_platform} \
2021-12-01 14:24:25 +04:00
%if "%target_arch" == "arm"
--with-arch=%arm_arch \
--with-fpu=%arm_fp_isa \
--with-float=%arm_fp_abi \
%endif
2021-06-08 13:14:45 +00:00
--prefix=%prefix \
--disable-bootstrap \
--disable-multiarch \
--disable-multilib \
--disable-werror \
--disable-shared \
--disable-nls \
--with-sysroot=%sysroot \
2021-06-09 05:57:48 +00:00
--with-build-sysroot=${stagedir}%sysroot \
2021-06-08 13:14:45 +00:00
--with-system-zlib \
--enable-plugins \
--enable-gold=yes \
--enable-ld=default \
2021-12-01 14:24:25 +04:00
%if "%target_arch" != "mipsel"
2021-06-08 13:14:45 +00:00
--enable-64-bit-bfd \
2021-12-01 14:24:25 +04:00
%endif
2021-06-08 13:14:45 +00:00
--enable-relro \
--enable-textrel-check=warning
%make_build
# XXX: avoid makeinstall for it puts $target libraries into /usr/lib64
2021-06-09 05:57:48 +00:00
%make_install install DESTDIR=${stagedir}
2022-06-05 19:04:43 +04:00
# for bootstrap toolchain (to compile target glibc)
%make_install install DESTDIR=${stage1dir}
2021-06-08 13:14:45 +00:00
2022-06-05 19:04:43 +04:00
# bootstrap gcc (for compiling target glibc)
cd ../obj_gcc_bootstrap
2021-07-29 21:21:13 +04:00
../gcc/configure \
2021-06-08 13:14:45 +00:00
--target=%target \
--host=%{_configure_platform} \
--build=%{_configure_platform} \
2021-12-01 14:24:25 +04:00
%if "%target_arch" == "arm"
--with-arch=%arm_arch \
--with-fpu=%arm_fp_isa \
--with-float=%arm_fp_abi \
%endif
2021-06-08 13:14:45 +00:00
--prefix=%prefix \
--disable-bootstrap \
--disable-multiarch \
--disable-multilib \
--disable-werror \
--with-sysroot=%sysroot \
2021-06-09 05:57:48 +00:00
--with-build-sysroot=${stagedir}%sysroot \
2022-06-05 19:04:43 +04:00
--enable-languages=c \
--with-newlib \
--without-headers \
2021-06-08 13:14:45 +00:00
--disable-nls \
2022-06-05 19:04:43 +04:00
--disable-shared \
--disable-threads \
2021-07-29 21:21:13 +04:00
--disable-libsanitizer \
2022-06-05 19:04:43 +04:00
--disable-libgomp \
--disable-libitm \
--disable-libquadmath \
--disable-libsanitizer \
--disable-libssp \
--disable-libvtv \
--disable-libatomic \
--disable-libcilkrts \
--enable-version-specific-runtime-libs \
--with-gcc-major-version-only \
2021-12-01 14:24:25 +04:00
--with-system-zlib \
%if "%target_arch" == "mipsel"
--with-arch-32=mips32r2 \
--with-fp-32=xx \
--with-lxc1-sxc1=no \
--with-madd4=no \
%endif
%if "%target_arch" == "riscv64"
--with-arch=rv64gc \
--with-abi=lp64d \
%endif
%nil
2021-06-08 13:14:45 +00:00
2022-06-05 19:04:43 +04:00
%make_build all-gcc all-target-libgcc
2021-06-08 13:14:45 +00:00
# XXX: avoid makeinstall for it puts $target libraries into /usr/lib64
2022-06-05 19:04:43 +04:00
%make_install install-gcc install-target-libgcc DESTDIR=${stage1dir}
2021-06-08 13:14:45 +00:00
2022-06-05 19:04:43 +04:00
# glibc
2021-06-08 13:14:45 +00:00
cd ../obj_glibc
# XXX: avoid %%configure since it puts target libraries/binaries into /usr/lib64
# Note: glibc's is a library, so $host must be the same as $target
2021-07-29 21:21:13 +04:00
../glibc/configure \
2021-06-08 13:14:45 +00:00
--host=%target \
--target=%target \
--build=%{_configure_platform} \
2021-12-01 14:24:25 +04:00
%if "%target_arch" == "arm"
--with-arch=%arm_arch \
--with-fpu=%arm_fp_isa \
--with-float=%arm_fp_abi \
%endif
2021-06-08 13:14:45 +00:00
--prefix=%prefix \
--with-sysroot=%sysroot \
2021-06-09 05:57:48 +00:00
--with-build-sysroot=${stagedir}%sysroot \
--with-headers=${stagedir}%sysroot/usr/include \
--with-lib=${stagedir}%sysroot/usr/lib \
2021-06-08 13:14:45 +00:00
--disable-multilib \
--disable-crypt \
2022-06-05 19:04:43 +04:00
libc_cv_forced_unwind=yes \
%nil
2021-06-08 13:14:45 +00:00
%make_build
# XXX: avoid makeinstall since it puts target libs into /usr/lib64
# Note: target glibc **must** be installed into sysroot to prevent
# native compilers from using it by default
2021-06-09 05:57:48 +00:00
%make_install install DESTDIR=${stagedir}%sysroot
2022-06-05 19:04:43 +04:00
# XXX: gcc needs this to locate crt{1,i}.o
mkdir -p -m755 ${stagedir}%sysroot/usr/lib
2021-06-08 13:14:45 +00:00
2022-06-05 19:04:43 +04:00
# Don't use bootstrap toolchain any more
export PATH=" $ { s t a g e d i r } % p r e f i x / b i n : $ { s a v e _ P A T H } "
# gcc
2021-06-08 13:14:45 +00:00
cd ../obj_gcc
2022-06-05 19:04:43 +04:00
# XXX: avoid %%configure puts $target libraries in /usr/lib64
../gcc/configure \
--target=%target \
--host=%{_configure_platform} \
--build=%{_configure_platform} \
%if "%target_arch" == "arm"
--with-arch=%arm_arch \
--with-fpu=%arm_fp_isa \
--with-float=%arm_fp_abi \
%endif
--prefix=%prefix \
--disable-bootstrap \
--disable-multiarch \
--disable-multilib \
--disable-werror \
--with-sysroot=%sysroot \
--with-build-sysroot=${stagedir}%sysroot \
--with-gcc-major-version-only \
--enable-languages=c,c++ \
--enable-version-specific-runtime-libs \
--disable-nls \
--disable-libsanitizer \
--with-system-zlib \
%if "%target_arch" == "mipsel"
--with-arch-32=mips32r2 \
--with-fp-32=xx \
--with-lxc1-sxc1=no \
--with-madd4=no \
%endif
%if "%target_arch" == "riscv64"
--with-arch=rv64gc \
--with-abi=lp64d \
%endif
%nil
2021-06-08 13:14:45 +00:00
%make_build
2022-06-05 19:04:43 +04:00
# XXX: avoid makeinstall for it puts $target libraries into /usr/lib64
2021-06-09 05:57:48 +00:00
%make_install install DESTDIR=${stagedir}
2021-06-08 13:14:45 +00:00
%install
2021-06-09 05:57:48 +00:00
export PATH=`pwd`/stage%prefix/bin:$PATH
%_make_bin -j%__nprocs \
2021-07-29 21:21:13 +04:00
-C linux \
2021-06-09 05:57:48 +00:00
O=`pwd`/obj_kheaders \
ARCH=%target_kernel \
INSTALL_HDR_PATH=%buildroot%sysroot/usr \
headers_install
cd obj_binutils
2021-06-11 16:08:28 +00:00
%make_install install DESTDIR=%buildroot tooldir=%prefix/libexec/gcc/%target
2021-06-09 05:57:48 +00:00
cd ../obj_glibc
%make_install install DESTDIR=%buildroot%sysroot
cd ../obj_gcc
%make_install install DESTDIR=%buildroot
2021-06-09 13:34:52 +00:00
# relocate target libgcc_s
2021-12-01 14:24:25 +04:00
if [ -d " % b u i l d r o o t % p r e f i x / l i b / g c c / % t a r g e t / l i b 6 4 " ] ; then
mv %buildroot%prefix/lib/gcc/%target/lib64/libgcc_s.so* %buildroot%prefix/lib/gcc/%target/%gcc_branch/
rmdir %buildroot%prefix/lib/gcc/%target/lib64
fi
2021-06-09 13:34:52 +00:00
2021-12-01 14:24:25 +04:00
%build root%prefix/bin/%target-gcc -dumpspecs > specs
%if "%target_arch" == "aarch64"
2021-06-09 17:08:54 +00:00
# XXX: native compiler sets /lib64/ld-linux-aarch64.so.1 as an ELF interpreter.
# Make sure cross-toolchain we build does the same thing.
sed -e " s ; / l i b / l d - l i n u x - a a r c h 6 4 ; / l i b 6 4 / l d - l i n u x - a a r c h 6 4 ; g " -i specs
2021-12-01 14:24:25 +04:00
%endif
2021-06-11 16:08:28 +00:00
# Assembler: %%target-as.
# Path is relative to %%prefix/lib/gcc/%%target/%%gcc_branch
sed -e '/^[*]invoke_as:/,/^[*]cpp:/ s; as ; ../../../../bin/%target-as ;' -i specs
# objcopy: %%target-objcopy
sed -e 's; objcopy ; ../../../../bin/%target-objcopy ;' -i specs
2021-06-09 17:08:54 +00:00
install -m 644 specs %buildroot%prefix/lib/gcc/%target/%gcc_branch/specs
2021-06-11 16:08:28 +00:00
# Note: collect2 (GCCs linker wrapper) searches for %%target-ld on its own.
# Alas it does not use relative paths and is not adjustable via the specs file
2021-06-09 17:08:54 +00:00
2021-06-11 23:02:19 +00:00
# XXX: apparently invoke_as: spec directive applies only to running assembler
# on compiler (cc1) output. The spec which describes compiling of `assembler`
# and `assembler-with-cpp` pseudo-languages seems to be hard-coded into GCC.
# As a result GCC still runs /usr/bin/as (instead of target assembler) when
# compiling .S files. Therefore install `as` symlinks in GCC libsubdir
# (%%prefix/lib/gcc/%%target/%%gcc_branch).
2021-07-29 21:21:13 +04:00
# Just in a case make symlinks to other tools.
2021-06-11 23:02:19 +00:00
for tool in ar as ld ld.bfd ld.gold nm objcopy objdump ranlib readelf strip; do
2021-12-01 14:24:25 +04:00
tool_path=" % b u i l d r o o t %_bindir / % t a r g e t - $ t o o l "
[ -f " $ t o o l _ p a t h " ] || continue
ln -sr " $ t o o l _ p a t h " %buildroot%prefix/lib/gcc/%target/%gcc_branch/$tool
# just in a case add a symlink into libexec too
ln -sr " $ t o o l _ p a t h " %buildroot%prefix/libexec/gcc/%target/%gcc_branch/$tool
2021-06-11 23:02:19 +00:00
done
2021-12-01 14:24:25 +04:00
%if "%target_libdir" == "lib64"
2021-06-09 17:08:54 +00:00
# XXX: ABI: which is correct location of ELF interpreter for aarch64?
# Native glibc provides ld-linux-aarch64.so.1 in both /lib64 and /lib.
# Do the same thing in cross-glibc
install -d -m 755 %buildroot%sysroot/lib
ln -s ../lib64/`basename %target_ld_linux` %buildroot%sysroot/lib/`basename %target_ld_linux`
2021-12-01 14:24:25 +04:00
%endif
2021-06-09 13:34:52 +00:00
2022-06-05 19:04:43 +04:00
# remove runtime bits, not necessary for a cross-toolchain
2021-06-09 07:01:27 +00:00
rm -rf %buildroot%sysroot/etc
rm -rf %buildroot%sysroot/var
rm -rf %buildroot%sysroot/sbin
rm -rf %buildroot%sysroot/usr/share
rm -rf %buildroot%sysroot/usr/bin
rm -rf %buildroot%sysroot/usr/sbin
rm -rf %buildroot%sysroot/usr/libexec
rm -rf %buildroot%sysroot/usr/lib64/audit
rm -rf %buildroot%sysroot/usr/lib64/gconv
2021-06-10 09:42:44 +00:00
rm -rf %buildroot%prefix/share/info
rm -rf %buildroot%prefix/share/man/man7
# python pretty-printers conflict with native compiler
rm -rf %buildroot%prefix/share/gcc-%gcc_branch/python
# conficts with the native compiler and is not particularly useful
rm -f %buildroot%prefix/%_lib/libcc1.so*
# Useless for Linux targets
2021-12-01 14:24:25 +04:00
rm -f %buildroot%_man1dir/%target-windmc*
rm -f %buildroot%_man1dir/%target-windres*
2021-06-10 11:16:38 +00:00
# libtool junk
find %buildroot%prefix/lib/gcc/%target/%gcc_branch -type f -name '*.la' -delete
find %buildroot%prefix/libexec/gcc -type f -name '*.la' -delete
# Target C++ runtime is used for linking only
find %buildroot%prefix/lib/gcc/%target/%gcc_branch -type f -name 'lib*-gdb.py' -delete
2021-06-09 07:01:27 +00:00
2021-06-09 13:34:52 +00:00
# XXX: gcc needs this to locate crt1.o
install -d -m 755 %buildroot%sysroot/usr/lib
2022-06-05 19:04:43 +04:00
# remove bootstrap toolchain
rm -rf %buildroot/stage1
2021-06-09 10:53:56 +00:00
# Leave alone $target libraries
2021-06-09 13:34:52 +00:00
%add_verify_elf_skiplist %sysroot/* %prefix/lib/gcc/%target/%gcc_branch/*
%add_findreq_skiplist %sysroot/* %prefix/lib/gcc/%target/%gcc_branch/*
%add_findprov_skiplist %sysroot/* %prefix/lib/gcc/%target/%gcc_branch/*
%add_debuginfo_skiplist %sysroot/* %prefix/lib/gcc/%target/%gcc_branch/*
2021-06-09 10:06:18 +00:00
2021-06-09 14:01:48 +00:00
%check
cat > hello.c <<EOF
#include <stdio.h>
int main(int argc, char** argv) {
printf(" H e l l o , % % s ! \n " , argc > 1 ? argv[1] : " w o r l d " );
return 0;
}
EOF
cat > hello.cpp <<EOF
#include <iostream>
int main(int argc, char** argv) {
std::cout << " H e l l o , " << (argc > 1 ? argv[1] : " w o r l d " ) << " ! " << std::endl;
return 0;
}
EOF
2021-06-09 17:09:54 +00:00
gcc_runtime_libdir=`dirname $(%buildroot%prefix/bin/%target-gcc --print-libgcc-file-name)`
2021-06-11 16:08:28 +00:00
# XXX: PATH= is necessary for collect2 to find %%target-ld
env PATH=%buildroot%prefix/bin:$PATH \
2021-06-09 14:01:48 +00:00
%build root%prefix/bin/%target-gcc -o hello_c hello.c || exit 2
2021-06-11 16:08:28 +00:00
env PATH=%buildroot%prefix/bin:$PATH \
2021-06-09 14:01:48 +00:00
%build root%prefix/bin/%target-g++ -o hello_cpp hello.cpp || exit 3
2021-06-08 13:14:45 +00:00
2021-06-09 17:09:54 +00:00
# Note: LD_LIBRARY_PATH is for **target** ld.so.
# Use qemu-user-static so qemu-user is not affected by LD_LIBRARY_PATH
env LD_LIBRARY_PATH=%buildroot%sysroot/lib64:${gcc_runtime_libdir} \
qemu-%target_qemu_arch-static -L %buildroot%sysroot ./hello_c || exit 5
env LD_LIBRARY_PATH=%buildroot%sysroot/lib64:${gcc_runtime_libdir} \
qemu-%target_qemu_arch-static -L %buildroot%sysroot ./hello_cpp || exit 7
2021-12-01 14:24:25 +04:00
%if "%target_arch" == "aarch64"
2021-06-11 23:02:19 +00:00
cat > bye.S <<EOF
#include <sys/syscall.h>
.arch armv8-a
2022-11-21 16:18:15 +04:00
.data
message: .asciz " b y e - b y e . . . \n "
2021-06-11 23:02:19 +00:00
.text
.align 2
.global _start
_start:
2022-11-21 16:18:15 +04:00
mov x8, __NR_write
mov x0, 1
adr x1, message
mov x2, 12
svc #0
2021-06-11 23:02:19 +00:00
mov x8, __NR_exit
mov x0, 0
svc #0
.section .note.GNU-stack," " ,@progbits
EOF
2021-12-01 14:24:25 +04:00
%endif
%if "%target_arch" == "arm"
cat > bye.S <<EOF
#include <sys/syscall.h>
.arch armv7-a
2022-11-21 16:18:15 +04:00
.data
message: .asciz " b y e - b y e . . . \n "
2021-12-01 14:24:25 +04:00
.text
.align 2
.global _start
_start:
2022-11-21 16:18:15 +04:00
mov r7, #__NR_write
mov r0, #1
ldr r1, address_of_message
mov r2, #12
swi #0
2021-12-01 14:24:25 +04:00
mov r0, #0
mov r7, #__NR_exit
swi #0
2022-11-21 16:18:15 +04:00
.align 4
address_of_message: .word message
2021-12-01 14:24:25 +04:00
.section .note.GNU-stack," " ,%progbits
EOF
%endif
%if "%target_arch" == "mipsel"
cat > bye.S <<EOF
#include <sys/syscall.h>
.text
.global __start
__start:
li \$a0, 0
li \$v0, __NR_exit
syscall
EOF
%endif
%if "%target_arch" == "riscv64"
cat > bye.S <<EOF
#include <sys/syscall.h>
.text
.global _start
_start:
addi a0, x0, 0
addi a7, x0, __NR_exit
ecall
EOF
%endif
2021-06-11 23:02:19 +00:00
2022-11-21 16:20:56 +04:00
%if "%target_arch" == "loongarch64"
cat > bye.S <<EOF
#include <sys/syscall.h>
.data
message: .asciz " b y e - b y e . . . \n "
.text
.global _start
_start:
li.w \$a7, __NR_write
li.w \$a0, 1 # stdout file descriptor
la \$a1, message
li.w \$a2, 12 # message length
syscall 0x0
li.w \$a7, __NR_exit
li.w \$a0, 0
syscall 0x0
.section .note.GNU-stack," " ,@progbits
EOF
2021-06-11 23:02:19 +00:00
env PATH=%buildroot%prefix/bin:$PATH \
%build root%prefix/bin/%target-gcc -static -nostdlib -o bye_asm bye.S || exit 11
qemu-%target_qemu_arch-static ./bye_asm || exit 13
2021-08-04 19:18:39 +04:00
%files -n gcc-%target
2021-06-15 14:55:40 +00:00
%_bindir /%target-gcc*
%_bindir /%target-cpp
%_bindir /%target-g++
%_bindir /%target-c++
%_bindir /%target-gcov*
2021-12-01 14:24:25 +04:00
%_bindir /%target-lto*
2021-06-09 10:06:18 +00:00
%prefix /lib/gcc/%target/%gcc_branch/*
%prefix /libexec/gcc/%target/*
2021-07-30 12:05:31 +04:00
# avoid 'static library packaging violation' "error"
%exclude %prefix/lib/gcc/%target/%gcc_branch/libatomic.a
%exclude %prefix/lib/gcc/%target/%gcc_branch/libgomp.a
2021-12-01 14:24:25 +04:00
%if 0%{?target_has_itm}
2021-07-30 12:05:31 +04:00
%exclude %prefix/lib/gcc/%target/%gcc_branch/libitm.a
2021-12-01 14:24:25 +04:00
%endif
2021-07-30 12:05:31 +04:00
%exclude %prefix/lib/gcc/%target/%gcc_branch/libssp.a
%exclude %prefix/lib/gcc/%target/%gcc_branch/libstdc++.a
# binunitls
2021-06-15 14:55:40 +00:00
%exclude %prefix/libexec/gcc/%target/bin/*
%exclude %prefix/libexec/gcc/%target/lib/*
2021-12-01 14:24:25 +04:00
%_man1dir/%target-cpp*
%_man1dir/%target-g++*
%_man1dir/%target-gcc*
%_man1dir/%target-gcov*
%_man1dir/%target-lto*
2021-06-15 14:55:40 +00:00
2021-08-04 19:18:39 +04:00
%files -n gcc-%target-static
2021-07-30 12:05:31 +04:00
%prefix /lib/gcc/%target/%gcc_branch/libatomic.a
%prefix /lib/gcc/%target/%gcc_branch/libgomp.a
2021-12-01 14:24:25 +04:00
%if 0%{?target_has_itm}
2021-07-30 12:05:31 +04:00
%prefix /lib/gcc/%target/%gcc_branch/libitm.a
2021-12-01 14:24:25 +04:00
%endif
2021-07-30 12:05:31 +04:00
%prefix /lib/gcc/%target/%gcc_branch/libssp.a
%prefix /lib/gcc/%target/%gcc_branch/libstdc++.a
%files -n cross-glibc-%target_arch
2021-06-08 13:14:45 +00:00
%sysroot/usr/include/*
2021-12-01 14:24:25 +04:00
%if "%target_libdir" == "lib64"
2021-06-10 09:42:44 +00:00
# XXX: gcc needs %%sysroot/usr/lib to locate C runtime (crt1.o)
2021-12-01 14:24:25 +04:00
%dir %sysroot/usr/lib
2021-06-08 13:14:45 +00:00
%sysroot/lib64/*
%sysroot/usr/lib64/*
2021-06-10 09:42:44 +00:00
# Compatibility symlink to ld.so
2021-06-09 17:08:54 +00:00
%sysroot/lib/*
2021-12-01 14:24:25 +04:00
%else
%sysroot/lib
%sysroot/usr/lib
%endif
%exclude %sysroot/usr/%target_libdir/libBrokenLocale.a
%exclude %sysroot/usr/%target_libdir/libanl.a
%exclude %sysroot/usr/%target_libdir/libdl.a
%exclude %sysroot/usr/%target_libdir/libm.a
%exclude %sysroot/usr/%target_libdir/libpthread.a
%exclude %sysroot/usr/%target_libdir/libresolv.a
%exclude %sysroot/usr/%target_libdir/librt.a
%exclude %sysroot/usr/%target_libdir/libutil.a
2021-06-15 14:55:40 +00:00
2021-07-30 12:05:31 +04:00
%files -n cross-glibc-static-%target_arch
2021-12-01 14:24:25 +04:00
%sysroot/usr/%target_libdir/libBrokenLocale.a
%sysroot/usr/%target_libdir/libanl.a
%sysroot/usr/%target_libdir/libdl.a
%sysroot/usr/%target_libdir/libm.a
%sysroot/usr/%target_libdir/libpthread.a
%sysroot/usr/%target_libdir/libresolv.a
%sysroot/usr/%target_libdir/librt.a
%sysroot/usr/%target_libdir/libutil.a
2021-07-30 12:05:31 +04:00
2021-07-29 21:21:13 +04:00
%files -n binutils-%target
2021-06-15 14:55:40 +00:00
%_bindir /%target-addr2line
%_bindir /%target-ar
%_bindir /%target-as
%_bindir /%target-c++filt
2021-12-01 14:24:25 +04:00
%if "%target_arch" != "riscv64"
2021-06-15 14:55:40 +00:00
%_bindir /%target-dwp
2021-12-01 14:24:25 +04:00
%endif
2021-06-15 14:55:40 +00:00
%_bindir /%target-elfedit
%_bindir /%target-gprof
%_bindir /%target-ld
%_bindir /%target-ld.bfd
2021-12-01 14:24:25 +04:00
%if "%target_arch" != "riscv64"
2021-06-15 14:55:40 +00:00
%_bindir /%target-ld.gold
2021-12-01 14:24:25 +04:00
%endif
2021-06-15 14:55:40 +00:00
%_bindir /%target-nm
%_bindir /%target-objcopy
%_bindir /%target-objdump
%_bindir /%target-ranlib
%_bindir /%target-readelf
%_bindir /%target-size
%_bindir /%target-strings
%_bindir /%target-strip
# gcc_tooldir
%prefix /libexec/gcc/%target/bin/*
%prefix /libexec/gcc/%target/lib/*
2021-12-01 14:24:25 +04:00
%_man1dir/%target-addr2line*
%_man1dir/%target-ar*
%_man1dir/%target-as*
%_man1dir/%target-c++filt*
%_man1dir/%target-dlltool*
%_man1dir/%target-elfedit*
%_man1dir/%target-gprof*
%_man1dir/%target-ld*
%_man1dir/%target-nm*
%_man1dir/%target-objcopy*
%_man1dir/%target-objdump*
%_man1dir/%target-ranlib*
%_man1dir/%target-readelf*
%_man1dir/%target-size*
%_man1dir/%target-strings*
%_man1dir/%target-strip*
2021-06-08 13:14:45 +00:00
%changelog
2022-06-05 15:33:17 +00:00
* Sun Jun 05 2022 Alexey Sheplyakov <asheplyakov@altlinux.org> 20220605-alt1
- Use slow 2-stage bootstrap to avoid a build failure with GCC 12
2021-12-01 14:24:47 +04:00
* Wed Dec 01 2021 Alexey Sheplyakov <asheplyakov@altlinux.org> 20211201-alt1
- Added armv7-a targeted compiler (arm-linux-gnueabihf)
- Partially merged riscv64/mipsel specs from iv@
2021-08-31 16:19:41 +04:00
* Tue Aug 31 2021 Alexey Sheplyakov <asheplyakov@altlinux.org> 20210831-alt1
- Fixed build failure due to (inappropriate) LTO enforcement
2021-08-04 20:04:42 +04:00
* Wed Aug 04 2021 Alexey Sheplyakov <asheplyakov@altlinux.org> 20210804-alt1
- Avoid breaking whenever GCC, binutils, or glibc gets updated
2021-07-29 21:24:49 +04:00
* Thu Jul 29 2021 Alexey Sheplyakov <asheplyakov@altlinux.org> 10.3.1-alt1
- Build GCC 10.3.1
- Disabled libsanitizer to avoid bootstrap problems
2021-06-15 15:00:14 +00:00
* Tue Jun 15 2021 Alexey Sheplyakov <asheplyakov@altlinux.org> 8.4.1-alt2
- Splitted into subpackages
2021-06-10 13:17:18 +00:00
* Fri Jun 11 2021 Alexey Sheplyakov <asheplyakov@altlinux.org> 8.4.1-alt1
2021-06-08 13:14:45 +00:00
- Initial build