blob: 9e16348b529e9bc243d4fc0b25543051579a2f27 [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 () {
Gilles Peskine3cbd69c2021-08-05 15:10:27 +020024 cat <<'EOF'
Gilles Peskine03ab5442021-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/build_info.h"
47
48EOF
49
Gilles Peskine3cbd69c2021-08-05 15:10:27 +020050 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 Peskine03ab5442021-07-09 15:19:28 +020062
Gilles Peskine3cbd69c2021-08-05 15:10:27 +020063 cat <<'EOF'
Gilles Peskine03ab5442021-07-09 15:19:28 +020064
65int 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}
72EOF
73}
74
75if [ -d include/mbedtls ]; then
Gilles Peskine3cbd69c2021-08-05 15:10:27 +020076 :
Gilles Peskine03ab5442021-07-09 15:19:28 +020077elif [ -d ../include/mbedtls ]; then
Gilles Peskine3cbd69c2021-08-05 15:10:27 +020078 cd ..
Gilles Peskine03ab5442021-07-09 15:19:28 +020079elif [ -d ../../include/mbedtls ]; then
Gilles Peskine3cbd69c2021-08-05 15:10:27 +020080 cd ../..
Gilles Peskine03ab5442021-07-09 15:19:28 +020081else
Gilles Peskine3cbd69c2021-08-05 15:10:27 +020082 echo >&2 "This script must be run from an Mbed TLS source tree."
83 exit 3
Gilles Peskine03ab5442021-07-09 15:19:28 +020084fi
85
86print_cpp >"${1:-programs/test/cpp_dummy_build.cpp}"