#!/bin/sh

if [ $0 != "./configure" ] ; then
	echo This script needs to be executed in the directory that
	echo contains this script.
	exit 1
fi

# Make sure we are running this script from the maradns base directory
if [ `pwd | awk -F/ '{print $NF}' | cut -f1 -d-` != "maradns" ] ; then
	echo This script needs to be run from the MaraDNS base
	echo directory \(the top-level directory created when the
	echo MaraDNS tar file was extracted\)
	exit 1
fi

# Set the directory for the build files
BUILDDIR=build
export BUILDDIR

# Show them the disclaimer
cat 00README.FIRST
echo -----
echo

# Try to determine what kind of system we are running
UNAME=`uname -s`

# Make sure the Makefile has the current version number of MaraDNS
# VERSION is a one line file in the form "VERSION=0.1.23" (without the
# quotes
if [ -f VERSION ] ; then
	cp VERSION Makefile
elif [ -f $BUILDDIR/VERSION ] ; then
	cp $BUILDDIR/VERSION Makefile
else
	pwd | awk -F- '{print "VERSION="$NF}' > Makefile
fi

# Set up the informaiton on where and when this version of MaraDNS was
# compiled
echo COMPILED=\"$UNAME system at `date`\" >> Makefile
echo COMPILED_DEBUG=\"$UNAME system at `date`\ \(Debug\)\" >> Makefile

# Give them a message dependent on what kind of systme they have
if echo $UNAME | grep -i linux > /dev/null ; then
	cat $BUILDDIR/Makefile.linux >> Makefile
	echo It looks like you are using Linux\; just type in \'make\'
elif echo $UNAME | grep -i sunos > /dev/null ; then
	cat $BUILDDIR/Makefile.solaris >> Makefile
	cp $BUILDDIR/install.solaris $BUILDDIR/install.locations
	echo It looks like you are using Solaris\; typing in \'make\'
	echo should work
	exit 0
elif echo $UNAME | grep -i darwin > /dev/null ; then
	cat $BUILDDIR/Makefile.darwin >> Makefile
	cp $BUILDDIR/install.darwin $BUILDDIR/install.locations
	echo It looks like you are using Darwin \(usually\; Mac OS X\)\;
	echo This should compile fine by typing in \'make\'.
	exit 0
elif echo $UNAME | grep -i freebsd > /dev/null ; then
	cat $BUILDDIR/Makefile.linux >> Makefile
	echo It looks like you are using FreeBSD\; this should compile
	echo fine by typing in \'make\'.  There is an official port here:
	echo
	echo	http://www.freebsd.org/cgi/query-pr.cgi?pr=28389
elif echo $UNAME | grep -i openbsd > /dev/null ; then
	cat $BUILDDIR/Makefile.linux >> Makefile
	echo It looks like you are using OpenBSD\; please read doc/faq.txt
	echo before trying to compile MaraDNS
elif echo $UNAME | grep -i cygwin > /dev/null ; then
	cat $BUILDDIR/Makefile.noflock >> Makefile
	echo It looks like you are using Cygwin\; this should compile file
	echo by typing in \'make\'.
else
	cat $BUILDDIR/Makefile.noflock >> Makefile
	echo I am not familiar with the OS you are running.  Please email
	echo Sam a copy of a working Makefile, and the output of 'uname -s'
	echo if you can get this to compile, install, and run.
	echo
	echo Note: If your OS does not have flock, define NO_FLOCK to 
	echo MaraDNS to compile w/o flock
fi

echo

