blob: 04f59006e1fc9699d81c3bdefbe60ad5cf5977ce [file] [log] [blame]
Paul Bakker34558732012-11-26 17:18:12 +01001#!/bin/bash
Simon Butcher768594d2016-05-23 00:22:58 +01002#
Bence Szépkúti44bfbe32020-08-19 16:54:51 +02003# Copyright The Mbed TLS Contributors
Bence Szépkúti4e9f7122020-06-05 13:02:18 +02004# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
5#
6# This file is provided under the Apache License 2.0, or the
7# GNU General Public License v2.0 or later.
8#
9# **********
10# Apache License 2.0:
Bence Szépkúti09b4f192020-05-26 01:54:15 +020011#
12# Licensed under the Apache License, Version 2.0 (the "License"); you may
13# not use this file except in compliance with the License.
14# You may obtain a copy of the License at
15#
16# http://www.apache.org/licenses/LICENSE-2.0
17#
18# Unless required by applicable law or agreed to in writing, software
19# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
20# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21# See the License for the specific language governing permissions and
22# limitations under the License.
23#
Bence Szépkúti4e9f7122020-06-05 13:02:18 +020024# **********
25#
26# **********
27# GNU General Public License v2.0 or later:
28#
29# This program is free software; you can redistribute it and/or modify
30# it under the terms of the GNU General Public License as published by
31# the Free Software Foundation; either version 2 of the License, or
32# (at your option) any later version.
33#
34# This program is distributed in the hope that it will be useful,
35# but WITHOUT ANY WARRANTY; without even the implied warranty of
36# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
37# GNU General Public License for more details.
38#
39# You should have received a copy of the GNU General Public License along
40# with this program; if not, write to the Free Software Foundation, Inc.,
41# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
42#
43# **********
44#
Simon Butcher768594d2016-05-23 00:22:58 +010045# Purpose
46#
47# Sets the version numbers in the source code to those given.
48#
49# Usage: bump_version.sh [ --version <version> ] [ --so-crypto <version>]
50# [ --so-x509 <version> ] [ --so-tls <version> ]
51# [ -v | --verbose ] [ -h | --help ]
52#
Paul Bakker34558732012-11-26 17:18:12 +010053
54VERSION=""
55SOVERSION=""
56
57# Parse arguments
58#
59until [ -z "$1" ]
60do
61 case "$1" in
62 --version)
63 # Version to use
64 shift
65 VERSION=$1
66 ;;
Manuel Pégourié-Gonnard752c5012015-06-25 11:54:52 +020067 --so-crypto)
Paul Bakker34558732012-11-26 17:18:12 +010068 shift
Manuel Pégourié-Gonnard752c5012015-06-25 11:54:52 +020069 SO_CRYPTO=$1
70 ;;
71 --so-x509)
72 shift
73 SO_X509=$1
74 ;;
75 --so-tls)
76 shift
77 SO_TLS=$1
Paul Bakker34558732012-11-26 17:18:12 +010078 ;;
79 -v|--verbose)
80 # Be verbose
81 VERBOSE="1"
82 ;;
83 -h|--help)
84 # print help
85 echo "Usage: $0"
Manuel Pégourié-Gonnard752c5012015-06-25 11:54:52 +020086 echo -e " -h|--help\t\tPrint this help."
Paul Bakker34558732012-11-26 17:18:12 +010087 echo -e " --version <version>\tVersion to bump to."
Manuel Pégourié-Gonnard752c5012015-06-25 11:54:52 +020088 echo -e " --so-crypto <version>\tSO version to bump libmbedcrypto to."
89 echo -e " --so-x509 <version>\tSO version to bump libmbedx509 to."
90 echo -e " --so-tls <version>\tSO version to bump libmbedtls to."
Paul Bakker34558732012-11-26 17:18:12 +010091 echo -e " -v|--verbose\t\tVerbose."
92 exit 1
93 ;;
94 *)
95 # print error
96 echo "Unknown argument: '$1'"
97 exit 1
98 ;;
99 esac
100 shift
101done
102
103if [ "X" = "X$VERSION" ];
104then
105 echo "No version specified. Unable to continue."
106 exit 1
107fi
108
109[ $VERBOSE ] && echo "Bumping VERSION in library/CMakeLists.txt"
Manuel Pégourié-Gonnardace35992015-06-25 11:51:12 +0200110sed -e "s/ VERSION [0-9.]\{1,\}/ VERSION $VERSION/g" < library/CMakeLists.txt > tmp
Paul Bakker34558732012-11-26 17:18:12 +0100111mv tmp library/CMakeLists.txt
112
Manuel Pégourié-Gonnard752c5012015-06-25 11:54:52 +0200113if [ "X" != "X$SO_CRYPTO" ];
Paul Bakker34558732012-11-26 17:18:12 +0100114then
Manuel Pégourié-Gonnard752c5012015-06-25 11:54:52 +0200115 [ $VERBOSE ] && echo "Bumping SOVERSION for libmbedcrypto in library/CMakeLists.txt"
116 sed -e "/mbedcrypto/ s/ SOVERSION [0-9]\{1,\}/ SOVERSION $SO_CRYPTO/g" < library/CMakeLists.txt > tmp
Paul Bakker34558732012-11-26 17:18:12 +0100117 mv tmp library/CMakeLists.txt
Paul Bakker91180722013-11-05 11:28:32 +0100118
Manuel Pégourié-Gonnard752c5012015-06-25 11:54:52 +0200119 [ $VERBOSE ] && echo "Bumping SOVERSION for libmbedcrypto in library/Makefile"
120 sed -e "s/SOEXT_CRYPTO=so.[0-9]\{1,\}/SOEXT_CRYPTO=so.$SO_CRYPTO/g" < library/Makefile > tmp
121 mv tmp library/Makefile
122fi
123
124if [ "X" != "X$SO_X509" ];
125then
126 [ $VERBOSE ] && echo "Bumping SOVERSION for libmbedx509 in library/CMakeLists.txt"
127 sed -e "/mbedx509/ s/ SOVERSION [0-9]\{1,\}/ SOVERSION $SO_X509/g" < library/CMakeLists.txt > tmp
128 mv tmp library/CMakeLists.txt
129
130 [ $VERBOSE ] && echo "Bumping SOVERSION for libmbedx509 in library/Makefile"
131 sed -e "s/SOEXT_X509=so.[0-9]\{1,\}/SOEXT_X509=so.$SO_X509/g" < library/Makefile > tmp
132 mv tmp library/Makefile
133fi
134
135if [ "X" != "X$SO_TLS" ];
136then
137 [ $VERBOSE ] && echo "Bumping SOVERSION for libmbedtls in library/CMakeLists.txt"
138 sed -e "/mbedtls/ s/ SOVERSION [0-9]\{1,\}/ SOVERSION $SO_TLS/g" < library/CMakeLists.txt > tmp
139 mv tmp library/CMakeLists.txt
140
141 [ $VERBOSE ] && echo "Bumping SOVERSION for libmbedtls in library/Makefile"
142 sed -e "s/SOEXT_TLS=so.[0-9]\{1,\}/SOEXT_TLS=so.$SO_TLS/g" < library/Makefile > tmp
Paul Bakker91180722013-11-05 11:28:32 +0100143 mv tmp library/Makefile
Paul Bakker34558732012-11-26 17:18:12 +0100144fi
145
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000146[ $VERBOSE ] && echo "Bumping VERSION in include/mbedtls/version.h"
Paul Bakker34558732012-11-26 17:18:12 +0100147read MAJOR MINOR PATCH <<<$(IFS="."; echo $VERSION)
148VERSION_NR="$( printf "0x%02X%02X%02X00" $MAJOR $MINOR $PATCH )"
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000149cat include/mbedtls/version.h | \
Manuel Pégourié-Gonnardace35992015-06-25 11:51:12 +0200150 sed -e "s/_VERSION_MAJOR .\{1,\}/_VERSION_MAJOR $MAJOR/" | \
151 sed -e "s/_VERSION_MINOR .\{1,\}/_VERSION_MINOR $MINOR/" | \
152 sed -e "s/_VERSION_PATCH .\{1,\}/_VERSION_PATCH $PATCH/" | \
153 sed -e "s/_VERSION_NUMBER .\{1,\}/_VERSION_NUMBER $VERSION_NR/" | \
154 sed -e "s/_VERSION_STRING .\{1,\}/_VERSION_STRING \"$VERSION\"/" | \
155 sed -e "s/_VERSION_STRING_FULL .\{1,\}/_VERSION_STRING_FULL \"mbed TLS $VERSION\"/" \
Paul Bakker34558732012-11-26 17:18:12 +0100156 > tmp
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +0000157mv tmp include/mbedtls/version.h
Paul Bakker34558732012-11-26 17:18:12 +0100158
159[ $VERBOSE ] && echo "Bumping version in tests/suites/test_suite_version.data"
Manuel Pégourié-Gonnardace35992015-06-25 11:51:12 +0200160sed -e "s/version:\".\{1,\}/version:\"$VERSION\"/g" < tests/suites/test_suite_version.data > tmp
Paul Bakker34558732012-11-26 17:18:12 +0100161mv tmp tests/suites/test_suite_version.data
162
Manuel Pégourié-Gonnardf234ff82015-01-22 17:01:27 +0000163[ $VERBOSE ] && echo "Bumping PROJECT_NAME in doxygen/mbedtls.doxyfile and doxygen/input/doc_mainpage.h"
164for i in doxygen/mbedtls.doxyfile doxygen/input/doc_mainpage.h;
Paul Bakker34558732012-11-26 17:18:12 +0100165do
Manuel Pégourié-Gonnardace35992015-06-25 11:51:12 +0200166 sed -e "s/mbed TLS v[0-9\.]\{1,\}/mbed TLS v$VERSION/g" < $i > tmp
Paul Bakker34558732012-11-26 17:18:12 +0100167 mv tmp $i
168done
169
Paul Bakker0f90d7d2014-04-30 11:49:44 +0200170[ $VERBOSE ] && echo "Re-generating library/error.c"
Manuel Pégourié-Gonnardd66f9002014-05-09 13:40:14 +0200171scripts/generate_errors.pl
Paul Bakker0f90d7d2014-04-30 11:49:44 +0200172
173[ $VERBOSE ] && echo "Re-generating library/version_features.c"
Manuel Pégourié-Gonnardd66f9002014-05-09 13:40:14 +0200174scripts/generate_features.pl
Manuel Pégourié-Gonnard71c8f202014-05-09 13:25:10 +0200175
176[ $VERBOSE ] && echo "Re-generating visualc files"
177scripts/generate_visualc_files.pl
Simon Butcher768594d2016-05-23 00:22:58 +0100178