blob: 86ed74eada4ae4150246616e8ad5badae957f8e2 [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
Dave Rodgman16799db2023-11-02 19:47:20 +00004# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
Bence Szépkútic7da1fe2020-05-26 01:54:15 +02005#
Simon Butcher768594d2016-05-23 00:22:58 +01006# Purpose
7#
8# Sets the version numbers in the source code to those given.
9#
10# Usage: bump_version.sh [ --version <version> ] [ --so-crypto <version>]
11# [ --so-x509 <version> ] [ --so-tls <version> ]
12# [ -v | --verbose ] [ -h | --help ]
13#
Paul Bakker34558732012-11-26 17:18:12 +010014
Gilles Peskine716b9732021-07-01 11:10:15 +020015set -e
16
Paul Bakker34558732012-11-26 17:18:12 +010017VERSION=""
18SOVERSION=""
19
20# Parse arguments
21#
22until [ -z "$1" ]
23do
24 case "$1" in
25 --version)
26 # Version to use
27 shift
28 VERSION=$1
29 ;;
Manuel Pégourié-Gonnard752c5012015-06-25 11:54:52 +020030 --so-crypto)
Paul Bakker34558732012-11-26 17:18:12 +010031 shift
Manuel Pégourié-Gonnard752c5012015-06-25 11:54:52 +020032 SO_CRYPTO=$1
33 ;;
34 --so-x509)
35 shift
36 SO_X509=$1
37 ;;
38 --so-tls)
39 shift
40 SO_TLS=$1
Paul Bakker34558732012-11-26 17:18:12 +010041 ;;
42 -v|--verbose)
43 # Be verbose
44 VERBOSE="1"
45 ;;
46 -h|--help)
47 # print help
48 echo "Usage: $0"
Manuel Pégourié-Gonnard752c5012015-06-25 11:54:52 +020049 echo -e " -h|--help\t\tPrint this help."
Paul Bakker34558732012-11-26 17:18:12 +010050 echo -e " --version <version>\tVersion to bump to."
Manuel Pégourié-Gonnard752c5012015-06-25 11:54:52 +020051 echo -e " --so-crypto <version>\tSO version to bump libmbedcrypto to."
52 echo -e " --so-x509 <version>\tSO version to bump libmbedx509 to."
53 echo -e " --so-tls <version>\tSO version to bump libmbedtls to."
Paul Bakker34558732012-11-26 17:18:12 +010054 echo -e " -v|--verbose\t\tVerbose."
55 exit 1
56 ;;
57 *)
58 # print error
59 echo "Unknown argument: '$1'"
60 exit 1
61 ;;
62 esac
63 shift
64done
65
66if [ "X" = "X$VERSION" ];
67then
68 echo "No version specified. Unable to continue."
69 exit 1
70fi
71
Gilles Peskineaa4862a2021-07-01 11:10:29 +020072[ $VERBOSE ] && echo "Bumping VERSION in CMakeLists.txt"
73sed -e "s/ VERSION [0-9.]\{1,\}/ VERSION $VERSION/g" < CMakeLists.txt > tmp
74mv tmp CMakeLists.txt
75
Paul Bakker34558732012-11-26 17:18:12 +010076[ $VERBOSE ] && echo "Bumping VERSION in library/CMakeLists.txt"
Manuel Pégourié-Gonnardace35992015-06-25 11:51:12 +020077sed -e "s/ VERSION [0-9.]\{1,\}/ VERSION $VERSION/g" < library/CMakeLists.txt > tmp
Paul Bakker34558732012-11-26 17:18:12 +010078mv tmp library/CMakeLists.txt
79
Manuel Pégourié-Gonnard752c5012015-06-25 11:54:52 +020080if [ "X" != "X$SO_CRYPTO" ];
Paul Bakker34558732012-11-26 17:18:12 +010081then
Manuel Pégourié-Gonnard752c5012015-06-25 11:54:52 +020082 [ $VERBOSE ] && echo "Bumping SOVERSION for libmbedcrypto in library/CMakeLists.txt"
83 sed -e "/mbedcrypto/ s/ SOVERSION [0-9]\{1,\}/ SOVERSION $SO_CRYPTO/g" < library/CMakeLists.txt > tmp
Paul Bakker34558732012-11-26 17:18:12 +010084 mv tmp library/CMakeLists.txt
Paul Bakker91180722013-11-05 11:28:32 +010085
Manuel Pégourié-Gonnard752c5012015-06-25 11:54:52 +020086 [ $VERBOSE ] && echo "Bumping SOVERSION for libmbedcrypto in library/Makefile"
Dave Rodgmanfca2bcc2022-08-12 10:17:18 +010087 sed -e "s/SOEXT_CRYPTO?=so.[0-9]\{1,\}/SOEXT_CRYPTO?=so.$SO_CRYPTO/g" < library/Makefile > tmp
Manuel Pégourié-Gonnard752c5012015-06-25 11:54:52 +020088 mv tmp library/Makefile
89fi
90
91if [ "X" != "X$SO_X509" ];
92then
93 [ $VERBOSE ] && echo "Bumping SOVERSION for libmbedx509 in library/CMakeLists.txt"
94 sed -e "/mbedx509/ s/ SOVERSION [0-9]\{1,\}/ SOVERSION $SO_X509/g" < library/CMakeLists.txt > tmp
95 mv tmp library/CMakeLists.txt
96
97 [ $VERBOSE ] && echo "Bumping SOVERSION for libmbedx509 in library/Makefile"
Dave Rodgmanfca2bcc2022-08-12 10:17:18 +010098 sed -e "s/SOEXT_X509?=so.[0-9]\{1,\}/SOEXT_X509?=so.$SO_X509/g" < library/Makefile > tmp
Manuel Pégourié-Gonnard752c5012015-06-25 11:54:52 +020099 mv tmp library/Makefile
100fi
101
102if [ "X" != "X$SO_TLS" ];
103then
104 [ $VERBOSE ] && echo "Bumping SOVERSION for libmbedtls in library/CMakeLists.txt"
105 sed -e "/mbedtls/ s/ SOVERSION [0-9]\{1,\}/ SOVERSION $SO_TLS/g" < library/CMakeLists.txt > tmp
106 mv tmp library/CMakeLists.txt
107
108 [ $VERBOSE ] && echo "Bumping SOVERSION for libmbedtls in library/Makefile"
Dave Rodgmanfca2bcc2022-08-12 10:17:18 +0100109 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 +0100110 mv tmp library/Makefile
Paul Bakker34558732012-11-26 17:18:12 +0100111fi
112
Gilles Peskine494678a2021-07-01 11:11:30 +0200113[ $VERBOSE ] && echo "Bumping VERSION in include/mbedtls/build_info.h"
Paul Bakker34558732012-11-26 17:18:12 +0100114read MAJOR MINOR PATCH <<<$(IFS="."; echo $VERSION)
115VERSION_NR="$( printf "0x%02X%02X%02X00" $MAJOR $MINOR $PATCH )"
Gilles Peskine494678a2021-07-01 11:11:30 +0200116cat include/mbedtls/build_info.h | \
Gilles Peskine5dd4d2e2021-12-14 20:17:33 +0100117 sed -e "s/\(# *define *[A-Z]*_VERSION\)_MAJOR .\{1,\}/\1_MAJOR $MAJOR/" | \
118 sed -e "s/\(# *define *[A-Z]*_VERSION\)_MINOR .\{1,\}/\1_MINOR $MINOR/" | \
119 sed -e "s/\(# *define *[A-Z]*_VERSION\)_PATCH .\{1,\}/\1_PATCH $PATCH/" | \
120 sed -e "s/\(# *define *[A-Z]*_VERSION\)_NUMBER .\{1,\}/\1_NUMBER $VERSION_NR/" | \
121 sed -e "s/\(# *define *[A-Z]*_VERSION\)_STRING .\{1,\}/\1_STRING \"$VERSION\"/" | \
Gilles Peskinee820c0a2023-08-03 17:45:20 +0200122 sed -e "s/\(# *define *[A-Z]*_VERSION\)_STRING_FULL .\{1,\}/\1_STRING_FULL \"Mbed TLS $VERSION\"/" \
Paul Bakker34558732012-11-26 17:18:12 +0100123 > tmp
Gilles Peskine494678a2021-07-01 11:11:30 +0200124mv tmp include/mbedtls/build_info.h
Paul Bakker34558732012-11-26 17:18:12 +0100125
126[ $VERBOSE ] && echo "Bumping version in tests/suites/test_suite_version.data"
David Horstmann05027f22025-05-02 11:41:19 +0100127sed -e "s/version:\".\{1,\}/version:\"$VERSION\"/g" < tests/suites/test_suite_version.data > tmp
128mv tmp tests/suites/test_suite_version.data
Paul Bakker34558732012-11-26 17:18:12 +0100129
Manuel Pégourié-Gonnardf234ff82015-01-22 17:01:27 +0000130[ $VERBOSE ] && echo "Bumping PROJECT_NAME in doxygen/mbedtls.doxyfile and doxygen/input/doc_mainpage.h"
131for i in doxygen/mbedtls.doxyfile doxygen/input/doc_mainpage.h;
Paul Bakker34558732012-11-26 17:18:12 +0100132do
Gilles Peskine48432782023-08-03 17:22:44 +0200133 sed -e "s/\\([Mm]bed TLS v\\)[0-9][0-9.]*/\\1$VERSION/g" < $i > tmp
Paul Bakker34558732012-11-26 17:18:12 +0100134 mv tmp $i
135done
136
Paul Bakker0f90d7d2014-04-30 11:49:44 +0200137[ $VERBOSE ] && echo "Re-generating library/error.c"
Manuel Pégourié-Gonnardd66f9002014-05-09 13:40:14 +0200138scripts/generate_errors.pl
Paul Bakker0f90d7d2014-04-30 11:49:44 +0200139
Jaeden Amero7cb47de2019-02-28 11:37:23 +0000140[ $VERBOSE ] && echo "Re-generating programs/test/query_config.c"
Andres Amaya Garcia4c981a02018-10-16 22:13:57 +0100141scripts/generate_query_config.pl
142
Paul Bakker0f90d7d2014-04-30 11:49:44 +0200143[ $VERBOSE ] && echo "Re-generating library/version_features.c"
Manuel Pégourié-Gonnardd66f9002014-05-09 13:40:14 +0200144scripts/generate_features.pl
Manuel Pégourié-Gonnard71c8f202014-05-09 13:25:10 +0200145
146[ $VERBOSE ] && echo "Re-generating visualc files"
147scripts/generate_visualc_files.pl
Simon Butcher768594d2016-05-23 00:22:58 +0100148