2018-04-04 23:44:29 +02:00
|
|
|
#!/usr/bin/env perl
|
2016-04-03 15:16:08 +02:00
|
|
|
#
|
2020-08-19 16:37:36 +02:00
|
|
|
# Copyright The Mbed TLS Contributors
|
Update license headers to Apache-2.0 OR GPL-2.0-or-later
This will allow us to ship the LTS branches in a single archive
This commit was generated using the following script:
# ========================
#!/bin/sh
header1='\ * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later\
*\
* This file is provided under the Apache License 2.0, or the\
* GNU General Public License v2.0 or later.\
*\
* **********\
* Apache License 2.0:\
*\
* Licensed under the Apache License, Version 2.0 (the "License"); you may\
* not use this file except in compliance with the License.\
* You may obtain a copy of the License at\
*\
* http://www.apache.org/licenses/LICENSE-2.0\
*\
* Unless required by applicable law or agreed to in writing, software\
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT\
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\
* See the License for the specific language governing permissions and\
* limitations under the License.\
*\
* **********\
*\
* **********\
* GNU General Public License v2.0 or later:\
*\
* This program is free software; you can redistribute it and/or modify\
* it under the terms of the GNU General Public License as published by\
* the Free Software Foundation; either version 2 of the License, or\
* (at your option) any later version.\
*\
* This program is distributed in the hope that it will be useful,\
* but WITHOUT ANY WARRANTY; without even the implied warranty of\
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\
* GNU General Public License for more details.\
*\
* You should have received a copy of the GNU General Public License along\
* with this program; if not, write to the Free Software Foundation, Inc.,\
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\
*\
* **********'
find -path './.git' -prune -o '(' -name '*.c' -o -name '*.cpp' -o -name '*.fmt' -o -name '*.h' ')' -print | xargs sed -i "
# Normalize the first line of the copyright headers (no text on the first line of a block comment)
/^\/\*.*Copyright.*Arm/I s/\/\*/&\n */
# Insert new copyright header
/SPDX-License-Identifier/ i\
$header1
# Delete old copyright header
/SPDX-License-Identifier/,$ {
# Delete lines until the one preceding the mbedtls declaration
N
1,/This file is part of/ {
/This file is part of/! D
}
}
"
# Format copyright header for inclusion into scripts
header2=$(echo "$header1" | sed 's/^\\\? \* \?/#/')
find -path './.git' -prune -o '(' -name '*.gdb' -o -name '*.pl' -o -name '*.py' -o -name '*.sh' ')' -print | xargs sed -i "
# Insert new copyright header
/SPDX-License-Identifier/ i\
$header2
# Delete old copyright header
/SPDX-License-Identifier/,$ {
# Delete lines until the one preceding the mbedtls declaration
N
1,/This file is part of/ {
/This file is part of/! D
}
}
"
# ========================
Signed-off-by: Bence Szépkúti <bence.szepkuti@arm.com>
2020-06-05 13:02:18 +02:00
|
|
|
# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
|
|
|
|
#
|
|
|
|
# This file is provided under the Apache License 2.0, or the
|
|
|
|
# GNU General Public License v2.0 or later.
|
|
|
|
#
|
|
|
|
# **********
|
|
|
|
# Apache License 2.0:
|
2020-05-26 01:54:15 +02:00
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
|
|
# not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
#
|
Update license headers to Apache-2.0 OR GPL-2.0-or-later
This will allow us to ship the LTS branches in a single archive
This commit was generated using the following script:
# ========================
#!/bin/sh
header1='\ * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later\
*\
* This file is provided under the Apache License 2.0, or the\
* GNU General Public License v2.0 or later.\
*\
* **********\
* Apache License 2.0:\
*\
* Licensed under the Apache License, Version 2.0 (the "License"); you may\
* not use this file except in compliance with the License.\
* You may obtain a copy of the License at\
*\
* http://www.apache.org/licenses/LICENSE-2.0\
*\
* Unless required by applicable law or agreed to in writing, software\
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT\
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\
* See the License for the specific language governing permissions and\
* limitations under the License.\
*\
* **********\
*\
* **********\
* GNU General Public License v2.0 or later:\
*\
* This program is free software; you can redistribute it and/or modify\
* it under the terms of the GNU General Public License as published by\
* the Free Software Foundation; either version 2 of the License, or\
* (at your option) any later version.\
*\
* This program is distributed in the hope that it will be useful,\
* but WITHOUT ANY WARRANTY; without even the implied warranty of\
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\
* GNU General Public License for more details.\
*\
* You should have received a copy of the GNU General Public License along\
* with this program; if not, write to the Free Software Foundation, Inc.,\
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\
*\
* **********'
find -path './.git' -prune -o '(' -name '*.c' -o -name '*.cpp' -o -name '*.fmt' -o -name '*.h' ')' -print | xargs sed -i "
# Normalize the first line of the copyright headers (no text on the first line of a block comment)
/^\/\*.*Copyright.*Arm/I s/\/\*/&\n */
# Insert new copyright header
/SPDX-License-Identifier/ i\
$header1
# Delete old copyright header
/SPDX-License-Identifier/,$ {
# Delete lines until the one preceding the mbedtls declaration
N
1,/This file is part of/ {
/This file is part of/! D
}
}
"
# Format copyright header for inclusion into scripts
header2=$(echo "$header1" | sed 's/^\\\? \* \?/#/')
find -path './.git' -prune -o '(' -name '*.gdb' -o -name '*.pl' -o -name '*.py' -o -name '*.sh' ')' -print | xargs sed -i "
# Insert new copyright header
/SPDX-License-Identifier/ i\
$header2
# Delete old copyright header
/SPDX-License-Identifier/,$ {
# Delete lines until the one preceding the mbedtls declaration
N
1,/This file is part of/ {
/This file is part of/! D
}
}
"
# ========================
Signed-off-by: Bence Szépkúti <bence.szepkuti@arm.com>
2020-06-05 13:02:18 +02:00
|
|
|
# **********
|
|
|
|
#
|
|
|
|
# **********
|
|
|
|
# GNU General Public License v2.0 or later:
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License along
|
|
|
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
#
|
|
|
|
# **********
|
|
|
|
#
|
2016-04-03 15:16:08 +02:00
|
|
|
# Purpose
|
|
|
|
#
|
|
|
|
# Comments and uncomments #define lines in the given header file and optionally
|
2016-06-21 11:09:25 +02:00
|
|
|
# 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.
|
2016-04-03 15:16:08 +02:00
|
|
|
#
|
|
|
|
# Usage: config.pl [-f <file> | --file <file>] [-o | --force]
|
2016-06-21 11:09:25 +02:00
|
|
|
# [set <symbol> <value> | unset <symbol> | get <symbol> |
|
|
|
|
# full | realfull]
|
2016-04-03 15:16:08 +02:00
|
|
|
#
|
|
|
|
# Full usage description provided below.
|
|
|
|
#
|
2017-09-28 12:49:46 +02:00
|
|
|
# The following options are disabled instead of enabled with "full".
|
2016-04-03 15:16:08 +02:00
|
|
|
#
|
2020-04-28 10:26:43 +02:00
|
|
|
# * Options that require additional build dependencies or unusual hardware.
|
|
|
|
# * Options that make testing less effective.
|
|
|
|
# * Options that are incompatible with other options, or more generally that
|
|
|
|
# interact with other parts of the code in such a way that a bulk enabling
|
|
|
|
# is not a good way to test them.
|
|
|
|
# * Options that remove features.
|
|
|
|
#
|
|
|
|
# The baremetal configuration excludes options that require a library or
|
|
|
|
# operating system feature that is typically not present on bare metal
|
|
|
|
# systems. Features that are excluded from "full" won't be in "baremetal"
|
|
|
|
# either.
|
2014-07-12 03:19:18 +02:00
|
|
|
|
|
|
|
use warnings;
|
|
|
|
use strict;
|
|
|
|
|
2016-04-03 15:16:08 +02:00
|
|
|
my $config_file = "include/mbedtls/config.h";
|
2014-07-12 03:19:18 +02:00
|
|
|
my $usage = <<EOU;
|
2016-04-03 15:16:08 +02:00
|
|
|
$0 [-f <file> | --file <file>] [-o | --force]
|
2016-06-21 11:09:25 +02:00
|
|
|
[set <symbol> <value> | unset <symbol> | get <symbol> |
|
2017-12-21 16:19:53 +01:00
|
|
|
full | realfull | baremetal]
|
2016-04-03 15:16:08 +02:00
|
|
|
|
|
|
|
Commands
|
2016-06-21 11:09:25 +02:00
|
|
|
set <symbol> [<value>] - Uncomments or adds a #define for the <symbol> to
|
2016-04-03 15:16:08 +02:00
|
|
|
the configuration file, and optionally making it
|
|
|
|
of <value>.
|
|
|
|
If the symbol isn't present in the file an error
|
|
|
|
is returned.
|
2016-06-21 11:09:25 +02:00
|
|
|
unset <symbol> - Comments out the #define for the given symbol if
|
|
|
|
present in the configuration file.
|
|
|
|
get <symbol> - Finds the #define for the given symbol, returning
|
2017-10-09 16:56:18 +02:00
|
|
|
an exitcode of 0 if the symbol is found, and 1 if
|
2016-06-21 11:09:25 +02:00
|
|
|
not. The value of the symbol is output if one is
|
|
|
|
specified in the configuration file.
|
2016-04-03 15:16:08 +02:00
|
|
|
full - Uncomments all #define's in the configuration file
|
2016-06-21 11:09:25 +02:00
|
|
|
excluding some reserved symbols, until the
|
2016-04-03 15:16:08 +02:00
|
|
|
'Module configuration options' section
|
|
|
|
realfull - Uncomments all #define's with no exclusions
|
2017-12-21 16:19:53 +01:00
|
|
|
baremetal - Sets full configuration suitable for baremetal build.
|
2016-04-03 15:16:08 +02:00
|
|
|
|
|
|
|
Options
|
|
|
|
-f | --file <filename> - The file or file path for the configuration file
|
|
|
|
to edit. When omitted, the following default is
|
|
|
|
used:
|
|
|
|
$config_file
|
|
|
|
-o | --force - If the symbol isn't present in the configuration
|
2016-11-06 13:45:15 +01:00
|
|
|
file when setting its value, a #define is
|
2016-04-03 15:16:08 +02:00
|
|
|
appended to the end of the file.
|
|
|
|
|
2014-07-12 03:19:18 +02:00
|
|
|
EOU
|
|
|
|
|
|
|
|
my @excluded = qw(
|
2020-04-28 10:28:14 +02:00
|
|
|
MBEDTLS_CTR_DRBG_USE_128_BIT_KEY
|
2015-04-08 12:49:31 +02:00
|
|
|
MBEDTLS_DEPRECATED_REMOVED
|
2020-04-29 15:44:00 +02:00
|
|
|
MBEDTLS_DEPRECATED_WARNING
|
2020-05-19 12:38:31 +02:00
|
|
|
MBEDTLS_ECP_NO_INTERNAL_RNG
|
2015-04-08 12:49:31 +02:00
|
|
|
MBEDTLS_HAVE_SSE2
|
2019-02-26 14:51:00 +01:00
|
|
|
MBEDTLS_MEMORY_BACKTRACE
|
|
|
|
MBEDTLS_MEMORY_BUFFER_ALLOC_C
|
2020-04-28 10:28:14 +02:00
|
|
|
MBEDTLS_MEMORY_DEBUG
|
|
|
|
MBEDTLS_NO_64BIT_MULTIPLICATION
|
2015-04-08 12:49:31 +02:00
|
|
|
MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
|
|
|
|
MBEDTLS_NO_PLATFORM_ENTROPY
|
2020-04-28 10:28:14 +02:00
|
|
|
MBEDTLS_NO_UDBL_DIVISION
|
|
|
|
MBEDTLS_PKCS11_C
|
|
|
|
MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
|
2018-10-30 19:21:41 +01:00
|
|
|
MBEDTLS_REMOVE_3DES_CIPHERSUITES
|
2020-04-28 10:28:14 +02:00
|
|
|
MBEDTLS_REMOVE_ARC4_CIPHERSUITES
|
|
|
|
MBEDTLS_RSA_NO_CRT
|
2015-04-08 12:49:31 +02:00
|
|
|
MBEDTLS_SSL_HW_RECORD_ACCEL
|
2020-07-28 10:53:06 +02:00
|
|
|
MBEDTLS_TEST_CONSTANT_FLOW_MEMSAN
|
2020-08-25 11:26:37 +02:00
|
|
|
MBEDTLS_TEST_CONSTANT_FLOW_VALGRIND
|
2020-04-28 10:28:14 +02:00
|
|
|
MBEDTLS_TEST_NULL_ENTROPY
|
2015-04-08 12:49:31 +02:00
|
|
|
MBEDTLS_X509_ALLOW_UNSUPPORTED_CRITICAL_EXTENSION
|
|
|
|
MBEDTLS_ZLIB_SUPPORT
|
2014-07-12 03:19:18 +02:00
|
|
|
_ALT\s*$
|
|
|
|
);
|
|
|
|
|
2017-12-21 10:28:39 +01:00
|
|
|
# Things that should be disabled in "baremetal"
|
|
|
|
my @excluded_baremetal = qw(
|
|
|
|
MBEDTLS_ENTROPY_NV_SEED
|
2020-04-28 10:28:14 +02:00
|
|
|
MBEDTLS_FS_IO
|
|
|
|
MBEDTLS_HAVEGE_C
|
2017-12-21 10:28:39 +01:00
|
|
|
MBEDTLS_HAVE_TIME
|
|
|
|
MBEDTLS_HAVE_TIME_DATE
|
|
|
|
MBEDTLS_MEMORY_BACKTRACE
|
|
|
|
MBEDTLS_MEMORY_BUFFER_ALLOC_C
|
2020-04-28 10:28:14 +02:00
|
|
|
MBEDTLS_NET_C
|
2017-12-21 10:28:39 +01:00
|
|
|
MBEDTLS_PLATFORM_FPRINTF_ALT
|
2020-04-28 10:41:20 +02:00
|
|
|
MBEDTLS_PLATFORM_NV_SEED_ALT
|
2020-04-28 10:28:14 +02:00
|
|
|
MBEDTLS_PLATFORM_TIME_ALT
|
|
|
|
MBEDTLS_THREADING_C
|
|
|
|
MBEDTLS_THREADING_PTHREAD
|
|
|
|
MBEDTLS_TIMING_C
|
2017-12-21 10:28:39 +01:00
|
|
|
);
|
|
|
|
|
2020-04-28 10:41:20 +02:00
|
|
|
# Things that should be enabled in "full" even if they match @excluded.
|
|
|
|
# Platform ALTs enable global variables that allow configuring the behavior
|
|
|
|
# but default to the default behavior, except for PLATFORM_SETUP_TEARDOWN_ALT
|
|
|
|
# which requires the application to provide relevant functions like
|
|
|
|
# non-platform ALTs.
|
2015-06-03 10:59:06 +02:00
|
|
|
my @non_excluded = qw(
|
2020-04-28 10:41:20 +02:00
|
|
|
PLATFORM_(?!SETUP_TEARDOWN_)[A-Z_0-9]+_ALT
|
2015-06-03 10:59:06 +02:00
|
|
|
);
|
|
|
|
|
2017-12-21 10:28:39 +01:00
|
|
|
# Things that should be enabled in "baremetal"
|
|
|
|
my @non_excluded_baremetal = qw(
|
|
|
|
MBEDTLS_NO_PLATFORM_ENTROPY
|
|
|
|
);
|
|
|
|
|
2016-04-03 15:16:08 +02:00
|
|
|
# Process the command line arguments
|
2014-07-12 03:19:18 +02:00
|
|
|
|
2016-04-03 15:16:08 +02:00
|
|
|
my $force_option = 0;
|
|
|
|
|
|
|
|
my ($arg, $name, $value, $action);
|
|
|
|
|
2016-04-04 14:49:10 +02:00
|
|
|
while ($arg = shift) {
|
2016-04-03 15:16:08 +02:00
|
|
|
|
|
|
|
# Check if the argument is an option
|
2016-04-04 14:49:10 +02:00
|
|
|
if ($arg eq "-f" || $arg eq "--file") {
|
2016-04-03 15:16:08 +02:00
|
|
|
$config_file = shift;
|
|
|
|
|
|
|
|
-f $config_file or die "No such file: $config_file\n";
|
|
|
|
|
|
|
|
}
|
2016-04-04 14:49:10 +02:00
|
|
|
elsif ($arg eq "-o" || $arg eq "--force") {
|
2016-04-03 15:16:08 +02:00
|
|
|
$force_option = 1;
|
2014-07-12 03:19:18 +02:00
|
|
|
|
2016-04-03 15:16:08 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
# ...else assume it's a command
|
|
|
|
$action = $arg;
|
|
|
|
|
2017-12-21 10:28:39 +01:00
|
|
|
if ($action eq "full" || $action eq "realfull" || $action eq "baremetal" ) {
|
2016-04-03 15:16:08 +02:00
|
|
|
# No additional parameters
|
|
|
|
die $usage if @ARGV;
|
|
|
|
|
|
|
|
}
|
2016-06-21 11:09:25 +02:00
|
|
|
elsif ($action eq "unset" || $action eq "get") {
|
2016-04-03 15:16:08 +02:00
|
|
|
die $usage unless @ARGV;
|
|
|
|
$name = shift;
|
|
|
|
|
|
|
|
}
|
|
|
|
elsif ($action eq "set") {
|
|
|
|
die $usage unless @ARGV;
|
|
|
|
$name = shift;
|
|
|
|
$value = shift if @ARGV;
|
|
|
|
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
die "Command '$action' not recognised.\n\n".$usage;
|
|
|
|
}
|
2014-07-12 03:19:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-23 22:57:06 +02:00
|
|
|
# If no command was specified, exit...
|
|
|
|
if ( not defined($action) ){ die $usage; }
|
|
|
|
|
2016-04-03 15:16:08 +02:00
|
|
|
# Check the config file is present
|
|
|
|
if (! -f $config_file) {
|
|
|
|
|
|
|
|
chdir '..' or die;
|
|
|
|
|
|
|
|
# Confirm this is the project root directory and try again
|
|
|
|
if ( !(-d 'scripts' && -d 'include' && -d 'library' && -f $config_file) ) {
|
|
|
|
die "If no file specified, must be run from the project root or scripts directory.\n";
|
|
|
|
}
|
2014-07-12 03:19:18 +02:00
|
|
|
}
|
2016-04-03 15:16:08 +02:00
|
|
|
|
|
|
|
|
|
|
|
# Now read the file and process the contents
|
2014-07-12 03:19:18 +02:00
|
|
|
|
|
|
|
open my $config_read, '<', $config_file or die "read $config_file: $!\n";
|
|
|
|
my @config_lines = <$config_read>;
|
|
|
|
close $config_read;
|
|
|
|
|
2017-12-21 10:28:39 +01:00
|
|
|
# Add required baremetal symbols to the list that is included.
|
|
|
|
if ( $action eq "baremetal" ) {
|
|
|
|
@non_excluded = ( @non_excluded, @non_excluded_baremetal );
|
|
|
|
}
|
|
|
|
|
|
|
|
my ($exclude_re, $no_exclude_re, $exclude_baremetal_re);
|
2016-01-04 12:57:32 +01:00
|
|
|
if ($action eq "realfull") {
|
|
|
|
$exclude_re = qr/^$/;
|
|
|
|
$no_exclude_re = qr/./;
|
|
|
|
} else {
|
|
|
|
$exclude_re = join '|', @excluded;
|
|
|
|
$no_exclude_re = join '|', @non_excluded;
|
|
|
|
}
|
2017-12-21 10:28:39 +01:00
|
|
|
if ( $action eq "baremetal" ) {
|
|
|
|
$exclude_baremetal_re = join '|', @excluded_baremetal;
|
|
|
|
}
|
2014-07-12 03:19:18 +02:00
|
|
|
|
2017-10-09 16:54:28 +02:00
|
|
|
my $config_write = undef;
|
|
|
|
if ($action ne "get") {
|
|
|
|
open $config_write, '>', $config_file or die "write $config_file: $!\n";
|
|
|
|
}
|
2014-07-12 03:19:18 +02:00
|
|
|
|
|
|
|
my $done;
|
|
|
|
for my $line (@config_lines) {
|
2017-12-21 10:28:39 +01:00
|
|
|
if ($action eq "full" || $action eq "realfull" || $action eq "baremetal" ) {
|
2014-07-12 03:19:18 +02:00
|
|
|
if ($line =~ /name SECTION: Module configuration options/) {
|
|
|
|
$done = 1;
|
|
|
|
}
|
|
|
|
|
2015-06-03 10:59:06 +02:00
|
|
|
if (!$done && $line =~ m!^//\s?#define! &&
|
2017-12-21 10:28:39 +01:00
|
|
|
( $line !~ /$exclude_re/ || $line =~ /$no_exclude_re/ ) &&
|
|
|
|
( $action ne "baremetal" || ( $line !~ /$exclude_baremetal_re/ ) ) ) {
|
2015-03-24 09:50:15 +01:00
|
|
|
$line =~ s!^//\s?!!;
|
|
|
|
}
|
2015-06-03 11:33:55 +02:00
|
|
|
if (!$done && $line =~ m!^\s?#define! &&
|
2017-12-21 10:28:39 +01:00
|
|
|
! ( ( $line !~ /$exclude_re/ || $line =~ /$no_exclude_re/ ) &&
|
|
|
|
( $action ne "baremetal" || ( $line !~ /$exclude_baremetal_re/ ) ) ) ) {
|
2015-03-24 09:50:15 +01:00
|
|
|
$line =~ s!^!//!;
|
2014-07-12 03:19:18 +02:00
|
|
|
}
|
|
|
|
} elsif ($action eq "unset") {
|
2015-06-23 17:42:51 +02:00
|
|
|
if (!$done && $line =~ /^\s*#define\s*$name\b/) {
|
2014-07-12 03:19:18 +02:00
|
|
|
$line = '//' . $line;
|
|
|
|
$done = 1;
|
|
|
|
}
|
|
|
|
} elsif (!$done && $action eq "set") {
|
2015-06-23 17:42:51 +02:00
|
|
|
if ($line =~ m!^(?://)?\s*#define\s*$name\b!) {
|
2014-07-12 03:19:18 +02:00
|
|
|
$line = "#define $name";
|
|
|
|
$line .= " $value" if defined $value && $value ne "";
|
|
|
|
$line .= "\n";
|
|
|
|
$done = 1;
|
|
|
|
}
|
2016-06-21 11:09:25 +02:00
|
|
|
} elsif (!$done && $action eq "get") {
|
2017-10-09 16:51:24 +02:00
|
|
|
if ($line =~ /^\s*#define\s*$name(?:\s+(.*?))\s*(?:$|\/\*|\/\/)/) {
|
2016-06-21 11:09:25 +02:00
|
|
|
$value = $1;
|
|
|
|
$done = 1;
|
|
|
|
}
|
2014-07-12 03:19:18 +02:00
|
|
|
}
|
|
|
|
|
2017-10-09 16:54:28 +02:00
|
|
|
if (defined $config_write) {
|
2017-10-10 11:26:45 +02:00
|
|
|
print $config_write $line or die "write $config_file: $!\n";
|
2017-10-09 16:54:28 +02:00
|
|
|
}
|
2014-07-12 03:19:18 +02:00
|
|
|
}
|
|
|
|
|
2016-04-03 15:16:08 +02:00
|
|
|
# Did the set command work?
|
2017-10-09 16:56:18 +02:00
|
|
|
if ($action eq "set" && $force_option && !$done) {
|
2016-04-03 15:16:08 +02:00
|
|
|
|
|
|
|
# If the force option was set, append the symbol to the end of the file
|
|
|
|
my $line = "#define $name";
|
|
|
|
$line .= " $value" if defined $value && $value ne "";
|
|
|
|
$line .= "\n";
|
|
|
|
$done = 1;
|
|
|
|
|
2017-10-09 16:54:28 +02:00
|
|
|
print $config_write $line or die "write $config_file: $!\n";
|
2016-04-03 15:16:08 +02:00
|
|
|
}
|
|
|
|
|
2017-10-09 16:54:28 +02:00
|
|
|
if (defined $config_write) {
|
|
|
|
close $config_write or die "close $config_file: $!\n";
|
|
|
|
}
|
2014-07-12 03:19:18 +02:00
|
|
|
|
2016-06-21 16:12:00 +02:00
|
|
|
if ($action eq "get") {
|
2017-10-09 16:56:18 +02:00
|
|
|
if ($done) {
|
2016-06-21 16:12:00 +02:00
|
|
|
if ($value ne '') {
|
2017-10-09 16:56:18 +02:00
|
|
|
print "$value\n";
|
2016-06-21 16:12:00 +02:00
|
|
|
}
|
|
|
|
exit 0;
|
|
|
|
} else {
|
|
|
|
# If the symbol was not found, return an error
|
2017-10-09 16:56:18 +02:00
|
|
|
exit 1;
|
2016-06-21 11:09:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-03 15:16:08 +02:00
|
|
|
if ($action eq "full" && !$done) {
|
|
|
|
die "Configuration section was not found in $config_file\n";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($action ne "full" && $action ne "unset" && !$done) {
|
|
|
|
die "A #define for the symbol $name was not found in $config_file\n";
|
|
|
|
}
|
2014-07-12 03:19:18 +02:00
|
|
|
|
|
|
|
__END__
|