%global _lib_dir /usr/lib
%global _service_path /usr/lib/systemd/system
%global debug_package %{nil}

Name:	 pigpio
Version: 1.79
Release: 4
Summary: Raspberry Pi GPIO control transitional package
License: Unlicense
URL:	 https://github.com/joan2937/pigpio
Source0: https://github.com/joan2937/pigpio/archive/%{version}/pigpio-%{version}.tar.gz

Patch0000: 09-filelayout.patch
Patch0001: remove-broken-comments-from-top-of-manpa.patch
Patch0002: pigpiod-service.patch

BuildRequires: make >= 3.78
BuildRequires: gcc >= 3.4.2
BuildRequires: python3
BuildRequires: python3-setuptools
Requires: libpigpiod-if2-1 = %{version}-%{release}
Requires: libpigpiod-if1 = %{version}-%{release}
Requires: libpigpiod-if-devel = %{version}-%{release}
Requires: libpigpio1 = %{version}-%{release}
Requires: libpigpio-devel = %{version}-%{release}
Requires: pigpio-tools = %{version}-%{release}
Requires: pigpiod = %{version}-%{release}
Requires: python3-pigpio = %{version}-%{release}
AutoReq: no
AutoProv: yes

Provides: pigpio = %{version}-%{release}

ExclusiveArch: aarch64
ExclusiveOS: Linux

%description
A set of software which allows control of the General Purpose Input Outputs (GPIO) locally or remotely.

%package -n libpigpiod-if2-1
Summary: Client library for GPIO
Provides: libpigpiod-if2-1 = %{version}-%{release}
%description -n libpigpiod-if2-1
This package provides the libpigpiod_if2 client library for Raspberry Pi GPIO control.

%package -n libpigpiod-if1
Summary: Client library for GPIO (deprecated)
Provides: libpigpiod-if1 = %{version}-%{release}
%description -n libpigpiod-if1
This package provides the deprecated libpigpiod_if client library

%package -n libpigpiod-if-devel
Summary: Development headers for client libraries for Raspberry Pi GPIO control
Provides: libpigpiod-if-devel = %{version}-%{release}
Requires: libpigpiod-if2-1 = %{version}-%{release}
Requires: libpigpiod-if1 = %{version}-%{release}
%description -n libpigpiod-if-devel
This package provides the development headers for the libpigpiod_if2 and libpigpiod_if client libraries.

%package -n libpigpio1
Summary: Library for Raspberry Pi GPIO control
Provides: libpigpio1 = %{version}-%{release}
%description -n libpigpio1
This package provides the pigpio library used to access the GPIO directly.

%package -n libpigpio-devel
Summary: Client tools for Raspberry Pi GPIO control
Provides: libpigpio-devel = %{version}-%{release}
Requires: libpigpio1 = %{version}-%{release}
%description -n libpigpio-devel
This package provides the development headers for the pigpio library used to access the GPIO directly.

%package -n pigpio-tools
Summary: Client tools for Raspberry Pi GPIO control
Provides: pigpio-tools = %{version}-%{release}
%description -n pigpio-tools
This package provides the pigs and pig2vcd tools.

%package -n pigpiod
Summary: Client tools for Raspberry Pi GPIO control
Provides: pigpiod = %{version}-%{release}
%description -n pigpiod
This package provides the pigpiod daemon which offers a socket and pipe interface to the underlying library.

%package -n python3-pigpio
Summary: Python module which talks to the pigpio daemon (Python 3)
Provides: python3-pigpio = %{version}-%{release}
Requires: python3
%description -n python3-pigpio
This package provides the python 3 client library.

%prep
%setup -q -n %{name}-%{version} -c
mv %{name} %{name}-%{version}

cd %{name}-%{version}
%patch0000 -p1
%patch0001 -p1
%patch0002 -p1

%build
cd %{name}-%{version}
make

%install
mkdir -p %{buildroot}%{_service_path}
cd %{name}-%{version}
make install DESTDIR=%{buildroot}
install -p -m 644 util/pigpiod.service %{buildroot}%{_service_path}

%files
%defattr (-, root, root)
%license %{name}-%{version}/UNLICENCE
%exclude %{_lib_dir}/python2*

%files -n libpigpiod-if2-1
%defattr (-, root, root)
%{_lib_dir}/libpigpiod_if2.so.1
%license %{name}-%{version}/UNLICENCE

%files -n libpigpiod-if1
%defattr (-, root, root)
%{_lib_dir}/libpigpiod_if.so.1
%license %{name}-%{version}/UNLICENCE

%files -n libpigpiod-if-devel
%defattr (-, root, root)
%{_lib_dir}/libpigpiod_if*.so
%{_includedir}/pigpiod_if*.h
%{_mandir}/man3/pigpiod_if.3*
%{_mandir}/man3/pigpiod_if2.3*
%license %{name}-%{version}/UNLICENCE

%files -n libpigpio1
%defattr (-, root, root)
%{_lib_dir}/libpigpio.so.1
%license %{name}-%{version}/UNLICENCE

%files -n libpigpio-devel
%defattr (-, root, root)
%{_lib_dir}/libpigpio.so
%{_includedir}/pigpio.h
%{_mandir}/man3/pigpio.3*
%license %{name}-%{version}/UNLICENCE

%files -n pigpio-tools
%defattr (-, root, root)
%{_bindir}/pig2vcd
%{_bindir}/pigs
%{_mandir}/man1/pigs.1*
%{_mandir}/man1/pig2vcd.1*
%license %{name}-%{version}/UNLICENCE

%files -n pigpiod
%defattr (-, root, root)
/opt/pigpio
%{_bindir}/pigpiod
%{_mandir}/man1/pigpiod.1*
%{_service_path}/pigpiod.service
%license %{name}-%{version}/UNLICENCE

%files -n python3-pigpio
%defattr (-, root, root)
%{_lib_dir}/python3*
%license %{name}-%{version}/UNLICENCE

%changelog
* Fri Nov 01 2024 Wenlong Zhang <zhangwenlong@loongson.cn> - 1.79-4
- revert to 1.79-2

* Wed Jun 19 2024 Wenlong Zhang <zhangwenlong@loongson.cn> - 1.79-3
- build for loongarch64

* Fri Aug 27 2021 Yafen Fang<yafen@iscas.ac.cn> - 1.79-2
- change package name libpigpiod-if-dev to libpigpiod-if-devel
- change package name libpigpio-dev to libpigpio-devel
- change installation directory of man files

* Mon May 17 2021 Yafen Fang<yafen@iscas.ac.cn> - 1.79-1
- init package