stm32lx: refactor and add support for STM32L0xx
[openocd.git] / tools / release / version.sh
blobd6c9434b3f2b0557b6264b083f08704f25b228d4
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).
6 # FIXME Remove more bash-isms. Fix errors making "ash -e" lose.
8 # NOTE Use with care! "RC" should only follow x.x.x, with
9 # vendor tags after that. Be traditional; avoid "rc0".
11 # NOTE: This *ONLY* updates the "configure.ac" 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.
17 . "tools/release/helpers.sh"
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.
32 do_version_sed() {
33 local OLD_VERSION="${PACKAGE_VERSION}"
34 local NEW_VERSION="$1"
35 local MSG="$2"
37 sed -i -e "/AC_INIT/ s|${OLD_VERSION}|${NEW_VERSION}|" configure.ac
38 package_info_load
39 echo "${MSG}: ${OLD_VERSION} -> ${NEW_VERSION}"
41 do_version_bump_sed() {
42 local NEW_VERSION="$1"
43 [ -z "${PACKAGE_VERSION_TAGS}" ] || \
44 NEW_VERSION="${NEW_VERSION}${PACKAGE_VERSION_TAGS}"
46 do_version_sed "${NEW_VERSION}" \
47 "Bump ${CMD} package version number"
49 do_version_bump_major() {
50 do_version_bump_sed "$((PACKAGE_MAJOR + 1)).0.0"
52 do_version_bump_minor() {
53 do_version_bump_sed "${PACKAGE_MAJOR}.$((PACKAGE_MINOR + 1)).0"
55 do_version_bump_micro() {
56 do_version_bump_sed "${PACKAGE_MAJOR_AND_MINOR}.$((PACKAGE_MICRO + 1))"
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}"
69 PACKAGE_VERSION_TAGS="${TAGS}"
70 do_version_bump_sed "${PACKAGE_VERSION_BASE}"
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}")"
78 do_version_bump() {
79 CMD="$1"
80 shift
81 case "${CMD}" in
82 major|minor|micro|final|tag)
83 "do_version_bump_${CMD}" "$@"
85 rc)
86 do_version_bump_tag "rc"
89 do_version_usage
91 esac
94 has_version_tag() {
95 test "${PACKAGE_VERSION/-${1}/}" != "${PACKAGE_VERSION}"
97 do_version_tag_value() {
98 local TAG="$1"
99 echo ${PACKAGE_VERSION_TAGS} | perl -ne "/-${TAG}"'(\d+)/ && print $1'
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"
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"
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
126 do_version_usage
128 esac
131 do_version() {
132 CMD="$1"
133 shift
134 case "${CMD}" in
135 tag|bump)
136 "do_version_${CMD}" "$@"
138 commit)
139 do_version_commit "$@"
142 do_version_usage
144 esac
147 package_info_load
148 do_version "$@"