File _cuda-repack.spec.in of Package cuda-repack
#
# spec file for package cuda-repack
#
# Copyright (c) 2024 SUSE LINUX GmbH, Nuernberg, Germany.
#
# 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 filebase @BUILD_FLAVOR@%{nil}
%define NO_RELOC 1
%define repo http://developer.download.nvidia.com/compute/cuda/repos/sles15/%_arch
%define _buildshell /bin/bash
%if "%filebase" == ""
%define _arch x86_64
@ALL_SOURCES@
ExclusiveArch: do_not_build
%define package_name cuda-repac
%else
%define package_name %{get_name %sourcefile}
ExclusiveArch: x86_64
%define my_arch x86_64
%endif
%define __pkg_summary NO SYMMARY
%define __pkg_description_line EMPTY
%define __pkg_description_next NONE
#%%trace
%define get_arch() %(rpm -q --qf "%%{ARCH}" -p %1)
%define get_name() %(rpm -q --qf "%%{NAME}" -p %1)
%define get_version() %(rpm -q --qf "%%{VERSION}" -p %1)
%define get_version_maj_min() %(rpm -q --qf "%%{VERSION}" -p %1 | cut -d . -f1-2)
%define get_license() %(rpm -q --qf "%%{LICENSE}" -p %1)
%define get_summary() %(rpm -q --qf "%%{SUMMARY}" -p %1)
%define get_group() %(rpm -q --qf "%%{GROUP}" -p %1)
%define get_description() %(rpm -q --qf "%%{DESCRIPTION}" -p %1)
%define sourcefile %( [ -e %{S:0} ] && echo %{S:0} || echo %{basename: %{S:0}})
# | grep -vE -e "^lib.*\.so.*" -e "rpmlib" -e "/bin/sh" -e "ldconfig"
%define get_requires() %(IFS="
"; for i in $(rpm -q --requires -p %1); do
echo "Requires: $i"; done)
# | grep -vE -e "^lib.*" -e "pkgconfig" -e "application" -e "%name"
%define get_provides() %(IFS="
"; for i in $(rpm -q --provides -p %1); do
echo "Provides: $i"; done)
%define get_conflicts() %(IFS="
"; for i in $(rpm -q --conflicts -p %1); do echo "Conflicts: $i"; done )
%define get_recommends() %(IFS="
"; for i in $(rpm -q --recommends -p %1); do echo "Recommends: $i"; done )
%define get_supplements() %(for i in %(IFS="
"; rpm -q --supplements -p %1); do echo "Supplements: $i"; done )
%define get_enhances() %(for i in %(IFS="
"; rpm -q --enhances -p %1); do echo "Enhances: $i"; done )
%define file %{filebase}.rpm
%define filelist %_sourcedir/filelist
%define _buildshell /bin/bash
%if "%filebase" != ""
Source0: %repo/%file
%endif
Source1: cuda-repack.rpmlintrc
Name: %package_name
Version: %{get_version %sourcefile}
Release: 0
Summary: %{expand:%{get_summary %sourcefile}}
#License: %%{get_license %%sourcefile}
License: SUSE-NonFree
Url: https://developer.nvidia.com/cuda-downloads
Group: %{get_group %sourcefile}
%if "%{suffix:%filebase}" == "noarch"
BuildArch: noarch
%endif
BuildRequires: cpio
BuildRequires: rpm
BuildRequires: sed
BuildRequires: coreutils
BuildRequires: fdupes
BuildRequires: pkgconfig
BuildRequires: chrpath
%{get_requires %{sourcefile}}
%{get_provides %{sourcefile}}
%{get_conflicts %{sourcefile}}
%{get_recommends %{sourcefile}}
%{get_supplements %{sourcefile}}
%{get_enhances %{sourcefile}}
%description
%{expand:%{get_description %sourcefile}}
%prep
%setup -T -c %{name}-%{version}
rpm2cpio %{S:0} | cpio -di
%build
shopt -s nullglob
rm -f %filelist; touch %filelist
for i in ./usr/%{_lib}/pkgconfig/*.pc; do
%{?NO_RELOC::} sed -i -e "/^cudaroot=/s,local,lib,g" $i
done
for i in ./etc/ld.so.conf.d/*; do
%{?NO_RELOC::} sed -i -e "s,/local/,/lib/,g" $i
echo "%%config /$i" >> %filelist
done
if [ -d ./usr/local ]; then
%if 0%{?NO_RELOC:1}
version=%{get_version_maj_min %sourcefile}
if [ -d ./usr/local/cuda-${version} ]; then
echo "%%dir /usr/local/cuda-${version}" >> %filelist
echo "/usr/local/cuda-${version}/*" >> %filelist
else
dir=$(ls -d ./usr/local/cuda-*.* 2>/dev/null | head -1)
echo "%%dir ${dir/\./}" >> %filelist
echo "${dir/\./}" >> %filelist
fi
%else
mkdir -p usr/lib
mv usr/local/* usr/lib
for i in usr/lib/*; do
[ -d $i ] && echo "%%dir /$i" >> %filelist
done
%endif
fi
echo /usr/share/licenses/%{name}/LICENSE
if [ -e ./usr/share/licenses/%{name}/LICENSE ]; then
mv ./usr/share/licenses/%{name}/LICENSE .
echo "%%license LICENSE" >> %filelist
fi
for i in etc usr/lib usr/bin /usr/share/man/man1 usr/lib64 usr/include usr/src; do
[ -d ./$i ] && echo "/$i/"'*' >> %filelist
done
exit 0
%install
for i in etc usr lib; do
[ -d ./$i ] && mv ./$i %{buildroot}/
done
for i in ./*; do
[ -d ./$i ] && { pwd; echo "Directory $i not copied"; exit 1; }
done
elf="$(echo -e \\x7fELF)"
for i in $(find %{buildroot}/usr -name "lib*.so.*" -o \( -perm /111 -a ! -type d -a ! -type l \) ); do
[ "$(head -c 4 $i)" = "$elf" ] && chrpath -d $i
done
for i in `find %{buildroot} -type l`; do
val=false
l=$(readlink $i);
d=$(dirname $i)
b=${d#%{buildroot}}
if [[ $l =~ ^/ ]]; then
test -e $l && val=true
else
test -e $d/$l || test -e $b/$l && val=true
fi
$val || { mkdir -p $d/$(dirname $l); touch $d/$l; echo "%ghost $b/$l" >> filelist; }
done
%fdupes -s %{buildroot}/usr
%fdupes -s .
%post -p /sbin/ldconfig
%postun -p /sbin/ldconfig
%if "%{package_name}" == "cuda-toolkit-12-8-config-common"
%posttrans
update-alternatives --install /usr/local/cuda cuda /usr/local/cuda-12.8 128
update-alternatives --install /usr/local/cuda-12 cuda-12 /usr/local/cuda-12.8 128
/sbin/ldconfig
%endif
%files -f %filelist
%changelog