blob: 5960a42555a12f860a3d0f296bba1464c3addbab [file] [log] [blame]
Jari Aaltod166f041997-06-05 14:59:13 +00001#! /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
Chet Ramey8868eda2020-12-06 15:51:17 -05008# Copyright (C) 1996-2020 Free Software Foundation, Inc.
Jari Aalto7117c2d2002-07-17 14:10:11 +00009#
Jari Aalto31859422009-01-12 13:36:28 +000010# 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 3 of the License, or
13# (at your option) any later version.
Jari Aalto7117c2d2002-07-17 14:10:11 +000014#
Jari Aalto31859422009-01-12 13:36:28 +000015# 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.
Jari Aalto7117c2d2002-07-17 14:10:11 +000019#
Jari Aalto31859422009-01-12 13:36:28 +000020# You should have received a copy of the GNU General Public License
21# along with this program. If not, see <http://www.gnu.org/licenses/>.
22#
Jari Aalto7117c2d2002-07-17 14:10:11 +000023
Jari Aaltod166f041997-06-05 14:59:13 +000024PROGNAME=`basename $0`
Jari Aaltof73dda02001-11-13 17:56:06 +000025USAGE="$PROGNAME [-b] [-S srcdir] -d version -p patchlevel [-s status] [-o outfile]"
26
27source_dir="."
Jari Aaltod166f041997-06-05 14:59:13 +000028
29while [ $# -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 ;;
Jari Aaltof73dda02001-11-13 17:56:06 +000036 -S) shift; source_dir="$1"; shift ;;
Jari Aaltod166f041997-06-05 14:59:13 +000037 *) echo "$PROGNAME: usage: $USAGE" >&2 ; exit 2 ;;
38 esac
39done
40
41# Required arguments
42if [ -z "$dist_version" ]; then
43 echo "${PROGNAME}: required argument -d missing" >&2
44 echo "$PROGNAME: usage: $USAGE" >&2
45 exit 1
46fi
47
Jari Aaltof73dda02001-11-13 17:56:06 +000048#if [ -z "$patch_level" ]; then
49# echo "${PROGNAME}: required argument -p missing" >&2
50# echo "$PROGNAME: usage: $USAGE" >&2
51# exit 1
52#fi
Jari Aaltod166f041997-06-05 14:59:13 +000053
54# Defaults
55if [ -z "$rel_status" ]; then
56 rel_status="release"
57fi
58
59build_ver=
60if [ -r .build ]; then
61 build_ver=`cat .build`
62fi
63if [ -z "$build_ver" ]; then
64 build_ver=0
65fi
66
67# increment the build version if that's what's required
68
69if [ -n "$inc_build" ]; then
Jari Aalto06285672006-10-10 14:15:34 +000070 build_ver=`expr 1 + $build_ver`
Jari Aaltod166f041997-06-05 14:59:13 +000071fi
72
Jari Aaltof73dda02001-11-13 17:56:06 +000073# what's the patch level?
74if [ -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
79fi
80if [ -z "$patch_level" ]; then
81 patch_level=0
82fi
83
Jari Aaltod166f041997-06-05 14:59:13 +000084# If we have an output file specified, make it the standard output
85if [ -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
92fi
93
94# Output the leading comment.
95echo "/* Version control for the shell. This file gets changed when you say"
96echo " \`make version.h' to the Makefile. It is created by mkversion. */"
97
Jari Aaltobb706242000-03-17 21:46:59 +000098# Output the distribution version. Single numbers are converted to x.00.
Jari Aalto95732b42005-12-07 14:08:12 +000099# Allow, as a special case, `[:digit:].[:digit:][:alpha:]' for
100# intermediate versions (e.g., `2.5a').
Jari Aaltobb706242000-03-17 21:46:59 +0000101# Any characters other than digits and `.' are invalid.
102case "$dist_version" in
Jari Aalto95732b42005-12-07 14:08:12 +0000103[0-9].[0-9][a-z]) ;; # special case
Jari Aaltobb706242000-03-17 21:46:59 +0000104*[!0-9.]*) echo "mkversion.sh: ${dist_version}: bad distribution version" >&2
105 exit 1 ;;
106*.*) ;;
107*) dist_version=${dist_version}.00 ;;
108esac
109
110dist_major=`echo $dist_version | sed 's:\..*$::'`
111[ -z "${dist_major}" ] && dist_major=0
112
113dist_minor=`echo $dist_version | sed 's:^.*\.::'`
114case "$dist_minor" in
Jari Aalto95732b42005-12-07 14:08:12 +0000115"") dist_minor=0 ;;
116[a-z]) dist_minor=0${dist_minor} ;;
117?) dist_minor=${dist_minor} ;;
Jari Aaltobb706242000-03-17 21:46:59 +0000118*) ;;
119esac
120
121#float_dist=`echo $dist_version | awk '{printf "%.2f\n", $1}'`
122float_dist=${dist_major}.${dist_minor}
Jari Aaltod166f041997-06-05 14:59:13 +0000123
124echo
125echo "/* The distribution version number of this shell. */"
126echo "#define DISTVERSION \"${float_dist}\""
127
128# Output the patch level
Jari Aaltof73dda02001-11-13 17:56:06 +0000129#echo
130#echo "/* The patch level of this version of the shell. */"
131#echo "#define PATCHLEVEL ${patch_level}"
Jari Aaltod166f041997-06-05 14:59:13 +0000132
133# Output the build version
134echo
135echo "/* The last built version of this shell. */"
136echo "#define BUILDVERSION ${build_ver}"
137
138# Output the release status
139echo
140echo "/* The release status of this shell. */"
141echo "#define RELSTATUS \"${rel_status}\""
142
Jari Aalto31859422009-01-12 13:36:28 +0000143echo
144echo "/* The default shell compatibility-level (the current version) */"
145echo "#define DEFAULT_COMPAT_LEVEL ${dist_major}${dist_minor}"
146
Jari Aaltod166f041997-06-05 14:59:13 +0000147# Output the SCCS version string
148sccs_string="${float_dist}.${patch_level}(${build_ver}) ${rel_status} GNU"
149echo
150echo "/* A version string for use by sccs and the what command. */"
151echo "#define SCCSVERSION \"@(#)Bash version ${sccs_string}\""
152
Jari Aaltof73dda02001-11-13 17:56:06 +0000153# extern function declarations
Jari Aaltob80f6442004-07-27 13:29:18 +0000154#echo
155#echo '/* Functions from version.c. */'
Chet Ramey8868eda2020-12-06 15:51:17 -0500156#echo 'extern char *shell_version_string PARAMS((void));'
157#echo 'extern void show_shell_version PARAMS((int));'
Jari Aaltof73dda02001-11-13 17:56:06 +0000158
Jari Aaltod166f041997-06-05 14:59:13 +0000159if [ -n "$inc_build" ]; then
160 # Make sure we can write to .build
161 if [ -f .build ] && [ ! -w .build ]; then
162 echo "$PROGNAME: cannot write to .build, not incrementing build version" >&2
163 else
164 echo "$build_ver" > .build
165 fi
166fi
167
168exit 0