#!/usr/local/bin/bash
# $Id: frontend.in,v 1.21 2003/02/05 17:24:18 jmmv Exp $
# bt_config's frontend.
#
# buildtool
# Copyright (c) 2002, Julio Merino.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in
#    the documentation and/or other materials provided with the
#    distribution.
# 3. Neither the name of the author nor the names of contributors may
#    be used to endorse or promote products derived from this software
#    without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS''
# AND ANY EXPRESS 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 AUTHOR OR
# 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.
#

if [ x"$__BUILDTOOL" != x"yes" ]; then
    echo "bt_config: this program must be run through buildtool"
    exit 1
fi

usage() {
    cat <<EOF
usage: bt_config [-h] [-f feature=value] [-d dir=value] [-H subject]
                 [-p prefix]

Extended help subjects (-H subject)
    dirs        show all customizable directories
    features    show all features supported by the package
EOF
}

if [ ! -f "./buildtool.d/defs" ]; then
    echo "bt_config: cannot find buildtool.d/defs file"
    exit 1
fi

if [ ! -f "./buildtool.d/config" ]; then
    echo "bt_config: cannot find buildtool.d/config script"
    exit 1
fi

. "./buildtool.d/defs"

# Load bt_config base module
. "/usr/local/share/buildtool-0/bt_config/base.subr"

# Load system configuration
if [ -f "/usr/local/etc/buildtool/bt_config.conf" ]; then
    echo "bt_config: loading system-wide configuration"
    . "/usr/local/etc/buildtool/bt_config.conf"
fi

if [ -f "buildtool.d/config_init" ]; then
    . "./buildtool.d/config_init"
fi
bt_argsinit

args=`POSIXLY_CORRECT=yes /usr/bin/getopt hf:d:H:p: $*`
set -- $args
while [ $# -gt 0 ]; do
    case $1 in
        -d)
            bt_dir_parse "$2"
            shift
            ;;
        -f)
            bt_feature_parse "$2"
            shift
            ;;
        -h)
            usage
            exit 1
            ;;
        -H)
            if [ x"$2" = x"features" ]; then
                bt_feature_list
            fi
            if [ x"$2" = x"dirs" ]; then
                bt_dir_list
            fi
            exit 0
            shift
            ;;
        -p)
            BT_PREFIX="$2"
            shift
            ;;
        --)
            shift; break
            ;;
    esac
    shift
done

# Parse the script
bt_init
. "./buildtool.d/config"
bt_finish

echo
echo "Configuration summary:"
echo "    Prefix is: $BT_PREFIX"
echo "    Static libraries: $BT_LIB_MKSTATIC, Shared libraries: $BT_LIB_MKPIC"

exit 0

# Local Variables: ***
# mode: shell-script ***
# End: ***
