File opencl-clang.spec of Package opencl-clang
%define realname opencl-clang
%define realver 15.0.2
%define srcext tar.gz
%define so_ver 15
%define llvm_ver 15
# turn off the generation of debuginfo rpm (RH9) ??
%global debug_package %{nil}
# Common info
Name: libopencl-clang%{?so_ver}
Version: %{realver}
Release: wiz%{?extraver:0.}1%{?dist}
License: BSD-3-Clause
Group: System/Libraries
URL: https://github.com/intel/opencl-clang
Summary: OpenCL wrapper library around clang
# Install-time parameters
Provides: %{realname} = %{version}-%{release}
Provides: libcommon_clang%{?so_ver} = %{version}-%{release}
Obsoletes: libcommon_clang%{?so_ver} < %{version}-%{release}
# Build-time parameters
BuildRequires: cmake >= 3.13.4
BuildRequires: gcc-c++
BuildRequires: ninja
BuildRequires: llvm%{llvm_ver}-devel
BuildRequires: llvm%{llvm_ver}
BuildRequires: clang%{llvm_ver}-devel
BuildRequires: clang%{llvm_ver}
BuildRequires: pkgconfig(LLVMSPIRVLib)
BuildRoot: %{_tmppath}/%{name}-root
Source0: https://github.com/intel/opencl-clang/archive/refs/tags/v%{realver}%{?extraver}.%{srcext}#/%{realname}-%{realver}%{?extraver}.%{srcext}
%description
Common clang is a thin wrapper library around clang. Common clang has
OpenCL-oriented API and is capable to compile OpenCL C kernels
to SPIR-V modules.
%package -n libopencl-clang-devel
Group: Development/Languages/C and C++
Summary: Development files for Common clang OpenCL wrapper library
Requires: %{name} = %{version}-%{release}
Provides: %{name}-devel = %{version}-%{release}
Provides: %{realname}-devel = %{version}-%{release}
Provides: libcommon_clang%{?so_ver}-devel = %{version}-%{release}
Provides: libcommon_clang-devel = %{version}-%{release}
Obsoletes: libcommon_clang-devel < %{version}-%{release}
%description -n libopencl-clang-devel
Common clang is a thin wrapper library around clang. Common clang has
OpenCL-oriented API and is capable to compile OpenCL C kernels
to SPIR-V modules.
This package provides headers and libraries required to build software using
Common clang OpenCL wrapper library.
# Preparation step (unpackung and patching if necessary)
%prep
%setup -q -n %{realname}-%{realver}%{?extraver}
%{__sed} -i '/\${OPENCL_CLANG_LINK_LIBS}/a\ %(llvm-config --libnames)' CMakeLists.txt
# Build step (compile/build binaries, documentation, etc)
%build
_CXXFLAGS='%{optflags} %{?gcc_lto} -include cstdint'
_LDFLAGS='-Wl,--as-needed -Wl,--strip-all -Wl,--no-undefined -Wl,-z,now -Wl,-z,relro %{?gcc_lto}'
cmake -S . -B tmp_build \
-G Ninja \
-Wno-dev \
-DCMAKE_INSTALL_PREFIX=%{_prefix} \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_CXX_FLAGS_RELEASE="$_CXXFLAGS" \
-DCMAKE_EXE_LINKER_FLAGS_RELEASE="$_LDFLAGS" \
-DCMAKE_MODULE_LINKER_FLAGS_RELEASE="$_LDFLAGS" \
-DCMAKE_SHARED_LINKER_FLAGS_RELEASE="$_LDFLAGS" \
-DCMAKE_SKIP_RPATH=YES \
-DCMAKE_VERBOSE_MAKEFILE=YES \
-DCMAKE_POLICY_VERSION_MINIMUM=3.5 \
\
-DUSE_PREBUILT_LLVM=YES \
-DLLVM_DIR=%{_libdir}/cmake/llvm
ninja -v -C tmp_build %{?_smp_mflags}
# Install built stuff
%install
DESTDIR=%{buildroot} ninja -v -C tmp_build install
# Cleanup
%clean
[ "%{buildroot}" != "/" ] && %{__rm} -rf %{buildroot}
# Files list
%files
%defattr(-,root,root)
%doc README.md
%{_libdir}/libopencl-clang.so.*
%files -n libopencl-clang-devel
%defattr(-,root,root)
%doc README.md
%dir %{_includedir}/cclang
%{_includedir}/cclang/*
%{_libdir}/libopencl-clang.so
%post -p /sbin/ldconfig
%postun -p /sbin/ldconfig
%changelog