blob: 41adf149ebe88e29fc5f489965b98ba9e5822867 [file] [log] [blame]
Gilles Peskine03ab5442021-07-09 15:19:28 +02001#!/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
18set -e
19
20# Ensure a reproducible order for *.h
21export LC_ALL=C
22
23print_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
48EOF
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
64int 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}
71EOF
72}
73
74if [ -d include/mbedtls ]; then
75 :
76elif [ -d ../include/mbedtls ]; then
77 cd ..
78elif [ -d ../../include/mbedtls ]; then
79 cd ../..
80else
81 echo >&2 "This script must be run from an Mbed TLS source tree."
82 exit 3
83fi
84
85print_cpp >"${1:-programs/test/cpp_dummy_build.cpp}"