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