blob: 2255986d24ddae150516470ae78149fc868b7927 [file] [log] [blame]
Gilles Peskine9b356402021-07-09 15:19:28 +02001#!/bin/sh
2
Gilles Peskine6eb80072021-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 Peskine9b356402021-07-09 15:19:28 +020016# Copyright The Mbed TLS Contributors
Dave Rodgman7ff79652023-11-03 12:04:52 +000017# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
Gilles Peskine9b356402021-07-09 15:19:28 +020018
19set -e
20
21# Ensure a reproducible order for *.h
22export LC_ALL=C
23
24print_cpp () {
Gilles Peskine560e1dc2021-08-05 15:10:27 +020025 cat <<'EOF'
Gilles Peskine9b356402021-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 Rodgman7ff79652023-11-03 12:04:52 +000032 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
Gilles Peskine9b356402021-07-09 15:19:28 +020033 *
Gilles Peskine9b356402021-07-09 15:19:28 +020034 */
35
36#include "mbedtls/config.h"
37
38EOF
39
40 for header in include/mbedtls/*.h include/psa/*.h; do
41 case ${header#include/} in
42 psa/crypto_config.h) :;; # not meant for direct inclusion
43 # Some of the psa/crypto_*.h headers are not meant to be included directly.
44 # They do have include guards that make them no-ops if psa/crypto.h
45 # has been included before. Since psa/crypto.h comes before psa/crypto_*.h
46 # in the wildcard enumeration, we don't need to skip those headers.
47 *) echo "#include \"${header#include/}\"";;
48 esac
49 done
50
Gilles Peskine560e1dc2021-08-05 15:10:27 +020051 cat <<'EOF'
Gilles Peskine9b356402021-07-09 15:19:28 +020052
53int main()
54{
55 mbedtls_platform_context *ctx = NULL;
56 mbedtls_platform_setup(ctx);
57 mbedtls_printf("CPP Build test passed\n");
58 mbedtls_platform_teardown(ctx);
59}
60EOF
61}
62
63if [ -d include/mbedtls ]; then
Gilles Peskine560e1dc2021-08-05 15:10:27 +020064 :
Gilles Peskine9b356402021-07-09 15:19:28 +020065elif [ -d ../include/mbedtls ]; then
Gilles Peskine560e1dc2021-08-05 15:10:27 +020066 cd ..
Gilles Peskine9b356402021-07-09 15:19:28 +020067elif [ -d ../../include/mbedtls ]; then
Gilles Peskine560e1dc2021-08-05 15:10:27 +020068 cd ../..
Gilles Peskine9b356402021-07-09 15:19:28 +020069else
Gilles Peskine560e1dc2021-08-05 15:10:27 +020070 echo >&2 "This script must be run from an Mbed TLS source tree."
71 exit 3
Gilles Peskine9b356402021-07-09 15:19:28 +020072fi
73
Gilles Peskine6eb80072021-08-05 15:13:57 +020074print_cpp >"${1:-$DEFAULT_OUTPUT_FILE}"