File spirv-llvm-translator.spec of Package spirv-llvm-translator

%define realname SPIRV-LLVM-Translator
%define srcext   tar.xz

%bcond_without ninja

%define llvm_ver 19
%define so_ver   19_1
%define lname libLLVMSPIRVLib%{?so_ver}

# turn off the generation of debuginfo rpm  (RH9) ??
#global debug_package %{nil}

# Common info
Name:          llvm-spirv
Version:       19.1.3+0~git20241220.b14e489
Release:       0
License:       BSD-3-Clause
Group:         System/Libraries
URL:           https://github.com/KhronosGroup/SPIRV-LLVM-Translator
Summary:       LLVM/SPIR-V Bi-Directional Translator library

# Install-time parameters
Supplements:   %{lname} = %{version}
Provides:      %{realname} = %{version}-%{release}
Obsoletes:     %{realname} < %{version}-%{release}

# Build-time parameters
BuildRequires: cmake >= 3.3
BuildRequires: gcc-c++
%if %{with ninja}
BuildRequires: ninja
%endif
BuildRequires: llvm%{llvm_ver}-devel
BuildRequires: pkgconfig(libxml-2.0)
BuildRequires: pkgconfig(SPIRV-Tools)
BuildRequires: pkgconfig(zlib)
BuildRequires: spirv-headers
BuildRoot:     %{_tmppath}/%{name}-root
Source0:       %{realname}-%{version}.%{srcext}
# https://build.opensuse.org/package/show/openSUSE%3AFactory/spirv-llvm-translator
#Patch1:         Revert-Add-support-for-LLVM_LINK_LLVM_DYLIB.patch
#Patch2:         Revert-added-translator-support-for-SPIRV_INTEL.patch
#Patch3:         spirv-llvm-translator_PR2258.patch

%description
The LLVM/SPIR-V Bi-Directional Translator, a library and tool for translation
between LLVM IR and SPIR-V.

%package -n %{lname}
Group:         System/Libraries
Summary:       LLVM/SPIR-V Bi-Directional Translator library
Suggests:      %{name} = %{version}
Provides:      libllvmspirvlib%{?so_ver}

%description -n %{lname}
The LLVM/SPIR-V Bi-Directional Translator, a library and tool for translation
between LLVM IR and SPIR-V.

%package -n libLLVMSPIRVLib-devel
Group:         Development/Languages/C and C++
Summary:       Development files for LLVM/SPIR-V Bi-Directional Translator library
Requires:      %{name} = %{version}-%{release}
Requires:      %{lname} = %{version}-%{release}
Provides:      libllvmspirvlib-devel = %{version}-%{release}
Provides:      %{name}-devel = %{version}-%{release}
Provides:      %{realname}-devel = %{version}-%{release}

%description -n libLLVMSPIRVLib-devel
The LLVM/SPIR-V Bi-Directional Translator, a library and tool for translation
between LLVM IR and SPIR-V.

This package provides headers and libraries required for building software using
the LLVM/SPIR-V Bi-Directional Translator library.

# Preparation step (unpackung and patching if necessary)
%prep
%autosetup -p1 -n %{realname}-%{version}

# Build step (compile/build binaries, documentation, etc)
%build
_CXXFLAGS='%{optflags} %{?gcc_lto}'
_LDFLAGS='-Wl,--as-needed -Wl,--strip-all -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,now -Wl,-z,relro %{?gcc_lto}'
mkdir tmp_build
cd tmp_build
cmake .. \
%if %{with ninja}
 -G Ninja \
%endif
 -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 \
 -DBUILD_SHARED_LIBS=YES \
 -DLLVM_EXTERNAL_SPIRV_HEADERS_SOURCE_DIR=%{_prefix} \
 -DLLVM_SPIRV_BUILD_EXTERNAL=YES
%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

%post   -n %{lname} -p /sbin/ldconfig
%postun -n %{lname} -p /sbin/ldconfig

# Files list
%files
%defattr(-,root,root)
%license LICENSE.TXT
%doc README.md
%_bindir/*

%files -n %{lname}
%defattr(-,root,root)
%license LICENSE.TXT
%{_libdir}/*.so.*

%files -n libLLVMSPIRVLib-devel
%defattr(-,root,root)
%license LICENSE.TXT
%{_includedir}/LLVMSPIRVLib/
%{_libdir}/*.so
%{_libdir}/pkgconfig/LLVMSPIRVLib.pc

%changelog
openSUSE Build Service is sponsored by