##
##  xv.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 information
Name:         xv
Summary:      X Window System Graphics Viewer
URL:          http://www.trilon.com/xv/
Vendor:       John Bradley
Packager:     The OpenPKG Project
Distribution: OpenPKG [EVAL]
Group:        XWindow
License:      XV
Version:      3.10a
Release:      20021201

#   list of sources
Source0:      ftp://ftp.cis.upenn.edu/pub/xv/xv-%{version}.tar.gz
Source1:      ftp://ftp.trilon.com/pub/xv/xv-%{version}-png-1.2d.tar.gz
Patch0:       ftp://ftp.cis.upenn.edu/pub/xv/xv-%{version}.JPEG-patch
Patch1:       ftp://ftp.cis.upenn.edu/pub/xv/xv-%{version}.TIFF-patch
Patch2:       ftp://ftp.trilon.com/pub/xv/patches/xvpng-1.2d-fix3.patch
Patch3:       xv.patch

#   build information
Prefix:       %{l_prefix}
BuildRoot:    %{l_buildroot}
BuildPreReq:  OpenPKG, openpkg >= 20020206, X11, jpeg, png, zlib, tiff
PreReq:       OpenPKG, openpkg >= 20020206, X11, jpeg, png, zlib, tiff, gzip
AutoReq:      no
AutoReqProv:  no

%description
    XV is an interactive image manipulation program for the X Window
    System. It can operate on images in the GIF, JPEG, TIFF, PBM, PGM,
    PPM, XPM, X11 bitmap, Sun Rasterfile, Targa, RLE, RGB, BMP, PCX, FITS,
    and PM formats on all known types of X displays. It can generate
    PostScript files, and if you have ghostscript (version 2.6 or above)
    installed on your machine, it can also display them.

    This OpenPKG copy of xv is patched for use with version 6 of the
    Independent JPEG Group's JPEG library. It is also patched for use
    with version 3.5.7 of Sam Leffler's TIFF library. It is also patched
    to additionally allow for PNG file viewing.

%prep
    %setup0 -q
    %setup1 -q -T -D -a 1
    %patch0 -p0
    %patch1 -p0
    %patch2 -p0
    %patch3 -p1
    %{l_patch} -p1 < xvpng.diff

    #   use our own gunzip command
    %{l_shtool} subst \
        -e 's;#undef USE_GUNZIP;#define USE_GUNZIP;' \
        -e 's;#    define GUNZIP "/usr/local/bin/gunzip -q";#define GUNZIP "%{l_prefix}/bin/gunzip -q";' \
        config.h

    #   use our own JPEG, TIFF and PNG libraries
    %{l_shtool} subst \
        -e 's;\(\tcd $(JPEGDIR)\).*;;' \
        -e 's;\(\t( cd $(TIFFDIR) \;\).*;;' \
        -e 's;\(JPEGINC = -I\)$(JPEGDIR);\1%{l_prefix}/include;' \
        -e 's;\(JPEGLIB = \)$(JPEGDIR)\(/libjpeg.a\);\1%{l_prefix}/lib\2;' \
        -e 's;\(PNGINC = -I\)$(PNGDIR);\1%{l_prefix}/include;' \
        -e 's;\(PNGLIB = -L\)$(PNGDIR)\(.*\);\1%{l_prefix}/lib\2;' \
        -e 's;\(ZLIBINC = -I\)$(ZLIBDIR);\1%{l_prefix}/include;' \
        -e 's;\(ZLIBLIB = -L\)$(ZLIBDIR)\(.*\);\1%{l_prefix}/lib\2;' \
        -e 's;\(TIFFINC = -I\)$(TIFFDIR);\1%{l_prefix}/include/tiff;' \
        -e 's;\(TIFFLIB = \)$(TIFFDIR)\(/libtiff.a\);\1%{l_prefix}/lib\2;' \
        Makefile

%build
    #   build package
    CCOPTS="-O"
    CCOPTS="$CCOPTS -I`%{l_prefix}/etc/rc --query x11_incdir`"
    CCOPTS="$CCOPTS -L`%{l_prefix}/etc/rc --query x11_libdir`"
    JPEGLIB=%{l_prefix}/lib/libjpeg.a
    %{l_make} %{l_mflags} CCOPTS="$CCOPTS"

%install
    rm -rf $RPM_BUILD_ROOT

    #   create hierarchy
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/bin \
        $RPM_BUILD_ROOT%{l_prefix}/share \
        $RPM_BUILD_ROOT%{l_prefix}/share/%{name} \
        $RPM_BUILD_ROOT%{l_prefix}/man/man1

    #   install package
    %{l_make} %{l_mflags} install \
        BINDIR=$RPM_BUILD_ROOT%{l_prefix}/bin \
        LIBDIR=$RPM_BUILD_ROOT%{l_prefix}/share/%{name} \
        MANSUF=1 MANDIR=$RPM_BUILD_ROOT%{l_prefix}/man/man1

    #   strip binaries
    strip $RPM_BUILD_ROOT%{l_prefix}/bin/* 2>/dev/null || true

    #   determine installation files
    %{l_rpmtool} files -v -ofiles -r$RPM_BUILD_ROOT %{l_files_std}

%files -f files

%clean
    rm -rf $RPM_BUILD_ROOT

