#!/bin/sh
#
# $Id: create_version_file,v 2.2 1998/11/12 00:22:05 diego Exp $
#
# This file should only be run automatically by make, not directly by
# the user.
#
# This script is part of the SUIF version control system.  It takes
# three arguments:
#	* A flag (-l or -p) specifying whether we're creating a library or
#	  a program version file.
#
#	* The name of the C file to create.
#
#	* The name(s) of the library target (only used with -l).
#
prog=`basename $0`

if [ $# -lt 2 ] ; then
    echo "$prog: {-p|-l} file.c targets"
    exit 1
fi

if [ -d ${2} ] ; then
    echo "$prog: directory "${2}" exists; unable to create file" 1>&2
    exit 1
fi

if [ "$1" = "-p" ] ; then
    name="prog"
else
    if [ "$3" = "" ] ; then
	echo "$prog: Missing library name"
	exit 1
    fi
    name=`basename $3 .a`
fi

if [ -r stamp-version ] ; then
    prog_version=`cat stamp-version`
else
    prog_version="(unnumbered test version)"
fi

if [ -r ${SUIFHOME}/stamp-version ] ; then
    suif_system_version=`cat ${SUIFHOME}/stamp-version`
else
    suif_system_version="(unknown version)"
fi

rm -f ${2}
touch ${2}
echo "/* Generated automatically by the Odyssey makefiles. */" >> ${2}
echo >> ${2}
echo "char *"${name}"_ver_string = \""${prog_version}"\";" >> ${2}
echo "char *"${name}"_who_string = \"Compiled "`date`" by "`whoami`" on" \
     `hostname`"\";" >> ${2}
echo "char *"${name}"_suif_string = \""${suif_system_version}"\";" >> ${2}
