blob: ef9996e4c2db76f65b3e078be3e5797ea761ac66 [file] [log] [blame]
Gilles Peskine03ab5442021-07-09 15:19:28 +02001#!/bin/sh
2
Gilles Peskine91e890e2021-08-05 15:13:57 +02003DEFAULT_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
Gilles Peskine03ab5442021-07-09 15:19:28 +020016# Copyright The Mbed TLS Contributors
Dave Rodgman16799db2023-11-02 19:47:20 +000017# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
Gilles Peskine03ab5442021-07-09 15:19:28 +020018
19set -e
20
21# Ensure a reproducible order for *.h
22export LC_ALL=C
23
24print_cpp () {
Gilles Peskine3cbd69c2021-08-05 15:10:27 +020025 cat <<'EOF'
Gilles Peskine03ab5442021-07-09 15:19:28 +020026/* 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
Dave Rodgman16799db2023-11-02 19:47:20 +000032 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
Gilles Peskine03ab5442021-07-09 15:19:28 +020033 *
Gilles Peskine03ab5442021-07-09 15:19:28 +020034 */
35
36#include "mbedtls/build_info.h"
37
38EOF
39
Ronald Cron7e5d61c2024-06-10 14:25:46 +020040 for header in include/mbedtls/*.h; do
Gilles Peskine3cbd69c2021-08-05 15:10:27 +020041 case ${header#include/} in
42 mbedtls/mbedtls_config.h) :;; # not meant for direct inclusion
Gilles Peskine9af413b2023-05-18 20:12:44 +020043 mbedtls/config_*.h) :;; # not meant for direct inclusion
Ronald Cron7e5d61c2024-06-10 14:25:46 +020044 *) echo "#include \"${header#include/}\"";;
45 esac
46 done
47
48 for header in tf-psa-crypto/include/psa/*.h; do
49 case ${header#tf-psa-crypto/include/} in
Gilles Peskine3cbd69c2021-08-05 15:10:27 +020050 psa/crypto_config.h) :;; # not meant for direct inclusion
Gilles Peskineb9664ee2023-09-04 16:54:38 +020051 psa/crypto_ajdust_config*.h) :;; # not meant for direct inclusion
Gilles Peskine3cbd69c2021-08-05 15:10:27 +020052 # Some of the psa/crypto_*.h headers are not meant to be included
53 # directly. They do have include guards that make them no-ops if
54 # psa/crypto.h has been included before. Since psa/crypto.h comes
55 # before psa/crypto_*.h in the wildcard enumeration, we don't need
56 # to skip those headers.
Ronald Cron7e5d61c2024-06-10 14:25:46 +020057 *) echo "#include \"${header#tf-psa-crypto/include/}\"";;
Gilles Peskine3cbd69c2021-08-05 15:10:27 +020058 esac
59 done
Gilles Peskine03ab5442021-07-09 15:19:28 +020060
Gilles Peskine3cbd69c2021-08-05 15:10:27 +020061 cat <<'EOF'
Gilles Peskine03ab5442021-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 Peskine3cbd69c2021-08-05 15:10:27 +020074 :
Gilles Peskine03ab5442021-07-09 15:19:28 +020075elif [ -d ../include/mbedtls ]; then
Gilles Peskine3cbd69c2021-08-05 15:10:27 +020076 cd ..
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 +020079else
Gilles Peskine3cbd69c2021-08-05 15:10:27 +020080 echo >&2 "This script must be run from an Mbed TLS source tree."
81 exit 3
Gilles Peskine03ab5442021-07-09 15:19:28 +020082fi
83
Gilles Peskine91e890e2021-08-05 15:13:57 +020084print_cpp >"${1:-$DEFAULT_OUTPUT_FILE}"