%global pkgvers 0
%global scdate0 20241205
%global schash0 61e281511164ca74de1a39994c1476ba14c512e2
%global branch0 main
%global source0 https://github.com/avrdudes/avr-libc.git

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

%define target  avr

Name:           %{target}-libc
Version:        2.2.1
Release:        %{scdate0}.%{pkgvers}.git%{sshort0}%{?dist}
Summary:        C library for use with GCC on Atmel AVR microcontrollers
License:        BSD
BuildArch:      noarch

URL:            http://www.nongnu.org/avr-libc

BuildRequires:  git make python3 autoconf automake libtool avr-gcc doxygen
%if 0%{?fedora} > 36
BuildRequires:  netpbm-progs transfig texlive-epstopdf config(latexmk) tex(tex) tex(latex)
BuildRequires:  tex(tocloft.sty) tex(hanging.sty) tex(adjustbox.sty) tex(stackengine.sty)
BuildRequires:  tex(etoc.sty) tex(multirow.sty) tex(ulem.sty) tex(sectsty.sty) tex(newunicodechar.sty)
%endif

%undefine _auto_set_build_flags
%global __brp_strip_lto %{nil}
%global __os_install_post /usr/lib/rpm/brp-compress
%global __provides_exclude_from ^%{_prefix}/%{target}/.*$
%global __requires_exclude_from ^%{_prefix}/%{target}/.*$
%global _binaries_in_noarch_packages_terminate_build 0

%description
AVR Libc is a Free Software project whose goal is to provide a high
quality C library for use with GCC on Atmel AVR microcontrollers.


%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 --no-pager log --format=fuller
%autosetup -D -p 1 -T -c -n %{name}


%build
sed -i 's|-name exit.o|-wholename avr4/exit.o|g' doc/api/Makefile.am
#$(shell cd $(top_srcdir) && echo "-I`pwd`/include")
sed -i 's|$(shell cd $(top_srcdir) && echo "-I`pwd`/include")|-I$(abs_top_srcdir)/include -I$(abs_top_builddir)/include|' doc/api/Makefile.am
find . -name '*.py' -exec sed -i 's|/env python|/env python3|' {} +
./bootstrap
mkdir -p build
pushd build
../configure \
    --prefix=%{_prefix} \
%if 0
    --enable-doc \
%endif
    --host=avr
%make_build
popd


%install
pushd build
%make_install
popd
# clean spurious
rm -rf %{buildroot}/%{_bindir}


%files
%license LICENSE
%doc NEWS AUTHORS README.md
%{_docdir}/%{name}-*
%{_prefix}/%{target}
%if 0
%{_mandir}/man3/*.gz
%endif


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