Name:               zvbi
Version:            0.2.42
Release:            1
Summary:            A library provides functions to capture and decode VBI data
License:            LGPLv2+ and GPLv2+ and BSD
URL:                https://github.com/zapping-vbi/zvbi
Source0:            %{url}/archive/v%{version}/%{name}-%{version}.tar.gz

Patch0001:          %{name}-0.2.24-tvfonts.patch
Patch0002:          %{name}-0.2.25-openfix.patch

BuildRequires:      gcc-c++ doxygen fontconfig gettext >= 0.21.0 libpng-devel
BuildRequires:      libICE-devel xorg-x11-font-utils systemd-units
BuildRequires:      autoconf automake libtool gettext-devel

Requires(post):     systemd-units fontconfig
Requires(preun):    systemd-units
Requires(postun):   systemd-units fontconfig

provides:           %{name}-fonts = %{version}-%{release}
Obsoletes:          %{name}-fonts < %{version}-%{release}
Provides:           xawtv-tv-fonts >= 3.95
Obsoletes:          xawtv-tv-fonts < 3.95

%description
The ZVBI library provides functions to read from Linux V4L, V4L2 and
FreeBSD BKTR raw VBI capture devices, from Linux DVB devices and
from a VBI proxy to share V4L and V4L2 VBI devices between multiple
applications.
It can demodulate raw to sliced VBI data in software, with support
for a wide range of formats, has functions to decode several popular
services including Teletext and Closed Caption, a Teletext cache
with search function, various text export and rendering functions.

%package            devel
Summary:            Development files for zvbi
Requires:           %{name} = %{version}-%{release} pkgconfig

%description        devel
The zvbi-devel package contains development files for zvbi.

%package            help
Summary:            Documents for zvbi

%description        help
The zvbi-help package contains related documents.

%prep
%autosetup -n %{name}-%{version} -p1

cat >zvbid.service <<EOF
[Unit]
Description=A Proxy For VBI Devices
After=syslog.target

[Service]
Type=forking
ExecStart=%{_sbindir}/zvbid

[Install]
WantedBy=multi-user.target
EOF

%build
autoreconf -fi
%configure --disable-rpath --enable-v4l --enable-dvb --enable-proxy
%make_build

cd contrib
./x11font

for font in *.bdf
do
  bdftopcf $font | gzip -9 -c > ${font%.bdf}.pcf.gz
done

mkfontdir -x .bdf .
echo "teletext -ets-teletext-medium-r-normal--*-200-75-75-c-120-iso10646-1" > fonts.alias
cd ..

%install
install -d %{buildroot}%{_datadir}/fonts/%{name}
%make_install

%delete_la_and_a

%find_lang %{name}

install -d %{buildroot}%{_unitdir}
install -m 644 zvbid.service %{buildroot}%{_unitdir}
install -m 0644 -p contrib/*.pcf.gz %{buildroot}%{_datadir}/fonts/%{name}
install -m 0644 -p contrib/fonts.* %{buildroot}%{_datadir}/fonts/%{name}
touch %{buildroot}%{_datadir}/fonts/%{name}/fonts.cache-1

install -d %{buildroot}%{_sysconfdir}/X11/fontpath.d
ln -sf %{_datadir}/fonts/%{name} %{buildroot}%{_sysconfdir}/X11/fontpath.d/%{name}

%post
/sbin/ldconfig
%systemd_post zvbid.service

fc-cache -f %{_datadir}/fonts/%{name} || :

%preun
%systemd_preun zvbid.service

%postun
/sbin/ldconfig
%systemd_postun_with_restart zvbid.service

if [ "$1" = "0" ]; then
    fc-cache -f %{_datadir}/fonts || :
fi

%files -f %{name}.lang
%doc AUTHORS COPYING COPYING.md
%{_bindir}/%{name}*
%{_sbindir}/zvbid
%{_unitdir}/zvbid.service
%{_libdir}/*.so.*
%dir %{_datadir}/fonts/%{name}
%{_datadir}/fonts/%{name}/*.gz
%{_datadir}/fonts/%{name}/fonts.dir
%{_datadir}/fonts/%{name}/fonts.alias
%{_sysconfdir}/X11/fontpath.d/%{name}
%ghost %{_datadir}/fonts/%{name}/fonts.cache-1

%files              devel
%{_includedir}/libzvbi.h
%{_libdir}/*.so
%{_libdir}/pkgconfig/%{name}-0.2.pc

%files              help
%doc BUGS ChangeLog NEWS README.md TODO
%{_mandir}/man1/*

%changelog
* Mon Sep 04 2023 yaoxin <yao_xin001@hoperun.com> - 0.2.42-1
- Update to 0.2.42

* Mon Dec 02 2019 Jiangping Hu <hujiangping@huawei.com> - 0.2.35-7
- Package init
