##
##  x11.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:         x11
Summary:      Information Resource for X11
URL:          -
Vendor:       The OpenPKG Project
Packager:     The OpenPKG Project
Distribution: OpenPKG [BASE]
Group:        Meta
License:      PD
Version:      20020829
Release:      20020829

#   list of sources
Source0:      rc.x11

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

%description
    This is the information resource package for X11.

%prep

%build

%install
    rm -rf $RPM_BUILD_ROOT

    x11_bindir=""
    x11_incdir=""
    x11_libdir=""

    #    search for binary directory
    for bindir in \
        `echo $PATH | sed -e 's/:/ /g'` \
        /usr/openwin/bin \
        /usr/[xX]/bin \
        /usr/[xX]11*/bin \
        /usr/[xX]386/bin \
        /usr/[xX]ree86/bin \
        /usr/local/[xX]/bin \
        /usr/local/[xX]11*/bin \
        /usr/local/[xX]386/bin \
        /usr/local/[xX]ree86/bin \
        /usr/athena/bin \
    ; do
        if [ -f "$bindir/xmkmf" ]; then
            x11_bindir="$bindir"
            break
        fi
    done

    #   search for include directory
    for incdir in \
        /usr/openwin/include \
        /usr/openwin/share/include \
        /usr/[xX]/include \
        /usr/[xX]11*/include \
        /usr/[xX]386/include \
        /usr/[xX]ree86/include \
        /usr/include \
        /usr/include/[xX] \
        /usr/include/[xX]11* \
        /usr/include/[xX]386 \
        /usr/include/[xX]free86 \
        /usr/local/include \
        /usr/local/include/[xX] \
        /usr/local/include/[xX]11* \
        /usr/local/include/[xX]386 \
        /usr/local/include/[xX]free86 \
        /usr/local/[xX]/include \
        /usr/local/[xX]11*/include \
        /usr/local/[xX]386/include \
        /usr/local/[xX]ree86/include \
        /usr/athena/include \
        /usr/unsupported/include \
    ; do
        if [ -f "$incdir/X11/Intrinsic.h" ]; then
            x11_incdir="$incdir"
            break
        fi
    done

    #   search for library directory
    for libdir in \
        /usr/openwin/lib \
        /usr/openwin/share/lib \
        /usr/[xX]/lib \
        /usr/[xX]11*/lib \
        /usr/[xX]386/lib \
        /usr/[xX]ree86/lib \
        /lib \
        /usr/lib \
        /usr/lib/[xX] \
        /usr/lib/[xX]11* \
        /usr/lib/[xX]386 \
        /usr/lib/[xX]free86 \
        /usr/local/lib \
        /usr/local/lib/[xX] \
        /usr/local/lib/[xX]11* \
        /usr/local/lib/[xX]386 \
        /usr/local/lib/[xX]free86 \
        /usr/local/[xX]/lib \
        /usr/local/[xX]11*/lib \
        /usr/local/[xX]386/lib \
        /usr/local/[xX]ree86/lib \
        /usr/athena/lib \
        /usr/unsupported/lib \
    ; do
        for ext in a so sl; do
            if [ -f "$libdir/libXt.$ext" ]; then
                x11_libdir="$libdir"
                break
            fi
        done
        if [ ".$x11_libdir" != . ]; then
            break
        fi
    done

    #   make sure everything was found
    if [ ".$x11_bindir" = . ] ||\
       [ ".$x11_incdir" = . ] ||\
       [ ".$x11_libdir" = . ]; then
       echo "************************************************************"
       echo "**  ERROR: SOME X11 INFORMATION COULD NOT BE DETERMINED!!"
       echo "**  ERROR: SOME X11 INFORMATION COULD NOT BE DETERMINED!!"
       echo "**"
       echo "**  We found out:"
       echo "**    X11 Binary  Directory: ${x11_bindir}"
       echo "**    X11 Include Directory: ${x11_incdir}"
       echo "**    X11 Library Directory: ${x11_libdir}"
       echo "**"
       echo "**  Unfortunately, some information is missing here."
       echo "**"
       echo "**  ERROR: SOME X11 INFORMATION COULD NOT BE DETERMINED!!"
       echo "**  ERROR: SOME X11 INFORMATION COULD NOT BE DETERMINED!!"
       echo "************************************************************"
       exit 1
    fi

    #   install rc file
    %{l_shtool} mkdir -f -p -m 755 \
        $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d/
    %{l_shtool} install -c -m 755 \
        -e 's;@l_prefix@;%{l_prefix};g' \
        -e "s;@x11_bindir@;${x11_bindir};g" \
        -e "s;@x11_incdir@;${x11_incdir};g" \
        -e "s;@x11_libdir@;${x11_libdir};g" \
        %{SOURCE rc.x11} $RPM_BUILD_ROOT%{l_prefix}/etc/rc.d/

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

%files -f files

%clean
    rm -rf $RPM_BUILD_ROOT

