#!/bin/sh

# zlibc configure script
if [ $# = 0 ] ; then
	echo Syntax: configure system >&2
	exit 1
fi

if [ $1 != linux -a $1 != sun ] ; then
	echo Only linux and sun systems are supported >&2
	exit 1
fi

echo "Locating gzip"
if [ $1 = linux ] ; then
	compressor=`type -p gzip`
else
	compressor=`which gzip`
fi

#	compressor=`type gzip | tail -1l | sed 's/^.*is //g' `


if [ "X$compressor" = X ]; then
	compressor='gzip'
	extension=".gz"
else
	echo "Found $compressor ; testing extension"
	touch testfile
	extension=`$compressor -vf testfile 2>&1 | tail -1l | sed 's/^.*testfile//g' `
	rm -f testfile$extension
	echo "Your gzip creates $extension files"
fi

echo "Checking existence of /proc filesystem"
if [ -d /proc ] ; then
	proc=yes
	echo "Found a /proc filesystem"
else
	proc=no
	echo "Found no /proc filesystem"
fi

uncompressor="$compressor -dc"

tmpdir="/tmp"

IFS=@

echo -n "Use autodetected defaults? (gzip, extension and proc) [default is yes]"
read a
if [ "X$a" = Xno -o "X$a" = Xn ] ; then

echo -n "Uncompressor program? [default is '$uncompressor']"
read a
if [ "X$a" != X ]; then
	uncompressor=$a
fi

echo -n "Extension for compressed files? [default is '$extension']"
read a
if [ "X$a" != X ]; then
	extension=$a
fi

echo -n "Use proc filesystem to find out command name? [default is $proc]"
read a
if [ "X$a" != X ]; then
	proc=$a
else
	proc=yes
fi

fi

echo -n "Maximal length of user-supplied extension? [default is 5]"
read a
if [ "X$a" != X ]; then
	maxextlen=$a
else
	maxextlen=5
fi

echo -n "Directory to put temporary files? [default is '$tmpdir']"
read a
if [ "X$a" != X ]; then
	tmpdir=$a
fi

echo -n "Enable Run time configuration? [default is yes]"
read a
if [ "X$a" != X ]; then
	rt=$a
else
	rt=yes
fi

if [ "$rt" = yes -o "$rt" = y ]; then
	echo -n "Name of per user configuration file [default is '.zlibrc' ]"
	read a
	if [ "X$a" != X ]; then
		userconf=$a
	else
		userconf=.zlibrc
	fi

	echo -n "Location of system wide configuration file [default is '/usr/lib/zlibrc']"
	read a
	if [ "X$a" != X ]; then
		systemconf=$a
	else
		systemconf=/usr/lib/zlibrc
	fi
fi

echo -n "Disable configuration with environmental variables? [default is no]"
read a
if [ "X$a" != X ]; then
	secu=$a
else
	secu=no
fi

exec >config.h

echo "/* this file is generated automatically, do not edit */"
echo

echo "/* directory for temporary uncompressed files */"
echo "#define TMP \"$tmpdir\""
echo

echo "/* extension for compressed files */"
echo "#define EXT \"$extension\""
echo

echo "/* maximal length of user-supplied extension */"
echo "#define MAXEXTLEN $maxextlen"
echo

echo "/* program used to uncompress files */"
echo -n "#define UNCOMPR \""
echo $uncompressor | sed -e 's/[ 	][ 	]*/", "/g' -e 's/$/"/g'
echo

if [ "$proc" = yes -o "$proc" = y ]; then
	echo "/* use /proc filesystem to find out command name */"
	echo "#define HAVE_PROC"
	echo
fi

if [ "$secu" = yes -o "$secu" = y ]; then
	echo "/* disable configuration with environmental variables, for"
	echo " * additional security"
	echo " */"
	echo "#define SECURITY"
	echo
fi

if [ "$rt" = no -o "$rt" = n ]; then
	echo "#define NO_RT_CONFIG"
else
	echo "/* per user configuration file */"
	echo "#define HOMECONF \"$userconf\""
	echo

	echo "/* system wide configuration file */"
	echo "#define SYSTEMCONF \"$systemconf\""
	echo
fi





