#!/bin/sh
# @(#) $Id: mkversion.sh,v 1.3 1992/07/11 12:09:47 tron Exp $

#    Copyright (C) 1987, 1988 Ronald S. Karr and Landon Curt Noll
#    Copyright (C) 1992  Ronald S. Karr
# 
# See the file COPYING, distributed with smail, for restriction
# and warranty information.

# Set up a shell, C-header and sed script file defining the current
# version and patch level for smail.
#
# The variable ROOT should be defined as a path to the root of the
# smail source directory.  This should be put in the environment before
# calling this shell script.

# Establish the root of the smail source directory
ROOT="`(cd "$ROOT"; pwd)`"

# Build the smail version number
echo "Read $ROOT/level ..." 1>&2

exec < "$ROOT/level"
read comment			# skip comment line
read VERSION dow month day time tz year
RELEASE_DATE="`echo $day-$month-$year |
	       tr '[A-Z]' '[a-z]' |
	       sed 's/..\(..\)$/\1/'`"

# Read the current patch number and patch date
echo "Read $ROOT/patchnum ..." 1>&2

. "$ROOT/patchnum"

# Build the shell version file
echo "Build version.sh ..." 1>&2

exec > "version.sh"

cat <<EOF
# DO NOT EDIT THIS FILE DIRECTLY, IT IS CREATED AUTOMATICALLY
# FROM THE SCRIPT $ROOT/conf/lib/mkversion.sh.  IF YOU MAKE
# CHANGES TO THIS FILE THEY ARE LIKELY TO GO AWAY.

# The current smail release from the file $ROOT/level
VERSION=$VERSION
RELEASE_DATE=$RELEASE_DATE

# Patch information from the file $ROOT/patchnum
PATCH_NUMBER=$PATCH_NUMBER
PATCH_DATE=$PATCH_DATE
EOF

# Build the C version file
echo "Build version.h ..." 1>&2

exec > "version.h"

cat <<EOF
/*
 * DO NOT EDIT THIS FILE DIRECTLY, IT IS CREATED AUTOMATICALLY
 * FROM THE SCRIPT $ROOT/conf/mkversion.sh.  IF YOU MAKE
 * CHANGES TO THIS FILE THEY ARE LIKELY TO GO AWAY.
 */

/* The current smail release from the file $ROOT/level */
#define VERSION "$VERSION"
#define RELEASE_DATE "$RELEASE_DATE"

/* Patch information, stored in $ROOT/patchnum */
#define PATCH_NUMBER "$PATCH_NUMBER"
#define PATCH_DATE "$PATCH_DATE"
EOF

# Build the sed version file
echo "Build version.sed ..." 1>&2

exec > "version.sed"

cat <<EOF
s|X_VERSION_X|$VERSION|g
s|X_RELEASE_DATE_X|$RELEASE_DATE|g
s|X_PATCH_NUMBER_X|$PATCH_NUMBER|g
s|X_PATCH_DATE_X|$PATCH_DATE|g
EOF

exit 0
