## START: Set by rpmautospec
## (rpmautospec version 0.3.0)
%define autorelease(e:s:pb:n) %{?-p:0.}%{lua:
    release_number = 2;
    base_release_number = tonumber(rpm.expand("%{?-b*}%{!?-b:1}"));
    print(release_number + base_release_number - 1);
}%{?-e:.%{-e*}}%{?-s:.%{-s*}}%{!?-n:%{?dist}}
## END: Set by rpmautospec

%global pypi_name asahi_firmware

# This package is arched because of the runtime requirement on liblzfse but
# it doesn't ship any binary objects itself
%global debug_package %{nil}

# For the generated library symbol suffix
%if 0%{?__isa_bits} == 32
%global libsymbolsuffix %{nil}
%else
%global libsymbolsuffix ()(%{__isa_bits}bit)
%endif

%global liblzfse_majver 1

Name:           asahi-installer
Version:        0.5.2
Release:        %autorelease
Summary:        Asahi Linux installer

License:        MIT
URL:            https://github.com/AsahiLinux/asahi-installer
Source:         %{url}/archive/v%{version}/%{name}-%{version}.tar.gz

BuildRequires:  python3-devel
BuildRequires:  sed

BuildRequires:  python3dist(asn1)

# LZFSE isn't supported on big-endian architectures
# https://github.com/lzfse/lzfse/issues/23
ExcludeArch:    s390x

%description
Asahi Linux installer

%package -n     python3-%{pypi_name}
Summary:        Asahi Linux firmware tools

# Ensure runtime dependencies are pulled in
Requires:       liblzfse.so.%{liblzfse_majver}%{libsymbolsuffix}
Requires:       python3dist(asn1)

%description -n python3-%{pypi_name}
Asahi Linux firmware tools

%prep
%autosetup -p1
# Replace bundled asn1 module with the system one and fix soname for liblzfse
rm asahi_firmware/asn1.py
sed -i asahi_firmware/img4.py \
  -e 's/from . import asn1/import asn1/' \
  -e 's/liblzfse.so/liblzfse.so.%{liblzfse_majver}/'

# Remove bundled macOS libraries we don't need
rm -r vendor

%generate_buildrequires
%pyproject_buildrequires -r

%build
%pyproject_wheel

%install
%pyproject_install
%pyproject_save_files %{pypi_name}

# remove this as it conflicts with the wrapper shipped in asahi-scripts
rm %{buildroot}%{_bindir}/asahi-fwextract

%check
%pyproject_check_import

%files -n python3-%{pypi_name} -f %{pyproject_files}
%license LICENSE
%doc README.md

%changelog
* Wed Jan 18 2023 Fedora Release Engineering <releng@fedoraproject.org> 0.5.2-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_38_Mass_Rebuild

* Fri Dec 09 2022 Davide Cavalca <dcavalca@fedoraproject.org> 0.5.2-1
- Update to 0.5.2; Fixes: RHBZ#2142330

* Sat Nov 05 2022 Davide Cavalca <dcavalca@fedoraproject.org> 0.5pre9-1
- Update to 0.5pre9; Fixes: RHBZ#2139345

* Mon Oct 31 2022 Davide Cavalca <dcavalca@fedoraproject.org> 0.5pre7-1
- Update to 0.5pre7; Fixes: RHBZ#2138560

* Thu Oct 27 2022 Davide Cavalca <dcavalca@fedoraproject.org> 0.5pre2-1
- Update to 0.5pre2

* Tue Sep 20 2022 Davide Cavalca <dcavalca@fedoraproject.org> 0.5pre1-2
- Make this package arched

* Mon Sep 19 2022 Davide Cavalca <dcavalca@fedoraproject.org> 0.5pre1-1
- Initial import; Fixes: RHBZ#2121984