bump_version.sh 5.0 KB

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