%global pkgvers 0
%global scdate0 20230811
%global schash0 b6394a0275eb94f39b86584fa1e0fa9a3766ed23
%global branch0 master
%global source0 https://github.com/Xyce/XDM.git

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

Name:           xdm
Version:        2.7.0
Release:        %{scdate0}.%{pkgvers}.git%{sshort0}%{?dist}
Summary:        XDM netlist converter
License:        GPLv3

URL:            https://github.com/Xyce/XDM

BuildRequires:  gcc-c++ cmake git boost-devel
BuildRequires:  python3-devel python3-setuptools boost-python3
%if 0%{?rhel}
BuildRequires:  boost-python3-devel
%endif

Requires:       %{name}-python3

%global _lto_cflags %{nil}
%global debug_package %{nil}
%undefine _hardened_build
%undefine _annotated_build
%global __cmake_in_source_build 1

%description
This is the XDM netlist converter, used to convert
PSPICE and HSPICE netists into Xyce format.

%package        python3
Summary:        Python extension for %{name}
Provides:       %{name}

%description    python3
This package contains python extension for %{name}.


%prep
%setup -T -c -n %{name}
find %{_builddir} -name SPECPARTS -exec rm -rf {} +
git clone --depth 1 -n -b %{branch0} %{source0} .
git fetch --depth 1 origin %{schash0}
git reset --hard %{schash0}
git log --format=fuller
# fix build
sed -i '1 i #include <math.h>' src/c_boost/expr/ast_common.hpp
# fix boost
%if 0%{?rhel} == 8
sed -i 's|COMPONENTS python${Python3_VERSION_MAJOR}${Python3_VERSION_MINOR}|COMPONENTS python${Python3_VERSION_MAJOR}|' CMakeLists.txt
%endif

%build
mkdir build
pushd build
%cmake .. -Wno-dev \
       -DCMAKE_SKIP_RPATH=ON \
       -DCMAKE_VERBOSE_MAKEFILE=OFF \
       -DCMAKE_BUILD_TYPE=Release
make %{?_smp_mflags}
popd


%install
pushd build
rm -rf %{buildroot}
mkdir -p %{buildroot}%{_bindir}
mkdir -p %{buildroot}%{_datadir}/%{name}
mkdir -p %{buildroot}%{python3_sitearch}
cp -pR xdm_bundle/xdm %{buildroot}%{python3_sitearch}/
cp -pR xdm_bundle/*.so %{buildroot}%{python3_sitearch}/xdm/
cp -pR xdm_bundle/*.xml %{buildroot}%{_datadir}/%{name}/
install -m644 xdm_bundle/License.txt %{buildroot}%{_datadir}/%{name}/
install -m755 xdm_bundle/xdm_bdl.py %{buildroot}%{_bindir}/
popd
# fix spurious
rm -rf %{buildroot}/%{python3_sitearch}/libboost*
sed -i 's|#!/usr/bin/env python|#!/usr/bin/python3|' %{buildroot}%{_bindir}/xdm_bdl.py
# fix inclusion
find . %{buildroot} -name '*.py' -exec sed -i 's|import SpiritCommon|from xdm import SpiritCommon|' {} +
find . %{buildroot} -name '*.py' -exec sed -i 's|import SpiritExprCommon|from xdm import SpiritExprCommon|' {} +
find . %{buildroot} -name '*.py' -exec sed -i 's|import XdmRapidXmlReader|from xdm import XdmRapidXmlReader|' {} +
# fix paths
sed -i 's|os.path.join(base_path, "|os.path.join("%{python3_sitearch}/%{name}", "|' %{buildroot}%{_bindir}/xdm_bdl.py
# strip elf
find . %{buildroot} -name '*.so' -exec strip {} +


%files
%doc README.md
%license License.txt
%doc build/xdm_bundle/docs
%{_bindir}/xdm_bdl.py

%files python3
%{_datadir}/*
%doc src/python/docs
%{python3_sitearch}/*


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