blob: 94e911515d3ef47bdf6fe9f3522476bebb307b09 [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
66 psa/crypto_config.h) :;; # not meant for direct inclusion
67 # Some of the psa/crypto_*.h headers are not meant to be included
68 # directly. They do have include guards that make them no-ops if
69 # psa/crypto.h has been included before. Since psa/crypto.h comes
70 # before psa/crypto_*.h in the wildcard enumeration, we don't need
71 # to skip those headers.
72 *) echo "#include \"${header#include/}\"";;
73 esac
74 done
Gilles Peskine03ab5442021-07-09 15:19:28 +020075
Gilles Peskine3cbd69c2021-08-05 15:10:27 +020076 cat <<'EOF'
Gilles Peskine03ab5442021-07-09 15:19:28 +020077
78int main()
79{
80 mbedtls_platform_context *ctx = NULL;
81 mbedtls_platform_setup(ctx);
82 mbedtls_printf("CPP Build test passed\n");
83 mbedtls_platform_teardown(ctx);
84}
85EOF
86}
87
88if [ -d include/mbedtls ]; then
Gilles Peskine3cbd69c2021-08-05 15:10:27 +020089 :
Gilles Peskine03ab5442021-07-09 15:19:28 +020090elif [ -d ../include/mbedtls ]; then
Gilles Peskine3cbd69c2021-08-05 15:10:27 +020091 cd ..
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 +020094else
Gilles Peskine3cbd69c2021-08-05 15:10:27 +020095 echo >&2 "This script must be run from an Mbed TLS source tree."
96 exit 3
Gilles Peskine03ab5442021-07-09 15:19:28 +020097fi
98
Gilles Peskine91e890e2021-08-05 15:13:57 +020099print_cpp >"${1:-$DEFAULT_OUTPUT_FILE}"