Gilles Peskine | 03ab544 | 2021-07-09 15:19:28 +0200 | [diff] [blame^] | 1 | #!/bin/sh |
| 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 | set -e |
| 19 | |
| 20 | # Ensure a reproducible order for *.h |
| 21 | export LC_ALL=C |
| 22 | |
| 23 | print_cpp () { |
| 24 | cat <<'EOF' |
| 25 | /* Automatically generated file. Do not edit. |
| 26 | * |
| 27 | * This program is a dummy C++ program to ensure Mbed TLS library header files |
| 28 | * can be included and built with a C++ compiler. |
| 29 | * |
| 30 | * Copyright The Mbed TLS Contributors |
| 31 | * SPDX-License-Identifier: Apache-2.0 |
| 32 | * |
| 33 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 34 | * not use this file except in compliance with the License. |
| 35 | * You may obtain a copy of the License at |
| 36 | * |
| 37 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 38 | * |
| 39 | * Unless required by applicable law or agreed to in writing, software |
| 40 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 41 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 42 | * See the License for the specific language governing permissions and |
| 43 | * limitations under the License. |
| 44 | */ |
| 45 | |
| 46 | #include "mbedtls/build_info.h" |
| 47 | |
| 48 | EOF |
| 49 | |
| 50 | for header in include/mbedtls/*.h include/psa/*.h; do |
| 51 | case ${header#include/} in |
| 52 | mbedtls/mbedtls_config.h) :;; # not meant for direct inclusion |
| 53 | psa/crypto_config.h) :;; # not meant for direct inclusion |
| 54 | # Some of the psa/crypto_*.h headers are not meant to be included directly. |
| 55 | # They do have include guards that make them no-ops if psa/crypto.h |
| 56 | # has been included before. Since psa/crypto.h comes before psa/crypto_*.h |
| 57 | # in the wildcard enumeration, we don't need to skip those headers. |
| 58 | *) echo "#include \"${header#include/}\"";; |
| 59 | esac |
| 60 | done |
| 61 | |
| 62 | cat <<'EOF' |
| 63 | |
| 64 | int main() |
| 65 | { |
| 66 | mbedtls_platform_context *ctx = NULL; |
| 67 | mbedtls_platform_setup(ctx); |
| 68 | mbedtls_printf("CPP Build test passed\n"); |
| 69 | mbedtls_platform_teardown(ctx); |
| 70 | } |
| 71 | EOF |
| 72 | } |
| 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 | |
| 85 | print_cpp >"${1:-programs/test/cpp_dummy_build.cpp}" |