%global _rules_path /lib/udev/rules.d
%global commitid 8fa944c74085aacd99da3e733af8dc5ac9b04fd9
%global debug_package %{nil}

Name:	 raspberrypi-userland
Version: 20220322
Release: 1
Summary: Libraries for interfacing to Raspberry Pi GPU
License: BSD-3-Clause
URL:	 https://github.com/raspberrypi/userland
Source0: https://github.com/raspberrypi/userland/archive/%{commitid}/userland-%{commitid}.tar.gz
Source11: 10-local-rpi.rules
Patch0000: set_gnu_install_paths.patch
Patch0001: disable_legacy.patch
Patch0002: mv-man-to-usr-share.patch
Patch0003: 0001-Add-MMAL-and-MMAL_APPS-to-64bit-builds.patch
Patch0004: 0002-Revert-Revert-mmal-Support-64-bit-clients.patch

BuildRequires: make >= 3.78
BuildRequires: gcc >= 3.4.2
BuildRequires: gcc-c++ cmake libEGL-devel libGL-devel
AutoReq: no
AutoProv: yes

Requires: libraspberrypi0 = %{version}-%{release}
Requires: libraspberrypi-bin = %{version}-%{release}
Requires: libraspberrypi-devel = %{version}-%{release}
Requires: libraspberrypi-help = %{version}-%{release}

Provides: raspberrypi-userland = %{version}-%{release}

ExclusiveArch: aarch64
ExclusiveOS: Linux

%description
This package contains libraries for interfacing to Raspberry Pi GPU.

%package -n libraspberrypi0
Summary: Libraries for the Raspberry Pi's VideoCore IV
Requires: raspberrypi-firmware
Provides: libraspberrypi0 = %{version}-%{release}
%description -n libraspberrypi0
This package provides MMAL and other libraries for the Raspberry Pi's
VideoCore IV multimedia processor.

%package -n libraspberrypi-bin
Summary: Miscellaneous Raspberry Pi utilities
Requires: libraspberrypi0 dtc
Provides: libraspberrypi-bin = %{version}-%{release}
%description -n libraspberrypi-bin
This package provides various utilities for interacting with the Raspberry Pi's VideoCore IV.

%package -n libraspberrypi-devel
Summary: Libraries for the Raspberry Pi's VideoCore IV (headers)
Requires: libraspberrypi0
Provides: libraspberrypi-devel = %{version}-%{release}
%description -n libraspberrypi-devel
This package provides headers and other development files for
MMAL and other libraries for the Raspberry Pi's VideoCore IV multimedia processor.

%package -n libraspberrypi-help
Summary: Libraries for the Raspberry Pi's VideoCore IV (docs)
Requires: libraspberrypi0
Provides: libraspberrypi-help = %{version}-%{release}
%description -n libraspberrypi-help
This package provides headers and other development files for
MMAL and other libraries for the Raspberry Pi's VideoCore IV multimedia processor.

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

cd %{name}-%{version}
cp %{SOURCE11} .
%patch0000 -p1
%patch0001 -p1
%patch0002 -p1
%patch0003 -p1
%patch0004 -p1

%build
cd %{name}-%{version}
mkdir -p build
cd build
cmake -DCMAKE_BUILD_TYPE=Release \
  -DVMCS_INSTALL_PREFIX=%{_prefix} \
  -DARM64=ON ../
make

%install
cd %{name}-%{version}
mkdir -p %{buildroot}%{_rules_path}
install -p -m 644 %{SOURCE11} %{buildroot}%{_rules_path}/
cd ./build
make install DESTDIR=%{buildroot}
cd %{buildroot}%{_mandir}/man1
gzip $(ls *.1)
cd %{buildroot}%{_mandir}/man7
gzip $(ls *.7)

%files
%defattr (-, root, root)
%license %{name}-%{version}/LICENCE

%files -n libraspberrypi0
%defattr (-, root, root)
%{_rules_path}/*
%{_libdir}/*.so.0
%license %{name}-%{version}/LICENCE
%doc %{name}-%{version}/README.md

%files -n libraspberrypi-bin
%defattr (-, root, root)
%{_bindir}/*
%{_mandir}/*
%license %{name}-%{version}/LICENCE

%files -n libraspberrypi-devel
%defattr (-, root, root)
%{_includedir}/*
%{_libdir}/*.a
%{_libdir}/pkgconfig
%{_libdir}/*.so
%license %{name}-%{version}/LICENCE

%files -n libraspberrypi-help
%defattr (-, root, root)
%license %{name}-%{version}/LICENCE

%changelog
* Tue Mar 22 2022 Yafen Fang<yafen@iscas.ac.cn> - 20220322-1
- update upstream to last commit (8fa944c74085aacd99da3e733af8dc5ac9b04fd9): mmal: Add mapping for IL OMX_IndexParamBrcmEnableIJGTableScaling param
- set install paths
- disable legacy
- update udev rules for raspi

* Wed Jan 26 2021 Yafen Fang<yafen@iscas.ac.cn> - 20210902-2
- add BuildRequires: gcc-c++

* Thu Sep 2  2021 Yafen Fang<yafen@iscas.ac.cn> - 20210902-1
- init package