##
##  prince7.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:         prince7
Summary:      Professional XML to PDF Renderer
URL:          http://www.princexml.com/
Vendor:       YesLogic Pty. Ltd.
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        EVAL
Group:        Typesetting
License:      Commercial
Version:      7.1
Release:      20111001

#   list of sources
Source0:      http://www.princexml.com/download/prince-%{version}-freebsd63.tar.gz
Source1:      http://www.princexml.com/download/prince-%{version}-linux.tar.gz
Source2:      http://www.princexml.com/download/prince-%{version}-sol10x86.tar.gz
Source3:      http://www.princexml.com/download/prince-%{version}-macosx.tar.gz
Source4:      prince.sh
Source5:      prince.txt

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101
PreReq:       OpenPKG, openpkg >= 20160101, fonts-free
Provides:     prince

%description
    Prince is a commercial program that converts XML and HTML into PDF
    documents. Prince can read many XML formats, including XHTML and
    SVG. Prince formats documents according to style sheets written in
    CSS.

%track
    prog prince7 = {
        disabled
        version   = %{version}
        url       = http://www.princexml.com/download/
        regex     = prince-(__VER__)-linux\.tar\.gz
    }

%prep
    %setup -q -T -c

%build
    #   unpack platform-specific distribution
    case "%{l_platform -t}" in
        *-freebsd* ) source="%{SOURCE0}" ;;
        *-linux*   ) source="%{SOURCE1}" ;;
        *-sunos*   ) source="%{SOURCE2}" ;;
        *-darwin*  ) source="%{SOURCE3}" ;;
        * ) echo "Sorry, platform %{l_platform -t} not supported" 1>&2; exit 1 ;;
    esac
    %{l_gzip} -d -c $source | %{l_tar} xf -

%install

    #   create installation hierarchy
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/bin \
        $RPM_BUILD_ROOT%{l_prefix}/etc/prince \
        $RPM_BUILD_ROOT%{l_prefix}/libexec/prince \
        $RPM_BUILD_ROOT%{l_prefix}/lib/prince

    #   install command line wrapper
    %{l_shtool} install -c -m 755 %{l_value -s -a} \
        %{SOURCE prince.sh} $RPM_BUILD_ROOT%{l_prefix}/bin/prince

    #   install program
    %{l_shtool} install -c -m 755 \
        prince-*/lib/prince/bin/prince \
        $RPM_BUILD_ROOT%{l_prefix}/libexec/prince/
    rm -rf prince-*/lib/prince/bin

    #   install license file
    %{l_shtool} install -c -m 644 \
        prince-*/lib/prince/license/license.dat \
        $RPM_BUILD_ROOT%{l_prefix}/etc/prince/
    ln -s \
        ../../etc/prince \
        $RPM_BUILD_ROOT%{l_prefix}/lib/prince/license
    rm -rf prince-*/lib/prince/license

    #   install data
    cp -rp prince-*/lib/prince/* \
        $RPM_BUILD_ROOT%{l_prefix}/lib/prince/

    #   extend fonts.css for finding standard fonts
    for name in `grep "^<file" %{SOURCE prince.txt} | sed -e 's;^.*name=";;' -e 's;".*$;;'`; do
        (echo ""; cat %{SOURCE prince.txt}; echo "") |\
            sed -e "1,/^<file name=\"$name\">/d" -e "/<\/file>/,\$d" >$name
        %{l_shtool} install -c -m 644 %{l_value -s -a} \
            $name $RPM_BUILD_ROOT%{l_prefix}/lib/prince/style/$name
    done

    #   determine installation files
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT \
        %{l_files_std} \
        '%config %{l_prefix}/etc/prince/*'

%files -f files

%clean

