#!/bin/sh
##
##  config.sh -- trivial GNU config.guess/config.sub frontend
##

#   path configuration
config_dir="@l_prefix@/libexec/config"
config_guess="$config_dir/config.guess"
config_sub="$config_dir/config.sub"

#   usage
if [ $# -eq 0 ]; then
    echo "$0 guess [-r]"
    echo "$0 install [directory]"
    exit 0
fi

#   dispatch commands
cmd="$1"; shift
case "$cmd" in
    guess )
        #   guess platform configuration
        raw=no
        if [ ".$1" = ".-r" ]; then
            shift
            raw=yes
        fi
        config=`sh $config_guess`
        if [ $raw = no ]; then
            config=`sh $config_sub "$config"`
        fi
        echo "$config"
        ;;
    install )
        #   install guessing scripts
        if [ $# -ne 1 ]; then
            dir="."
        else
            dir="$1"; shift
        fi
        if [ -f $dir/config.guess ]; then
            echo "updating $dir/config.guess"
            chmod u+w $dir/config.guess
        else
            echo "creating $dir/config.guess"
        fi
        cp $config_guess $dir/config.guess
        chmod a+x $dir/config.guess
        if [ -f $dir/config.sub ]; then
            echo "updating $dir/config.sub"
            chmod u+w $dir/config.sub
        else
            echo "creating $dir/config.sub"
        fi
        cp $config_sub $dir/config.sub
        chmod a+x $dir/config.sub
        ;;
esac

