blob: fb0743db9e80a7afc1a80208f36819738abcd426 [file] [log] [blame]
Gilles Peskine9b356402021-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 () {
Gilles Peskine560e1dc2021-08-05 15:10:27 +020024 cat <<'EOF'
Gilles Peskine9b356402021-07-09 15:19:28 +020025/* 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/config.h"
47
48EOF
49
50 for header in include/mbedtls/*.h include/psa/*.h; do
51 case ${header#include/} in
52 psa/crypto_config.h) :;; # not meant for direct inclusion
53 # Some of the psa/crypto_*.h headers are not meant to be included directly.
54 # They do have include guards that make them no-ops if psa/crypto.h
55 # has been included before. Since psa/crypto.h comes before psa/crypto_*.h
56 # in the wildcard enumeration, we don't need to skip those headers.
57 *) echo "#include \"${header#include/}\"";;
58 esac
59 done
60
Gilles Peskine560e1dc2021-08-05 15:10:27 +020061 cat <<'EOF'
Gilles Peskine9b356402021-07-09 15:19:28 +020062
63int main()
64{
65 mbedtls_platform_context *ctx = NULL;
66 mbedtls_platform_setup(ctx);
67 mbedtls_printf("CPP Build test passed\n");
68 mbedtls_platform_teardown(ctx);
69}
70EOF
71}
72
73if [ -d include/mbedtls ]; then
Gilles Peskine560e1dc2021-08-05 15:10:27 +020074 :
Gilles Peskine9b356402021-07-09 15:19:28 +020075elif [ -d ../include/mbedtls ]; then
Gilles Peskine560e1dc2021-08-05 15:10:27 +020076 cd ..
Gilles Peskine9b356402021-07-09 15:19:28 +020077elif [ -d ../../include/mbedtls ]; then
Gilles Peskine560e1dc2021-08-05 15:10:27 +020078 cd ../..
Gilles Peskine9b356402021-07-09 15:19:28 +020079else
Gilles Peskine560e1dc2021-08-05 15:10:27 +020080 echo >&2 "This script must be run from an Mbed TLS source tree."
81 exit 3
Gilles Peskine9b356402021-07-09 15:19:28 +020082fi
83
84print_cpp >"${1:-programs/test/cpp_dummy_build.cpp}"