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 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 () { 37 cat <<'EOF' 38/* 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/config.h" 60 61EOF 62 63 for header in include/mbedtls/*.h include/psa/*.h; do 64 case ${header#include/} in 65 psa/crypto_config.h) :;; # not meant for direct inclusion 66 # Some of the psa/crypto_*.h headers are not meant to be included directly. 67 # They do have include guards that make them no-ops if psa/crypto.h 68 # has been included before. Since psa/crypto.h comes before psa/crypto_*.h 69 # in the wildcard enumeration, we don't need to skip those headers. 70 *) echo "#include \"${header#include/}\"";; 71 esac 72 done 73 74 cat <<'EOF' 75 76int main() 77{ 78 mbedtls_platform_context *ctx = NULL; 79 mbedtls_platform_setup(ctx); 80 mbedtls_printf("CPP Build test passed\n"); 81 mbedtls_platform_teardown(ctx); 82} 83EOF 84} 85 86if [ -d include/mbedtls ]; then 87 : 88elif [ -d ../include/mbedtls ]; then 89 cd .. 90elif [ -d ../../include/mbedtls ]; then 91 cd ../.. 92else 93 echo >&2 "This script must be run from an Mbed TLS source tree." 94 exit 3 95fi 96 97print_cpp >"${1:-$DEFAULT_OUTPUT_FILE}" 98