1#!/bin/bash 2# 3# Copyright The Mbed TLS Contributors 4# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later 5# 6# 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# 14 15set -e 16 17VERSION="" 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 ;; 30 --so-crypto) 31 shift 32 SO_CRYPTO=$1 33 ;; 34 --so-x509) 35 shift 36 SO_X509=$1 37 ;; 38 --so-tls) 39 shift 40 SO_TLS=$1 41 ;; 42 -v|--verbose) 43 # Be verbose 44 VERBOSE="1" 45 ;; 46 -h|--help) 47 # print help 48 echo "Usage: $0" 49 echo -e " -h|--help\t\tPrint this help." 50 echo -e " --version <version>\tVersion to bump to." 51 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." 54 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 72[ $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 76[ $VERBOSE ] && echo "Bumping VERSION in library/CMakeLists.txt" 77sed -e "s/ VERSION [0-9.]\{1,\}/ VERSION $VERSION/g" < library/CMakeLists.txt > tmp 78mv tmp library/CMakeLists.txt 79 80if [ "X" != "X$SO_CRYPTO" ]; 81then 82 [ $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 84 mv tmp library/CMakeLists.txt 85 86 [ $VERBOSE ] && echo "Bumping SOVERSION for libmbedcrypto in library/Makefile" 87 sed -e "s/SOEXT_CRYPTO?=so.[0-9]\{1,\}/SOEXT_CRYPTO?=so.$SO_CRYPTO/g" < library/Makefile > tmp 88 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" 98 sed -e "s/SOEXT_X509?=so.[0-9]\{1,\}/SOEXT_X509?=so.$SO_X509/g" < library/Makefile > tmp 99 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" 109 sed -e "s/SOEXT_TLS?=so.[0-9]\{1,\}/SOEXT_TLS?=so.$SO_TLS/g" < library/Makefile > tmp 110 mv tmp library/Makefile 111fi 112 113[ $VERBOSE ] && echo "Bumping VERSION in include/mbedtls/build_info.h" 114read MAJOR MINOR PATCH <<<$(IFS="."; echo $VERSION) 115VERSION_NR="$( printf "0x%02X%02X%02X00" $MAJOR $MINOR $PATCH )" 116cat include/mbedtls/build_info.h | \ 117 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\"/" | \ 122 sed -e "s/\(# *define *[A-Z]*_VERSION\)_STRING_FULL .\{1,\}/\1_STRING_FULL \"Mbed TLS $VERSION\"/" \ 123 > tmp 124mv tmp include/mbedtls/build_info.h 125 126[ $VERBOSE ] && echo "Bumping version in tests/suites/test_suite_version.data" 127sed -e "s/version:\".\{1,\}/version:\"$VERSION\"/g" < tests/suites/test_suite_version.data > tmp 128mv tmp tests/suites/test_suite_version.data 129 130[ $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; 132do 133 sed -e "s/\\([Mm]bed TLS v\\)[0-9][0-9.]*/\\1$VERSION/g" < $i > tmp 134 mv tmp $i 135done 136 137[ $VERBOSE ] && echo "Re-generating library/error.c" 138scripts/generate_errors.pl 139 140[ $VERBOSE ] && echo "Re-generating programs/test/query_config.c" 141scripts/generate_query_config.pl 142 143[ $VERBOSE ] && echo "Re-generating library/version_features.c" 144scripts/generate_features.pl 145 146[ $VERBOSE ] && echo "Re-generating visualc files" 147scripts/generate_visualc_files.pl 148 149