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/build_info.h" 60 61EOF 62 63 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 75 76 cat <<'EOF' 77 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 89 : 90elif [ -d ../include/mbedtls ]; then 91 cd .. 92elif [ -d ../../include/mbedtls ]; then 93 cd ../.. 94else 95 echo >&2 "This script must be run from an Mbed TLS source tree." 96 exit 3 97fi 98 99print_cpp >"${1:-$DEFAULT_OUTPUT_FILE}" 100