%define cross_arch      arm
%define cross_triplet   arm-none-eabi
%define cross_sysroot   %{_prefix}/%{cross_triplet}/sys-root

%global majorversion   10.3
%global minorversion   2021.07
%global gccversion     10.3.1

Name:       %{cross_triplet}-gdb-arm
Version:    %{majorversion}_%{minorversion}
Release:    1%{?dist}
Summary:    GDB for (remote) debugging (%{cross_triplet})

Group:      Development/Debuggers
License:    GPLv3+
URL:        https://developer.arm.com/open-source/gnu-toolchain/gnu-rm
Source0:    https://developer.arm.com/-/media/Files/downloads/gnu-rm/%{majorversion}-%{minorversion}/gcc-arm-none-eabi-%{majorversion}-%{minorversion}-src.tar.bz2
#Patch0:     armgdb-compile.patch
#Patch1:     arm-gdb-python.patch

BuildRequires: texinfo
BuildRequires: ncurses-devel
BuildRequires: python-devel
BuildRequires: texinfo-tex
BuildRequires: expat-devel
BuildRequires: flex
BuildRequires: bison
BuildRequires: gcc
BuildRequires: gcc-c++
BuildRequires: mpfr-devel
%if 0%{?fedora} >= 27
BuildRequires: libipt-devel
%endif
BuildRequires: python2-devel
%if 0%{?fedora} >= 29 || 0%{?rhel} >= 8
BuildRequires: python-unversioned-command
%endif

%description
This is a version of GDB, the GNU Project debugger, for (remote)
debugging %{cross_triplet} binaries. GDB allows you to see and modify what is
going on inside another program while it is executing.

%package devel
Summary: GDB for (remote) debugging (%{cross_triplet})
Group: Development/Debuggers
Requires: %{name} = %{version}-%{release}

%description devel
This is a version of GDB, the GNU Project debugger, for (remote)
debugging %{cross_triplet} binaries.  GDB allows you to see and modify what is
going on inside another program while it is executing.  This package
contains development headers for working with gdb.


%prep
%autosetup -n gcc-arm-none-eabi-%{majorversion}-%{minorversion}
pushd src
tar xjf gdb.tar.bz2
popd
#patch0 -p0 -b .xx
#pushd src/gdb
#patch1 -p0 -b .python
#popd

%build
cd %{_builddir}/gcc-arm-none-eabi-%{majorversion}-%{minorversion}/src
mkdir -p gdb-build
cd gdb-build
../gdb/configure \
    --prefix=%{_prefix} \
    --mandir=%{_mandir} \
    --infodir=%{_infodir} \
    --host=%{_target_platform} \
    --build=%{_target_platform} \
    --target=%{cross_triplet} \
    --disable-nls \
    --disable-sim \
    --disable-gas \
    --disable-binutils \
    --disable-ld \
    --disable-gprof \
    --with-libexpat \
    --with-lzma=no \
    --with-system-gdbinit=%{_prefix}/arm-none-eabi/lib/gdbinit \
    --with-python=yes \
    --with-gdb-datadir=%{_datarootdir}/gdb-%{cross_triplet}-%{gccversion} \
    "--with-pkgversion=GNU Tools for ARM Embedded Processors"

make %{?_smp_mflags}

%install
cd %{_builddir}/gcc-arm-none-eabi-%{majorversion}-%{minorversion}/src/gdb-build

make DESTDIR=%{buildroot} install
#make DESTDIR=%{buildroot} install-html install-pdf

# we don't want these as this is a cross-compiler
rm -rf $RPM_BUILD_ROOT%{_infodir}
rm -f $RPM_BUILD_ROOT%{_libdir}/libiberty.a

# Get rid of the shared lib
rm -f $RPM_BUILD_ROOT%{_libdir}/lib%{cross_triplet}-sim.a

# Non-linux targets don't have syscalls
rm -rf $RPM_BUILD_ROOT%{_prefix}/share/gdb/syscalls


%files
%license src/gdb/{COPYING?,COPYING?.LIB}
%{_bindir}/%{cross_triplet}-*
%{_mandir}/man1/%{cross_triplet}-*.1.gz
%{_mandir}/man5/%{cross_triplet}-*.5.gz
%dir %{_datarootdir}/gdb-%{cross_triplet}-%{gccversion}
%{_datarootdir}/gdb-%{cross_triplet}-%{gccversion}/*

%files devel
%defattr(-,root,root,-)
%{_includedir}/gdb/jit-reader.h

%changelog
* Mon Aug 30 2021 Thomas Sailer <t.sailer@alumni.ethz.ch> - 2021.07-1
- update

* Thu Apr 08 2021 Thomas Sailer <t.sailer@alumni.ethz.ch> - 10_2020q4-1
- update

* Tue Aug 11 2020 Thomas Sailer <t.sailer@alumni.ethz.ch> - 9_2020q2-1
- update

* Sat Sep 28 2019 Thomas Sailer <t.sailer@alumni.ethz.ch> - 8_2019q3-1
- update

* Wed Feb 13 2019 Thomas Sailer <t.sailer@alumni.ethz.ch> - 8_2018q4-1
- update

* Tue Nov 14 2017 Thomas Sailer <t.sailer@alumni.ethz.ch> - 6_2017q2-1
- Update

* Sat Jan 28 2017 Thomas Sailer <t.sailer@alumni.ethz.ch> - 5_4_2016q3_20160926-0
- Initial spec file