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 () { |
Gilles Peskine | 3cbd69c | 2021-08-05 15:10:27 +0200 | [diff] [blame] | 24 | cat <<'EOF' |
Gilles Peskine | 03ab544 | 2021-07-09 15:19:28 +0200 | [diff] [blame] | 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 | |
Gilles Peskine | 3cbd69c | 2021-08-05 15:10:27 +0200 | [diff] [blame] | 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 |
| 55 | # directly. They do have include guards that make them no-ops if |
| 56 | # psa/crypto.h has been included before. Since psa/crypto.h comes |
| 57 | # before psa/crypto_*.h in the wildcard enumeration, we don't need |
| 58 | # to skip those headers. |
| 59 | *) echo "#include \"${header#include/}\"";; |
| 60 | esac |
| 61 | done |
Gilles Peskine | 03ab544 | 2021-07-09 15:19:28 +0200 | [diff] [blame] | 62 | |
Gilles Peskine | 3cbd69c | 2021-08-05 15:10:27 +0200 | [diff] [blame] | 63 | cat <<'EOF' |
Gilles Peskine | 03ab544 | 2021-07-09 15:19:28 +0200 | [diff] [blame] | 64 | |
| 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 | |
| 75 | if [ -d include/mbedtls ]; then |
Gilles Peskine | 3cbd69c | 2021-08-05 15:10:27 +0200 | [diff] [blame] | 76 | : |
Gilles Peskine | 03ab544 | 2021-07-09 15:19:28 +0200 | [diff] [blame] | 77 | elif [ -d ../include/mbedtls ]; then |
Gilles Peskine | 3cbd69c | 2021-08-05 15:10:27 +0200 | [diff] [blame] | 78 | cd .. |
Gilles Peskine | 03ab544 | 2021-07-09 15:19:28 +0200 | [diff] [blame] | 79 | elif [ -d ../../include/mbedtls ]; then |
Gilles Peskine | 3cbd69c | 2021-08-05 15:10:27 +0200 | [diff] [blame] | 80 | cd ../.. |
Gilles Peskine | 03ab544 | 2021-07-09 15:19:28 +0200 | [diff] [blame] | 81 | else |
Gilles Peskine | 3cbd69c | 2021-08-05 15:10:27 +0200 | [diff] [blame] | 82 | echo >&2 "This script must be run from an Mbed TLS source tree." |
| 83 | exit 3 |
Gilles Peskine | 03ab544 | 2021-07-09 15:19:28 +0200 | [diff] [blame] | 84 | fi |
| 85 | |
| 86 | print_cpp >"${1:-programs/test/cpp_dummy_build.cpp}" |