bump_version.sh 5.1 KB

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