#!/bin/sh

ETC_DIR=/etc/ax25
SBIN_DIR=/usr/sbin
BIN_DIR=/usr/bin
LIB_DIR=/usr/lib
VAR_DIR=/var/ax25

echo -n "Your machine architecture is ... "
ARCH=`uname -m`
echo $ARCH

echo -n "Checking man directory... "
MAN_DIR=""
for mandir in /usr/share/man /usr/man
do
	if [ -d $mandir ]
	then
		echo $mandir
		MAN_DIR=$mandir
	fi
done

echo -n "Checking for the existence of the Zlib headers... "
ZLIB=""
HAVEZLIB="#undef"
for zlibdir in /usr/include /usr/local/include
do
	if [ -f $zlibdir/zlib.h ]
	then
		echo $zlibdir/zlib.h
		ZLIB="-lz"
		HAVEZLIB="#define"
	fi
done
if [ -z "$ZLIB" ]
then
	echo "not found."
	echo "            Without Zlib Node will lack compression support"
	echo "            See INSTALL for more information."
	echo
fi

# Global protocol definition symbols for programmers that want to conditionally
# compile
	HAVEAX25="#undef"
	HAVENETROM="#undef"
	HAVEROSE="#undef"

	echo -n "Include support for the AX.25 protocol ? [Y/n]: "; read answer
	if [ "$answer" = "Y" -o "$answer" = "y" -o "$answer" = "" ]
	then
		HAVEAX25="#define"
	fi
	#
	echo -n "Include support for the NetRom protocol ? [Y/n]: "; read answer
	if [ "$answer" = "Y" -o "$answer" = "y" -o "$answer" = "" ]
	then
		HAVEAX25="#define"
		HAVENETROM="#define"
	fi
	#
	echo -n "Include support for the Rose protocol ? [Y/n]: "; read answer
	if [ "$answer" = "Y" -o "$answer" = "y" -o "$answer" = "" ]
	then
		HAVEAX25="#define"
		HAVEROSE="#define"
	fi

echo "Creating Makefile.include"

sed -e "s~@ARCH@~$ARCH~g; \
	s~@ETC_DIR@~$ETC_DIR~g; \
	s~@LIB_DIR@~$LIB_DIR~g; \
	s~@SBIN_DIR@~$SBIN_DIR~g; \
	s~@BIN_DIR@~$BIN_DIR~g; \
	s~@VAR_DIR@~$VAR_DIR~g; \
	s~@MAN_DIR@~$MAN_DIR~g; \
	s~@ZLIB@~$ZLIB~g" <Makefile.include.in >Makefile.include

echo "Creating config.h"

sed -e "s~@ETC_DIR@~$ETC_DIR~g; \
	s~@LIB_DIR@~$LIB_DIR~g; \
	s~@SBIN_DIR@~$SBIN_DIR~g; \
	s~@BIN_DIR@~$BIN_DIR~g; \
	s~@VAR_DIR@~$VAR_DIR~g; \
	s~@MAN_DIR@~$MAN_DIR~g; \
	s~@HAVEAX25@~$HAVEAX25~g; \
	s~@HAVENETROM@~$HAVENETROM~g; \
	s~@HAVEROSE@~$HAVEROSE~g; \
	s~@HAVEZLIB@~$HAVEZLIB~g" <config.h.in >config.h

echo "Configuration successful"

exit 0

