1#!/bin/bash 2# 3# Copyright The Mbed TLS Contributors 4# 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# 18# 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# 26 27VERSION="" 28SOVERSION="" 29 30# Parse arguments 31# 32until [ -z "$1" ] 33do 34 case "$1" in 35 --version) 36 # Version to use 37 shift 38 VERSION=$1 39 ;; 40 --so-crypto) 41 shift 42 SO_CRYPTO=$1 43 ;; 44 --so-x509) 45 shift 46 SO_X509=$1 47 ;; 48 --so-tls) 49 shift 50 SO_TLS=$1 51 ;; 52 -v|--verbose) 53 # Be verbose 54 VERBOSE="1" 55 ;; 56 -h|--help) 57 # print help 58 echo "Usage: $0" 59 echo -e " -h|--help\t\tPrint this help." 60 echo -e " --version <version>\tVersion to bump to." 61 echo -e " --so-crypto <version>\tSO version to bump libmbedcrypto to." 62 echo -e " --so-x509 <version>\tSO version to bump libmbedx509 to." 63 echo -e " --so-tls <version>\tSO version to bump libmbedtls to." 64 echo -e " -v|--verbose\t\tVerbose." 65 exit 1 66 ;; 67 *) 68 # print error 69 echo "Unknown argument: '$1'" 70 exit 1 71 ;; 72 esac 73 shift 74done 75 76if [ "X" = "X$VERSION" ]; 77then 78 echo "No version specified. Unable to continue." 79 exit 1 80fi 81 82[ $VERBOSE ] && echo "Bumping VERSION in library/CMakeLists.txt" 83sed -e "s/ VERSION [0-9.]\{1,\}/ VERSION $VERSION/g" < library/CMakeLists.txt > tmp 84mv tmp library/CMakeLists.txt 85 86if [ "X" != "X$SO_CRYPTO" ]; 87then 88 [ $VERBOSE ] && echo "Bumping SOVERSION for libmbedcrypto in library/CMakeLists.txt" 89 sed -e "/mbedcrypto/ s/ SOVERSION [0-9]\{1,\}/ SOVERSION $SO_CRYPTO/g" < library/CMakeLists.txt > tmp 90 mv tmp library/CMakeLists.txt 91 92 [ $VERBOSE ] && echo "Bumping SOVERSION for libmbedcrypto in library/Makefile" 93 sed -e "s/SOEXT_CRYPTO=so.[0-9]\{1,\}/SOEXT_CRYPTO=so.$SO_CRYPTO/g" < library/Makefile > tmp 94 mv tmp library/Makefile 95fi 96 97if [ "X" != "X$SO_X509" ]; 98then 99 [ $VERBOSE ] && echo "Bumping SOVERSION for libmbedx509 in library/CMakeLists.txt" 100 sed -e "/mbedx509/ s/ SOVERSION [0-9]\{1,\}/ SOVERSION $SO_X509/g" < library/CMakeLists.txt > tmp 101 mv tmp library/CMakeLists.txt 102 103 [ $VERBOSE ] && echo "Bumping SOVERSION for libmbedx509 in library/Makefile" 104 sed -e "s/SOEXT_X509=so.[0-9]\{1,\}/SOEXT_X509=so.$SO_X509/g" < library/Makefile > tmp 105 mv tmp library/Makefile 106fi 107 108if [ "X" != "X$SO_TLS" ]; 109then 110 [ $VERBOSE ] && echo "Bumping SOVERSION for libmbedtls in library/CMakeLists.txt" 111 sed -e "/mbedtls/ s/ SOVERSION [0-9]\{1,\}/ SOVERSION $SO_TLS/g" < library/CMakeLists.txt > tmp 112 mv tmp library/CMakeLists.txt 113 114 [ $VERBOSE ] && echo "Bumping SOVERSION for libmbedtls in library/Makefile" 115 sed -e "s/SOEXT_TLS=so.[0-9]\{1,\}/SOEXT_TLS=so.$SO_TLS/g" < library/Makefile > tmp 116 mv tmp library/Makefile 117fi 118 119[ $VERBOSE ] && echo "Bumping VERSION in include/mbedtls/version.h" 120read MAJOR MINOR PATCH <<<$(IFS="."; echo $VERSION) 121VERSION_NR="$( printf "0x%02X%02X%02X00" $MAJOR $MINOR $PATCH )" 122cat include/mbedtls/version.h | \ 123 sed -e "s/_VERSION_MAJOR .\{1,\}/_VERSION_MAJOR $MAJOR/" | \ 124 sed -e "s/_VERSION_MINOR .\{1,\}/_VERSION_MINOR $MINOR/" | \ 125 sed -e "s/_VERSION_PATCH .\{1,\}/_VERSION_PATCH $PATCH/" | \ 126 sed -e "s/_VERSION_NUMBER .\{1,\}/_VERSION_NUMBER $VERSION_NR/" | \ 127 sed -e "s/_VERSION_STRING .\{1,\}/_VERSION_STRING \"$VERSION\"/" | \ 128 sed -e "s/_VERSION_STRING_FULL .\{1,\}/_VERSION_STRING_FULL \"mbed TLS $VERSION\"/" \ 129 > tmp 130mv tmp include/mbedtls/version.h 131 132[ $VERBOSE ] && echo "Bumping version in tests/suites/test_suite_version.data" 133sed -e "s/version:\".\{1,\}/version:\"$VERSION\"/g" < tests/suites/test_suite_version.data > tmp 134mv tmp tests/suites/test_suite_version.data 135 136[ $VERBOSE ] && echo "Bumping PROJECT_NAME in doxygen/mbedtls.doxyfile and doxygen/input/doc_mainpage.h" 137for i in doxygen/mbedtls.doxyfile doxygen/input/doc_mainpage.h; 138do 139 sed -e "s/mbed TLS v[0-9\.]\{1,\}/mbed TLS v$VERSION/g" < $i > tmp 140 mv tmp $i 141done 142 143[ $VERBOSE ] && echo "Re-generating library/error.c" 144scripts/generate_errors.pl 145 146[ $VERBOSE ] && echo "Re-generating programs/test/query_config.c" 147scripts/generate_query_config.pl 148 149[ $VERBOSE ] && echo "Re-generating library/version_features.c" 150scripts/generate_features.pl 151 152[ $VERBOSE ] && echo "Re-generating visualc files" 153scripts/generate_visualc_files.pl 154 155