d641cf060cdb2331322e955cbeda6bf12e94845e
[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] [-S srcdir] -d version -p patchlevel [-s status] [-o outfile]"
10
11 source_dir="."
12
13 while [ $# -gt 0 ]; do
14         case "$1" in
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 ;;
22         esac
23 done
24
25 # Required arguments
26 if [ -z "$dist_version" ]; then
27         echo "${PROGNAME}: required argument -d missing" >&2
28         echo "$PROGNAME: usage: $USAGE" >&2
29         exit 1
30 fi
31
32 #if [ -z "$patch_level" ]; then
33 #       echo "${PROGNAME}: required argument -p missing" >&2
34 #       echo "$PROGNAME: usage: $USAGE" >&2
35 #       exit 1
36 #fi
37
38 # Defaults
39 if [ -z "$rel_status" ]; then
40         rel_status="release"
41 fi
42
43 build_ver=
44 if [ -r .build ]; then
45         build_ver=`cat .build`
46 fi
47 if [ -z "$build_ver" ]; then
48         build_ver=0
49 fi
50
51 # increment the build version if that's what's required
52
53 if [ -n "$inc_build" ]; then
54         build_ver=`expr $build_ver + 1`
55 fi
56
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}'`
62         fi
63 fi
64 if [ -z "$patch_level" ]; then
65         patch_level=0
66 fi
67
68 # If we have an output file specified, make it the standard output
69 if [ -n "$OUTFILE" ]; then
70         if exec >$OUTFILE; then
71                 :
72         else
73                 echo "${PROGNAME}: cannot redirect standard output to $OUTFILE" >&2
74                 exit 1
75         fi
76 fi
77
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. */"
81
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
89                 exit 1 ;;
90 *.*)    ;;
91 *)      dist_version=${dist_version}.00 ;;
92 esac
93
94 dist_major=`echo $dist_version | sed 's:\..*$::'`
95 [ -z "${dist_major}" ] && dist_major=0
96
97 dist_minor=`echo $dist_version | sed 's:^.*\.::'`
98 case "$dist_minor" in
99 "")     dist_minor=00 ;;
100 [a-z])  dist_minor=00${dist_minor} ;;
101 ?)      dist_minor=0${dist_minor} ;;
102 *)      ;;
103 esac
104
105 #float_dist=`echo $dist_version | awk '{printf "%.2f\n", $1}'`
106 float_dist=${dist_major}.${dist_minor}
107
108 echo
109 echo "/* The distribution version number of this shell. */"
110 echo "#define DISTVERSION \"${float_dist}\""
111
112 # Output the patch level
113 #echo
114 #echo "/* The patch level of this version of the shell. */"
115 #echo "#define PATCHLEVEL ${patch_level}"
116
117 # Output the build version
118 echo
119 echo "/* The last built version of this shell. */"
120 echo "#define BUILDVERSION ${build_ver}"
121
122 # Output the release status
123 echo
124 echo "/* The release status of this shell. */"
125 echo "#define RELSTATUS \"${rel_status}\""
126
127 # Output the SCCS version string
128 sccs_string="${float_dist}.${patch_level}(${build_ver}) ${rel_status} GNU"
129 echo
130 echo "/* A version string for use by sccs and the what command. */"
131 echo "#define SCCSVERSION \"@(#)Bash version ${sccs_string}\""
132
133 # extern function declarations
134 echo
135 echo '/* Functions from version.c. */'
136 echo 'extern char *shell_version_string __P((void));'
137 echo 'extern void show_shell_version __P((int));'
138
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
143         else
144                 echo "$build_ver" > .build
145         fi
146 fi
147         
148 exit 0