##
##  tex4ht.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 information
Name:         tex4ht
Summary:      TeX-based authoring system for producing hypertext
URL:          http://www.cis.ohio-state.edu/~gurari/TeX4ht/
Vendor:       Eitan M. Gurari
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        EVAL
Group:        Typesetting
License:      LPPL
Version:      20030119
Release:      20080101

#   list of sources
Source0:      http://www.cis.ohio-state.edu/~gurari/TeX4ht/ufiles.zip
Source1:      http://www.cis.ohio-state.edu/~gurari/fix/newt4ht.zip
Source2:      http://www.cis.ohio-state.edu/~gurari/fix/htf.zip
Source3:      tex4ht.env

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101, infozip
PreReq:       OpenPKG, openpkg >= 20160101, tetex, ghostscript, imagemagick

%description
    TeX4ht is a highly configurable TeX-based authoring system for producing
    hypertext. It interacts with TeX-based applications through style files and
    postprocessors, leaving the processing of the source files to the native
    TeX compiler. Consequently, TeX4ht can handle the features of TeX-based
    systems in general, and of the LaTeX and AMS style files in particular.

%track
    prog tex4ht = {
        disabled
        comment   = "rse: unversioned distribution files only"
        version   = %{version}
        url       = http://www.cis.ohio-state.edu/~gurari/TeX4ht/
        regex     = .+
    }

%prep
    rm -rf $RPM_BUILD_DIR/tex4ht-%{version}
    %{l_shtool} mkdir -f -p -m 755 $RPM_BUILD_DIR/tex4ht-%{version}

%build
    cd $RPM_BUILD_DIR/tex4ht-%{version}
    %{l_prefix}/bin/unzip \
        %{SOURCE newt4ht.zip} \
        tex4ht.c t4ht.c
    %{l_cc} -o tex4ht tex4ht.c -DENVFILE='"%{l_prefix}/etc/tex4ht/tex4ht.env"' \
        -DHAVE_DIRENT_H
    %{l_cc} -o t4ht   t4ht.c   -DENVFILE='"%{l_prefix}/etc/tex4ht/tex4ht.env"'

%install
    HT_BIN_FILES="ht htlatex httex httexi"

    #   create directories
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/bin \
        $RPM_BUILD_ROOT%{l_prefix}/etc/tex4ht \
        $RPM_BUILD_ROOT%{l_prefix}/share/texmf/tex/generic/tex4ht

    #   install binaries
    %{l_shtool} install -c -s -m 755 \
        tex4ht-%{version}/tex4ht \
        tex4ht-%{version}/t4ht \
        $RPM_BUILD_ROOT%{l_prefix}/bin/
    for i in $HT_BIN_FILES; do
        ln -s ../share/texmf/tex/generic/tex4ht/$i \
            $RPM_BUILD_ROOT%{l_prefix}/bin/$i
    done

    #   install configuration file
    %{l_shtool} install -c -m 644 %{l_value -s -a} \
        %{SOURCE tex4ht.env} \
        $RPM_BUILD_ROOT%{l_prefix}/etc/tex4ht/
    ln -s ../../../../../etc/tex4ht/tex4ht.env \
        $RPM_BUILD_ROOT%{l_prefix}/share/texmf/tex/generic/tex4ht/tex4ht.env

    #   creating the so-called bookkeeping file
    %{l_shtool} install -c -m 666 \
        /dev/null \
        $RPM_BUILD_ROOT%{l_prefix}/share/texmf/tex/generic/tex4ht/tex4ht.fls

    #   unpacking original vendor source
    %{l_prefix}/bin/unzip \
        -d $RPM_BUILD_ROOT%{l_prefix}/share/texmf/tex/generic/tex4ht/ \
        %{SOURCE ufiles.zip} \
        -x tex4ht.env \*.c test\*.tex | %{l_shtool} prop

    #   unpacking fix pack
    %{l_prefix}/bin/unzip -o \
        -d $RPM_BUILD_ROOT%{l_prefix}/share/texmf/tex/generic/tex4ht/ \
        %{SOURCE newt4ht.zip} \
        -x \*.c \*.exe | %{l_shtool} prop

    #   unpacking fonts
    %{l_prefix}/bin/unzip -o \
        -d $RPM_BUILD_ROOT%{l_prefix}/share/texmf/tex/generic/tex4ht/ \
        %{SOURCE htf.zip} | %{l_shtool} prop

    #   fixing permissions
    find $RPM_BUILD_ROOT%{l_prefix}/share/texmf/tex/generic/tex4ht/ \
        -type d -exec chmod 755 {} \;
    find $RPM_BUILD_ROOT%{l_prefix}/share/texmf/tex/generic/tex4ht/ \
        -type f -exec chmod 644 {} \;
    for i in $HT_BIN_FILES; do
        chmod 755 $RPM_BUILD_ROOT%{l_prefix}/share/texmf/tex/generic/tex4ht/$i
    done

    #   building file list
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT %{l_files_std} \
        '%config %{l_prefix}/etc/tex4ht/*' \
        '%attr(0666,%{l_musr},%{l_mgrp}) \
            %{l_prefix}/share/texmf/tex/generic/tex4ht/tex4ht.fls'

%files -f files

%clean

%post
    echo "Running mktexlsr to rebuild teTeX ls-R database..." | %{l_rpmtool} msg -t notice
    $RPM_INSTALL_PREFIX/bin/mktexlsr >/dev/null 2>&1 || true

