%global pkgvers 0
%global scdate0 20230922
%global schash0 9ccbf1cf434e9ec0206b8121c6f1bbf9cf506864
%global branch0 master
%global source0 https://github.com/flashrom/flashrom.git

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

Name:           flashrom
Version:        %(curl -s https://raw.githubusercontent.com/flashrom/flashrom/%{schash0}/VERSION | sed 's|.[a-z,A-Z]||g')
Release:        %{scdate0}.%{pkgvers}.git%{sshort0}%{?dist}
Summary:        Simple program for reading/writing flash chips content
License:        GPLv2

URL:            https://flashrom.org

BuildRequires:  git gcc gnupg2 meson pciutils-devel
BuildRequires:  libftdi-devel libjaylink-devel python3-sphinx
%if 0%{?fedora} >= 37 || 0%{?rhel} > 9
BuildRequires:  libusb-compat-0.1-devel
%else
BuildRequires:  libusb-devel
%endif
BuildRequires:  libusbx-devel systemd zlib-devel
%ifarch %{ix86} x86_64 aarch64
BuildRequires:  dmidecode
Requires:       dmidecode
%endif
Requires:       udev
# see rhbz #495226
ExcludeArch:    s390 s390x

%description
flashrom is a utility for identifying, reading, writing, verifying and erasing
flash chips. It is designed to flash BIOS/EFI/coreboot/firmware/optionROM
images on mainboards, network/graphics/storage controller cards, and various
other programmer devices.

%package       devel
Summary:       Development package for %{name}
Requires:      %{name}%{?_isa} = %{version}-%{release}

%description   devel
Files for development with %{name}.

%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
# Replace GROUP="plugdev" specifiers with TAG+="uaccess"
sed -e 's/MODE="[0-9]*", GROUP="plugdev"/TAG+="uaccess"/g' util/flashrom_udev.rules -i

%build
mopt="-Dtests=disabled"
%if 0%{?rhel}
mopt="$mopt -Dman-pages=disabled"
%endif
%meson $mopt
%meson_build

%install
%meson_install

install -D -p -m 0644 util/flashrom_udev.rules %{buildroot}/%{_udevrulesdir}/60_flashrom.rules
rm %{buildroot}/%{_libdir}/libflashrom.a

%files
%license COPYING
%doc README.rst
%{_docdir}/%{name}
%{_sbindir}/%{name}
%{_libdir}/libflashrom.so.1
%{_libdir}/libflashrom.so.1.0.0
%{_udevrulesdir}/60_flashrom.rules
%{_datadir}/bash-completion/completions/flashrom.bash
%if ! 0%{?rhel}
%{_mandir}/man8/%{name}.*
%endif

%files devel
%{_includedir}/libflashrom.h
%{_libdir}/libflashrom.so
%{_libdir}/pkgconfig/flashrom.pc

%changelog
* Mon Mar 20 2023 Balint Cristian <cristian.balint@gmail.com>
- github releases

* Thu Feb 09 2023 Richard Hughes <richard@hughsie.com> - 1.3.0-1
- Update to latest upstream release