3 # Simple program to make new version numbers for the shell.
4 # Big deal, but it was getting out of hand to do everything
5 # in the makefile. This creates a file named by the -o option,
6 # otherwise everything is echoed to the standard output.
9 USAGE="$PROGNAME [-b] -d version -p patchlevel [-s status] [-o outfile]"
11 while [ $# -gt 0 ]; do
13 -o) shift; OUTFILE=$1; shift ;;
14 -b) shift; inc_build=yes ;;
15 -s) shift; rel_status=$1; shift ;;
16 -p) shift; patch_level=$1; shift ;;
17 -d) shift; dist_version=$1; shift ;;
18 *) echo "$PROGNAME: usage: $USAGE" >&2 ; exit 2 ;;
23 if [ -z "$dist_version" ]; then
24 echo "${PROGNAME}: required argument -d missing" >&2
25 echo "$PROGNAME: usage: $USAGE" >&2
29 if [ -z "$patch_level" ]; then
30 echo "${PROGNAME}: required argument -p missing" >&2
31 echo "$PROGNAME: usage: $USAGE" >&2
36 if [ -z "$rel_status" ]; then
41 if [ -r .build ]; then
42 build_ver=`cat .build`
44 if [ -z "$build_ver" ]; then
48 # increment the build version if that's what's required
50 if [ -n "$inc_build" ]; then
51 build_ver=`expr $build_ver + 1`
54 # If we have an output file specified, make it the standard output
55 if [ -n "$OUTFILE" ]; then
56 if exec >$OUTFILE; then
59 echo "${PROGNAME}: cannot redirect standard output to $OUTFILE" >&2
64 # Output the leading comment.
65 echo "/* Version control for the shell. This file gets changed when you say"
66 echo " \`make version.h' to the Makefile. It is created by mkversion. */"
68 # Output the distribution version. Single numbers are converted to x.00.
69 # Any characters other than digits and `.' are invalid.
70 case "$dist_version" in
71 *[!0-9.]*) echo "mkversion.sh: ${dist_version}: bad distribution version" >&2
74 *) dist_version=${dist_version}.00 ;;
77 dist_major=`echo $dist_version | sed 's:\..*$::'`
78 [ -z "${dist_major}" ] && dist_major=0
80 dist_minor=`echo $dist_version | sed 's:^.*\.::'`
83 ?) dist_minor=0${dist_minor} ;;
87 #float_dist=`echo $dist_version | awk '{printf "%.2f\n", $1}'`
88 float_dist=${dist_major}.${dist_minor}
91 echo "/* The distribution version number of this shell. */"
92 echo "#define DISTVERSION \"${float_dist}\""
94 # Output the patch level
96 echo "/* The patch level of this version of the shell. */"
97 echo "#define PATCHLEVEL ${patch_level}"
99 # Output the build version
101 echo "/* The last built version of this shell. */"
102 echo "#define BUILDVERSION ${build_ver}"
104 # Output the release status
106 echo "/* The release status of this shell. */"
107 echo "#define RELSTATUS \"${rel_status}\""
109 # Output the SCCS version string
110 sccs_string="${float_dist}.${patch_level}(${build_ver}) ${rel_status} GNU"
112 echo "/* A version string for use by sccs and the what command. */"
113 echo "#define SCCSVERSION \"@(#)Bash version ${sccs_string}\""
115 if [ -n "$inc_build" ]; then
116 # Make sure we can write to .build
117 if [ -f .build ] && [ ! -w .build ]; then
118 echo "$PROGNAME: cannot write to .build, not incrementing build version" >&2
120 echo "$build_ver" > .build