#!/bin/sh
##
##  rpm-config -- OpenPKG RPM Library Build Utility
##  Copyright (c) 2000-2005 OpenPKG Foundation e.V. <http://openpkg.net/>
##  Copyright (c) 2000-2005 Ralf S. Engelschall <http://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.
##
##  rpm-config.sh: program
##

rpm_version="@l_version@"
rpm_cc="@l_cc@"
rpm_cppflags="@l_cppflags@"
rpm_cflags="@l_cflags@"
rpm_ldflags="@l_ldflags@"
rpm_libs="@l_libs@"

usage="rpm-config"
usage="$usage [--cc] [--cppflags] [--cflags] [--ldflags] [--libs]"
usage="$usage [--help] [--version]"
if [ $# -eq 0 ]; then
    echo "rpm-config:Error: Invalid option" 1>&2
    echo "rpm-config:Usage: $usage" 1>&2
    exit 1
fi

output=''
prev=''
for option
do
    if [ ".$prev" != . ]; then
        eval "$prev=\$option"
        prev=''
        continue
    fi
    case "$option" in
        -*=*) optarg=`echo "$option" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
           *) optarg='' ;;
    esac
    case "$option" in
        --help|-h)
            echo "Usage: $usage"
            exit 0
            ;;
        --version|-v)
            echo "OpenPKG RPM $rpm_version"
            exit 0
            ;;
        --cc)
            output="$output $rpm_cc"
            ;;
        --cppflags)
            output="$output $rpm_cppflags"
            ;;
        --cflags)
            output="$output $rpm_cflags"
            ;;
        --ldflags)
            output="$output $rpm_ldflags"
            ;;
        --libs)
            output="$output $rpm_libs"
            ;;
        * )
            echo "rpm-config:Error: Invalid option" 1>&2
            echo "rpm-config:Usage: $usage" 1>&2
            exit 1;
            ;;
    esac
done
if [ ".$prev" != . ]; then
    echo "rpm-config:Error: missing argument to --`echo $prev | sed 's/_/-/g'`" 1>&2
    exit 1
fi

if [ ".$output" != . ]; then
    echo "$output" | sed -e 's/^ *//' -e 's/ *$//'
fi

