blob: 6a4a69d8dd154314bdf6095f8818d4570c53573f [file] [log] [blame]
Paul Bakker34558732012-11-26 17:18:12 +01001#!/bin/bash
Simon Butcher768594d2016-05-23 00:22:58 +01002#
Bence Szépkúti1e148272020-08-07 13:07:28 +02003# Copyright The Mbed TLS Contributors
Bence Szépkútic7da1fe2020-05-26 01:54:15 +02004# SPDX-License-Identifier: Apache-2.0
5#
6# Licensed under the Apache License, Version 2.0 (the "License"); you may
7# not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17#
Simon Butcher768594d2016-05-23 00:22:58 +010018# Purpose
19#
20# Sets the version numbers in the source code to those given.
21#
22# Usage: bump_version.sh [ --version <version> ] [ --so-crypto <version>]
23# [ --so-x509 <version> ] [ --so-tls <version> ]
24# [ -v | --verbose ] [ -h | --help ]
25#
Paul Bakker34558732012-11-26 17:18:12 +010026
Gilles Peskine716b9732021-07-01 11:10:15 +020027set -e
28
Paul Bakker34558732012-11-26 17:18:12 +010029VERSION=""
30SOVERSION=""
31
32# Parse arguments
33#
34until [ -z "$1" ]
35do
36 case "$1" in
37 --version)
38 # Version to use
39 shift
40 VERSION=$1
41 ;;
Manuel Pégourié-Gonnard752c5012015-06-25 11:54:52 +020042 --so-crypto)
Paul Bakker34558732012-11-26 17:18:12 +010043 shift
Manuel Pégourié-Gonnard752c5012015-06-25 11:54:52 +020044 SO_CRYPTO=$1
45 ;;
46 --so-x509)
47 shift
48 SO_X509=$1
49 ;;
50 --so-tls)
51 shift
52 SO_TLS=$1
Paul Bakker34558732012-11-26 17:18:12 +010053 ;;
54 -v|--verbose)
55 # Be verbose
56 VERBOSE="1"
57 ;;
58 -h|--help)
59 # print help
60 echo "Usage: $0"
Manuel Pégourié-Gonnard752c5012015-06-25 11:54:52 +020061 echo -e " -h|--help\t\tPrint this help."
Paul Bakker34558732012-11-26 17:18:12 +010062 echo -e " --version <version>\tVersion to bump to."
Manuel Pégourié-Gonnard752c5012015-06-25 11:54:52 +020063 echo -e " --so-crypto <version>\tSO version to bump libmbedcrypto to."
64 echo -e " --so-x509 <version>\tSO version to bump libmbedx509 to."
65 echo -e " --so-tls <version>\tSO version to bump libmbedtls to."
Paul Bakker34558732012-11-26 17:18:12 +010066 echo -e " -v|--verbose\t\tVerbose."
67 exit 1
68 ;;
69 *)
70 # print error
71 echo "Unknown argument: '$1'"
72 exit 1
73 ;;
74 esac
75 shift
76done
77
78if [ "X" = "X$VERSION" ];
79then
80 echo "No version specified. Unable to continue."
81 exit 1
82fi
83
Gilles Peskineaa4862a2021-07-01 11:10:29 +020084[ $VERBOSE ] && echo "Bumping VERSION in CMakeLists.txt"
85sed -e "s/ VERSION [0-9.]\{1,\}/ VERSION $VERSION/g" < CMakeLists.txt > tmp
86mv tmp CMakeLists.txt
87
Paul Bakker34558732012-11-26 17:18:12 +010088[ $VERBOSE ] && echo "Bumping VERSION in library/CMakeLists.txt"
Manuel Pégourié-Gonnardace35992015-06-25 11:51:12 +020089sed -e "s/ VERSION [0-9.]\{1,\}/ VERSION $VERSION/g" < library/CMakeLists.txt > tmp
Paul Bakker34558732012-11-26 17:18:12 +010090mv tmp library/CMakeLists.txt
91
Manuel Pégourié-Gonnard752c5012015-06-25 11:54:52 +020092if [ "X" != "X$SO_CRYPTO" ];
Paul Bakker34558732012-11-26 17:18:12 +010093then
Manuel Pégourié-Gonnard752c5012015-06-25 11:54:52 +020094 [ $VERBOSE ] && echo "Bumping SOVERSION for libmbedcrypto in library/CMakeLists.txt"
95 sed -e "/mbedcrypto/ s/ SOVERSION [0-9]\{1,\}/ SOVERSION $SO_CRYPTO/g" < library/CMakeLists.txt > tmp
Paul Bakker34558732012-11-26 17:18:12 +010096 mv tmp library/CMakeLists.txt
Paul Bakker91180722013-11-05 11:28:32 +010097
Manuel Pégourié-Gonnard752c5012015-06-25 11:54:52 +020098 [ $VERBOSE ] && echo "Bumping SOVERSION for libmbedcrypto in library/Makefile"
99 sed -e "s/SOEXT_CRYPTO=so.[0-9]\{1,\}/SOEXT_CRYPTO=so.$SO_CRYPTO/g" < library/Makefile > tmp
100 mv tmp library/Makefile
101fi
102
103if [ "X" != "X$SO_X509" ];
104then
105 [ $VERBOSE ] && echo "Bumping SOVERSION for libmbedx509 in library/CMakeLists.txt"
106 sed -e "/mbedx509/ s/ SOVERSION [0-9]\{1,\}/ SOVERSION $SO_X509/g" < library/CMakeLists.txt > tmp
107 mv tmp library/CMakeLists.txt
108
109 [ $VERBOSE ] && echo "Bumping SOVERSION for libmbedx509 in library/Makefile"
110 sed -e "s/SOEXT_X509=so.[0-9]\{1,\}/SOEXT_X509=so.$SO_X509/g" < library/Makefile > tmp
111 mv tmp library/Makefile
112fi
113
114if [ "X" != "X$SO_TLS" ];
115then
116 [ $VERBOSE ] && echo "Bumping SOVERSION for libmbedtls in library/CMakeLists.txt"
117 sed -e "/mbedtls/ s/ SOVERSION [0-9]\{1,\}/ SOVERSION $SO_TLS/g" < library/CMakeLists.txt > tmp
118 mv tmp library/CMakeLists.txt
119
120 [ $VERBOSE ] && echo "Bumping SOVERSION for libmbedtls in library/Makefile"
121 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 +0100122 mv tmp library/Makefile
Paul Bakker34558732012-11-26 17:18:12 +0100123fi
124
Gilles Peskine494678a2021-07-01 11:11:30 +0200125[ $VERBOSE ] && echo "Bumping VERSION in include/mbedtls/build_info.h"
Paul Bakker34558732012-11-26 17:18:12 +0100126read MAJOR MINOR PATCH <<<$(IFS="."; echo $VERSION)
127VERSION_NR="$( printf "0x%02X%02X%02X00" $MAJOR $MINOR $PATCH )"
Gilles Peskine494678a2021-07-01 11:11:30 +0200128cat include/mbedtls/build_info.h | \
Manuel Pégourié-Gonnardace35992015-06-25 11:51:12 +0200129 sed -e "s/_VERSION_MAJOR .\{1,\}/_VERSION_MAJOR $MAJOR/" | \
130 sed -e "s/_VERSION_MINOR .\{1,\}/_VERSION_MINOR $MINOR/" | \
131 sed -e "s/_VERSION_PATCH .\{1,\}/_VERSION_PATCH $PATCH/" | \
132 sed -e "s/_VERSION_NUMBER .\{1,\}/_VERSION_NUMBER $VERSION_NR/" | \
133 sed -e "s/_VERSION_STRING .\{1,\}/_VERSION_STRING \"$VERSION\"/" | \
134 sed -e "s/_VERSION_STRING_FULL .\{1,\}/_VERSION_STRING_FULL \"mbed TLS $VERSION\"/" \
Paul Bakker34558732012-11-26 17:18:12 +0100135 > tmp
Gilles Peskine494678a2021-07-01 11:11:30 +0200136mv tmp include/mbedtls/build_info.h
Paul Bakker34558732012-11-26 17:18:12 +0100137
138[ $VERBOSE ] && echo "Bumping version in tests/suites/test_suite_version.data"
Manuel Pégourié-Gonnardace35992015-06-25 11:51:12 +0200139sed -e "s/version:\".\{1,\}/version:\"$VERSION\"/g" < tests/suites/test_suite_version.data > tmp
Paul Bakker34558732012-11-26 17:18:12 +0100140mv tmp tests/suites/test_suite_version.data
141
Manuel Pégourié-Gonnardf234ff82015-01-22 17:01:27 +0000142[ $VERBOSE ] && echo "Bumping PROJECT_NAME in doxygen/mbedtls.doxyfile and doxygen/input/doc_mainpage.h"
143for i in doxygen/mbedtls.doxyfile doxygen/input/doc_mainpage.h;
Paul Bakker34558732012-11-26 17:18:12 +0100144do
Manuel Pégourié-Gonnardace35992015-06-25 11:51:12 +0200145 sed -e "s/mbed TLS v[0-9\.]\{1,\}/mbed TLS v$VERSION/g" < $i > tmp
Paul Bakker34558732012-11-26 17:18:12 +0100146 mv tmp $i
147done
148
Paul Bakker0f90d7d2014-04-30 11:49:44 +0200149[ $VERBOSE ] && echo "Re-generating library/error.c"
Manuel Pégourié-Gonnardd66f9002014-05-09 13:40:14 +0200150scripts/generate_errors.pl
Paul Bakker0f90d7d2014-04-30 11:49:44 +0200151
Jaeden Amero7cb47de2019-02-28 11:37:23 +0000152[ $VERBOSE ] && echo "Re-generating programs/test/query_config.c"
Andres Amaya Garcia4c981a02018-10-16 22:13:57 +0100153scripts/generate_query_config.pl
154
Paul Bakker0f90d7d2014-04-30 11:49:44 +0200155[ $VERBOSE ] && echo "Re-generating library/version_features.c"
Manuel Pégourié-Gonnardd66f9002014-05-09 13:40:14 +0200156scripts/generate_features.pl
Manuel Pégourié-Gonnard71c8f202014-05-09 13:25:10 +0200157
158[ $VERBOSE ] && echo "Re-generating visualc files"
159scripts/generate_visualc_files.pl
Simon Butcher768594d2016-05-23 00:22:58 +0100160