##
##  ghostscript.spec -- OpenPKG RPM Specification
##  Copyright (c) 2000-2003 Cable & Wireless Deutschland GmbH
##  Copyright (c) 2000-2003 The OpenPKG Project <http://www.openpkg.org/>
##  Copyright (c) 2000-2003 Ralf S. Engelschall <rse@engelschall.com>
##
##  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       8.00
%define       V_mini       800
%define       V_font       6.0
%define       V_jpeg       6b
%define       V_png        1.2.5
%define       V_zlib       1.1.4

#   package information
Name:         ghostscript
Summary:      Ghostscript, Postscript and PDF Rendering Engine
URL:          http://www.cs.wisc.edu/~ghost/
Vendor:       Aladdin Enterprises
Packager:     The OpenPKG Project
Distribution: OpenPKG [BASE]
Group:        Graphics
License:      Aladdin
Version:      %{V_real}
Release:      20030112

#   package options
%option       with_x11     %{l_test -p x11}

#   list of sources
Source0:      ftp://mirror.cs.wisc.edu/pub/mirrors/ghost/AFPL/gs%{V_mini}/ghostscript-%{V_real}.tar.bz2
Source1:      ftp://mirror.cs.wisc.edu/pub/mirrors/ghost/AFPL/gs%{V_mini}/jpegsrc.v%{V_jpeg}.tar.gz
Source2:      ftp://mirror.cs.wisc.edu/pub/mirrors/ghost/AFPL/gs%{V_mini}/libpng-%{V_png}.tar.gz
Source3:      ftp://mirror.cs.wisc.edu/pub/mirrors/ghost/AFPL/gs%{V_mini}/zlib-%{V_zlib}.tar.gz
Source4:      ftp://mirror.cs.wisc.edu/pub/mirrors/ghost/AFPL/fonts/ghostscript-fonts-std-%{V_font}.tar.gz
Source5:      ftp://mirror.cs.wisc.edu/pub/mirrors/ghost/AFPL/fonts/ghostscript-fonts-other-%{V_font}.tar.gz

#   build information
Prefix:       %{l_prefix}
BuildRoot:    %{l_buildroot}
BuildPreReq:  OpenPKG, openpkg >= 20030103, gcc, make
PreReq:       OpenPKG, openpkg >= 20030103
%if "%{with_x11}" == "yes"
BuildPreReq:  X11
PreReq:       X11
%endif
AutoReq:      no
AutoReqProv:  no

%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.

%prep
    %setup0 -q -c
    %setup1 -q -T -D -a 1
    %setup2 -q -T -D -a 2
    %setup3 -q -T -D -a 3
    %setup4 -q -T -D -a 4
    %setup5 -q -T -D -a 5
    mv jpeg-%{V_jpeg}  ghostscript-%{version}/jpeg
    mv libpng-%{V_png} ghostscript-%{version}/libpng
    mv zlib-%{V_zlib}  ghostscript-%{version}/zlib

%build
    mtcflags=""
    mtldflags=""
    case "%{l_target}" in
        *-freebsd* ) mtcflags=""; mtldflags="-lc_r"     ;;
        *-linux*   ) mtcflags=""; mtldflags="-lpthread" ;;
        *-solaris* ) mtcflags=""; mtldflags="-lpthread" ;;
    esac
    cd ghostscript-%{version}
%if "%{with_x11}" == "yes"
    x11_inc="-I`%{l_prefix}/etc/rc --query x11_incdir`"
    x11_lib="-L`%{l_prefix}/etc/rc --query x11_libdir`"
%else
    x11_inc=""
    x11_lib=""
%endif
    %{l_shtool} subst \
         -e "s;^STDLIBS=-lpthread -lm;STDLIBS=$mtldflags -lm;" \
         -e "s;^prefix = /usr/local;prefix = %{l_prefix};" \
         -e "s;CC=gcc;CC=%{l_cc};" \
         -e "s;GCFLAGS=.*\\(-fno.*\\)\$;GCFLAGS=\$1;" \
         -e "s;XCFLAGS=.*\$;XCFLAGS=$mtcflags;" \
         -e "s;XINCLUDE=.*\$;XINCLUDE=$x11_inc;" \
         -e "s;XLIBDIRS=.*\$;XLIBDIRS=$x11_lib;" \
         src/unix-gcc.mak
%if "%{with_x11}" != "yes"
    %{l_shtool} subst \
         -e 's;DEVICE_DEVS=.*$;DEVICE_DEVS=;' \
         src/unix-gcc.mak
%endif
    %{l_make} %{l_mflags} -f src/unix-gcc.mak

%install
    rm -rf $RPM_BUILD_ROOT
    ( cd ghostscript-%{version}
      %{l_shtool} mkdir -f -p -m 755 $RPM_BUILD_ROOT%{l_prefix}
      %{l_make} %{l_mflags} -f src/unix-gcc.mak install DEVICE_DEVS="" \
          prefix=$RPM_BUILD_ROOT%{l_prefix}
    )
    %{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}/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
    rm -rf $RPM_BUILD_ROOT

