File cuda-repack.spec 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
Source10: %repo/cuda-cccl-12-9-12.9.27-1.%_arch.rpm
Source11: %repo/cuda-crt-12-9-12.9.41-1.%_arch.rpm
Source12: %repo/cuda-cudart-12-9-12.9.79-1.%_arch.rpm
Source13: %repo/cuda-cudart-devel-12-9-12.9.79-1.%_arch.rpm
Source14: %repo/cuda-nvcc-12-9-12.9.41-1.%_arch.rpm
Source15: %repo/cuda-nvvm-12-9-12.9.41-1.%_arch.rpm
Source16: %repo/cuda-driver-devel-12-9-12.9.79-1.%_arch.rpm
Source17: %repo/libcublas-12-9-12.9.1.4-1.%_arch.rpm
Source18: %repo/libcublas-devel-12-9-12.9.1.4-1.%_arch.rpm
Source19: %repo/cuda-toolkit-12-9-config-common-12.9.79-1.noarch.rpm
Source20: %repo/cuda-toolkit-12-config-common-12.9.79-1.noarch.rpm
Source21: %repo/cuda-toolkit-config-common-12.9.79-1.noarch.rpm
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_version_major() %(rpm -q --qf "%%{VERSION}" -p %1 | cut -d . -f1)
%define get_version_minor() %(rpm -q --qf "%%{VERSION}" -p %1 | cut -d . -f2)
%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 links %_sourcedir/links
%define _buildshell /bin/bash
%define cuda_version %{get_version_maj_min %sourcefile}
%define cuda_major %{get_version_major %sourcefile}
%define cuda_minor %{get_version_minor %sourcefile}
%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}}
# We need to plug dangling links during installation
# Now, we need a place to pack away the plugs
%package links
Summary: Empty
BuildArch: noarch
%description links
Links
%files links -f %links
%prep
%setup -T -c %{name}-%{version}
rpm2cpio %{S:0} | cpio -di
%build
shopt -s nullglob
rm -f %filelist; touch %filelist
# Handle dangling links
touch %links
for i in `find . -type l`; do
val=false
l=$(readlink $i);
d=$(dirname $i)
b=${d#.}
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" >> %links; \
echo "%exclude $b/$l" >> %filelist; }
done
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=%{cuda_version}
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
%if 0%{?suse_version} >= 1600
[ -d %{buildroot}/%_libdir/pkgconfig ] && chmod a-w %{buildroot}/%_libdir/pkgconfig || true
%endif
%fdupes -s %{buildroot}/usr
%fdupes -s .
%post -p /sbin/ldconfig
%postun -p /sbin/ldconfig
%if "%{package_name}" == "cuda-toolkit-%{cuda_version}-config-common"
%posttrans
update-alternatives --install /usr/local/cuda cuda /usr/local/cuda-%{cuda_version} %{cuda_major}%{cuda_minor}
update-alternatives --install /usr/local/cuda-%{cuda_major} cuda-%{cuda_major} /usr/local/cuda-%{cuda_version} %{cuda_major}%{cuda_minor}
/sbin/ldconfig
%endif
%files -f %filelist
%changelog