##
##  ghostscript.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 versions
%define       V_real       9.56.1
%define       V_comp       9561
%define       V_font_std   8.11
%define       V_font_other 6.0

#   package information
Name:         ghostscript
Summary:      Ghostscript, Postscript and PDF Rendering Engine
URL:          http://ghostscript.com/
Vendor:       Aladdin Enterprises
Packager:     OpenPKG Project
Distribution: OpenPKG Community
Class:        BASE
Group:        Postscript
License:      GPL
Version:      %{V_real}
Release:      20220802

#   package options
%option       with_a4      yes

#   list of sources
Source0:      https://github.com/ArtifexSoftware/ghostpdl-downloads/releases/download/gs%{V_comp}/ghostscript-%{V_real}.tar.gz
Source1:      http://download.sourceforge.net/gs-fonts/ghostscript-fonts-std-%{V_font_std}.tar.gz
Source2:      http://download.sourceforge.net/gs-fonts/ghostscript-fonts-other-%{V_font_other}.tar.gz
Patch0:       ghostscript.patch

#   build information
BuildPreReq:  OpenPKG, openpkg >= 20160101, gcc, make
PreReq:       OpenPKG, openpkg >= 20160101
BuildPreReq:  libiconv, libidn, png, zlib, freetype, jpeg, openjpeg, lcms
PreReq:       libiconv, libidn, png, zlib, freetype, jpeg, openjpeg, lcms

%description
    Ghostscript is an interpreter for the PostScript language, with the
    ability to convert PostScript language files to many raster formats,
    view them on displays, and print them on printers that don't have
    PostScript language capability built in. It also works with Portable
    Document Format files (PDF), providing the same set of functionality
    as with PostScript.

%track
    prog ghostscript = {
        version   = %{version}
        url       = http://www.ghostscript.com/download/gsdnld.html
        regex     = ghostscript-(__VER__)\.tar\.gz
    }

%prep
    %setup -q -c
    %setup -q -T -D -a 1
    %setup -q -T -D -a 2
    %patch -p0 -d ghostscript-%{version}

%build
    ( cd ghostscript-%{version}
      rm -rf libpng zlib freetype lcms2 jpeg openjpeg tiff
      CC="%{l_cc}" \
      CFLAGS="%{l_cflags -O}" \
      CPPFLAGS="%{l_cppflags tiff libidn .}" \
      LDFLAGS="%{l_ldflags}" \
      ./configure \
          --prefix=%{l_prefix} \
          --mandir=%{l_prefix}/man \
          --with-fontpath=%{l_prefix}/share/ghostscript/fonts \
          --disable-cups \
          --disable-gtk \
          --without-x \
          --with-libiconv=gnu \
          --with-libidn \
          --with-drivers=ALL
      %{l_make} %{l_mflags -O}
    ) || exit $?

%install
    ( cd ghostscript-%{version}
      %{l_make} %{l_mflags} install DESTDIR="$RPM_BUILD_ROOT"
    ) || exit $?
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/share/ghostscript/fonts
    %{l_shtool} install -c fonts/* \
        $RPM_BUILD_ROOT%{l_prefix}/share/ghostscript/fonts/
    rm -rf $RPM_BUILD_ROOT%{l_prefix}/share/ghostscript/%{V_real}/doc
    rm -rf $RPM_BUILD_ROOT%{l_prefix}/share/ghostscript/%{V_real}/examples
    rm -rf $RPM_BUILD_ROOT%{l_prefix}/man/de
    for prg in eps2eps gsbj gsdj gslj gsdj500 ps2pdf12 ps2pdf13; do
        rm -f $RPM_BUILD_ROOT%{l_prefix}/bin/$prg
        rm -f $RPM_BUILD_ROOT%{l_prefix}/man/man1/$prg.1
    done
    mv $RPM_BUILD_ROOT%{l_prefix}/bin/ps2pdf14 \
       $RPM_BUILD_ROOT%{l_prefix}/bin/ps2pdf
    for prg in fixmswrd.pl lprsetup.sh pj-gs.sh pv.sh sysvlp.sh unix-lpr.sh; do
        rm -f $RPM_BUILD_ROOT%{l_prefix}/bin/$prg
    done
    for man in ansi2knr.1; do
        rm -f $RPM_BUILD_ROOT%{l_prefix}/man/man1/$man
    done
    strip $RPM_BUILD_ROOT%{l_prefix}/bin/* >/dev/null 2>&1 || true
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT %{l_files_std}

%files -f files

%clean

