configure: add some autoconf emulation.

This commit is contained in:
Jonathan Moore Liles 2008-05-25 11:26:53 -05:00
parent 0d40ca5b6b
commit 1c599fd7f6
2 changed files with 112 additions and 24 deletions

6
configure vendored
View File

@ -9,9 +9,9 @@ begin
begin_options begin_options
ask "Install prefix?" prefix /usr/local ask "Install prefix" prefix /usr/local
ask "Require LASH?" USE_LASH yes ask "Require LASH" USE_LASH yes
ask "Build for debugging?" USE_DEBUG no ask "Build for debugging" USE_DEBUG no
begin_tests begin_tests

View File

@ -14,29 +14,98 @@ fatal ()
exit 255 exit 255
} }
[ $# -gt 0 ] && fatal "This is not an autoconf script. Run it without any options and you will be prompted." UPDATE=no
HELP=no
split ()
{
while [ $# -gt 0 ]
do
echo $1
shift 1
done
}
if [ $# -gt 0 ]
then
case "$1" in
--update)
UPDATE=yes
shift 1
;;
--help)
HELP=yes
shift 1
;;
*)
# fatal "This is not an autoconf script. Run it without any options and you will be prompted."
;;
esac
if [ $# -gt 0 ]
then
echo "## options" > make.conf
split "$@" | sed '
s/--\(enable\|disable\)-\([^ =]\+\)/--\1-\U\2/g;
s/--enable-\([^ =]\+\)=\(.*\)/USE_\1=\2/g;
s/--enable-\([^ =]\+\)/USE_\1=yes/g;
s/--disable-\([^ =]\+\)/USE_\1=no/g;
s/--\([^ =]\+\)/\1/g;
' | sed -n '/^[^ =]\+=./p' >> make.conf
UPDATE=yes;
fi
fi
ask () ask ()
{ {
local A D local A D
D="`eval echo \\$$2`" D="`eval echo \\$$2`"
D=${D:-$3} D=${D:-$3}
echo -n "$BLACK$BOLD::$SGR0 $1 [$BOLD${D}$SGR0] " if [ $HELP = yes ]
read A then
A=${A:-$D} echo -en "\t"
if [ "$3" = yes ] || [ "$3" = no ] if [ "$D" = yes ] || [ "$D" = no ]
then then
case "$A" in if [ "$D" = yes ]
no | n | N) A=no ;; then
yes | y | Y) A=yes ;; echo -n "$2" | sed s/^USE_/--enable-/ | tr '[[:upper:]]' '[[:lower:]]'
* ) fatal "Invalid response. Must be 'yes' or 'no'" ;; else
esac echo -n "$2" | sed s/^USE_/--disable-/ | tr '[[:upper:]]' '[[:lower:]]'
fi fi
else
echo -n "--$2" | tr '[[:upper:]]' '[[:lower:]]'
fi
append "${2}=${A:-$D}" echo -e "\t$1"
return
fi
echo -n "$BLACK$BOLD::$SGR0 ${1}? [$BOLD${D}$SGR0] "
if [ $UPDATE = yes ]
then
A="$D"
echo
else
read A
A=${A:-$D}
fi
if [ "$3" = yes ] || [ "$3" = no ]
then
case "$A" in
no | n | N) A=no ;;
yes | y | Y) A=yes ;;
* ) fatal "Invalid response. Must be 'yes' or 'no'" ;;
esac
fi
append "${2}=${A:-$D}"
} }
ok () ok ()
@ -101,15 +170,34 @@ begin_options ()
# get the old values # get the old values
extract_options extract_options
echo > make.conf if [ $HELP = yes ]
append "# This file was automatically generated on `date`. Any changes may be lost!" then
append "## options" echo "****"
echo "This is not an autoconf script! Run without any arguments and you will be prompted."
echo "Alternatively, you may use the following autoconf style arguments for"
echo "non-interactive configuration."
echo "****"
echo
echo " Available options:"
echo
else
echo > make.conf
append "# This file was automatically generated on `date`. Any changes may be lost!"
append "## options"
echo "--- Configuration required ---" if [ $UPDATE = yes ]
then
echo "--- Updating configuration ---"
else
echo "--- Configuration required ---"
fi
fi
} }
begin_tests () begin_tests ()
{ {
[ $HELP = yes ] && exit 0
append "## libs" append "## libs"
extract_options extract_options
} }
@ -173,7 +261,7 @@ test_version ()
if [ $2 != -ge ] && [ $2 != -le ] if [ $2 != -ge ] && [ $2 != -le ]
then then
fatal "Syntax error" fatal "Syntax error"
fi fi
_test_version $1 $2 $3 _test_version $1 $2 $3