blob: a55051652628b80ab87cc57e826e9078df5f3ced [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
17# SPDX-License-Identifier: Apache-2.0
18#
19# Licensed under the Apache License, Version 2.0 (the "License"); you may
20# not use this file except in compliance with the License.
21# You may obtain a copy of the License at
22#
23# http://www.apache.org/licenses/LICENSE-2.0
24#
25# Unless required by applicable law or agreed to in writing, software
26# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
27# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
28# See the License for the specific language governing permissions and
29# limitations under the License.
30
31set -e
32
33# Ensure a reproducible order for *.h
34export LC_ALL=C
35
36print_cpp () {
Gilles Peskine3cbd69c2021-08-05 15:10:27 +020037 cat <<'EOF'
Gilles Peskine03ab5442021-07-09 15:19:28 +020038/* Automatically generated file. Do not edit.
39 *
40 * This program is a dummy C++ program to ensure Mbed TLS library header files
41 * can be included and built with a C++ compiler.
42 *
43 * Copyright The Mbed TLS Contributors
44 * SPDX-License-Identifier: Apache-2.0
45 *
46 * Licensed under the Apache License, Version 2.0 (the "License"); you may
47 * not use this file except in compliance with the License.
48 * You may obtain a copy of the License at
49 *
50 * http://www.apache.org/licenses/LICENSE-2.0
51 *
52 * Unless required by applicable law or agreed to in writing, software
53 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
54 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
55 * See the License for the specific language governing permissions and
56 * limitations under the License.
57 */
58
59#include "mbedtls/build_info.h"
60
61EOF
62
Gilles Peskine3cbd69c2021-08-05 15:10:27 +020063 for header in include/mbedtls/*.h include/psa/*.h; do
64 case ${header#include/} in
65 mbedtls/mbedtls_config.h) :;; # not meant for direct inclusion
Gilles Peskine9af413b2023-05-18 20:12:44 +020066 mbedtls/config_*.h) :;; # not meant for direct inclusion
Gilles Peskine3cbd69c2021-08-05 15:10:27 +020067 psa/crypto_config.h) :;; # not meant for direct inclusion
Gilles Peskineb9664ee2023-09-04 16:54:38 +020068 psa/crypto_ajdust_config*.h) :;; # not meant for direct inclusion
Gilles Peskine3cbd69c2021-08-05 15:10:27 +020069 # Some of the psa/crypto_*.h headers are not meant to be included
70 # directly. They do have include guards that make them no-ops if
71 # psa/crypto.h has been included before. Since psa/crypto.h comes
72 # before psa/crypto_*.h in the wildcard enumeration, we don't need
73 # to skip those headers.
74 *) echo "#include \"${header#include/}\"";;
75 esac
76 done
Gilles Peskine03ab5442021-07-09 15:19:28 +020077
Gilles Peskine3cbd69c2021-08-05 15:10:27 +020078 cat <<'EOF'
Gilles Peskine03ab5442021-07-09 15:19:28 +020079
80int main()
81{
82 mbedtls_platform_context *ctx = NULL;
83 mbedtls_platform_setup(ctx);
84 mbedtls_printf("CPP Build test passed\n");
85 mbedtls_platform_teardown(ctx);
86}
87EOF
88}
89
90if [ -d include/mbedtls ]; then
Gilles Peskine3cbd69c2021-08-05 15:10:27 +020091 :
Gilles Peskine03ab5442021-07-09 15:19:28 +020092elif [ -d ../include/mbedtls ]; then
Gilles Peskine3cbd69c2021-08-05 15:10:27 +020093 cd ..
Gilles Peskine03ab5442021-07-09 15:19:28 +020094elif [ -d ../../include/mbedtls ]; then
Gilles Peskine3cbd69c2021-08-05 15:10:27 +020095 cd ../..
Gilles Peskine03ab5442021-07-09 15:19:28 +020096else
Gilles Peskine3cbd69c2021-08-05 15:10:27 +020097 echo >&2 "This script must be run from an Mbed TLS source tree."
98 exit 3
Gilles Peskine03ab5442021-07-09 15:19:28 +020099fi
100
Gilles Peskine91e890e2021-08-05 15:13:57 +0200101print_cpp >"${1:-$DEFAULT_OUTPUT_FILE}"