File cross-aaa_base.spec of Package cross-aaa_base

#
# spec file
#
# Copyright (c) 2023 SUSE LLC
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via https://bugs.opensuse.org/
#


%define tarch @BUILD_FLAVOR@
%if "@BUILD_FLAVOR@" == ""
ExclusiveArch:  skipit
# workaround spec file validator package name check
%define pkg_name cross-aaa_base
%else
%define pkg_name cross-%{tarch}-aaa_base
%endif

# keep in sync with macros.cross definition
%define cross_sysroot %{_prefix}/%{tarch}-suse-linux/sys-root

Name:           %pkg_name
Summary:        Infrastructure for cross compiling on SUSE
License:        GPL-3.0-or-later
Group:          Development/Tools/Other
Version:        0.1
Release:        0
Source0:        LICENSE.GPL3
Source1:        macros.cross
Source2:        01-check-file-architectures-of-rpms
# https://gist.github.com/jerome-pouiller/c403786c1394f53f44a3b61214489e6f
Source3:        cross-compile-ldd

%description
This package provides infrastructure for cross architecture building using
the build script:

 * rpm macro definitions
 * post build check for host architecture binaries in build results
 * a pkg-config wrapper for cross building

%prep

%build
cp %{S:0} .

cat > cross-buildsystem.sh <<EOF
# Setting up cross compiler
export CC=%{tarch}-suse-linux-gcc
export CXX=%{tarch}-suse-linux-g++
export CROSS_COMPILE=/usr/bin/%{tarch}-suse-linux-
EOF

cat > cross-pkg-config <<EOF
#!/bin/sh

# A wrapper for pkg-config to take the default SUSE sysroot into account

export PKG_CONFIG_PATH=
export PKG_CONFIG_LIBDIR=%cross_sysroot%{_libdir}/pkgconfig:%cross_sysroot/usr/share/pkgconfig
export PKG_CONFIG_SYSROOT_DIR=%cross_sysroot

exec pkg-config "\$@"
EOF

%install
install -D -m 0755 cross-pkg-config %buildroot%{_bindir}/cross-%{tarch}-pkg-config
install -D -m 0755 %{S:3} %buildroot%{_bindir}/%{tarch}-suse-linux-ldd
install -D -m 0644 cross-buildsystem.sh %buildroot/etc/profile.d/cross-buildsystem.sh
install -D -m 0644 %{S:1} %buildroot/etc/rpm/macros.cross
install -D -m 0755 %{S:2} %buildroot/usr/lib/build/checks/01-check-file-architectures-of-rpms
sed -i -e 's,@ARCH@,%{tarch},' %buildroot/etc/rpm/macros.cross

%files
%license LICENSE.GPL3
%{_bindir}/cross-%{tarch}-pkg-config
%{_bindir}/%{tarch}-suse-linux-ldd
/usr/lib/build/checks/*
/etc/rpm/macros.cross
/etc/profile.d/cross-buildsystem.sh

%changelog
openSUSE Build Service is sponsored by