%global pkgvers 0
%global scdate0 20250305
%global schash0 2d3ce939443e42b383ba1cd0392bec61e2381c99
%global branch0 master
%global source0 https://github.com/sylefeb/Silice.git

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

Name:           silice
Version:        0
Release:        %{scdate0}.%{pkgvers}.git%{sshort0}%{?dist}
Summary:        A language for hardcoding Algorithms into FPGA hardware

License:        GPLv3
URL:            https://github.com/sylefeb/Silice

Patch0:         silice-antlr4.patch

BuildRequires:  cmake gcc-c++ make git
%if 0%{?fedora}
BuildRequires:  antlr4 antlr4-runtime antlr4-cpp-runtime-devel
%endif
%if 0%{?rhel}
BuildRequires:  libuuid-devel java-devel
%endif
#luabind-devel

%global __cmake_in_source_build 1

%description
A language for hardcoding Algorithms into FPGA hardware


%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 submodule init
git submodule sync
git submodule update
git log --format=fuller
%patch -P 0 -p1 -b .antlr~


%build
%global optflags %(echo "%{optflags}" | sed "s|-Werror=format-security||g")
%if 0%{?fedora}
# external antlr4
rm -rf antlr/antlr4-*-source
rm -rf antlr/*.jar
sed -i '/add_subdirectory(antlr\/antlr4-cpp-runtime/d' CMakeLists.txt
sed -i 's|antlr4_static|antlr4-runtime|' CMakeLists.txt
sed -i '/TARGETS antlr4-runtime/d' CMakeLists.txt
echo '#/bin/bash' > antlr/antlr.sh
echo 'javac -cp "/usr/share/java/antlr4/antlr4-runtime.jar" $*' > antlr/jvc.sh
echo '/usr/bin/antlr4 $*' >> antlr/antlr.sh
export CXXFLAGS="%{optflags} -I%{_includedir}/antlr4-runtime"
%endif
%if 0%{?rhel}
export CXXFLAGS="%{optflags} -D_GLIBCXX_USE_CXX11_ABI=0"
%endif
# external lua
#rm -rf src/libs/lua
#rm -rf src/libs/luabind-deboostified
#sed -i '/add_subdirectory(src\/libs\/lua/d' CMakeLists.txt
mkdir -p build
pushd build
%cmake .. -Wno-dev \
       -DCMAKE_SKIP_RPATH=ON \
       -DCMAKE_VERBOSE_MAKEFILE=OFF \
       -DCMAKE_BUILD_TYPE=RelWithDebInfo
make V=0 %{?_smp_mflags}
popd


%install
mkdir -p %{buildroot}%{_bindir}/
install -Dpm755 -t %{buildroot}%{_bindir}/ build/%{name}


%files
%doc README.md
%doc tools projects
%doc learn-silice frameworks
%{_bindir}/*
%license LICENSE.md
%license LICENSE_GPLv3


%changelog
* Sun Oct 03 2021 Cristian Balint <cristian.balint@gmail.com>
- github update release