summaryrefslogtreecommitdiff
path: root/support/mkversion.sh
blob: 08a5d9812b6791503c9fd98e2827aa37cbc20066 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#! /bin/sh

# Simple program to make new version numbers for the shell.
# Big deal, but it was getting out of hand to do everything
# in the makefile.  This creates a file named by the -o option,
# otherwise everything is echoed to the standard output.

# Copyright (C) 1996-2002 Free Software Foundation, Inc.
#
#   This program is free software: you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation, either version 3 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

PROGNAME=`basename $0`
USAGE="$PROGNAME [-b] [-S srcdir] -d version -p patchlevel [-s status] [-o outfile]"

source_dir="."

while [ $# -gt 0 ]; do
	case "$1" in
	-o)	shift; OUTFILE=$1; shift ;;
	-b)	shift; inc_build=yes ;;
	-s)	shift; rel_status=$1; shift ;;
	-p)	shift; patch_level=$1; shift ;;
	-d)	shift; dist_version=$1; shift ;;
	-S)	shift; source_dir="$1"; shift ;;
	*)	echo "$PROGNAME: usage: $USAGE" >&2 ; exit 2 ;;
	esac
done

# Required arguments
if [ -z "$dist_version" ]; then
	echo "${PROGNAME}: required argument -d missing" >&2
	echo "$PROGNAME: usage: $USAGE" >&2
	exit 1
fi

#if [ -z "$patch_level" ]; then
#	echo "${PROGNAME}: required argument -p missing" >&2
#	echo "$PROGNAME: usage: $USAGE" >&2
#	exit 1
#fi

# Defaults
if [ -z "$rel_status" ]; then
	rel_status="release"
fi

build_ver=
if [ -r .build ]; then
	build_ver=`cat .build`
fi
if [ -z "$build_ver" ]; then
	build_ver=0
fi

# increment the build version if that's what's required

if [ -n "$inc_build" ]; then
	build_ver=`expr 1 + $build_ver`
fi

# what's the patch level?
if [ -z "$patch_level" ]; then
	patchlevel_h=$source_dir/patchlevel.h
	if [ -s $patchlevel_h ]; then
		patch_level=`cat $patchlevel_h | grep '^#define[ 	]*PATCHLEVEL' | awk '{print $NF}'`
	fi
fi
if [ -z "$patch_level" ]; then
	patch_level=0
fi

# If we have an output file specified, make it the standard output
if [ -n "$OUTFILE" ]; then
	if exec >$OUTFILE; then
		:
	else
		echo "${PROGNAME}: cannot redirect standard output to $OUTFILE" >&2
		exit 1
	fi
fi

# Output the leading comment.
echo "/* Version control for the shell.  This file gets changed when you say"
echo "   \`make version.h' to the Makefile.  It is created by mkversion. */"

# Output the distribution version.  Single numbers are converted to x.00.
# Allow, as a special case, `[:digit:].[:digit:][:alpha:]' for
# intermediate versions (e.g., `2.5a').
# Any characters other than digits and `.' are invalid.
case "$dist_version" in
[0-9].[0-9][a-z])	;;	# special case
*[!0-9.]*)	echo "mkversion.sh: ${dist_version}: bad distribution version" >&2
		exit 1 ;;
*.*)	;;
*)	dist_version=${dist_version}.00 ;;
esac

dist_major=`echo $dist_version | sed 's:\..*$::'`
[ -z "${dist_major}" ] && dist_major=0

dist_minor=`echo $dist_version | sed 's:^.*\.::'`
case "$dist_minor" in
"")	dist_minor=0 ;;
[a-z])	dist_minor=0${dist_minor} ;;
?)	dist_minor=${dist_minor} ;;
*)	;;
esac

#float_dist=`echo $dist_version | awk '{printf "%.2f\n", $1}'`
float_dist=${dist_major}.${dist_minor}

echo
echo "/* The distribution version number of this shell. */"
echo "#define DISTVERSION \"${float_dist}\""

# Output the patch level
#echo
#echo "/* The patch level of this version of the shell. */"
#echo "#define PATCHLEVEL ${patch_level}"

# Output the build version
echo
echo "/* The last built version of this shell. */"
echo "#define BUILDVERSION ${build_ver}"

# Output the release status
echo
echo "/* The release status of this shell. */"
echo "#define RELSTATUS \"${rel_status}\""

echo
echo "/* The default shell compatibility-level (the current version) */"
echo "#define DEFAULT_COMPAT_LEVEL ${dist_major}${dist_minor}"

# Output the SCCS version string
sccs_string="${float_dist}.${patch_level}(${build_ver}) ${rel_status} GNU"
echo
echo "/* A version string for use by sccs and the what command. */"
echo "#define SCCSVERSION \"@(#)Bash version ${sccs_string}\""

# extern function declarations
#echo
#echo '/* Functions from version.c. */'
#echo 'extern char *shell_version_string __P((void));'
#echo 'extern void show_shell_version __P((int));'

if [ -n "$inc_build" ]; then
	# Make sure we can write to .build
	if [ -f .build ] && [ ! -w .build ]; then
		echo "$PROGNAME: cannot write to .build, not incrementing build version" >&2
	else
		echo "$build_ver" > .build
	fi
fi
	
exit 0