#!/bin/sh
#
# $Header: /home/richard/myntp/chrony/chrony-1.0/RCS/configure,v 1.9 1998/05/20 06:10:46 richard Exp $
#
# =======================================================================
#
# chronyd/chronyc - Programs for keeping computer clocks accurate.
#
# Copyright (C) 1997-1998 Richard P. Curnow <richard@curnow.demon.co.uk>
# All rights reserved.
#
# For conditions of use, refer to the file LICENCE.
#
# =======================================================================



# This configure script determines the operating system type and version

SYSTEM=`uname -s`
VERSION=`uname -r`
EXTRA_LIBS=""
EXTRA_CLI_LIBS=""
EXTRA_OBJECTS=""
INSTALL_PREFIX=/usr/local

for option
do
    case "$option" in
    --prefix=* | --install_prefix=* )
	INSTALL_PREFIX=`echo $option | sed -e 's/[^=]*=//;'`
    ;;
    * )
    echo "Unrecognized option : " $option
    esac
done

case $SYSTEM in
    SunOS )
	case $VERSION in
	    4.* )
		echo "#define SUNOS " `echo $VERSION | awk -F. '{printf("%1d%1d%1d",$1,$2,$3);}'` > options.h
		EXTRA_OBJECTS="sys_sunos.o strerror.o"
		EXTRA_LIBS="-lkvm"
		echo "Configuring for SunOS $VERSION"
		;;
	    5.* )
		echo "#define SOLARIS " `echo $VERSION | awk -F. '{printf("%1d%1d",$1,$2);}'` > options.h
		EXTRA_OBJECTS="sys_solaris.o"
		EXTRA_LIBS="-lsocket -lnsl -lkvm -lelf"
		EXTRA_CLI_LIBS="-lsocket -lnsl"
		echo "Configuring for Solaris (SunOS version $VERSION)"
		;;
	esac
    ;;
    Linux )
        echo "#define LINUX " > options.h
	EXTRA_OBJECTS="sys_linux.o rtc_linux.o"
	echo "Configuring for Linux"
    ;;
    * )
	echo "Sorry, I don't know how to build this software on your system."
	exit 1
    ;;
esac

sed -e "s%@EXTRA_OBJECTS@%${EXTRA_OBJECTS}%;\
	s%@EXTRA_LIBS@%${EXTRA_LIBS}%;\
	s%@EXTRA_CLI_LIBS@%${EXTRA_CLI_LIBS}%;\
	s%@INSTALL_PREFIX@%${INSTALL_PREFIX}%;"\
	< Makefile.in > Makefile
