fbrosson | 533407a | 2018-04-04 21:44:29 +0000 | [diff] [blame] | 1 | #!/usr/bin/env perl |
SimonB | 60f2cf9 | 2016-04-03 14:16:08 +0100 | [diff] [blame] | 2 | # |
| 3 | # This file is part of mbed TLS (https://tls.mbed.org) |
| 4 | # |
| 5 | # Copyright (c) 2014-2016, ARM Limited, All Rights Reserved |
| 6 | # |
| 7 | # Purpose |
| 8 | # |
| 9 | # Comments and uncomments #define lines in the given header file and optionally |
Simon Butcher | 4ae8691 | 2016-06-21 10:09:25 +0100 | [diff] [blame] | 10 | # sets their value or can get the value. This is to provide scripting control of |
| 11 | # what preprocessor symbols, and therefore what build time configuration flags |
| 12 | # are set in the 'config.h' file. |
SimonB | 60f2cf9 | 2016-04-03 14:16:08 +0100 | [diff] [blame] | 13 | # |
| 14 | # Usage: config.pl [-f <file> | --file <file>] [-o | --force] |
Simon Butcher | 4ae8691 | 2016-06-21 10:09:25 +0100 | [diff] [blame] | 15 | # [set <symbol> <value> | unset <symbol> | get <symbol> | |
| 16 | # full | realfull] |
SimonB | 60f2cf9 | 2016-04-03 14:16:08 +0100 | [diff] [blame] | 17 | # |
| 18 | # Full usage description provided below. |
| 19 | # |
Hanno Becker | 7c0f17d | 2017-09-28 11:49:46 +0100 | [diff] [blame] | 20 | # The following options are disabled instead of enabled with "full". |
SimonB | 60f2cf9 | 2016-04-03 14:16:08 +0100 | [diff] [blame] | 21 | # |
Gilles Peskine | 108ebf2 | 2020-04-28 10:26:43 +0200 | [diff] [blame] | 22 | # * Options that require additional build dependencies or unusual hardware. |
| 23 | # * Options that make testing less effective. |
| 24 | # * Options that are incompatible with other options, or more generally that |
| 25 | # interact with other parts of the code in such a way that a bulk enabling |
| 26 | # is not a good way to test them. |
| 27 | # * Options that remove features. |
SimonB | 60f2cf9 | 2016-04-03 14:16:08 +0100 | [diff] [blame] | 28 | # |
Gilles Peskine | 108ebf2 | 2020-04-28 10:26:43 +0200 | [diff] [blame] | 29 | # The baremetal configuration excludes options that require a library or |
| 30 | # operating system feature that is typically not present on bare metal |
| 31 | # systems. Features that are excluded from "full" won't be in "baremetal" |
| 32 | # either. |
Manuel Pégourié-Gonnard | ab3d862 | 2014-07-12 03:19:18 +0200 | [diff] [blame] | 33 | |
| 34 | use warnings; |
| 35 | use strict; |
| 36 | |
SimonB | 60f2cf9 | 2016-04-03 14:16:08 +0100 | [diff] [blame] | 37 | my $config_file = "include/mbedtls/config.h"; |
Manuel Pégourié-Gonnard | ab3d862 | 2014-07-12 03:19:18 +0200 | [diff] [blame] | 38 | my $usage = <<EOU; |
SimonB | 60f2cf9 | 2016-04-03 14:16:08 +0100 | [diff] [blame] | 39 | $0 [-f <file> | --file <file>] [-o | --force] |
Simon Butcher | 4ae8691 | 2016-06-21 10:09:25 +0100 | [diff] [blame] | 40 | [set <symbol> <value> | unset <symbol> | get <symbol> | |
Azim Khan | c3c3a68 | 2017-12-21 15:19:53 +0000 | [diff] [blame] | 41 | full | realfull | baremetal] |
Manuel Pégourié-Gonnard | ab3d862 | 2014-07-12 03:19:18 +0200 | [diff] [blame] | 42 | |
SimonB | 60f2cf9 | 2016-04-03 14:16:08 +0100 | [diff] [blame] | 43 | Commands |
Simon Butcher | 4ae8691 | 2016-06-21 10:09:25 +0100 | [diff] [blame] | 44 | set <symbol> [<value>] - Uncomments or adds a #define for the <symbol> to |
SimonB | 60f2cf9 | 2016-04-03 14:16:08 +0100 | [diff] [blame] | 45 | the configuration file, and optionally making it |
| 46 | of <value>. |
| 47 | If the symbol isn't present in the file an error |
| 48 | is returned. |
Simon Butcher | 4ae8691 | 2016-06-21 10:09:25 +0100 | [diff] [blame] | 49 | unset <symbol> - Comments out the #define for the given symbol if |
| 50 | present in the configuration file. |
| 51 | get <symbol> - Finds the #define for the given symbol, returning |
Gilles Peskine | d98e9e8 | 2017-10-09 16:56:18 +0200 | [diff] [blame] | 52 | an exitcode of 0 if the symbol is found, and 1 if |
Simon Butcher | 4ae8691 | 2016-06-21 10:09:25 +0100 | [diff] [blame] | 53 | not. The value of the symbol is output if one is |
| 54 | specified in the configuration file. |
SimonB | 60f2cf9 | 2016-04-03 14:16:08 +0100 | [diff] [blame] | 55 | full - Uncomments all #define's in the configuration file |
Simon Butcher | 4ae8691 | 2016-06-21 10:09:25 +0100 | [diff] [blame] | 56 | excluding some reserved symbols, until the |
SimonB | 60f2cf9 | 2016-04-03 14:16:08 +0100 | [diff] [blame] | 57 | 'Module configuration options' section |
| 58 | realfull - Uncomments all #define's with no exclusions |
Azim Khan | c3c3a68 | 2017-12-21 15:19:53 +0000 | [diff] [blame] | 59 | baremetal - Sets full configuration suitable for baremetal build. |
SimonB | 60f2cf9 | 2016-04-03 14:16:08 +0100 | [diff] [blame] | 60 | |
| 61 | Options |
| 62 | -f | --file <filename> - The file or file path for the configuration file |
| 63 | to edit. When omitted, the following default is |
| 64 | used: |
| 65 | $config_file |
| 66 | -o | --force - If the symbol isn't present in the configuration |
Brian J Murray | 2adecba | 2016-11-06 04:45:15 -0800 | [diff] [blame] | 67 | file when setting its value, a #define is |
SimonB | 60f2cf9 | 2016-04-03 14:16:08 +0100 | [diff] [blame] | 68 | appended to the end of the file. |
| 69 | |
| 70 | EOU |
| 71 | |
Manuel Pégourié-Gonnard | ab3d862 | 2014-07-12 03:19:18 +0200 | [diff] [blame] | 72 | my @excluded = qw( |
Gilles Peskine | d6189e1 | 2020-04-28 10:28:14 +0200 | [diff] [blame^] | 73 | MBEDTLS_CTR_DRBG_USE_128_BIT_KEY |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 74 | MBEDTLS_DEPRECATED_REMOVED |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 75 | MBEDTLS_HAVE_SSE2 |
Hanno Becker | 307dfcd | 2019-02-26 13:51:00 +0000 | [diff] [blame] | 76 | MBEDTLS_MEMORY_BACKTRACE |
| 77 | MBEDTLS_MEMORY_BUFFER_ALLOC_C |
Gilles Peskine | d6189e1 | 2020-04-28 10:28:14 +0200 | [diff] [blame^] | 78 | MBEDTLS_MEMORY_DEBUG |
| 79 | MBEDTLS_NO_64BIT_MULTIPLICATION |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 80 | MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES |
| 81 | MBEDTLS_NO_PLATFORM_ENTROPY |
Gilles Peskine | d6189e1 | 2020-04-28 10:28:14 +0200 | [diff] [blame^] | 82 | MBEDTLS_NO_UDBL_DIVISION |
| 83 | MBEDTLS_PKCS11_C |
| 84 | MBEDTLS_PLATFORM_NO_STD_FUNCTIONS |
Andres Amaya Garcia | 5d8aade | 2018-10-30 18:21:41 +0000 | [diff] [blame] | 85 | MBEDTLS_REMOVE_3DES_CIPHERSUITES |
Gilles Peskine | d6189e1 | 2020-04-28 10:28:14 +0200 | [diff] [blame^] | 86 | MBEDTLS_REMOVE_ARC4_CIPHERSUITES |
| 87 | MBEDTLS_RSA_NO_CRT |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 88 | MBEDTLS_SSL_HW_RECORD_ACCEL |
Gilles Peskine | d6189e1 | 2020-04-28 10:28:14 +0200 | [diff] [blame^] | 89 | MBEDTLS_TEST_NULL_ENTROPY |
Manuel Pégourié-Gonnard | 2cf5a7c | 2015-04-08 12:49:31 +0200 | [diff] [blame] | 90 | MBEDTLS_X509_ALLOW_UNSUPPORTED_CRITICAL_EXTENSION |
| 91 | MBEDTLS_ZLIB_SUPPORT |
Manuel Pégourié-Gonnard | ab3d862 | 2014-07-12 03:19:18 +0200 | [diff] [blame] | 92 | _ALT\s*$ |
| 93 | ); |
| 94 | |
Azim Khan | 0d44573 | 2017-12-21 09:28:39 +0000 | [diff] [blame] | 95 | # Things that should be disabled in "baremetal" |
| 96 | my @excluded_baremetal = qw( |
Gilles Peskine | d6189e1 | 2020-04-28 10:28:14 +0200 | [diff] [blame^] | 97 | MBEDTLS_DEPRECATED_WARNING |
Azim Khan | 0d44573 | 2017-12-21 09:28:39 +0000 | [diff] [blame] | 98 | MBEDTLS_ENTROPY_NV_SEED |
Gilles Peskine | d6189e1 | 2020-04-28 10:28:14 +0200 | [diff] [blame^] | 99 | MBEDTLS_FS_IO |
| 100 | MBEDTLS_HAVEGE_C |
Azim Khan | 0d44573 | 2017-12-21 09:28:39 +0000 | [diff] [blame] | 101 | MBEDTLS_HAVE_TIME |
| 102 | MBEDTLS_HAVE_TIME_DATE |
Azim Khan | 0d44573 | 2017-12-21 09:28:39 +0000 | [diff] [blame] | 103 | MBEDTLS_MEMORY_BACKTRACE |
| 104 | MBEDTLS_MEMORY_BUFFER_ALLOC_C |
Gilles Peskine | d6189e1 | 2020-04-28 10:28:14 +0200 | [diff] [blame^] | 105 | MBEDTLS_NET_C |
Azim Khan | 0d44573 | 2017-12-21 09:28:39 +0000 | [diff] [blame] | 106 | MBEDTLS_PLATFORM_FPRINTF_ALT |
Gilles Peskine | d6189e1 | 2020-04-28 10:28:14 +0200 | [diff] [blame^] | 107 | MBEDTLS_PLATFORM_TIME_ALT |
| 108 | MBEDTLS_THREADING_C |
| 109 | MBEDTLS_THREADING_PTHREAD |
| 110 | MBEDTLS_TIMING_C |
Azim Khan | 0d44573 | 2017-12-21 09:28:39 +0000 | [diff] [blame] | 111 | ); |
| 112 | |
Manuel Pégourié-Gonnard | b752715 | 2015-06-03 09:59:06 +0100 | [diff] [blame] | 113 | # Things that should be enabled in "full" even if they match @excluded |
| 114 | my @non_excluded = qw( |
| 115 | PLATFORM_[A-Z0-9]+_ALT |
| 116 | ); |
| 117 | |
Azim Khan | 0d44573 | 2017-12-21 09:28:39 +0000 | [diff] [blame] | 118 | # Things that should be enabled in "baremetal" |
| 119 | my @non_excluded_baremetal = qw( |
| 120 | MBEDTLS_NO_PLATFORM_ENTROPY |
| 121 | ); |
| 122 | |
SimonB | 60f2cf9 | 2016-04-03 14:16:08 +0100 | [diff] [blame] | 123 | # Process the command line arguments |
Manuel Pégourié-Gonnard | ab3d862 | 2014-07-12 03:19:18 +0200 | [diff] [blame] | 124 | |
SimonB | 60f2cf9 | 2016-04-03 14:16:08 +0100 | [diff] [blame] | 125 | my $force_option = 0; |
Manuel Pégourié-Gonnard | ab3d862 | 2014-07-12 03:19:18 +0200 | [diff] [blame] | 126 | |
SimonB | 60f2cf9 | 2016-04-03 14:16:08 +0100 | [diff] [blame] | 127 | my ($arg, $name, $value, $action); |
| 128 | |
SimonB | 73883c1 | 2016-04-04 13:49:10 +0100 | [diff] [blame] | 129 | while ($arg = shift) { |
SimonB | 60f2cf9 | 2016-04-03 14:16:08 +0100 | [diff] [blame] | 130 | |
| 131 | # Check if the argument is an option |
SimonB | 73883c1 | 2016-04-04 13:49:10 +0100 | [diff] [blame] | 132 | if ($arg eq "-f" || $arg eq "--file") { |
SimonB | 60f2cf9 | 2016-04-03 14:16:08 +0100 | [diff] [blame] | 133 | $config_file = shift; |
| 134 | |
| 135 | -f $config_file or die "No such file: $config_file\n"; |
| 136 | |
| 137 | } |
SimonB | 73883c1 | 2016-04-04 13:49:10 +0100 | [diff] [blame] | 138 | elsif ($arg eq "-o" || $arg eq "--force") { |
SimonB | 60f2cf9 | 2016-04-03 14:16:08 +0100 | [diff] [blame] | 139 | $force_option = 1; |
| 140 | |
| 141 | } |
| 142 | else |
| 143 | { |
| 144 | # ...else assume it's a command |
| 145 | $action = $arg; |
| 146 | |
Azim Khan | 0d44573 | 2017-12-21 09:28:39 +0000 | [diff] [blame] | 147 | if ($action eq "full" || $action eq "realfull" || $action eq "baremetal" ) { |
SimonB | 60f2cf9 | 2016-04-03 14:16:08 +0100 | [diff] [blame] | 148 | # No additional parameters |
| 149 | die $usage if @ARGV; |
| 150 | |
| 151 | } |
Simon Butcher | 4ae8691 | 2016-06-21 10:09:25 +0100 | [diff] [blame] | 152 | elsif ($action eq "unset" || $action eq "get") { |
SimonB | 60f2cf9 | 2016-04-03 14:16:08 +0100 | [diff] [blame] | 153 | die $usage unless @ARGV; |
| 154 | $name = shift; |
| 155 | |
| 156 | } |
| 157 | elsif ($action eq "set") { |
| 158 | die $usage unless @ARGV; |
| 159 | $name = shift; |
| 160 | $value = shift if @ARGV; |
| 161 | |
| 162 | } |
| 163 | else { |
| 164 | die "Command '$action' not recognised.\n\n".$usage; |
| 165 | } |
Manuel Pégourié-Gonnard | ab3d862 | 2014-07-12 03:19:18 +0200 | [diff] [blame] | 166 | } |
| 167 | } |
| 168 | |
Simon Butcher | 3d26513 | 2016-06-23 21:57:06 +0100 | [diff] [blame] | 169 | # If no command was specified, exit... |
| 170 | if ( not defined($action) ){ die $usage; } |
| 171 | |
SimonB | 60f2cf9 | 2016-04-03 14:16:08 +0100 | [diff] [blame] | 172 | # Check the config file is present |
| 173 | if (! -f $config_file) { |
Manuel Pégourié-Gonnard | ab3d862 | 2014-07-12 03:19:18 +0200 | [diff] [blame] | 174 | |
SimonB | 60f2cf9 | 2016-04-03 14:16:08 +0100 | [diff] [blame] | 175 | chdir '..' or die; |
| 176 | |
| 177 | # Confirm this is the project root directory and try again |
| 178 | if ( !(-d 'scripts' && -d 'include' && -d 'library' && -f $config_file) ) { |
| 179 | die "If no file specified, must be run from the project root or scripts directory.\n"; |
| 180 | } |
Manuel Pégourié-Gonnard | ab3d862 | 2014-07-12 03:19:18 +0200 | [diff] [blame] | 181 | } |
SimonB | 60f2cf9 | 2016-04-03 14:16:08 +0100 | [diff] [blame] | 182 | |
| 183 | |
| 184 | # Now read the file and process the contents |
Manuel Pégourié-Gonnard | ab3d862 | 2014-07-12 03:19:18 +0200 | [diff] [blame] | 185 | |
| 186 | open my $config_read, '<', $config_file or die "read $config_file: $!\n"; |
| 187 | my @config_lines = <$config_read>; |
| 188 | close $config_read; |
| 189 | |
Azim Khan | 0d44573 | 2017-12-21 09:28:39 +0000 | [diff] [blame] | 190 | # Add required baremetal symbols to the list that is included. |
| 191 | if ( $action eq "baremetal" ) { |
| 192 | @non_excluded = ( @non_excluded, @non_excluded_baremetal ); |
| 193 | } |
| 194 | |
| 195 | my ($exclude_re, $no_exclude_re, $exclude_baremetal_re); |
Manuel Pégourié-Gonnard | 1989caf | 2016-01-04 12:57:32 +0100 | [diff] [blame] | 196 | if ($action eq "realfull") { |
| 197 | $exclude_re = qr/^$/; |
| 198 | $no_exclude_re = qr/./; |
| 199 | } else { |
| 200 | $exclude_re = join '|', @excluded; |
| 201 | $no_exclude_re = join '|', @non_excluded; |
| 202 | } |
Azim Khan | 0d44573 | 2017-12-21 09:28:39 +0000 | [diff] [blame] | 203 | if ( $action eq "baremetal" ) { |
| 204 | $exclude_baremetal_re = join '|', @excluded_baremetal; |
| 205 | } |
Manuel Pégourié-Gonnard | ab3d862 | 2014-07-12 03:19:18 +0200 | [diff] [blame] | 206 | |
Gilles Peskine | 01f57e3 | 2017-10-09 16:54:28 +0200 | [diff] [blame] | 207 | my $config_write = undef; |
| 208 | if ($action ne "get") { |
| 209 | open $config_write, '>', $config_file or die "write $config_file: $!\n"; |
| 210 | } |
Manuel Pégourié-Gonnard | ab3d862 | 2014-07-12 03:19:18 +0200 | [diff] [blame] | 211 | |
| 212 | my $done; |
| 213 | for my $line (@config_lines) { |
Azim Khan | 0d44573 | 2017-12-21 09:28:39 +0000 | [diff] [blame] | 214 | if ($action eq "full" || $action eq "realfull" || $action eq "baremetal" ) { |
Manuel Pégourié-Gonnard | ab3d862 | 2014-07-12 03:19:18 +0200 | [diff] [blame] | 215 | if ($line =~ /name SECTION: Module configuration options/) { |
| 216 | $done = 1; |
| 217 | } |
| 218 | |
Manuel Pégourié-Gonnard | b752715 | 2015-06-03 09:59:06 +0100 | [diff] [blame] | 219 | if (!$done && $line =~ m!^//\s?#define! && |
Azim Khan | 0d44573 | 2017-12-21 09:28:39 +0000 | [diff] [blame] | 220 | ( $line !~ /$exclude_re/ || $line =~ /$no_exclude_re/ ) && |
| 221 | ( $action ne "baremetal" || ( $line !~ /$exclude_baremetal_re/ ) ) ) { |
Manuel Pégourié-Gonnard | ea0920f | 2015-03-24 09:50:15 +0100 | [diff] [blame] | 222 | $line =~ s!^//\s?!!; |
| 223 | } |
Manuel Pégourié-Gonnard | 7ee5ddd | 2015-06-03 10:33:55 +0100 | [diff] [blame] | 224 | if (!$done && $line =~ m!^\s?#define! && |
Azim Khan | 0d44573 | 2017-12-21 09:28:39 +0000 | [diff] [blame] | 225 | ! ( ( $line !~ /$exclude_re/ || $line =~ /$no_exclude_re/ ) && |
| 226 | ( $action ne "baremetal" || ( $line !~ /$exclude_baremetal_re/ ) ) ) ) { |
Manuel Pégourié-Gonnard | ea0920f | 2015-03-24 09:50:15 +0100 | [diff] [blame] | 227 | $line =~ s!^!//!; |
Manuel Pégourié-Gonnard | ab3d862 | 2014-07-12 03:19:18 +0200 | [diff] [blame] | 228 | } |
| 229 | } elsif ($action eq "unset") { |
Manuel Pégourié-Gonnard | 7f9049b | 2015-06-23 17:42:51 +0200 | [diff] [blame] | 230 | if (!$done && $line =~ /^\s*#define\s*$name\b/) { |
Manuel Pégourié-Gonnard | ab3d862 | 2014-07-12 03:19:18 +0200 | [diff] [blame] | 231 | $line = '//' . $line; |
| 232 | $done = 1; |
| 233 | } |
| 234 | } elsif (!$done && $action eq "set") { |
Manuel Pégourié-Gonnard | 7f9049b | 2015-06-23 17:42:51 +0200 | [diff] [blame] | 235 | if ($line =~ m!^(?://)?\s*#define\s*$name\b!) { |
Manuel Pégourié-Gonnard | ab3d862 | 2014-07-12 03:19:18 +0200 | [diff] [blame] | 236 | $line = "#define $name"; |
| 237 | $line .= " $value" if defined $value && $value ne ""; |
| 238 | $line .= "\n"; |
| 239 | $done = 1; |
| 240 | } |
Simon Butcher | 4ae8691 | 2016-06-21 10:09:25 +0100 | [diff] [blame] | 241 | } elsif (!$done && $action eq "get") { |
Gilles Peskine | f0f55cc | 2017-10-09 16:51:24 +0200 | [diff] [blame] | 242 | if ($line =~ /^\s*#define\s*$name(?:\s+(.*?))\s*(?:$|\/\*|\/\/)/) { |
Simon Butcher | 4ae8691 | 2016-06-21 10:09:25 +0100 | [diff] [blame] | 243 | $value = $1; |
| 244 | $done = 1; |
| 245 | } |
Manuel Pégourié-Gonnard | ab3d862 | 2014-07-12 03:19:18 +0200 | [diff] [blame] | 246 | } |
| 247 | |
Gilles Peskine | 01f57e3 | 2017-10-09 16:54:28 +0200 | [diff] [blame] | 248 | if (defined $config_write) { |
Gilles Peskine | 8ca0e8f | 2017-10-10 11:26:45 +0200 | [diff] [blame] | 249 | print $config_write $line or die "write $config_file: $!\n"; |
Gilles Peskine | 01f57e3 | 2017-10-09 16:54:28 +0200 | [diff] [blame] | 250 | } |
Manuel Pégourié-Gonnard | ab3d862 | 2014-07-12 03:19:18 +0200 | [diff] [blame] | 251 | } |
| 252 | |
SimonB | 60f2cf9 | 2016-04-03 14:16:08 +0100 | [diff] [blame] | 253 | # Did the set command work? |
Gilles Peskine | d98e9e8 | 2017-10-09 16:56:18 +0200 | [diff] [blame] | 254 | if ($action eq "set" && $force_option && !$done) { |
SimonB | 60f2cf9 | 2016-04-03 14:16:08 +0100 | [diff] [blame] | 255 | |
| 256 | # If the force option was set, append the symbol to the end of the file |
| 257 | my $line = "#define $name"; |
| 258 | $line .= " $value" if defined $value && $value ne ""; |
| 259 | $line .= "\n"; |
| 260 | $done = 1; |
| 261 | |
Gilles Peskine | 01f57e3 | 2017-10-09 16:54:28 +0200 | [diff] [blame] | 262 | print $config_write $line or die "write $config_file: $!\n"; |
SimonB | 60f2cf9 | 2016-04-03 14:16:08 +0100 | [diff] [blame] | 263 | } |
| 264 | |
Gilles Peskine | 01f57e3 | 2017-10-09 16:54:28 +0200 | [diff] [blame] | 265 | if (defined $config_write) { |
| 266 | close $config_write or die "close $config_file: $!\n"; |
| 267 | } |
Manuel Pégourié-Gonnard | ab3d862 | 2014-07-12 03:19:18 +0200 | [diff] [blame] | 268 | |
Simon Butcher | dd9895d | 2016-06-21 15:12:00 +0100 | [diff] [blame] | 269 | if ($action eq "get") { |
Gilles Peskine | d98e9e8 | 2017-10-09 16:56:18 +0200 | [diff] [blame] | 270 | if ($done) { |
Simon Butcher | dd9895d | 2016-06-21 15:12:00 +0100 | [diff] [blame] | 271 | if ($value ne '') { |
Gilles Peskine | d98e9e8 | 2017-10-09 16:56:18 +0200 | [diff] [blame] | 272 | print "$value\n"; |
Simon Butcher | dd9895d | 2016-06-21 15:12:00 +0100 | [diff] [blame] | 273 | } |
| 274 | exit 0; |
| 275 | } else { |
| 276 | # If the symbol was not found, return an error |
Gilles Peskine | d98e9e8 | 2017-10-09 16:56:18 +0200 | [diff] [blame] | 277 | exit 1; |
Simon Butcher | 4ae8691 | 2016-06-21 10:09:25 +0100 | [diff] [blame] | 278 | } |
Simon Butcher | 4ae8691 | 2016-06-21 10:09:25 +0100 | [diff] [blame] | 279 | } |
| 280 | |
SimonB | 60f2cf9 | 2016-04-03 14:16:08 +0100 | [diff] [blame] | 281 | if ($action eq "full" && !$done) { |
| 282 | die "Configuration section was not found in $config_file\n"; |
| 283 | |
| 284 | } |
| 285 | |
| 286 | if ($action ne "full" && $action ne "unset" && !$done) { |
| 287 | die "A #define for the symbol $name was not found in $config_file\n"; |
| 288 | } |
Manuel Pégourié-Gonnard | ab3d862 | 2014-07-12 03:19:18 +0200 | [diff] [blame] | 289 | |
| 290 | __END__ |