From 4ae869139a23789f07545241f362a97f04229133 Mon Sep 17 00:00:00 2001 From: Simon Butcher Date: Tue, 21 Jun 2016 10:09:25 +0100 Subject: [PATCH] Adds 'get' command to scripts/config.pl to retrieve config state Adds 'get' command to indicate if the option is enabled in the given configuration file, and to returns it's value if one has been set. --- scripts/config.pl | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/scripts/config.pl b/scripts/config.pl index 84ec38ed7..04a9a7452 100755 --- a/scripts/config.pl +++ b/scripts/config.pl @@ -7,12 +7,13 @@ # Purpose # # Comments and uncomments #define lines in the given header file and optionally -# sets their value. This is to provide scripting control of what preprocessor -# symbols, and therefore what build time configuration flags are set in the -# 'config.h' file. +# sets their value or can get the value. This is to provide scripting control of +# what preprocessor symbols, and therefore what build time configuration flags +# are set in the 'config.h' file. # # Usage: config.pl [-f | --file ] [-o | --force] -# [set | unset | full | realfull] +# [set | unset | get | +# full | realfull] # # Full usage description provided below. # @@ -43,18 +44,23 @@ use strict; my $config_file = "include/mbedtls/config.h"; my $usage = < | --file ] [-o | --force] - [set | unset | full | realfull] + [set | unset | get | + full | realfull] Commands - set [ to + set [] - Uncomments or adds a #define for the to the configuration file, and optionally making it of . If the symbol isn't present in the file an error is returned. - unset - Comments out any #define present in the - configuration file. + unset - Comments out the #define for the given symbol if + present in the configuration file. + get - Finds the #define for the given symbol, returning + an exitcode of 0 if the symbol is found, and -1 if + not. The value of the symbol is output if one is + specified in the configuration file. full - Uncomments all #define's in the configuration file - excluding some reserved symbols, until the + excluding some reserved symbols, until the 'Module configuration options' section realfull - Uncomments all #define's with no exclusions @@ -122,7 +128,7 @@ while ($arg = shift) { die $usage if @ARGV; } - elsif ($action eq "unset") { + elsif ($action eq "unset" || $action eq "get") { die $usage unless @ARGV; $name = shift; @@ -195,6 +201,11 @@ for my $line (@config_lines) { $line .= "\n"; $done = 1; } + } elsif (!$done && $action eq "get") { + if ($line =~ /^\s*#define\s*$name\s*(.*)\s*\b/) { + $value = $1; + $done = 1; + } } print $config_write $line; @@ -214,6 +225,15 @@ if ($action eq "set"&& $force_option && !$done) { close $config_write; +if ($action eq "get" && $done) { + if ($value ne '') { + print $value; + } + exit 0; +} else { + exit -1; +} + if ($action eq "full" && !$done) { die "Configuration section was not found in $config_file\n";