#!/bin/sh

if echo '\c' | grep -s c >/dev/null 2>&1
then
	ECHO_N="echo -n"
	ECHO_C=""
else
	ECHO_N="echo"
	ECHO_C='\c'
fi

echo
echo "PHP Construction Kit / FI2 Installation"
echo
echo "If you do not understand any of the following questions,"
echo "then the default should be safe - simply hit 'Return'."
echo

$ECHO_N "Do you have mSQL installed on this system? [yN] $ECHO_C"
read a
if [ "$a" = "y" ] || [ "$a" = "Y" ]
then
$ECHO_N "Top of your mSQL install tree? [/usr/local/Minerva] $ECHO_C"
HLM=-DHAVE_LIBMSQL=1
read INST_TOP
if [ "$INST_TOP." = "." ]
then
	INST_TOP=/usr/local/Minerva
fi
else
	INST_TOP=
fi

$ECHO_N "Do you have Tom Boutell's GD library installed on this system? [yN] $ECHO_C"
read a
if [ "$a" = "y" ] || [ "$a" = "Y" ]
then
echo "Your libgd.a and gd*.h files should be in the standard lib and include"
echo "directories, or alternatively you may copy them to the PHP src directory."
HGD=-DHAVE_LIBGD=1
HLNK=-lgd
else
HGD=
HLNK=
fi

$ECHO_N "Would you like to include access control support? [Yn] $ECHO_C"
read a
if [ "$a." = "." ] || [ "$a" = "y" ] || [ "$a" = "Y" ]
then
	ACCESS_CONTROL=-DACCESS_CONTROL
	echo 
	echo "You need to choose an access control directory."
	echo "This directory must be readable and writable by the"
	echo "user id under which your http server runs."
	echo "It does not need to be on your WWW path, but don't"
	echo "leave it as \"/tmp\""
	echo
	$ECHO_N "Access control directory? [/tmp] $ECHO_C"
	read b
	if [ "$b." = "." ]
	then
		b=/tmp
	fi
	ACCESS_DIR=-DACCESS_DIR=\\\\\"$b\\\\\"
else
	ACCESS_CONTROL=
	ACCESS_DIR=
fi

$ECHO_N "Would you like to include page logging support? [Yn] $ECHO_C"
read a
if [ "$a." = "." ] || [ "$a" = "y" ] || [ "$a" = "Y" ]
then
	LOGGING=-DLOGGING
	echo 
	echo "You need to choose a page logging directory."
	echo "This directory must be readable and writable by the"
	echo "user id under which your http server runs."
	echo "It does not need to be on your WWW path, but don't"
	echo "leave it as \"/tmp\""
	echo
	$ECHO_N "Page logging directory? [/tmp] $ECHO_C"
	read b
	if [ "$b." = "." ]
	then
		b=/tmp
	fi
	LOG_DIR=-DLOG_DIR=\\\\\"$b\\\\\"
else
	LOGGING=
	LOG_DIR=
fi

$ECHO_N "Would you like to include file upload support? [Yn] $ECHO_C"
read a
if [ "$a." = "." ] || [ "$a" = "y" ] || [ "$a" = "Y" ]
then
	FILE_UPLOAD=-DFILE_UPLOAD
else
	FILE_UPLOAD=
fi

./configure

mv src/Makefile src/Makefile.$$
if [ "$INST_TOP." = "." ]
then
sed "	s,@MSQL_INCLUDE@,,
		s,@LIBMSQL@,,
		s,@MSQL_DEF@,,
		s,@MSQL_LIB@,,
		s,@HGD@,$HGD,
		s,@HLNK@,$HLNK,
		s,@ACCESS_CONTROL@,$ACCESS_CONTROL,
		s,@ACCESS_DIR@,$ACCESS_DIR,
		s,@LOGGING@,$LOGGING,
		s,@LOG_DIR@,$LOG_DIR,
		s,@FILE_UPLOAD@,$FILE_UPLOAD,
" < src/Makefile.$$ > src/Makefile
else
sed "	s,@MSQL_INCLUDE@,-I$INST_TOP/include,
		s,@LIBMSQL@,-lmsql,
		s,@MSQL_DEF@,$HLM,
		s,@MSQL_LIB@,-L$INST_TOP/lib,
		s,@HGD@,$HGD,
		s,@HLNK@,$HLNK,
		s,@ACCESS_CONTROL@,$ACCESS_CONTROL,
		s,@ACCESS_DIR@,$ACCESS_DIR,
		s,@LOGGING@,$LOGGING,
		s,@LOG_DIR@,$LOG_DIR,
		s,@FILE_UPLOAD@,$FILE_UPLOAD,
" < src/Makefile.$$ > src/Makefile
fi
rm src/Makefile.$$
touch src/*.c

echo "If none of -ldbm, -ldb nor -lgdbm were found, you should"
echo "probably get one of them.  It will work without these, but"
echo "but performance-wise you will gain a lot by installing"
echo "gdbm."
echo ""
echo "If the above item is ok, you are ready to compile"
echo "the package.  Type: cd src; make"
