1#!/bin/sh
2
3DEFAULT_OUTPUT_FILE=programs/test/cpp_dummy_build.cpp
4
5if [ "$1" = "--help" ]; then
6    cat <<EOF
7Usage: $0 [OUTPUT]
8Generate a C++ dummy build program that includes all the headers.
9OUTPUT defaults to "programs/test/cpp_dummy_build.cpp".
10Run this program from the root of an Mbed TLS directory tree or from
11its "programs" or "programs/test" subdirectory.
12EOF
13    exit
14fi
15
16# Copyright The Mbed TLS Contributors
17# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
18
19set -e
20
21# Ensure a reproducible order for *.h
22export LC_ALL=C
23
24print_cpp () {
25    cat <<'EOF'
26/* Automatically generated file. Do not edit.
27 *
28 *  This program is a dummy C++ program to ensure Mbed TLS library header files
29 *  can be included and built with a C++ compiler.
30 *
31 *  Copyright The Mbed TLS Contributors
32 *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
33 *
34 */
35
36#include "mbedtls/build_info.h"
37
38EOF
39
40    for header in include/mbedtls/*.h include/psa/*.h; do
41        case ${header#include/} in
42            mbedtls/mbedtls_config.h) :;; # not meant for direct inclusion
43            mbedtls/config_*.h) :;; # not meant for direct inclusion
44            psa/crypto_config.h) :;; # not meant for direct inclusion
45            psa/crypto_ajdust_config*.h) :;; # not meant for direct inclusion
46            # Some of the psa/crypto_*.h headers are not meant to be included
47            # directly. They do have include guards that make them no-ops if
48            # psa/crypto.h has been included before. Since psa/crypto.h comes
49            # before psa/crypto_*.h in the wildcard enumeration, we don't need
50            # to skip those headers.
51            *) echo "#include \"${header#include/}\"";;
52        esac
53    done
54
55    cat <<'EOF'
56
57int main()
58{
59    mbedtls_platform_context *ctx = NULL;
60    mbedtls_platform_setup(ctx);
61    mbedtls_printf("CPP Build test passed\n");
62    mbedtls_platform_teardown(ctx);
63}
64EOF
65}
66
67if [ -d include/mbedtls ]; then
68    :
69elif [ -d ../include/mbedtls ]; then
70    cd ..
71elif [ -d ../../include/mbedtls ]; then
72    cd ../..
73else
74    echo >&2 "This script must be run from an Mbed TLS source tree."
75    exit 3
76fi
77
78print_cpp >"${1:-$DEFAULT_OUTPUT_FILE}"
79