]> git.sur5r.net Git - openocd/blob - tools/release/version.sh
Change checkpatch.pl tab expanding to 4 characters.
[openocd] / tools / release / version.sh
1 #!/bin/bash
2 # version.sh: openocd version process automation
3 # Copyright (C) 2009 by Zachary T Welch <zw@superlucidity.net>
4 # Release under the GNU GPL v2 (or later versions).
5
6 # FIXME Remove more bash-isms.  Fix errors making "ash -e" lose.
7
8 # NOTE Use with care!  "RC" should only follow x.x.x, with
9 # vendor tags after that.  Be traditional; avoid "rc0".
10
11 # NOTE:  This *ONLY* updates the "configure.in" version tag.
12 # It does not affect GIT tags.  Use this script immediately
13 # before making a release, to remove the "-dev" tag and to
14 # update the version label.  Then commit the change and tag
15 # that commit to match the version label.
16
17 . "tools/release/helpers.sh"
18
19 do_version_usage() {
20         cat << USAGE
21 usage: $0 <command>
22 Version Commands:
23   tag {add|remove} <label>     Add or remove the specified tag.
24   bump {major|minor|micro|rc}  Bump the specified version number, and
25                                reset less-significant numbers to zero.
26   bump tag <label>             Add or bump a versioned tag (e.g. -rcN).
27   bump final <label>           Remove a versioned tag (e.g. -rcN).
28 USAGE
29 # REVISIT ... "commit" not listed.
30 }
31
32 do_version_sed() {
33         local OLD_VERSION="${PACKAGE_VERSION}"
34         local NEW_VERSION="$1"
35         local MSG="$2"
36
37         sed -i -e "/AC_INIT/ s|${OLD_VERSION}|${NEW_VERSION}|" configure.in
38         package_info_load
39         echo "${MSG}: ${OLD_VERSION} -> ${NEW_VERSION}"
40 }
41 do_version_bump_sed() {
42         local NEW_VERSION="$1"
43         [ -z "${PACKAGE_VERSION_TAGS}" ] || \
44                 NEW_VERSION="${NEW_VERSION}${PACKAGE_VERSION_TAGS}"
45
46         do_version_sed "${NEW_VERSION}" \
47                 "Bump ${CMD} package version number"
48 }
49 do_version_bump_major() {
50         do_version_bump_sed "$((PACKAGE_MAJOR + 1)).0.0"
51 }
52 do_version_bump_minor() {
53         do_version_bump_sed "${PACKAGE_MAJOR}.$((PACKAGE_MINOR + 1)).0"
54 }
55 do_version_bump_micro() {
56         do_version_bump_sed "${PACKAGE_MAJOR_AND_MINOR}.$((PACKAGE_MICRO + 1))"
57 }
58 do_version_bump_tag() {
59         local TAG="$1"
60         [ "${TAG}" ] || die "TAG argument is missing"
61         local TAGS="${PACKAGE_VERSION_TAGS}"
62         if has_version_tag "${TAG}"; then
63                 local RC=$(do_version_tag_value "${TAG}")
64                 RC=$((${RC} + 1))
65                 TAGS=$(echo ${TAGS} | perl -npe "s/-${TAG}[\\d]*/-${TAG}${RC}/")
66         else
67                 TAGS="-${TAG}0${PACKAGE_VERSION_TAGS}"
68         fi
69         PACKAGE_VERSION_TAGS="${TAGS}"
70         do_version_bump_sed "${PACKAGE_VERSION_BASE}"
71 }
72 do_version_bump_final() {
73         local TAG="$1"
74         [ "${TAG}" ] || die "TAG argument is missing"
75         has_version_tag "${TAG}" || die "-${TAG} tag is missing"
76         do_version_tag_remove "${TAG}$(do_version_tag_value "${TAG}")"
77 }
78 do_version_bump() {
79         CMD="$1"
80         shift
81         case "${CMD}" in
82         major|minor|micro|final|tag)
83                 "do_version_bump_${CMD}" "$@"
84                 ;;
85         rc)
86                 do_version_bump_tag "rc"
87                 ;;
88         *)
89                 do_version_usage
90                 ;;
91         esac
92 }
93
94 has_version_tag() {
95         test "${PACKAGE_VERSION/-${1}/}" != "${PACKAGE_VERSION}"
96 }
97 do_version_tag_value() {
98         local TAG="$1"
99         echo ${PACKAGE_VERSION_TAGS} | perl -ne "/-${TAG}"'(\d+)/ && print $1'
100 }
101 do_version_tag_add() {
102         local TAG="$1"
103         has_version_tag "${TAG}" && \
104                 die "error: tag '-${TAG}' exists in '${PACKAGE_VERSION}'"
105         do_version_sed "${PACKAGE_VERSION}-${TAG}" \
106                 "Add '-${TAG}' version tag"
107 }
108 do_version_tag_remove() {
109         local TAG="$1"
110         has_version_tag "${TAG}" || \
111                 die "error: tag '-${TAG}' missing from '${PACKAGE_VERSION}'"
112         do_version_sed "${PACKAGE_VERSION/-${TAG}/}" \
113                 "Remove '-${TAG}' version tag"
114 }
115 do_version_tag() {
116         CMD="$1"
117         shift
118         case "${CMD}" in
119         add|remove)
120                 local i=
121                 for i in "$@"; do
122                         "do_version_tag_${CMD}" "${i}"
123                 done
124                 ;;
125         *)
126                 do_version_usage
127                 ;;
128         esac
129 }
130
131 do_version() {
132         CMD="$1"
133         shift
134         case "${CMD}" in
135         tag|bump)
136                 "do_version_${CMD}" "$@"
137                 ;;
138         commit)
139                 do_version_commit "$@"
140                 ;;
141         *)
142                 do_version_usage
143                 ;;
144         esac
145 }
146
147 package_info_load
148 do_version "$@"
149