File spirv-tools.spec of Package spirv-tools

%define realname SPIRV-Tools
%define realver  2024.3
%define srcext   tar.gz

# See: DEPS
%define  abseil_revision        1315c900e1ddbb08a23e06eeb9a06450052ccb5e
%define  effcee_revision        d74d33d93043952a99ae7cd7458baf6bc8df1da0
%define  googletest_revision    1d17ea141d2c11b8917d2c7d029f1c4e2b9769b2
%define  protobuf_revision      v21.12
%define  re2_revision           4a8cee3dd3c3d81b6fe8b867811e193d5819df07
%define  spirv_headers_revision 2acb319af38d43be3ea76bfabf3998e5281d8d12

%bcond_without ninja

%define so_ver   13

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

%if 0%{?rhel} >= 8
%define python3_pkg platform-python
%define python3     %{_libexecdir}/platform-python
%else
%define python3_pkg python3
%define python3     %{_bindir}/python3
%endif

# Common info
Name:          spirv-tools
Version:       %{realver}
Release:       wiz%{?extraver:0.}1%{?dist}
License:       Apache-2.0
Group:         Development/Tools/Other
URL:           https://github.com/KhronosGroup/SPIRV-Tools
Summary:       API and commands for processing SPIR-V modules

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

# Build-time parameters
BuildRequires: cmake >= 2.8.12
BuildRequires: pkg-config
BuildRequires: gcc-c++
BuildRequires: %{python3_pkg}
%if %{with ninja}
BuildRequires: ninja
%endif
BuildRoot:     %{_tmppath}/%{name}-root
Source0:       https://github.com/KhronosGroup/SPIRV-Tools/archive/refs/tags/v%{realver}%{?extraver}.%{srcext}#/%{realname}-%{realver}%{?extraver}.%{srcext}
# DEPS
Source11:       https://github.com/abseil/abseil-cpp/archive/%{abseil_revision}.%{srcext}#/abseil-cpp.%{srcext}
Source12:       https://github.com/google/effcee/archive/%{effcee_revision}.%{srcext}#/effcee.%{srcext}
Source13:       https://github.com/google/googletest/archive/%{googletest_revision}.%{srcext}#/googletest.%{srcext}
Source14:       https://github.com/protocolbuffers/protobuf/archive/refs/tags/%{protobuf_revision}.%{srcext}#/protobuf.%{srcext}
Source15:       https://github.com/google/re2/archive/%{re2_revision}.%{srcext}#/re2.%{srcext}
Source16:       https://github.com/KhronosGroup/SPIRV-Headers/archive/%{spirv_headers_revision}.%{srcext}#/spirv-headers.%{srcext}

%description
The SPIR-V Tools package provides an API and commands for processing
SPIR-V modules.

The package includes an assembler, binary module parser, disassembler,
validator, and optimizer for SPIR-V. Except for the optimizer, all are based on
a common static library. The library contains all of the implementation details,
and is used in the standalone tools whilst also enabling integration into other
code bases directly. The optimizer implementation resides in its own library,
which depends on the core library.

%package -n lib%{realname}
Group:         System/Libraries
Summary:       Shared libraries for %{realname}

%description -n lib%{realname}
The SPIR-V Tools package provides an API and commands for processing
SPIR-V modules.

This package provides shared libraries for %{realname}.

%package devel
Group:         Development/Languages/C and C++
Summary:       Development stuff for %{realname}

Requires:      lib%{realname} = %{version}-%{release}

%description devel
The SPIR-V Tools package provides an API and commands for processing
SPIR-V modules.

This package provides headers and libraries to build software
using %{realname}.

# Preparation step (unpackung and patching if necessary)
%prep
%setup -q -n %{realname}-%{realver}%{?extraver} -a11 -a12 -a13 -a14 -a15 -a16
for src in abseil-cpp effcee googletest protobuf re2; do
  mv -f $src-* external/${src%-*}
done
mv -v SPIRV-Headers-* external/spirv-headers

# Build step (compile/build binaries, documentation, etc)
%build
_CFLAGS='%{optflags} %{?gcc_lto}'
_LDFLAGS='-Wl,--as-needed -Wl,--strip-all -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,now -Wl,-z,relro %{?gcc_lto}'
_CMAKE_ARGS=(
 -DCMAKE_INSTALL_PREFIX=%{_prefix}
 -DCMAKE_BUILD_TYPE=Release
 -DCMAKE_C_FLAGS_RELEASE="$_CFLAGS"
 -DCMAKE_CXX_FLAGS_RELEASE="$_CFLAGS"
 -DCMAKE_EXE_LINKER_FLAGS_RELEASE="$_LDFLAGS"
 -DCMAKE_MODULE_LINKER_FLAGS_RELEASE="$_LDFLAGS"
 -DCMAKE_SHARED_LINKER_FLAGS_RELEASE="$_LDFLAGS"
 -DCMAKE_VERBOSE_MAKEFILE=YES
)
cmake -S . -B tmp_build \
%if %{with ninja}
 -G Ninja \
%endif
 "${_CMAKE_ARGS[@]}" \
 \
 -DSPIRV_TOOLS_BUILD_STATIC=NO \
 -DSPIRV_TOOLS_LIBRARY_TYPE=SHARED \
 -DSPIRV_SKIP_TESTS=YES
%if %{with ninja}
ninja -v -C tmp_build %{?_smp_mflags}
%else
%{__make} -C tmp_build%{?_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
# Fix shebang
%{__sed} -ri '1 s|^#!/usr/bin/env.+$|#!/bin/sh|' %{buildroot}%{_bindir}/spirv-lesspipe.sh

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

%files -n lib%{realname}
%defattr(-,root,root)
%{_libdir}/lib%{realname}*.so

%files devel
%defattr(-,root,root)
%license LICENSE
%doc CODE_OF_CONDUCT.md CONTRIBUTING.md README.md
%{_includedir}/%{name}/
%{_libdir}/pkgconfig/%{realname}-shared.pc
%{_libdir}/pkgconfig/%{realname}.pc
%dir %{_libdir}/cmake/%{realname}-diff
%dir %{_libdir}/cmake/%{realname}-link
%dir %{_libdir}/cmake/%{realname}-lint
%dir %{_libdir}/cmake/%{realname}-opt
%dir %{_libdir}/cmake/%{realname}-reduce
%dir %{_libdir}/cmake/%{realname}-tools
%dir %{_libdir}/cmake/%{realname}
%dir %{_libdir}/cmake
%{_libdir}/cmake/%{realname}-diff/*.cmake
%{_libdir}/cmake/%{realname}-link/*.cmake
%{_libdir}/cmake/%{realname}-lint/*.cmake
%{_libdir}/cmake/%{realname}-opt/*.cmake
%{_libdir}/cmake/%{realname}-reduce/*.cmake
%{_libdir}/cmake/%{realname}-tools/*.cmake
%{_libdir}/cmake/%{realname}/*.cmake

%post   -n lib%{realname} -p /sbin/ldconfig
%postun -n lib%{realname} -p /sbin/ldconfig

%changelog
openSUSE Build Service is sponsored by