generate_cpp_dummy_build.sh 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #!/bin/sh
  2. DEFAULT_OUTPUT_FILE=programs/test/cpp_dummy_build.cpp
  3. if [ "$1" = "--help" ]; then
  4. cat <<EOF
  5. Usage: $0 [OUTPUT]
  6. Generate a C++ dummy build program that includes all the headers.
  7. OUTPUT defaults to "programs/test/cpp_dummy_build.cpp".
  8. Run this program from the root of an Mbed TLS directory tree or from
  9. its "programs" or "programs/test" subdirectory.
  10. EOF
  11. exit
  12. fi
  13. # Copyright The Mbed TLS Contributors
  14. # SPDX-License-Identifier: Apache-2.0
  15. #
  16. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  17. # not use this file except in compliance with the License.
  18. # You may obtain a copy of the License at
  19. #
  20. # http://www.apache.org/licenses/LICENSE-2.0
  21. #
  22. # Unless required by applicable law or agreed to in writing, software
  23. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  24. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  25. # See the License for the specific language governing permissions and
  26. # limitations under the License.
  27. set -e
  28. # Ensure a reproducible order for *.h
  29. export LC_ALL=C
  30. print_cpp () {
  31. cat <<'EOF'
  32. /* Automatically generated file. Do not edit.
  33. *
  34. * This program is a dummy C++ program to ensure Mbed TLS library header files
  35. * can be included and built with a C++ compiler.
  36. *
  37. * Copyright The Mbed TLS Contributors
  38. * SPDX-License-Identifier: Apache-2.0
  39. *
  40. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  41. * not use this file except in compliance with the License.
  42. * You may obtain a copy of the License at
  43. *
  44. * http://www.apache.org/licenses/LICENSE-2.0
  45. *
  46. * Unless required by applicable law or agreed to in writing, software
  47. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  48. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  49. * See the License for the specific language governing permissions and
  50. * limitations under the License.
  51. */
  52. #include "mbedtls/build_info.h"
  53. EOF
  54. for header in include/mbedtls/*.h include/psa/*.h; do
  55. case ${header#include/} in
  56. mbedtls/mbedtls_config.h) :;; # not meant for direct inclusion
  57. psa/crypto_config.h) :;; # not meant for direct inclusion
  58. # Some of the psa/crypto_*.h headers are not meant to be included
  59. # directly. They do have include guards that make them no-ops if
  60. # psa/crypto.h has been included before. Since psa/crypto.h comes
  61. # before psa/crypto_*.h in the wildcard enumeration, we don't need
  62. # to skip those headers.
  63. *) echo "#include \"${header#include/}\"";;
  64. esac
  65. done
  66. cat <<'EOF'
  67. int main()
  68. {
  69. mbedtls_platform_context *ctx = NULL;
  70. mbedtls_platform_setup(ctx);
  71. mbedtls_printf("CPP Build test passed\n");
  72. mbedtls_platform_teardown(ctx);
  73. }
  74. EOF
  75. }
  76. if [ -d include/mbedtls ]; then
  77. :
  78. elif [ -d ../include/mbedtls ]; then
  79. cd ..
  80. elif [ -d ../../include/mbedtls ]; then
  81. cd ../..
  82. else
  83. echo >&2 "This script must be run from an Mbed TLS source tree."
  84. exit 3
  85. fi
  86. print_cpp >"${1:-$DEFAULT_OUTPUT_FILE}"