##
##  fonts-free.spec -- OpenPKG RPM Package Specification
##  Copyright (c) 2000-2025 OpenPKG Project <http://openpkg.org/>
##
##  Permission to use, copy, modify, and distribute this software for
##  any purpose with or without fee is hereby granted, provided that
##  the above copyright notice and this permission notice appear in all
##  copies.
##
##  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
##  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
##  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
##  IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
##  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
##  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
##  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
##  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
##  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
##  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
##  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
##  SUCH DAMAGE.
##

#   package version
%define       V_liberation 2.00.5
%define       V_texgyre    2_501

#   package information
Name:         fonts-free
Summary:      Free-Available High-Quality Fonts
URL:          http://www.openpkg.org/
Vendor:       OpenPKG Project
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        EVAL
Group:        Graphics
License:      Open Source
Version:      20191228
Release:      20191228

#   list of sources
Source0:      https://github.com/liberationfonts/liberation-fonts/files/2926169/liberation-fonts-ttf-%{V_liberation}.tar.gz
Source1:      http://www.gust.org.pl/projects/e-foundry/tex-gyre/whole/tg%{V_texgyre}otf.zip
Source3:      fonts-free.conf

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101
PreReq:       OpenPKG, openpkg >= 20160101, fontconfig

%description
    This is a collection of high-quality fonts from the Liberation and
    TeX Gyre projects which are freely available which can replace the
    standard 35 Postscript fonts.

%track
    prog fonts-free:liberation = {
        version   = %{V_liberation}
        url       = https://github.com/liberationfonts/liberation-fonts/releases
        regex     = liberation-fonts-ttf-(__VER__)\.tar\.gz
    }
    prog fonts-free:texgyre = {
        version   = %{V_texgyre}
        url       = http://www.gust.org.pl/projects/e-foundry/tex-gyre/whole
        regex     = tg(__VER__)otf\.zip
    }

%prep
    %setup -q -c
    %setup -q -T -D -a 1

%build

%install
    #   install description
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/share/fonts-free

    #   install font: Liberation
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/share/fonts-free/Liberation
    cp  liberation-fonts-ttf-*/Liberation*.ttf \
        $RPM_BUILD_ROOT%{l_prefix}/share/fonts-free/Liberation/

    #   install font: TeX Gyre
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/share/fonts-free/TexGyre
    cp tg*/texgyr*.otf \
        $RPM_BUILD_ROOT%{l_prefix}/share/fonts-free/TexGyre/

    #   hook into fontconfig(1)
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/etc/fontconfig/conf.avail \
        $RPM_BUILD_ROOT%{l_prefix}/etc/fontconfig/conf.d
    %{l_shtool} install -c -m 644 %{l_value -s -a} \
        %{SOURCE fonts-free.conf} \
        $RPM_BUILD_ROOT%{l_prefix}/etc/fontconfig/conf.avail/
    ln -s ../conf.avail/fonts-free.conf \
        $RPM_BUILD_ROOT%{l_prefix}/etc/fontconfig/conf.d/99-fonts-free.conf

    #   determine installation files
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT %{l_files_std}

%files -f files

%clean

%post
    #   update fontconfig cache
    $RPM_INSTALL_PREFIX/bin/fc-cache -f 2>/dev/null || true
    exit 0

