bump_version.sh 5.9 KB

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