#!/bin/sh
#
# File:         genmake
#
# Author:       Ulli Horlacher (framstag@rus.uni-stuttgart.de)
#
# History:      18 Sep 95   Framstag      initial version
#
# Shell script to generate the real Makefile and start make.
#
# This file is covered by the GNU General Public License
#

SYSTEM=""

if [ -x /usr/bin/uname ];	then SYSTEM=`/usr/bin/uname`; fi
if [ -x /bin/uname ];		then SYSTEM=`/bin/uname`; fi
if [ -d /usr/apollo/bin ];	then SYSTEM=`ver sys5.3 /bin/uname`; fi
if [ -d /usr/bin/ncrm ];	then SYSTEM=NCR; fi
if [ -f /usr/bin/swconfig ];	then SYSTEM=SCO; fi

if [ "$SYSTEM" = "" ]; then
  if [ -d /NextApps ]; then
#   hostinfo | grep I386 >/dev/null
#   if [ $? = 0 ]; then
#     SYSTEM=NEXT386
#   else
#     SYSTEM=NEXT
#   fi
    SYSTEM=NEXT
  fi
fi

if [ "$SYSTEM" = "SunOS" ]; then
  case `uname -a | awk '{print $3}'` in
    4*) SYSTEM=SOLARIS1;;
    5*) SYSTEM=SOLARIS2;;
  esac
fi

SYSTEM=`echo $SYSTEM | tr [a-z] [A-Z]`

case "$SYSTEM" in
  *BSD*)	SYSTEM=BSD;;
  A/UX)		SYSTEM=AUX;;
  *OSF/1*)	SYSTEM=OSF1;;
  HP-UX)	SYSTEM=HPUX;;
  SMP_DC.SO*)	SYSTEM=PYRAMID;;
esac

rm -f Makefile
exec >Makefile
cat <<EOD
# Makefile automaticly generated by genmake. 
# DO NOT TOUCH THIS FILE! 
# Instead edit makefile.template 

EOD

case "$SYSTEM" in
  IRIX*)	echo "CC=gcc -Wall -D$SYSTEM";;
  NEXT)		echo "CC=cc  -Wall -posix -O -DNEXT";;
  HPUX)		echo "CC=gcc -Wall -O2 -DHPUX";;
  *)		echo "CC=gcc -Wall -ansi -O2 -D$SYSTEM";;
esac

case "$SYSTEM" in
  SOLARIS*)	echo "LINK=gcc -lsocket -lnsl";;
  NEXT)		echo "LINK=cc";;
  *)		echo "LINK=gcc";;
esac

awk '/^#===/{exit}END{while(getline)print}' makefile.template

cat <<EOD


make:	
	genmake; make
EOD
