#!/bin/sh
#
# Configure script for pvmsync
# $Id: configure,v 1.2.4.41 2000/03/16 17:12:27 ajp Exp $
#
# Copyright (C) 1999, 2000 Andrew J. Pitman
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#

#
# Revision (version) 1, release 1
export REV="1"; export REL="2"; export PAT="4"
export SUBDIRS="include lib tools man"

# Set PATH
export PATH="$PATH:/bin:/usr/bin"

#
# pvmsync is Linux-specific
if [ "`uname -s`" != "Linux" -o "$OSTYPE" != "linux" ]; then
  echo "ERROR: Linux only for this release";
  exit 1
fi

#
# We need UNIX 98 rwlocks and POSIX semaphores
if [ "`uname -r | awk -F. '{print $2}'`" != 2 ]; then
  echo "ERROR: Linux 2.2 required";
  exit 1
fi

#
# We need gcc (version 2)
if [ `which gcc` != "" ]; then
  echo "Have gcc... good";
  if [ "`gcc -v 2>&1 | grep 'version' | awk '{print $3}' | \
	awk -F. '{print $1}'`" != 2 ]; then
	  echo "WARNING: gcc should be version 2";
  else
	  echo "gcc is version 2";
  fi
else
  echo "ERROR: No gcc in $PATH";
  exit 1
fi

#
# Command line options
while [ $# -ge 1 ]; do
  case $1 in

    --log-syslog)
        export LOG_SYSLOG="-D__LOG_SYSLOG" ;;

    --rundir=*)
        export RUNDIR="`echo $1 | sed 's/--rundir=//'`" ;;

    *)
        echo "Usage: $0 [--help] [--log-syslog] [--rundir=<rundir>]";
        exit 1 ;;

  esac
  shift
done

echo "Configuring pvmsync $REV.$REL.$PAT"

export DIRLEV=1

#
# Create config.h from config.h.in
echo "Creating config.h"
if [ "$RUNDIR" = "" ]; then
  export RUNDIR="/var/run/pvmsync";
fi
export BUILD_DATE="`date | awk '{print $2,$3,$4,$6}'`"
sed "s%^/\*--rundir--\*/%#define rundir     \"$RUNDIR\"%g; \
        s%^/\*--build_date--\*/%#define BUILD_DATE \"$BUILD_DATE\"%" \
        config.h.in >config.h ; echo "done."

#
# Create Makefiles from Makefile.in
echo "Creating Makefile"
sed "s/^LOG_SYSLOG=/LOG_SYSLOG=$LOG_SYSLOG/; \
        s%^RUN_DIR=%RUN_DIR=             $RUNDIR%" Makefile.in \
	>Makefile ; echo "done."

export DIRLEV=2
echo "Creating level $DIRLEV Makefiles....";
for dir in $SUBDIRS; \
	do sh -c "echo 'creating $dir/Makefile'; cd $dir ; \
           cp -f Makefile.in Makefile" ; done
echo "done."

