##
##  lcdf-typetools.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_typetools   2.110
%define       V_t1utils     1.42
%define       V_autofont    0.96
%define       V_fontools    20180701

#   package information
Name:         lcdf-typetools
Summary:      LCDF Typegraphy Tools
URL:          http://www.lcdf.org/type/
Vendor:       Eddie Kohler
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        PLUS
Group:        Typesetting
License:      GPL+MIT-style
Version:      %{V_typetools}
Release:      20230830

#   list of sources
Source0:      http://www.lcdf.org/type/lcdf-typetools-%{V_typetools}.tar.gz
Source1:      http://www.lcdf.org/type/t1utils-%{V_t1utils}.tar.gz
Source2:      http://www.lcdf.org/type/Autofont-%{V_autofont}.tar.gz
Source3:      http://download.openpkg.org/components/versioned/fontools/fontools-%{V_fontools}.zip

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101
PreReq:       OpenPKG, openpkg >= 20160101
BuildPreReq:  perl, perl-openpkg, infozip, gcc, gcc::with_cxx = yes
PreReq:       perl

%description
    The LCDF Typetools package contains several command-line programs
    for manipulating PostScript Type 1 and PostScript-flavored OpenType
    fonts. It also contains additional command-line tools for dealing
    with Type 1 fonts from a revision of I. Lee Hetheringtons beloved
    t1utils. Finally, it contains Autofont and FonTools, a set of tools
    for automating the font generation for TeX.

%track
    prog lcdf-typetools:typetools = {
        version   = %{V_typetools}
        url       = http://www.lcdf.org/type/
        regex     = lcdf-typetools-(__VER__)\.tar\.gz
    }
    prog lcdf-typetools:t1utils = {
        version   = %{V_t1utils}
        url       = http://www.lcdf.org/type/
        regex     = t1utils-(__VER__)\.tar\.gz
    }
    prog lcdf-typetools:autofont = {
        version   = %{V_autofont}
        url       = http://www.lcdf.org/type/
        regex     = Autofont-(__VER__)\.tar\.gz
    }
    prog lcdf-typetools:fontools = {
        version   = %{V_fontools}
        url       = http://download.openpkg.org/components/versioned/fontools/
        regex     = fontools-(__VER__)\.zip
    }

%prep
    %setup -q -c
    %setup -q -T -D -a1
    %setup -q -T -D -a2
    %{l_prefix}/bin/unzip -q -x %{SOURCE3}

%build
    #   build LCDF TypeTools
    ( cd lcdf-typetools-%{V_typetools}
      CC="%{l_cc}" \
      CXX="%{l_cxx}" \
      CFLAGS="%{l_cflags -O}" \
      CXXFLAGS="%{l_cxxflags -O}" \
      CPPFLAGS="%{l_cppflags}" \
      LDFLAGS="%{l_ldflags}" \
      ./configure \
          --prefix=%{l_prefix} \
          --mandir=%{l_prefix}/man \
          --without-kpathsea
      %{l_make} %{l_mflags -O}
    ) || exit $?

    #   build LCDF T1Utils
    ( cd t1utils-%{V_t1utils}
      CC="%{l_cc}" \
      CFLAGS="%{l_cflags -O}" \
      CPPFLAGS="%{l_cppflags}" \
      LDFLAGS="%{l_ldflags}" \
      ./configure \
          --prefix=%{l_prefix} \
          --mandir=%{l_prefix}/man
      %{l_make} %{l_mflags -O}
    ) || exit $?

    #   build LCDF AutoFont
    %{l_prefix}/bin/perl-openpkg prepare
    ( cd Autofont-%{V_autofont}
      %{l_prefix}/bin/perl-openpkg configure
      %{l_prefix}/bin/perl-openpkg build
    ) || exit $?

%install
    #   install LCDF TypeTools
    ( cd lcdf-typetools-%{V_typetools}
      %{l_make} %{l_mflags} install AM_MAKEFLAGS="DESTDIR=$RPM_BUILD_ROOT"
    ) || exit $?

    #   install LCDF T1Utils
    ( cd t1utils-%{V_t1utils}
      %{l_make} %{l_mflags} install AM_MAKEFLAGS="DESTDIR=$RPM_BUILD_ROOT"
    ) || exit $?

    #   install LCDF AutoFont
    ( cd Autofont-%{V_autofont}
      %{l_prefix}/bin/perl-openpkg install
    ) || exit $?

    #   install FonTools
    ( cd fontools
      %{l_shtool} install -c -m 755 \
          -e 's;/usr/bin/perl;%{l_prefix}/bin/perl;' \
          bin/* $RPM_BUILD_ROOT%{l_prefix}/bin/
      %{l_shtool} install -c -m 644 \
          doc/*.1 $RPM_BUILD_ROOT%{l_prefix}/man/man1/
      %{l_shtool} mkdir -f -p -m 755 \
          $RPM_BUILD_ROOT%{l_prefix}/share/texmf/fonts/enc/dvips/lcdf-typetools/fontools
      %{l_shtool} install -c -m 644 \
          share/* $RPM_BUILD_ROOT%{l_prefix}/share/texmf/fonts/enc/dvips/lcdf-typetools/fontools/
    ) || exit $?

    #   post-adjust installation area
    %{l_prefix}/bin/perl-openpkg -F perl-openpkg-files fixate cleanup
    strip $RPM_BUILD_ROOT%{l_prefix}/bin/* >/dev/null 2>&1 || true

    #   determine installation files
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
        %{l_files_std} `cat perl-openpkg-files`

%files -f files

%clean

%post
    #   update TeX hashes
    $RPM_INSTALL_PREFIX/bin/texhash >/dev/null 2>&1 || true
    exit 0

%postun
    #   update TeX hashes
    $RPM_INSTALL_PREFIX/bin/texhash >/dev/null 2>&1 || true
    exit 0

