%global pkgvers 0
%global scdate0 20250209
%global schash0 4c00c3ef8d47a9d8b7fd3b1d80bafe18c618d9be
%global branch0 master
%global source0 https://github.com/MikePopoloski/slang.git

%global sshort0 %{expand:%%{lua:print(('%{schash0}'):sub(1,8))}}

Name:           sv-lang
Version:        8.0
Release:        %{scdate0}.%{pkgvers}.git%{sshort0}%{?dist}
Summary:        SystemVerilog compiler and language services
License:        MIT

URL:            https://github.com/MikePopoloski/slang

BuildRequires:  git cmake doxygen
BuildRequires:  python3 python3-devel python3-setuptools
%if ! (0%{?rhel} || (0%{?fedora} > 34 && 0%{?fedora} < 37))
BuildRequires:  fmt-devel catch-devel pybind11-devel
%endif
%if 0%{?rhel} == 8
BuildRequires:  gcc-toolset-12-build
BuildRequires:  gcc-toolset-12-binutils
BuildRequires:  gcc-toolset-12-gcc
BuildRequires:  gcc-toolset-12-gcc-c++
BuildRequires:  gcc-toolset-12-annobin-plugin-gcc
%else
BuildRequires:  gcc-c++
%endif

%global __cmake_in_source_build 1

%description
Slang is a software library that provides various components
for lexing, parsing, type checking, and elaborating SystemVerilog code.

%package        devel
Summary:        Development library of %{name}
Requires:       %{name} = %{version}-%{release}

%description    devel
Development files for %{name} library

%package        python
Summary:        Python library of %{name}
Requires:       %{name} = %{version}-%{release}

%description    python
Python bindings for %{name} library


%prep
%setup -T -c -n %{name}
git clone --depth 1 -n -b %{branch0} %{source0} .
git fetch --depth 1 origin %{schash0}
git reset --hard %{schash0}
git log --format=fuller
# python destination
sed -i 's|DESTINATION .)|DESTINATION ${Python_SITEARCH})|' bindings/CMakeLists.txt
# no tests
sed -i '/tests/d' tools/tidy/CMakeLists.txt
# non-existent
sed -i '/span.hpp/d' external/CMakeLists.txt


%build
mkdir -p build
pushd build
%if 0%{?rhel} == 8
%undefine _annotated_build
%{?enable_devtoolset12:%{enable_devtoolset12}}
%endif

%cmake .. -Wno-dev \
       -DCMAKE_SKIP_RPATH=ON \
       -DCMAKE_VERBOSE_MAKEFILE=OFF \
       -DCMAKE_BUILD_TYPE=RelWithDebInfo \
       -DBUILD_SHARED_LIB=ON \
       -DSLANG_LIB_NAME="svlang" \
       -DSLANG_INCLUDE_DOCS=OFF \
       -DSLANG_INCLUDE_TESTS=OFF \
       -DSLANG_INCLUDE_PYLIB=ON \
       -DSLANG_INCLUDE_TOOLS=ON \
       -DSLANG_INCLUDE_INSTALL=ON
%cmake_build
popd


%install
pushd build
%cmake_install
popd
# clean externals
rm -rf %{buildroot}/%{_includedir}/*.*
find %{buildroot}/%{_includedir} -mindepth 1 -maxdepth 1 ! -name 'slang' -type d -not -path '.' -exec rm -rf {} +


%check
export LD_LIBRARY_PATH=%{buildroot}/%{_libdir}:%{_builddir}/%{name}/build/lib
pushd build
make test || true
popd


%files
%license LICENSE
%doc README.md
%{_bindir}/*
%exclude %{_libdir}/cmake/*
%{_libdir}/*


%files devel
%{_includedir}/slang
%{_datadir}/pkgconfig/*
%{_libdir}/cmake/*

%files python
%{python3_sitearch}/*


%changelog
* Sun Jun 19 2022 Cristian Balint <cristian.balint@gmail.com>
- github update releases