Imported from ../bash-2.01.tar.gz.
[platform/upstream/bash.git] / support / mkversion.sh
1 #! /bin/sh
2
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.
7
8 PROGNAME=`basename $0`
9 USAGE="$PROGNAME [-b] -d version -p patchlevel [-s status]"
10
11 while [ $# -gt 0 ]; do
12         case "$1" in
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 ;;
19         esac
20 done
21
22 # Required arguments
23 if [ -z "$dist_version" ]; then
24         echo "${PROGNAME}: required argument -d missing" >&2
25         echo "$PROGNAME: usage: $USAGE" >&2
26         exit 1
27 fi
28
29 if [ -z "$patch_level" ]; then
30         echo "${PROGNAME}: required argument -p missing" >&2
31         echo "$PROGNAME: usage: $USAGE" >&2
32         exit 1
33 fi
34
35 # Defaults
36 if [ -z "$rel_status" ]; then
37         rel_status="release"
38 fi
39
40 build_ver=
41 if [ -r .build ]; then
42         build_ver=`cat .build`
43 fi
44 if [ -z "$build_ver" ]; then
45         build_ver=0
46 fi
47
48 # increment the build version if that's what's required
49
50 if [ -n "$inc_build" ]; then
51         build_ver=`expr $build_ver + 1`
52 fi
53
54 # If we have an output file specified, make it the standard output
55 if [ -n "$OUTFILE" ]; then
56         if exec >$OUTFILE; then
57                 :
58         else
59                 echo "${PROGNAME}: cannot redirect standard output to $OUTFILE" >&2
60                 exit 1
61         fi
62 fi
63
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. */"
67
68 # Output the distribution version
69 float_dist=`echo $dist_version | awk '{printf "%.2f\n", $1}'`
70
71 echo
72 echo "/* The distribution version number of this shell. */"
73 echo "#define DISTVERSION \"${float_dist}\""
74
75 # Output the patch level
76 echo
77 echo "/* The patch level of this version of the shell. */"
78 echo "#define PATCHLEVEL ${patch_level}"
79
80 # Output the build version
81 echo
82 echo "/* The last built version of this shell. */"
83 echo "#define BUILDVERSION ${build_ver}"
84
85 # Output the release status
86 echo
87 echo "/* The release status of this shell. */"
88 echo "#define RELSTATUS \"${rel_status}\""
89
90 # Output the SCCS version string
91 sccs_string="${float_dist}.${patch_level}(${build_ver}) ${rel_status} GNU"
92 echo
93 echo "/* A version string for use by sccs and the what command. */"
94 echo "#define SCCSVERSION \"@(#)Bash version ${sccs_string}\""
95
96 if [ -n "$inc_build" ]; then
97         # Make sure we can write to .build
98         if [ -f .build ] && [ ! -w .build ]; then
99                 echo "$PROGNAME: cannot write to .build, not incrementing build version" >&2
100         else
101                 echo "$build_ver" > .build
102         fi
103 fi
104         
105 exit 0