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 | # Copyright (C) 1996-2002 Free Software Foundation, Inc.
|
---|
9 | #
|
---|
10 | # This program is free software; you can redistribute it and/or modify
|
---|
11 | # it under the terms of the GNU General Public License as published by
|
---|
12 | # the Free Software Foundation; either version 2, or (at your option)
|
---|
13 | # any later version.
|
---|
14 | #
|
---|
15 | # This program is distributed in the hope that it will be useful,
|
---|
16 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
18 | # GNU General Public License for more details.
|
---|
19 | #
|
---|
20 | # You should have received a copy of the GNU General Public License
|
---|
21 | # along with this program; if not, write to the Free Software
|
---|
22 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
|
---|
23 |
|
---|
24 | PROGNAME=`basename $0`
|
---|
25 | USAGE="$PROGNAME [-b] [-S srcdir] -d version -p patchlevel [-s status] [-o outfile]"
|
---|
26 |
|
---|
27 | source_dir="."
|
---|
28 |
|
---|
29 | while [ $# -gt 0 ]; do
|
---|
30 | case "$1" in
|
---|
31 | -o) shift; OUTFILE=$1; shift ;;
|
---|
32 | -b) shift; inc_build=yes ;;
|
---|
33 | -s) shift; rel_status=$1; shift ;;
|
---|
34 | -p) shift; patch_level=$1; shift ;;
|
---|
35 | -d) shift; dist_version=$1; shift ;;
|
---|
36 | -S) shift; source_dir="$1"; shift ;;
|
---|
37 | *) echo "$PROGNAME: usage: $USAGE" >&2 ; exit 2 ;;
|
---|
38 | esac
|
---|
39 | done
|
---|
40 |
|
---|
41 | # Required arguments
|
---|
42 | if [ -z "$dist_version" ]; then
|
---|
43 | echo "${PROGNAME}: required argument -d missing" >&2
|
---|
44 | echo "$PROGNAME: usage: $USAGE" >&2
|
---|
45 | exit 1
|
---|
46 | fi
|
---|
47 |
|
---|
48 | #if [ -z "$patch_level" ]; then
|
---|
49 | # echo "${PROGNAME}: required argument -p missing" >&2
|
---|
50 | # echo "$PROGNAME: usage: $USAGE" >&2
|
---|
51 | # exit 1
|
---|
52 | #fi
|
---|
53 |
|
---|
54 | # Defaults
|
---|
55 | if [ -z "$rel_status" ]; then
|
---|
56 | rel_status="release"
|
---|
57 | fi
|
---|
58 |
|
---|
59 | build_ver=
|
---|
60 | if [ -r .build ]; then
|
---|
61 | build_ver=`cat .build`
|
---|
62 | fi
|
---|
63 | if [ -z "$build_ver" ]; then
|
---|
64 | build_ver=0
|
---|
65 | fi
|
---|
66 |
|
---|
67 | # increment the build version if that's what's required
|
---|
68 |
|
---|
69 | if [ -n "$inc_build" ]; then
|
---|
70 | build_ver=`expr $build_ver + 1`
|
---|
71 | fi
|
---|
72 |
|
---|
73 | # what's the patch level?
|
---|
74 | if [ -z "$patch_level" ]; then
|
---|
75 | patchlevel_h=$source_dir/patchlevel.h
|
---|
76 | if [ -s $patchlevel_h ]; then
|
---|
77 | patch_level=`cat $patchlevel_h | grep '^#define[ ]*PATCHLEVEL' | awk '{print $NF}'`
|
---|
78 | fi
|
---|
79 | fi
|
---|
80 | if [ -z "$patch_level" ]; then
|
---|
81 | patch_level=0
|
---|
82 | fi
|
---|
83 |
|
---|
84 | # If we have an output file specified, make it the standard output
|
---|
85 | if [ -n "$OUTFILE" ]; then
|
---|
86 | if exec >$OUTFILE; then
|
---|
87 | :
|
---|
88 | else
|
---|
89 | echo "${PROGNAME}: cannot redirect standard output to $OUTFILE" >&2
|
---|
90 | exit 1
|
---|
91 | fi
|
---|
92 | fi
|
---|
93 |
|
---|
94 | # Output the leading comment.
|
---|
95 | echo "/* Version control for the shell. This file gets changed when you say"
|
---|
96 | echo " \`make version.h' to the Makefile. It is created by mkversion. */"
|
---|
97 |
|
---|
98 | # Output the distribution version. Single numbers are converted to x.00.
|
---|
99 | # Allow, as a special case, `[:digit:].[:digit:][:alpha:]' for
|
---|
100 | # intermediate versions (e.g., `2.5a').
|
---|
101 | # Any characters other than digits and `.' are invalid.
|
---|
102 | case "$dist_version" in
|
---|
103 | [0-9].[0-9][a-z]) ;; # special case
|
---|
104 | *[!0-9.]*) echo "mkversion.sh: ${dist_version}: bad distribution version" >&2
|
---|
105 | exit 1 ;;
|
---|
106 | *.*) ;;
|
---|
107 | *) dist_version=${dist_version}.00 ;;
|
---|
108 | esac
|
---|
109 |
|
---|
110 | dist_major=`echo $dist_version | sed 's:\..*$::'`
|
---|
111 | [ -z "${dist_major}" ] && dist_major=0
|
---|
112 |
|
---|
113 | dist_minor=`echo $dist_version | sed 's:^.*\.::'`
|
---|
114 | case "$dist_minor" in
|
---|
115 | "") dist_minor=0 ;;
|
---|
116 | [a-z]) dist_minor=0${dist_minor} ;;
|
---|
117 | ?) dist_minor=${dist_minor} ;;
|
---|
118 | *) ;;
|
---|
119 | esac
|
---|
120 |
|
---|
121 | #float_dist=`echo $dist_version | awk '{printf "%.2f\n", $1}'`
|
---|
122 | float_dist=${dist_major}.${dist_minor}
|
---|
123 |
|
---|
124 | echo
|
---|
125 | echo "/* The distribution version number of this shell. */"
|
---|
126 | echo "#define DISTVERSION \"${float_dist}\""
|
---|
127 |
|
---|
128 | # Output the patch level
|
---|
129 | #echo
|
---|
130 | #echo "/* The patch level of this version of the shell. */"
|
---|
131 | #echo "#define PATCHLEVEL ${patch_level}"
|
---|
132 |
|
---|
133 | # Output the build version
|
---|
134 | echo
|
---|
135 | echo "/* The last built version of this shell. */"
|
---|
136 | echo "#define BUILDVERSION ${build_ver}"
|
---|
137 |
|
---|
138 | # Output the release status
|
---|
139 | echo
|
---|
140 | echo "/* The release status of this shell. */"
|
---|
141 | echo "#define RELSTATUS \"${rel_status}\""
|
---|
142 |
|
---|
143 | # Output the SCCS version string
|
---|
144 | sccs_string="${float_dist}.${patch_level}(${build_ver}) ${rel_status} GNU"
|
---|
145 | echo
|
---|
146 | echo "/* A version string for use by sccs and the what command. */"
|
---|
147 | echo "#define SCCSVERSION \"@(#)Bash version ${sccs_string}\""
|
---|
148 |
|
---|
149 | # extern function declarations
|
---|
150 | #echo
|
---|
151 | #echo '/* Functions from version.c. */'
|
---|
152 | #echo 'extern char *shell_version_string __P((void));'
|
---|
153 | #echo 'extern void show_shell_version __P((int));'
|
---|
154 |
|
---|
155 | if [ -n "$inc_build" ]; then
|
---|
156 | # Make sure we can write to .build
|
---|
157 | if [ -f .build ] && [ ! -w .build ]; then
|
---|
158 | echo "$PROGNAME: cannot write to .build, not incrementing build version" >&2
|
---|
159 | else
|
---|
160 | echo "$build_ver" > .build
|
---|
161 | fi
|
---|
162 | fi
|
---|
163 |
|
---|
164 | exit 0
|
---|