Name:		rocm-device-libs
Version:	3.9.0
Release:	0%{?dist}
Summary:	ROCm Device Library

License:	NCSA
URL:		https://github.com/RadeonOpenCompute/ROCm
Source0:	https://github.com/RadeonOpenCompute/ROCR-Device-Libs/archive/rocm-%{version}.tar.gz

# if not defined, define these macros
%{!?el8: %define el8 0}
%{!?fc32: %define fc32 0}
%{!?fc33: %define fc33 0}

Patch0:		0001-adjust-CMake-Target-to-match-install-path.patch
Patch1:		0001-Revert-Increase-cmake-version-to-match-llvm.patch
%if %{el8} || %{fc32} || %{fc33}
Patch2:		0001-Revert-Use-the-added-clang-builtins.patch
%endif

BuildArch: noarch

BuildRequires:  gcc
BuildRequires:  gcc-c++
BuildRequires:  clang-devel
BuildRequires:	cmake
BuildRequires:	llvm-devel
BuildRequires:	zlib-devel
# The f32 and epel8 build probably need this
BuildRequires:	llvm-static
# At least epel8 build needs libtinfo.so
BuildRequires:	ncurses-devel


%description
ROCm Device Library

%prep
%autosetup -n  ROCm-Device-Libs-rocm-%{version} -p1

%build
mkdir build
cd build

%cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo
%cmake_build


%install
cd build
%cmake_install

%define clang_resource_dir "%(clang --print-resource-dir)"

# TODO: usually cmake would install the .bc files to /usr/amdgcn/bincode/
#       Moving things to the clang resource dir should be the best choice currently:
#       https://reviews.llvm.org/D82930
mkdir -p %{buildroot}%{clang_resource_dir}
mv %{buildroot}%{_prefix}/amdgcn %{buildroot}%{clang_resource_dir}/
mv %{buildroot}%{_prefix}/lib/cmake %{buildroot}%{_libdir}

%ldconfig_scriptlets

%files
%doc README.md
%license LICENSE
%{_libdir}/cmake
# TODO: not sure how to use the clang_resource_dir macro here
%{_libdir}/clang

%changelog
* Mon Nov 23 2020 Philipp Knechtges - 3.9.0-0
- Initial commit