view setup @ 1:4d6502ffaa5e

Initial revision
author darius
date Sat, 06 Dec 1997 04:36:59 +0000
parents
children
line wrap: on
line source

#!/bin/sh
#
# NETREK II -- Paradise server setup script
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for any NON-COMMERCIAL purpose
# (read the files 'src/copyright*.h')) and without 
# fee is hereby granted, provided that this copyright notice appear in all 
# copies.  No representations are made about the suitability of this 
# software for any purpose.  This software is provided "as is" without 
# express or implied warranty.
# 
#    Xtrek Copyright 1986                            Chris Guthrie
#    Netrek (Xtrek II) Copyright 1989                Kevin P. Smith
#                                                    Scott Silvey
#    Paradise (Netrek II) Copyright 1993             Larry Denys
#                                                    Kurt Olsen
#                                                    Brandon Gillespie
#                                                    Rob Forsman
#
#    Comprehensive Credits available in the file docs/CREDITS
#
# Note: this is just a quick hack I made, we can probably improve it later
#  -Brandon

trap "rm -f test.c a.out core $0.tmp; exit" 2 3

t="     "
i="- "

echo "-- Netrek II (Paradise) --

${t}Setup script for the Netrek II (Paradise) Server.

${t}To rebuild the Makefile using previous options (in the instance that
${t}Makefile.in was changed), use the \"-p\" (previous) flag, \"make
${t}makefile\" will also execute \"setup -p\".
"

# figure out what to do with echo -- from perl's Configure
# This blows chunks on Linux; fixed line from echotmp to $0.tmp.

(echo "hi there \c" ; echo " ") > $0.tmp
if grep c $0.tmp >/dev/null 2>&1 ; then
        echo "${i}Supressing newlines with -n..."
        n='-n'
        c=''
else
        echo "${i}Supressing newlines with \\\c..."
        n=''
        c='\c'
fi

echo ''
echo $n "${i}The asterisk should be here => $c"
echo '*'
echo ''

if [ X$1 != X -a X$1 = X"-p" ]; then
	echo "${i}Reading previous setup configuration..."
	if [ ! -f etc/$0.conf ]; then
                echo 
		echo "${t}previous configuration file (etc/$0.conf) not found!"
		exit 1
	fi
else

###########################################################################
# Global vars
LIBS="-lm"

###########################################################################
SYS=`(/bin/uname || /usr/bin/uname) 2>/dev/null`

case $SYS in
SunOS)
        # check for Solaris the hard way
	if [ "`/bin/uname -rs | cut -c0-9`" != "SunOS 4.1" ]; then
		SYS="SOLARIS"
		CCOPTIONS="-DSYSV -DSVR4 ${CCOPTIONS}"
		LIBS="-lnsl -lsocket ${LIBS}"
	fi
	;;
HP-UX)
	CCOPTIONS="-Ae -DSYSV ${CCOPTIONS}"
	;;
IRIX)
	CCOPTIONS="-mips2 -DSYSV -DSVR4 -DBAD_SVR4_HACKS ${CCOPTIONS}"
	LIBS="-lsun ${LIBS}"
	;;
OSF1)
	CCOPTIONS="-DSYSV ${CCOPTIONS}"
	;;
*)
	# this is a hack because Unixware returns odd things with /bin/uname
	echo $n "Are you running Unixware? [yn] (default: n) $c"
	read ANSWER
	if [ X$ANSWER = X"y" ]; then
		SYS="UNIXWARE"
		CCOPTIONS="-DSYSV -DSVR4 -DBAD_SVR4_HACKS ${CCOPTIONS}"
		LIBS="-lnsl -lsocket -lresolv ${LIBS}"
	fi
	;;
esac

echo ""
echo "${i}Looks like you are running ${SYS}..."
# Should probably check for RAND48, will add later if anybody complains
CCOPTIONS="-D${SYS} -DHAVE_RAND48 ${CCOPTIONS}"


############################################################################
## compiler
echo ""
echo $n "${i}Checking for cc or gcc...$c"

cat > test.c <<EOF
int main() { exit(0); }
EOF
err=`eval "(gcc test.c >/dev/null) 2>&1"`
rm -f test.c a.out

if [ X"$err" != X ]; then
	echo "using cc"
	CC=cc
else
	echo "using gcc"
	CC=gcc
fi

echo $n "
	1 -- Basic optimization (-O -s)
	2 -- Full optimization (-O2 -s)
	3 -- Debug, no optimization (-g)

Specify optimization/debug state. [123] (default: 1) $c"

read DEBUG

if [ X${DEBUG} = X ]; then
	DEBUG="1"
fi

if [ ${DEBUG} = "1" ]; then
	DEBUG="Basic optimization."
	CDEBUGFLAGS="-O -s"
elif [ ${DEBUG} = "2" ]; then
	DEBUG="Full optimization."
	CDEBUGFLAGS="-O2 -s"
elif [ ${DEBUG} = "3" ]; then
	while [ "${DEBUG}" = "3" ]; do
		echo $n "
	gdb     -- GNU Debugger
	dbx     -- source level debugger
	none    -- no debugger
	<other> -- other debugger

