##
##  acroread.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.
##

%define       V_real 5.06
%define       V_comp 506

#   package information
Name:         acroread
Summary:      Acrobat Reader
URL:          http://www.adobe.com/products/acrobat/
Vendor:       Adobe
Packager:     The OpenPKG Project
Distribution: OpenPKG [EVAL]
Group:        Graphics
License:      Commercial
Version:      %{V_real}
Release:      20021003

#   list of sources
Source0:      ftp://ftp.adobe.com/pub/adobe/acrobatreader/unix/5.x/linux-%{V_comp}.tar.gz
Source1:      ftp://ftp.adobe.com/pub/adobe/acrobatreader/unix/5.x/solaris-%{V_comp}.tar.gz

#   build information
Prefix:       %{l_prefix}
BuildRoot:    %{l_buildroot}
BuildPreReq:  OpenPKG, openpkg >= 20021002
PreReq:       OpenPKG, openpkg >= 20021002, X11
AutoReq:      no
AutoReqProv:  no

%description
    This is the freely-available Adobe Acrobat Reader (v5) for the
    Adobe Portable Document Format (PDF).

%prep
    %setup -q -T -c -n acroread-%{version}

%build
    #   no-op

%install
    rm -rf $RPM_BUILD_ROOT

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

    #   unpack the corresponding binary only
    case "%{l_target}" in
        *-freebsd* )
            tarball="%{SOURCE linux-%{V_comp}.tar.gz}"
            shell="/compat/linux/bin/sh"
            ;;
        *-linux* )
            tarball="%{SOURCE linux-%{V_comp}.tar.gz}"
            shell="/bin/sh"
            ;;
        *-solaris* )
            tarball="%{SOURCE solaris-%{V_comp}.tar.gz}"
            shell="/bin/sh"
            ;;
        * ) echo "Platform %{l_target} not supported" | %{l_rpmtool} msg -b
            exit 1
            ;;
    esac
    %{l_gzip} -c -d $tarball | %{l_tar} xf -

    #   perform the standard installation procedure
    %{l_shtool} subst -e 's;Linux);Linux|FreeBSD);' INSTALL
    PAGER="cat"
    export PAGER
    ( echo "ACCEPT"
      echo "$RPM_BUILD_ROOT%{l_prefix}/libexec/acroread"
    ) | $shell INSTALL

    #   post-adjust installation tree
    mv $RPM_BUILD_ROOT%{l_prefix}/libexec/acroread/bin/acroread \
       $RPM_BUILD_ROOT%{l_prefix}/bin/acroread
    rm -rf $RPM_BUILD_ROOT%{l_prefix}/libexec/acroread/bin
    %{l_shtool} subst \
        -e "s;$RPM_BUILD_ROOT%{l_prefix}/libexec;%{l_prefix}/libexec;g" \
        $RPM_BUILD_ROOT%{l_prefix}/bin/acroread
    case "%{l_target}" in
        *-freebsd* )
            %{l_shtool} subst -e 's;#!/bin/sh;#!/compat/linux/bin/sh;' \
                $RPM_BUILD_ROOT%{l_prefix}/bin/acroread
            brandelf -t Linux \
                $RPM_BUILD_ROOT%{l_prefix}/libexec/acroread/Reader/intellinux/bin/*
            ;;
    esac

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

%files -f files

%clean
    rm -rf $RPM_BUILD_ROOT

%post
    if [ $1 -eq 1 ]; then
        case "%{l_target}" in
            *-freebsd*)
                if [ ! -f /compat/linux/bin/sh ]; then
                    ( echo "The Linux ABI base system is not installed under /compat/linux/."
                      echo "Please install the FreeBSD port/package linux_base."
                    ) | %{l_rpmtool} msg -b
                fi
                ( if [ -r /etc/defaults/rc.conf ]; then
                      . /etc/defaults/rc.conf
                  fi
                  if [ -r /etc/rc.conf ]; then
                      . /etc/rc.conf
                  fi
                  case ${linux_enable} in
                      [Yy][Ee][Ss])
                          ;;
                      * )
                          ( echo "Acrobat Reader requires the Linux ABI in the kernel."
                            echo "Run /usr/sbin/linux manually before running TSM"
                            echo "or add the following line to /etc/rc.conf:"
                            echo "linux_enable=\"YES\""
                          ) | %{l_rpmtool} msg -b
                          ;;
                  esac
                )
                ;;
        esac
    fi

