• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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# 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:
11#
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#
24# **********
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#
45# 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#
53
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      ;;
67    --so-crypto)
68      shift
69      SO_CRYPTO=$1
70      ;;
71    --so-x509)
72      shift
73      SO_X509=$1
74      ;;
75    --so-tls)
76      shift
77      SO_TLS=$1
78      ;;
79    -v|--verbose)
80      # Be verbose
81      VERBOSE="1"
82      ;;
83    -h|--help)
84      # print help
85      echo "Usage: $0"
86      echo -e "  -h|--help\t\tPrint this help."
87      echo -e "  --version <version>\tVersion to bump to."
88      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."
91      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"
110sed -e "s/ VERSION [0-9.]\{1,\}/ VERSION $VERSION/g" < library/CMakeLists.txt > tmp
111mv tmp library/CMakeLists.txt
112
113if [ "X" != "X$SO_CRYPTO" ];
114then
115  [ $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
117  mv tmp library/CMakeLists.txt
118
119  [ $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
143  mv tmp library/Makefile
144fi
145
146[ $VERBOSE ] && echo "Bumping VERSION in include/mbedtls/version.h"
147read MAJOR MINOR PATCH <<<$(IFS="."; echo $VERSION)
148VERSION_NR="$( printf "0x%02X%02X%02X00" $MAJOR $MINOR $PATCH )"
149cat include/mbedtls/version.h |                                    \
150    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\"/" \
156    > tmp
157mv tmp include/mbedtls/version.h
158
159[ $VERBOSE ] && echo "Bumping version in tests/suites/test_suite_version.data"
160sed -e "s/version:\".\{1,\}/version:\"$VERSION\"/g" < tests/suites/test_suite_version.data > tmp
161mv tmp tests/suites/test_suite_version.data
162
163[ $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;
165do
166  sed -e "s/mbed TLS v[0-9\.]\{1,\}/mbed TLS v$VERSION/g" < $i > tmp
167  mv tmp $i
168done
169
170[ $VERBOSE ] && echo "Re-generating library/error.c"
171scripts/generate_errors.pl
172
173[ $VERBOSE ] && echo "Re-generating programs/ssl/query_config.c"
174scripts/generate_query_config.pl
175
176[ $VERBOSE ] && echo "Re-generating library/version_features.c"
177scripts/generate_features.pl
178
179[ $VERBOSE ] && echo "Re-generating visualc files"
180scripts/generate_visualc_files.pl
181
182