non/scripts/config-funcs

298 lines
5.1 KiB
Plaintext
Raw Normal View History

#!/bin/sh
#
# Copyright (C) 2008 Jonathan Moore Liles
# This file is licensed under version 2 of the GPL.
. scripts/colors
# support functions for 'configure' scripts.
2008-05-18 17:30:06 +02:00
fatal ()
{
echo "$BOLD$RED$*$SGR0" > /dev/stderr
exit 255
}
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
2008-05-18 17:30:06 +02:00
ask ()
{
2008-05-25 19:12:51 +02:00
local A D O
D="`eval echo \\$$2`"
D=${D:-$3}
if [ $HELP = yes ]
then
2008-05-25 19:12:51 +02:00
if [ "$3" = yes ] || [ "$3" = no ]
then
2008-05-25 19:12:51 +02:00
O=`echo -n "$2" | sed s/^USE_/--enable-/ | tr '[[:upper:]]' '[[:lower:]]'`
else
2008-05-25 19:12:51 +02:00
O=`echo -n "--$2" | tr '[[:upper:]]' '[[:lower:]]'`
fi
2008-05-25 19:12:51 +02:00
printf " ${BOLD}${GREEN}%-15s${SGR0}\t%-40s (currently: ${BOLD}%s${SGR0})\n" "$O" "$1" "$D"
return
fi
2008-05-18 06:28:36 +02:00
echo -n "$BLACK$BOLD::$SGR0 ${1}? [$BOLD${D}$SGR0] "
2008-05-18 06:28:36 +02:00
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 ()
{
2008-05-18 05:06:03 +02:00
echo "$BOLD${GREEN}ok${SGR0}"
}
failed ()
{
echo "$BOLD${RED}failed!${SGR0}" > /dev/stderr
rm -f make.conf
}
2008-05-18 06:28:36 +02:00
using ()
{
[ "`eval echo \\$USE_$1`" = yes ]
return $?
}
upcase ()
{
echo "$*" | tr '[[:lower:]]' '[[:upper:]]'
}
extract_options ()
{
local line name value
if [ -f make.conf ]
then
{
while read line
do
[ "$line" = "## options" ] && break
done
while read line
do
if [ "$line" = "## libs" ]
then
break
else
name=${line%=*}
value=${line#*=}
eval "$name='$value'"
fi
done
} < make.conf
fi
}
begin ()
{
echo -n "Checking sanity..."
require_command pkg-config pkg-config > /dev/null
ok
}
2008-05-25 19:12:51 +02:00
warn ()
{
echo "${BOLD}${YELLOW}* ${SGR0}$*"
}
begin_options ()
{
# get the old values
extract_options
if [ $HELP = yes ]
then
2008-05-25 19:12:51 +02:00
warn "This is not an autoconf script! Run without any arguments and you will be prompted."
warn "Alternatively, you may use the following autoconf style arguments for"
warn "non-interactive configuration."
echo
echo " Available options:"
echo
else
echo > make.conf
append "# This file was automatically generated on `date`. Any changes may be lost!"
append "## options"
if [ $UPDATE = yes ]
then
echo "--- Updating configuration ---"
else
echo "--- Configuration required ---"
fi
fi
}
begin_tests ()
{
[ $HELP = yes ] && exit 0
append "## libs"
extract_options
}
append ()
{
echo "$1" >> make.conf
}
end ()
{
echo "--- Configuration complete ---"
touch make.conf
}
require_command ()
{
echo -n "Checking for ${BOLD}$1${SGR0}..."
if ! [ -x "`which $2`" ]
then
failed
fatal "Command $1 not found."
else
ok
fi
}
require_package ()
{
local name
echo -n "Checking for $BOLD$1$SGR0..."
if ! pkg-config --exists $3
then
failed
fatal "Required package $1 doesn't appear to be installed."
elif ! pkg-config --atleast-version $2 $3
then
failed
fatal "The installed version of $1 (`pkg-config --mod-version $3`) is too old."
fi
name="`upcase \"$1\"`"
append "${name}_LIBS=`pkg-config --libs $3`"
append "${name}_CFLAGS=-DHAVE_${1} `pkg-config --cflags $3`"
ok
return 0
}
2008-05-18 17:30:06 +02:00
_test_version ()
{
[ $1 $4 $5 ] && [ $2 $4 $6 ] && [ $3 $4 $7 ]
}
test_version ()
{
local IFS
IFS='.'
2008-05-18 19:00:27 +02:00
if [ $2 != -ge ] && [ $2 != -le ]
then
fatal "Syntax error"
2008-05-18 19:00:27 +02:00
fi
2008-05-18 17:30:06 +02:00
_test_version $1 $2 $3
}
2008-05-18 19:00:27 +02:00
version_of ()
{
echo `pkg-config --modversion $1`
}
require_FLTK ()
{
2008-05-18 17:30:06 +02:00
local use
echo -n "Checking for ${BOLD}FLTK${SGR0}..."
FLTK_VERSION=`fltk-config --version`
2008-05-18 17:30:06 +02:00
if ! test_version $FLTK_VERSION -ge $1
then
failed
fatal "The installed FLTK version ($FLTK_VERSION) is too old."
else
ok
fi
2008-05-18 17:30:06 +02:00
use=
while [ $# -gt 1 ]
do
shift 1
use="$use --use-$1"
done
append "FLTK_LIBS=`fltk-config $use --ldflags`"
append "FLTK_CFLAGS=`fltk-config $use --cflags`"
}