c6682924117c8578de99392bafdec508f1f27b68
[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] [-o outfile]"
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.  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
72                 exit 1 ;;
73 *.*)    ;;
74 *)      dist_version=${dist_version}.00 ;;
75 esac
76
77 dist_major=`echo $dist_version | sed 's:\..*$::'`
78 [ -z "${dist_major}" ] && dist_major=0
79
80 dist_minor=`echo $dist_version | sed 's:^.*\.::'`
81 case "$dist_minor" in
82 "")     dist_minor=00 ;;
83 ?)      dist_minor=0${dist_minor} ;;
84 *)      ;;
85 esac
86
87 #float_dist=`echo $dist_version | awk '{printf "%.2f\n", $1}'`
88 float_dist=${dist_major}.${dist_minor}
89
90 echo
91 echo "/* The distribution version number of this shell. */"
92 echo "#define DISTVERSION \"${float_dist}\""
93
94 # Output the patch level
95 echo
96 echo "/* The patch level of this version of the shell. */"
97 echo "#define PATCHLEVEL ${patch_level}"
98
99 # Output the build version
100 echo
101 echo "/* The last built version of this shell. */"
102 echo "#define BUILDVERSION ${build_ver}"
103
104 # Output the release status
105 echo
106 echo "/* The release status of this shell. */"
107 echo "#define RELSTATUS \"${rel_status}\""
108
109 # Output the SCCS version string
110 sccs_string="${float_dist}.${patch_level}(${build_ver}) ${rel_status} GNU"
111 echo
112 echo "/* A version string for use by sccs and the what command. */"
113 echo "#define SCCSVERSION \"@(#)Bash version ${sccs_string}\""
114
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
119         else
120                 echo "$build_ver" > .build
121         fi
122 fi
123         
124 exit 0