blob: 5baa41cb5abae2d8bc1a290dbacdfeefa787878b [file] [log] [blame]
Andres AG509ba692018-10-26 18:41:08 +01001/*
2 * Query the Mbed TLS compile time configuration
3 *
Bence Szépkúti1e148272020-08-07 13:07:28 +02004 * Copyright The Mbed TLS Contributors
Andres AG509ba692018-10-26 18:41:08 +01005 * SPDX-License-Identifier: Apache-2.0
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may
8 * not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
Andres AG509ba692018-10-26 18:41:08 +010018 */
19
Bence Szépkútic662b362021-05-27 11:25:03 +020020#include "mbedtls/build_info.h"
Andres AG509ba692018-10-26 18:41:08 +010021
22#if defined(MBEDTLS_PLATFORM_C)
23#include "mbedtls/platform.h"
24#else
25#include <stdio.h>
26#include <stdlib.h>
27#define mbedtls_printf printf
28#define MBEDTLS_EXIT_FAILURE EXIT_FAILURE
29#endif
30
Jerry Yu2fcb0562022-07-27 17:30:49 +080031#define USAGE \
32 "usage: %s [ -all | -any | -l ] <MBEDTLS_CONFIG> ...\n\n" \
33 "This program takes command line arguments which correspond to\n" \
34 "the string representation of Mbed TLS compile time configurations.\n\n" \
Jerry Yu08dccc12022-08-10 10:02:04 +080035 "If \"--all\" and \"--any\" are not used, then, if all given arguments\n" \
36 "are defined in the Mbed TLS build, 0 is returned; otherwise 1 is\n" \
37 "returned. If only one argument is given, the macro expansion of that\n" \
38 "configuration will be printed (if any).\n" \
Jerry Yu2fcb0562022-07-27 17:30:49 +080039 "-l\tPrint all available configuration.\n" \
40 "-all\tReturn 0 if all configurations are defined. Otherwise, return 1\n" \
41 "-any\tReturn 0 if any configuration is defined. Otherwise, return 1\n" \
42 "-h\tPrint this usage\n"
43
Jerry Yua15f3cc2021-12-06 13:44:39 +080044#include <string.h>
Gilles Peskinec772b182021-01-12 15:55:10 +010045#include "query_config.h"
Andres AG509ba692018-10-26 18:41:08 +010046
47int main( int argc, char *argv[] )
48{
Jerry Yu2fcb0562022-07-27 17:30:49 +080049 int i;
50
51 if ( argc == 1 || strcmp( argv[1], "-h" ) == 0 )
Andres AG509ba692018-10-26 18:41:08 +010052 {
53 mbedtls_printf( USAGE, argv[0] );
54 return( MBEDTLS_EXIT_FAILURE );
55 }
56
Jerry Yua15f3cc2021-12-06 13:44:39 +080057 if( strcmp( argv[1], "-l" ) == 0 )
58 {
59 list_config();
60 return( 0 );
61 }
62
Jerry Yu2fcb0562022-07-27 17:30:49 +080063 if( strcmp( argv[1], "-all" ) == 0 )
64 {
65 for( i = 2; i < argc; i++ )
66 {
67 if( query_config( argv[i] ) != 0 )
68 return( 1 );
69 }
70 return( 0 );
71 }
72
73 if( strcmp( argv[1], "-any" ) == 0 )
74 {
75 for( i = 2; i < argc; i++ )
76 {
77 if( query_config( argv[i] ) == 0 )
78 return( 0 );
79 }
80 return( 1 );
81 }
82
83 for( i = 1; i < argc; i++ )
84 {
85 if( query_config( argv[i] ) != 0 )
86 return( 1 );
87 }
88
89 return( 0 );
Andres AG509ba692018-10-26 18:41:08 +010090}