#! /bin/sh
PROGNAME=`basename $0`
USAGE="$PROGNAME [-b] [-S srcdir] -d version -p patchlevel [-s status] [-o outfile]"
source_dir="."
while [ $ case "$1" in
-o) shift; OUTFILE=$1; shift ;;
-b) shift; inc_build=yes ;;
-s) shift; rel_status=$1; shift ;;
-p) shift; patch_level=$1; shift ;;
-d) shift; dist_version=$1; shift ;;
-S) shift; source_dir="$1"; shift ;;
*) echo "$PROGNAME: usage: $USAGE" >&2 ; exit 2 ;;
esac
done
if [ -z "$dist_version" ]; then
echo "${PROGNAME}: required argument -d missing" >&2
echo "$PROGNAME: usage: $USAGE" >&2
exit 1
fi
if [ -z "$rel_status" ]; then
rel_status="release"
fi
build_ver=
if [ -r .build ]; then
build_ver=`cat .build`
fi
if [ -z "$build_ver" ]; then
build_ver=0
fi
if [ -n "$inc_build" ]; then
build_ver=`expr 1 + $build_ver`
fi
if [ -z "$patch_level" ]; then
patchlevel_h=$source_dir/patchlevel.h
if [ -s $patchlevel_h ]; then
patch_level=`cat $patchlevel_h | grep '^ fi
fi
if [ -z "$patch_level" ]; then
patch_level=0
fi
if [ -n "$OUTFILE" ]; then
if exec >$OUTFILE; then
:
else
echo "${PROGNAME}: cannot redirect standard output to $OUTFILE" >&2
exit 1
fi
fi
echo "/* Version control for the shell. This file gets changed when you say"
echo " \`make version.h' to the Makefile. It is created by mkversion. */"
case "$dist_version" in
[0-9].[0-9][a-z]) ;; *[!0-9.]*) echo "mkversion.sh: ${dist_version}: bad distribution version" >&2
exit 1 ;;
*.*) ;;
*) dist_version=${dist_version}.00 ;;
esac
dist_major=`echo $dist_version | sed 's:\..*$::'`
[ -z "${dist_major}" ] && dist_major=0
dist_minor=`echo $dist_version | sed 's:^.*\.::'`
case "$dist_minor" in
"") dist_minor=0 ;;
[a-z]) dist_minor=0${dist_minor} ;;
?) dist_minor=${dist_minor} ;;
*) ;;
esac
float_dist=${dist_major}.${dist_minor}
echo
echo "/* The distribution version number of this shell. */"
echo "#define DISTVERSION \"${float_dist}\""
echo
echo "/* The last built version of this shell. */"
echo "#define BUILDVERSION ${build_ver}"
echo
echo "/* The release status of this shell. */"
echo "#define RELSTATUS \"${rel_status}\""
sccs_string="${float_dist}.${patch_level}(${build_ver}) ${rel_status} GNU"
echo
echo "/* A version string for use by sccs and the what command. */"
echo "#define SCCSVERSION \"@(#)Bash version ${sccs_string}\""
if [ -n "$inc_build" ]; then
if [ -f .build ] && [ ! -w .build ]; then
echo "$PROGNAME: cannot write to .build, not incrementing build version" >&2
else
echo "$build_ver" > .build
fi
fi
exit 0