%global pkgvers 2
%global scdate0 20220220
%global schash0 fd59fbb80c731e62634d07647c089ec2f7a84d7d
%global branch0 main
%global source0 https://github.com/tomverbeure/gdbwave.git

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

Name:           gdbwave
Version:        0
Release:        %{scdate0}.%{pkgvers}.git%{sshort0}%{?dist}
Summary:        GDB server to debug CPU simulation waveform traces
License:        MIT

URL:            https://github.com/tomverbeure/gdbwave

BuildRequires:  git make gcc-c++ riscv64-unknown-elf-gcc riscv64-unknown-elf-newlib zlib-devel
Requires:       riscv64-unknown-elf-gdb riscv64-unknown-elf-newlib openocd

%undefine _missing_build_ids_terminate_build

%description
GDB server to debug CPU simulation waveform traces.

%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


%build
sed -i -e 's|$(RISCV_TOOLCHAIN)/||g' src/Makefile
sed -i -e 's|$(TOOLS_PREFIX)/||g' test_data/sw_semihosting/Makefile
sed -i -e 's|rv32ic|rv32ic_zicsr_zifencei|' test_data/sw_semihosting/Makefile
sed -i -e 's|-march=$(MARCH) -g -ggdb -mabi=ilp32|-march=rv32ic -g -ggdb -mabi=ilp32|' test_data/sw_semihosting/Makefile
pushd src
make %{?_smp_mflags}
popd
pushd test_data/sw_semihosting
make %{?_smp_mflags}
mv -f progmem.??? ..
popd

%install
mkdir -p %{buildroot}/%{_bindir}
install -D -pm 755 src/gdbwave %{buildroot}/%{_bindir}/


%files
%license LICENSE
%doc README.md
%doc test_data
%{_bindir}/*


%changelog
* Thu Feb 24 2022 Cristian Balint <cristian.balint@gmail.com>
- update github releases