#!/bin/sh
CFLAGS=""
if [ `uname` = Linux ]
then
  VERSION=`uname -r | cut -b1`
  CFLAGS=-DLINUX$VERSION
  for dir in /usr/local/lib /usr/lib
  do
    for lib in gz z
    do
      if [ -f $dir/lib$lib.a ]
      then
	if [ "$LFLAGS" = "" ]
	then
	  for hdr in /usr/local/include /usr/include
	  do
	    if [ -f $hdr/zlib.h ]
	    then
	      if [ "`grep -c '.*int.*compress2' $hdr/zlib.h`" != "0" ]
	      then
		CFLAGS="-I$dir -DCOMPRESS $CFLAGS"
		LFLAGS="-L$dir -l$lib"
	      else
		echo "Please upgrade your zlib package to at least 1.1.3"
		echo "You can find it at:"
		echo "http://www.cdrom.com/pub/infozip/zlib/"
		echo "Building vpnd with runtime compression disabled."
	      fi
	    fi
	  done
	fi
      fi
    done
  done
  if [ "$VERSION" = "2" ]
  then
    if [ -f /usr/include/linux/if_slip.h ]
    then
      if [ ! -f /usr/include/net/if_slip.h ]
      then
	CFLAGS="$CFLAGS -DLINSLIP"
      fi
    fi
  fi
  (
  echo '# uncomment the following line for debug code'
  echo '#DEBUG=-DDEBUG'
  if [ "$VERSION" = "1" ]
  then
    echo "ADDON=randomd"
  fi
  echo "CC=gcc"
  echo "LINK=gcc"
  echo "CFLAGS=$CFLAGS -Wall -O3 \$(DEBUG) -c"
  echo "LFLAGS=-s $LFLAGS"
  cat Makefile.in
  ) > Makefile
else
  echo "Operating system not (yet) supported. Please port!!!"
  exit 1
fi
