generate_cpp_dummy_build.sh 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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/config.h"
  53. EOF
  54. for header in include/mbedtls/*.h include/psa/*.h; do
  55. case ${header#include/} in
  56. psa/crypto_config.h) :;; # not meant for direct inclusion
  57. # Some of the psa/crypto_*.h headers are not meant to be included directly.
  58. # They do have include guards that make them no-ops if psa/crypto.h
  59. # has been included before. Since psa/crypto.h comes before psa/crypto_*.h
  60. # in the wildcard enumeration, we don't need to skip those headers.
  61. *) echo "#include \"${header#include/}\"";;
  62. esac
  63. done
  64. cat <<'EOF'
  65. int main()
  66. {
  67. mbedtls_platform_context *ctx = NULL;
  68. mbedtls_platform_setup(ctx);
  69. mbedtls_printf("CPP Build test passed\n");
  70. mbedtls_platform_teardown(ctx);
  71. }
  72. EOF
  73. }
  74. if [ -d include/mbedtls ]; then
  75. :
  76. elif [ -d ../include/mbedtls ]; then
  77. cd ..
  78. elif [ -d ../../include/mbedtls ]; then
  79. cd ../..
  80. else
  81. echo >&2 "This script must be run from an Mbed TLS source tree."
  82. exit 3
  83. fi
  84. print_cpp >"${1:-$DEFAULT_OUTPUT_FILE}"