blob: a70e6daef32d61a49ea2a491b6cffcb511b78806 [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
Dave Rodgman16799db2023-11-02 19:47:20 +00005 * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
Andres AG509ba692018-10-26 18:41:08 +01006 */
7
Bence Szépkútic662b362021-05-27 11:25:03 +02008#include "mbedtls/build_info.h"
Andres AG509ba692018-10-26 18:41:08 +01009
Andres AG509ba692018-10-26 18:41:08 +010010#include "mbedtls/platform.h"
Andres AG509ba692018-10-26 18:41:08 +010011
Jerry Yu2fcb0562022-07-27 17:30:49 +080012#define USAGE \
13 "usage: %s [ -all | -any | -l ] <MBEDTLS_CONFIG> ...\n\n" \
14 "This program takes command line arguments which correspond to\n" \
15 "the string representation of Mbed TLS compile time configurations.\n\n" \
Jerry Yu08dccc12022-08-10 10:02:04 +080016 "If \"--all\" and \"--any\" are not used, then, if all given arguments\n" \
17 "are defined in the Mbed TLS build, 0 is returned; otherwise 1 is\n" \
Jerry Yu62c87632022-08-11 10:18:36 +080018 "returned. Macro expansions of configurations will be printed (if any).\n" \
Jerry Yu2fcb0562022-07-27 17:30:49 +080019 "-l\tPrint all available configuration.\n" \
20 "-all\tReturn 0 if all configurations are defined. Otherwise, return 1\n" \
21 "-any\tReturn 0 if any configuration is defined. Otherwise, return 1\n" \
22 "-h\tPrint this usage\n"
23
Jerry Yua15f3cc2021-12-06 13:44:39 +080024#include <string.h>
Gilles Peskinec772b182021-01-12 15:55:10 +010025#include "query_config.h"
Andres AG509ba692018-10-26 18:41:08 +010026
Gilles Peskine449bd832023-01-11 14:50:10 +010027int main(int argc, char *argv[])
Andres AG509ba692018-10-26 18:41:08 +010028{
Jerry Yu2fcb0562022-07-27 17:30:49 +080029 int i;
30
Aditya Deshpande9b45f6b2023-02-03 16:15:30 +000031 if (argc < 2 || strcmp(argv[1], "-h") == 0) {
Gilles Peskine449bd832023-01-11 14:50:10 +010032 mbedtls_printf(USAGE, argv[0]);
33 return MBEDTLS_EXIT_FAILURE;
Andres AG509ba692018-10-26 18:41:08 +010034 }
35
Gilles Peskine449bd832023-01-11 14:50:10 +010036 if (strcmp(argv[1], "-l") == 0) {
Jerry Yua15f3cc2021-12-06 13:44:39 +080037 list_config();
Gilles Peskine449bd832023-01-11 14:50:10 +010038 return 0;
Jerry Yua15f3cc2021-12-06 13:44:39 +080039 }
40
Gilles Peskine449bd832023-01-11 14:50:10 +010041 if (strcmp(argv[1], "-all") == 0) {
42 for (i = 2; i < argc; i++) {
43 if (query_config(argv[i]) != 0) {
44 return 1;
45 }
Jerry Yu2fcb0562022-07-27 17:30:49 +080046 }
Gilles Peskine449bd832023-01-11 14:50:10 +010047 return 0;
Jerry Yu2fcb0562022-07-27 17:30:49 +080048 }
49
Gilles Peskine449bd832023-01-11 14:50:10 +010050 if (strcmp(argv[1], "-any") == 0) {
51 for (i = 2; i < argc; i++) {
52 if (query_config(argv[i]) == 0) {
53 return 0;
54 }
Jerry Yu2fcb0562022-07-27 17:30:49 +080055 }
Gilles Peskine449bd832023-01-11 14:50:10 +010056 return 1;
Jerry Yu2fcb0562022-07-27 17:30:49 +080057 }
58
Gilles Peskine449bd832023-01-11 14:50:10 +010059 for (i = 1; i < argc; i++) {
60 if (query_config(argv[i]) != 0) {
61 return 1;
62 }
Jerry Yu2fcb0562022-07-27 17:30:49 +080063 }
64
Gilles Peskine449bd832023-01-11 14:50:10 +010065 return 0;
Andres AG509ba692018-10-26 18:41:08 +010066}