%global pkgvers 0
%global scdate0 20250318
%global schash0 c537cd0acec29d58e70b88870a8b32c4b834f4d2
%global branch0 master
%global source0 https://github.com/chipsalliance/UHDM.git

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

Name:           uhdm
Version:        %(curl -s https://raw.githubusercontent.com/chipsalliance/UHDM/%{schash0}/CMakeLists.txt | grep "UHDM VERSION" | awk '{print $3}' | sed 's|[^[:digit:].]||g')
Release:        %{scdate0}.%{pkgvers}.git%{sshort0}%{?dist}
Summary:        Universal Hardware Data Model
License:        Apache

URL:            https://github.com/chipsalliance/UHDM

BuildRequires:  gcc-c++ git cmake python3 swig python3-devel
BuildRequires:  python3-setuptools capnproto capnproto-devel python3-orderedmutidict

%global __cmake_in_source_build 1

%description
A complete modeling of the IEEE SystemVerilog Object Model
with VPI Interface, Elaborator, Serialization, Visitor and Listener.

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

%description    devel
Development library for %{name}.

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

%description    python
Development library for %{name}.


%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
# sover
sed -i -e 's|uhdm PROPERTIES|uhdm PROPERTIES SOVERSION 1 VERSION 1.0|' CMakeLists.txt
# stdfs
%if 0%{?rhel} == 8
sed -i -e 's|PRIVATE uhdm|PRIVATE uhdm stdc++fs|g' CMakeLists.txt
%endif
# install path
sed -i 's|DESTINATION lib/|DESTINATION %{_lib}/|' CMakeLists.txt
sed -i 's|${CMAKE_INSTALL_LIBDIR}/uhdm|${CMAKE_INSTALL_LIBDIR}/|' CMakeLists.txt
sed -i 's|${CMAKE_INSTALL_PREFIX}/lib|${CMAKE_INSTALL_PREFIX}/%{_lib}/uhdm|' CMakeLists.txt
sed -i 's|${CMAKE_INSTALL_PREFIX}/${Python_site_packages}|${Python_site_packages}|' python/CMakeLists.txt


%build
mkdir -p build
pushd build
%cmake .. -Wno-dev \
       -DCMAKE_SKIP_RPATH=ON \
       -DCMAKE_SKIP_BUILD_RPATH=ON \
       -DCMAKE_VERBOSE_MAKEFILE=OFF \
       -DCMAKE_BUILD_TYPE=RelWithDebInfo \
       -DCMAKE_INSTALL_LIBDIR=%{_libdir} \
       -DCMAKE_INSTALL_INCLUDEDIR=%{_includedir} \
       -DUHDM_BUILD_TESTS=OFF \
       -DUHDM_WITH_PYTHON=ON \
       -DUHDM_USE_HOST_CAPNP=ON

make %{?_smp_mflags}
popd

%install
pushd build
make install DESTDIR=%{buildroot}
popd
# fix libpath
#mkdir -p %{buildroot}/%{_libdir}/uhdm/
#mv -f %{buildroot}/%{_libdir}/uhdm/*.so* %{buildroot}/%{_libdir}/
#mv -f %{buildroot}/usr/lib/* %{buildroot}/%{_libdir}/


%files
%doc README.md
%license LICENSE
%{_bindir}/*
%{_datadir}/*
%{_libdir}/*.so.*

%files devel
%{_includedir}/*
%{_prefix}/%{_lib}/*.so
%{_libdir}/cmake/*
%{_libdir}/pkgconfig/*

%files python
%{python3_sitelib}/*


%changelog
* Sat Mar 12 2022 Balint Cristian <cristian.balint@gmail.com>
- github update releases