File opencl-clang.spec of Package opencl-clang

%define realname opencl-clang
%define realver  17.0.1
%define srcext   tar.gz

%bcond_without ninja

%define so_ver   17

# 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.4.3
BuildRequires: gcc-c++
%if %{with ninja}
BuildRequires: ninja
%endif
BuildRequires: llvm-devel  >= %{so_ver}.0 llvm-devel  < %{so_ver}.1
BuildRequires: clang-devel >= %{so_ver}.0 clang-devel < %{so_ver}.1
BuildRequires: clang       >= %{so_ver}.0 clang       < %{so_ver}.1
BuildRequires: pkgconfig(LLVMSPIRVLib)
BuildRequires: pkgconfig(libxml-2.0)
BuildRoot:     %{_tmppath}/%{name}-root
Source0:       https://codeload.github.com/intel/opencl-clang/%{srcext}/refs/tags/v%{realver}#/%{realname}-%{version}%{?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}'
_LDFLAGS='-Wl,--as-needed -Wl,--strip-all -Wl,--no-undefined -Wl,-z,now -Wl,-z,relro %{?gcc_lto}'
mkdir tmp_build
cd tmp_build
cmake .. \
%if %{with ninja}
 -G Ninja \
%endif
 -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 \
 \
 -DUSE_PREBUILT_LLVM=YES \
 -DPREFERRED_LLVM_VERSION=%(rpm -q --qf '%{VERSION}' llvm-devel) \
 -DLLVM_DIR=%{_libdir}/cmake/llvm
%if %{with ninja}
ninja -v %{?_smp_mflags}
%else
%{__make} %{?_smp_mflags}
%endif

# Install built stuff
%install
%if %{with ninja}
DESTDIR=%{buildroot} ninja -v -C tmp_build install
%else
%{__make} -C tmp_build install DESTDIR=%{buildroot}
%endif

# Cleanup
%clean
[ "%{buildroot}" != "/" ] && %{__rm} -rf %{buildroot}

# Files list
%files
%defattr(-,root,root)
%doc README.md
%{_libdir}/libopencl-clang.so.%{?so_ver}*

%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
openSUSE Build Service is sponsored by