Use which debugger? (default: none) $c"
		read DEBUGGER
		if [ X${DEBUGGER} = X ]; then
			DEBUGGER="none"
		fi

		if [ ${DEBUGGER} = "none" ]; then
			DEBUG="Debug (No debugger), no optimization"
			CDEBUGFLAGS="-g"
		elif [ ${DEBUGGER} = "gdb" ]; then
			DEBUG="Debug (GNU debugger), no optimization"
			CDEBUGFLAGS="-ggdb"
		elif [ ${DEBUGGER} = "dbx" ]; then
			DEBUG="Debug, no optimization"
			CDEBUGFLAGS="-gdbx"
		else
			echo $n "${t}\"${DEBUGGER}\" is an unknown debugger, use anyway? [yn] (default: y) $c"
			read ANSWER
			if [ X${ANSWER} = X"y" ]; then
				DEBUG="Debug (Other: ${DEBUGGER}), no optimization"
				CDEBUGFLAGS="-g${DEBUGGER}"
			fi
		fi
	done
else
	echo "$0: unknown option \"${DEBUG}\", exiting."
	exit 1
fi

#########################################################################

if [ -f "rsa/Makefile" ]; then
	echo $n "
	You seem to have the RSA files.  RSA verification is NOT required
	for the server to function, and is usually enabled only on high
	profile public servers.

Do you wish to enable RSA verification? [yn] (default: n) $c"

	read ANSWER
	if [ X${ANSWER} = X"y" ]; then
		RSA="-DAUTHORIZE"
		AUTHOBJS="rsa-server.o rsa_util.o reserved.o"
	else
		RSA=""
		AUTHOBJS=""
	fi
else
	echo "
	RSA files do not exist, RSA verification is not enabled (RSA
	verification is not required for the server to run, and is
	usually only enabled on high profile public servers)."
fi

###########################################################################
echo ""
echo $n "${i}Does the mp library exist...$c"

cat > test.c <<EOF
int main() { exit(0); }
int t() { main(); }
EOF

err=`eval "($CC test.c -lmp >/dev/null) 2>&1"`
rm -f test.c a.out

if [ -z "$err" ]; then
	echo "yes."
	LIBS="-lmp ${LIBS}"
	if [ ! -z "$RSA" ]; then
		echo ""
		echo "${i}Using appropriate mp RSA files."
		echo ""
		AUTHOBJS="rsa-server.o rsa_utilmp.o reserved.o"
	fi
else
	echo "no."
fi

###########################################################################
# strdup()

echo $n "${i}Does strdup() exist...$c"

cat > test.c <<EOF
#include <string.h>
main () { char *str, *str2 = "test\n"; str = strdup(str2); }
EOF

err=`eval "($CC test.c >/dev/null) 2>&1"`
if [ ! -z "$err" ]; then
	CCOPTIONS="${CCOPTIONS} -DNO_STRDUP "
	echo "no."
else
	echo "yes."
fi

rm -f test.c a.out

##########################################################################
# qsort()

echo $n "${i}Does qsort() exist...$c"

cat > test.c <<EOF
#include <string.h>
main () { qsort(); }
EOF

err=`eval "($CC test.c >/dev/null) 2>&1"`
rm -f test.c a.out

if [ ! -z "$err" ]; then
	CCOPTIONS="${CCOPTIONS} -DNO_QSORT"
	echo "no."
else
	echo "yes."
fi

##########################################################################

# This is inefficient to do it seperately for each option, but it is
# the cleanest way.

echo "sed \"s:^#@@LIBS@:LIBS=${LIBS}:g\" src/Makefile.in > /tmp/a\$\$.setup" > etc/$0.conf
echo "sed \"s:^#@@CC@:CC=${CC}:g\" /tmp/a\$\$.setup > /tmp/\$\$.setup" >> etc/$0.conf
echo "sed \"s:^#@@CDEBUGFLAGS@:CDEBUGFLAGS=${CDEBUGFLAGS}:g\" /tmp/\$\$.setup > /tmp/a\$\$.setup" >> etc/$0.conf
echo "sed \"s:^#@@RSA@:RSA=${RSA}:g\" /tmp/a\$\$.setup > /tmp/\$\$.setup" >> etc/$0.conf
echo "sed \"s:^#@@AUTHOBJS@:AUTHOBJS=${AUTHOBJS}:g\" /tmp/\$\$.setup > /tmp/a\$\$.setup" >> etc/$0.conf
echo "sed \"s:^#@@CCOPTIONS@:CCOPTIONS=${CCOPTIONS}:g\" /tmp/a\$\$.setup > /tmp/\$\$.setup" >> etc/$0.conf
echo "echo \$\$" >> etc/$0.conf

# This 'fi' is from the first if (checking "-d")
fi

echo ""
echo $n "${i}Generating \"src/Makefile\" from \"src/Makefile.in\"...$c"

SPID=`sh etc/$0.conf`

echo "# This file generated by \"$0\" on `date`." > /tmp/${SPID}.Makefile
echo "# Make changes to \"Makefile.in\" and run the setup script" >> /tmp/${SPID}.Makefile
echo "#" >> /tmp/${SPID}.Makefile

cat /tmp/${SPID}.Makefile > src/Makefile
cat /tmp/${SPID}.setup >> src/Makefile

rm -f /tmp/${SPID}.setup
rm -f /tmp/a${SPID}.setup
rm -f /tmp/${SPID}.Makefile

echo "Done."
echo ""
echo "	use 'make <option>' to compile the server."
echo ""
echo "	To change the server game configuration check the file \"src/config.h\"."
echo ""

exit