File intel-graphics-compiler.spec of Package intel-graphics-compiler

%define realname intel-graphics-compiler
%define realver  2.18.5
%define srcext   tar.gz

%define so_ver   2

%define llvm_ver 15

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

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

# Common info
Name:          igc
Version:       %{realver}
Release:       wiz%{?extraver:0.}1%{?dist}
License:       MIT
Group:         System/Libraries
URL:           https://github.com/intel/intel-graphics-compiler
Summary:       Intel(R) Graphics Compiler for OpenCL(TM)

# Install-time parameters
Provides:      %{realname} = %{version}-%{release}
Provides:      libiga%{__isa_bits}-%{?so_ver}
Provides:      libigc%{?so_ver} = %{version}-%{release}
Provides:      libigdfcl%{?so_ver} = %{version}-%{release}
Obsoletes:     libigc%{?so_ver} < %{version}-%{release}
Obsoletes:     libigdfcl%{?so_ver} < %{version}-%{release}

# Build-time parameters
BuildRequires: cmake >= 3.13.4
BuildRequires: gcc-c++
BuildRequires: bison flex
BuildRequires: ninja
BuildRequires: %{python_pkg} %{python_pkg}-Mako %{python_pkg}-PyYAML
BuildRequires: libstdc++-devel
BuildRequires: opencl-clang-devel
BuildRequires: llvm%{llvm_ver}-devel
BuildRequires: clang%{llvm_ver}-devel
BuildRequires: lld%{llvm_ver}-devel
BuildRequires: pkgconfig(zlib)
BuildRequires: pkgconfig(libzstd)
BuildRequires: spirv-headers spirv-tools-devel
BuildRequires: libLLVMSPIRVLib-devel
BuildRequires: libLLVMGenXIntrinsics-devel
BuildRequires: libffi-devel
#!BuildIgnore: clang-tools
BuildRoot:     %{_tmppath}/%{name}-root
Source0:       https://github.com/intel/intel-graphics-compiler/archive/refs/tags/v%{realver}%{?extraver}.%{srcext}#/%{realname}-%{realver}%{?extraver}.%{srcext}
Source2:       https://github.com/llvm/llvm-project/raw/refs/heads/release/%{llvm_ver}.x/libunwind/include/mach-o/compact_unwind_encoding.h

%description
The Intel(R) Graphics Compiler for OpenCL(TM) is an llvm based compiler for
OpenCL(TM) targeting Intel Gen graphics hardware architecture.

%package devel
Group:         Development/Languages/C and C++
Summary:       Development files for Intel(R) Graphics Compiler for OpenCL(TM)
Requires:      %{name} = %{version}-%{release}
Provides:      %{realname}-devel = %{version}-%{release}
Provides:      libiga%{__isa_bits}-devel
Provides:      libigc-devel
Provides:      libigdfcl-devel
Provides:      pkgconfig(igc-opencl) = %{version}-%{release}

%description devel
The Intel(R) Graphics Compiler for OpenCL(TM) is an llvm based compiler for
OpenCL(TM) targeting Intel Gen graphics hardware architecture.

This package contains headers and libraries required to embed Intel(R) Graphics
Compiler into other software.

# Preparation step (unpackung and patching if necessary)
%prep
%setup -q -n %{realname}-%{realver}%{?extraver}
%{__sed} -ri '/REGEX MATCH/ s|\(\[0-9\]\(|([0-9]+(|' IGC/BiFModule/CMakeLists.txt
%{__sed} -ri '/cmake_minimum_required/ s/[0-9.]+/3.5/' IGC/MDAutogen/CMakeLists.txt 
grep -rFl llvm/ADT/Triple.h * | xargs sed -i 's|llvm/ADT/Triple.h|llvm/TargetParser/Triple.h|'
### LLVM 15.x
%{__install} -d IGC/common/llvm/TargetParser
%{__ln_s} /usr/include/llvm/ADT/Triple.h IGC/common/llvm/TargetParser/Triple.h

# Build step (compile/build binaries, documentation, etc)
%build
_LLVM_VER=$(rpm -q --qf '%%{VERSION}' llvm%{llvm_ver}-devel)
_CFLAGS='%{optflags} -Wno-error=deprecated-declarations -Wno-error=odr -Wno-error=maybe-uninitialized -Wno-error=cpp -Wno-error=free-nonheap-object'
_LDFLAGS='-Wl,--strip-all -Wl,-z,noexecstack -Wl,-z,now -Wl,-z,relro -fuse-ld=%{?with_gold:gold -Wl,--threads}%{!?with_gold:bfd}'
_CMAKE_ARGS=(
 -Wno-dev
 -G Ninja
 -DCMAKE_INSTALL_PREFIX=%{_prefix}
 -DCMAKE_INSTALL_LIBDIR=%{_libdir}
 -DCMAKE_INSTALL_FULL_LIBDIR=%{_libdir}
 -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
)
%{__install} -D -m0644 %{S:2} tmp_build/IGC/llvm-deps/src/libunwind/include/mach-o/compact_unwind_encoding.h
cmake -S . -B tmp_build \
 "${_CMAKE_ARGS[@]}" \
 \
 -DCMAKE_POLICY_VERSION_MINIMUM=3.5 \
 \
 -DIGC_OPTION__CLANG_MODE=Prebuilds \
 -DIGC_OPTION__LLVM_MODE=Prebuilds \
 -DIGC_OPTION__LLVM_PREFERRED_VERSION=$_LLVM_VER \
 -DIGC_OPTION__LLD_MODE=Prebuilds \
 -DIGC_OPTION__SPIRV_TRANSLATOR_MODE=Prebuilds \
 -DIGC_OPTION__SPIRV_TOOLS_MODE=Prebuilds \
 -DIGC_OPTION__VC_INTRINSICS_MODE=Prebuilds \
 -Dopencl-header=%{_libdir}/clang/$_LLVM_VER/include/opencl-c.h \
 \
 -DPYTHON_EXECUTABLE=%{python_bin}
ninja -v -C tmp_build %{?_smp_mflags}

# Install built stuff
%install
DESTDIR=%{buildroot} ninja -v -C tmp_build install

# Files list
%files
%defattr(-,root,root)
%doc README.md
%{_bindir}/*
%{_libdir}/libiga%{__isa_bits}.so.%{?so_ver}*
%{_libdir}/libigc.so.%{?so_ver}*
%{_libdir}/libigdfcl.so.%{?so_ver}*
%exclude %{_libdir}/igc2/NOTICES.txt

%files devel
%defattr(-,root,root)
%doc README.md
%{_includedir}/iga/
%{_includedir}/igc/
%{_includedir}/visa/
%{_libdir}/libiga%{__isa_bits}.so
%{_libdir}/libigc.so
%{_libdir}/libigdfcl.so
%{_libdir}/pkgconfig/igc-opencl.pc

%post   -p /sbin/ldconfig
%postun -p /sbin/ldconfig

%changelog
openSUSE Build Service is sponsored by