%global _ld_path /etc/ld.so.conf.d
%global _rules_path /lib/udev/rules.d
%global _opt_bin_path /opt/vc/bin
%global _opt_man_path /opt/vc/man
%global commitid 97bc8180ad682b004ea224d1db7b8e108eda4397
%global debug_package %{nil}

Name:	 raspberrypi-userland
Version: 20210902
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
Source10: 00-vmcs.conf
Source11: 10-local-rpi.rules

Patch0000: 0001-Revert-Revert-Add-MMAL-and-MMAL_APPS-to-64bit-builds.patch
Patch0001: 0002-Revert-Revert-mmal-Support-64-bit-clients.patch

BuildRequires: make >= 3.78
BuildRequires: gcc >= 3.4.2
BuildRequires: cmake ncurses-devel bison gzip
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: EGL/GLES/OpenVG/etc. libraries for the Raspberry Pi's VideoCore IV
Requires: raspberrypi-firmware
Provides: libraspberrypi0 = %{version}-%{release}
%description -n libraspberrypi0
This package provides implementations of EGL, OpenGL ES, OpenVG, OpenWF
Composition, and others 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: EGL/GLES/OpenVG/etc. 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 implementations
of EGL, OpenGL ES, OpenVG, OpenWF Composition, and others for the Raspberry Pi's
VideoCore IV multimedia processor.

%package -n libraspberrypi-help
Summary: EGL/GLES/OpenVG/etc. libraries for the Raspberry Pi's VideoCore IV (headers)
Requires: libraspberrypi0
Provides: libraspberrypi-help = %{version}-%{release}
%description -n libraspberrypi-help
This package provides headers, example code, and other development files for
implementations of EGL, OpenGL ES, OpenVG, OpenWF Composition, and others 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 %{SOURCE10} .
cp %{SOURCE11} .
%patch0000 -p1
%patch0001 -p1

%build
cd %{name}-%{version}
mkdir -p build/raspberry/release
cd build/raspberry/release
cmake -DCMAKE_BUILD_TYPE=Release -DARM64=ON ../../..
make

%install
cd %{name}-%{version}
mkdir -p %{buildroot}%{_ld_path}
mkdir -p %{buildroot}%{_rules_path}
install -p -m 644 %{SOURCE10} %{buildroot}%{_ld_path}/
install -p -m 644 %{SOURCE11} %{buildroot}%{_rules_path}/
cd ./build/raspberry/release
make install DESTDIR=%{buildroot}
mkdir -p %{buildroot}%{_bindir}
cd %{buildroot}%{_bindir}
ln -s ../..%{_opt_bin_path}/raspistill ./
ln -s ../..%{_opt_bin_path}/raspivid ./
ln -s ../..%{_opt_bin_path}/raspividyuv ./
ln -s ../..%{_opt_bin_path}/raspiyuv ./
ln -s ../..%{_opt_bin_path}/tvservice ./
ln -s ../..%{_opt_bin_path}/vcgencmd ./
ln -s ../..%{_opt_bin_path}/vchiq_test ./
ln -s ../..%{_opt_bin_path}/dtoverlay ./
ln -s ../..%{_opt_bin_path}/dtoverlay-pre ./
ln -s ../..%{_opt_bin_path}/dtoverlay-post ./
ln -s ../..%{_opt_bin_path}/dtoverlay ./dtparam
ln -s ../..%{_opt_bin_path}/dtmerge ./
mkdir -p %{buildroot}%{_mandir}/man1
mkdir -p %{buildroot}%{_mandir}/man7
cd %{buildroot}%{_opt_man_path}/man1
gzip $(ls *.1)
cd %{buildroot}%{_mandir}/man1
ln -s $(ls ../../../..%{_opt_man_path}/man1/*.1.gz) ./
cd %{buildroot}%{_opt_man_path}/man7
gzip $(ls *.7)
cd %{buildroot}%{_mandir}/man7
ln -s $(ls ../../../..%{_opt_man_path}/man7/*.7.gz) ./

%post -p /sbin/ldconfig
%postun -p /sbin/ldconfig

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

%files -n libraspberrypi0
%defattr (-, root, root)
%dir /opt/vc
%dir /opt/vc/lib
%{_ld_path}/*
%{_rules_path}/*
/opt/vc/lib/lib*.so
/opt/vc/lib/plugins
%license %{name}-%{version}/LICENCE

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

%files -n libraspberrypi-devel
%defattr (-, root, root)
%dir /opt/vc
%dir /opt/vc/lib
/opt/vc/include
/opt/vc/lib/lib*.a
/opt/vc/lib/pkgconfig
%license %{name}-%{version}/LICENCE

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

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