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] [-S srcdir] -d version -p patchlevel [-s status] [-o outfile]"
13 while [ $# -gt 0 ]; do
15 -o) shift; OUTFILE=$1; shift ;;
16 -b) shift; inc_build=yes ;;
17 -s) shift; rel_status=$1; shift ;;
18 -p) shift; patch_level=$1; shift ;;
19 -d) shift; dist_version=$1; shift ;;
20 -S) shift; source_dir="$1"; shift ;;
21 *) echo "$PROGNAME: usage: $USAGE" >&2 ; exit 2 ;;
26 if [ -z "$dist_version" ]; then
27 echo "${PROGNAME}: required argument -d missing" >&2
28 echo "$PROGNAME: usage: $USAGE" >&2
32 #if [ -z "$patch_level" ]; then
33 # echo "${PROGNAME}: required argument -p missing" >&2
34 # echo "$PROGNAME: usage: $USAGE" >&2
39 if [ -z "$rel_status" ]; then
44 if [ -r .build ]; then
45 build_ver=`cat .build`
47 if [ -z "$build_ver" ]; then
51 # increment the build version if that's what's required
53 if [ -n "$inc_build" ]; then
54 build_ver=`expr $build_ver + 1`
57 # what's the patch level?
58 if [ -z "$patch_level" ]; then
59 patchlevel_h=$source_dir/patchlevel.h
60 if [ -s $patchlevel_h ]; then
61 patch_level=`cat $patchlevel_h | grep '^#define[ ]*PATCHLEVEL' | awk '{print $NF}'`
64 if [ -z "$patch_level" ]; then
68 # If we have an output file specified, make it the standard output
69 if [ -n "$OUTFILE" ]; then
70 if exec >$OUTFILE; then
73 echo "${PROGNAME}: cannot redirect standard output to $OUTFILE" >&2
78 # Output the leading comment.
79 echo "/* Version control for the shell. This file gets changed when you say"
80 echo " \`make version.h' to the Makefile. It is created by mkversion. */"
82 # Output the distribution version. Single numbers are converted to x.00.
83 # Allow, as a special case, `[:digit:].[:digit:][:digit:][:alpha:]' for
84 # intermediate versions (e.g., `2.05a').
85 # Any characters other than digits and `.' are invalid.
86 case "$dist_version" in
87 [0-9].[0-9][0-9][a-z]) ;; # special case
88 *[!0-9.]*) echo "mkversion.sh: ${dist_version}: bad distribution version" >&2
91 *) dist_version=${dist_version}.00 ;;
94 dist_major=`echo $dist_version | sed 's:\..*$::'`
95 [ -z "${dist_major}" ] && dist_major=0
97 dist_minor=`echo $dist_version | sed 's:^.*\.::'`
100 [a-z]) dist_minor=00${dist_minor} ;;
101 ?) dist_minor=0${dist_minor} ;;
105 #float_dist=`echo $dist_version | awk '{printf "%.2f\n", $1}'`
106 float_dist=${dist_major}.${dist_minor}
109 echo "/* The distribution version number of this shell. */"
110 echo "#define DISTVERSION \"${float_dist}\""
112 # Output the patch level
114 #echo "/* The patch level of this version of the shell. */"
115 #echo "#define PATCHLEVEL ${patch_level}"
117 # Output the build version
119 echo "/* The last built version of this shell. */"
120 echo "#define BUILDVERSION ${build_ver}"
122 # Output the release status
124 echo "/* The release status of this shell. */"
125 echo "#define RELSTATUS \"${rel_status}\""
127 # Output the SCCS version string
128 sccs_string="${float_dist}.${patch_level}(${build_ver}) ${rel_status} GNU"
130 echo "/* A version string for use by sccs and the what command. */"
131 echo "#define SCCSVERSION \"@(#)Bash version ${sccs_string}\""
133 # extern function declarations
135 echo '/* Functions from version.c. */'
136 echo 'extern char *shell_version_string __P((void));'
137 echo 'extern void show_shell_version __P((int));'
139 if [ -n "$inc_build" ]; then
140 # Make sure we can write to .build
141 if [ -f .build ] && [ ! -w .build ]; then
142 echo "$PROGNAME: cannot write to .build, not incrementing build version" >&2
144 echo "$build_ver" > .build