This Trac instance is not used for development anymore!

We migrated our development workflow to git and Gitea.
To test the future redirection, replace trac by ariadne in the page URL.

source: ps/trunk/build/premake/premake5/contrib/mbedtls/scripts/config.pl

Last change on this file was 20366, checked in by Itms, 7 years ago

Alpha 12 version of Premake 5, including prebuilt binary for Windows.
Directly taken from https://premake.github.io/.

Refs #3729.

File size: 3.2 KB
Line 
1#!/usr/bin/perl
2
3# Tune the configuration file
4
5use warnings;
6use strict;
7
8my $usage = <<EOU;
9$0 [-f <file>] unset <name>
10$0 [-f <file>] set <name> [<value>]
11EOU
12# for our eyes only:
13# $0 [-f <file>] full|realfull
14
15# Things that shouldn't be enabled with "full".
16# Notes:
17# - MBEDTLS_X509_ALLOW_EXTENSIONS_NON_V3 and
18# MBEDTLS_X509_ALLOW_UNSUPPORTED_CRITICAL_EXTENSION could be enabled if the
19# respective tests were adapted
20my @excluded = qw(
21MBEDTLS_DEPRECATED_REMOVED
22MBEDTLS_HAVE_SSE2
23MBEDTLS_PLATFORM_NO_STD_FUNCTIONS
24MBEDTLS_ECP_DP_M221_ENABLED
25MBEDTLS_ECP_DP_M383_ENABLED
26MBEDTLS_ECP_DP_M511_ENABLED
27MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES
28MBEDTLS_NO_PLATFORM_ENTROPY
29MBEDTLS_REMOVE_ARC4_CIPHERSUITES
30MBEDTLS_SSL_HW_RECORD_ACCEL
31MBEDTLS_X509_ALLOW_EXTENSIONS_NON_V3
32MBEDTLS_X509_ALLOW_UNSUPPORTED_CRITICAL_EXTENSION
33MBEDTLS_ZLIB_SUPPORT
34MBEDTLS_PKCS11_C
35_ALT\s*$
36);
37
38# Things that should be enabled in "full" even if they match @excluded
39my @non_excluded = qw(
40PLATFORM_[A-Z0-9]+_ALT
41);
42
43my $config_file = "include/mbedtls/config.h";
44
45# get -f option
46if (@ARGV >= 2 && $ARGV[0] eq "-f") {
47 shift; # -f
48 $config_file = shift;
49
50 -f $config_file or die "No such file: $config_file\n";
51} else {
52 if (! -f $config_file) {
53 chdir '..' or die;
54 -f $config_file
55 or die "Without -f, must be run from root or scripts\n"
56 }
57}
58
59# get action
60die $usage unless @ARGV;
61my $action = shift;
62
63my ($name, $value);
64if ($action eq "full" || $action eq "realfull") {
65 # nothing to do
66} elsif ($action eq "unset") {
67 die $usage unless @ARGV;
68 $name = shift;
69} elsif ($action eq "set") {
70 die $usage unless @ARGV;
71 $name = shift;
72 $value = shift if @ARGV;
73} else {
74 die $usage;
75}
76die $usage if @ARGV;
77
78open my $config_read, '<', $config_file or die "read $config_file: $!\n";
79my @config_lines = <$config_read>;
80close $config_read;
81
82my ($exclude_re, $no_exclude_re);
83if ($action eq "realfull") {
84 $exclude_re = qr/^$/;
85 $no_exclude_re = qr/./;
86} else {
87 $exclude_re = join '|', @excluded;
88 $no_exclude_re = join '|', @non_excluded;
89}
90
91open my $config_write, '>', $config_file or die "write $config_file: $!\n";
92
93my $done;
94for my $line (@config_lines) {
95 if ($action eq "full" || $action eq "realfull") {
96 if ($line =~ /name SECTION: Module configuration options/) {
97 $done = 1;
98 }
99
100 if (!$done && $line =~ m!^//\s?#define! &&
101 ( $line !~ /$exclude_re/ || $line =~ /$no_exclude_re/ ) ) {
102 $line =~ s!^//\s?!!;
103 }
104 if (!$done && $line =~ m!^\s?#define! &&
105 ! ( $line !~ /$exclude_re/ || $line =~ /$no_exclude_re/ ) ) {
106 $line =~ s!^!//!;
107 }
108 } elsif ($action eq "unset") {
109 if (!$done && $line =~ /^\s*#define\s*$name\b/) {
110 $line = '//' . $line;
111 $done = 1;
112 }
113 } elsif (!$done && $action eq "set") {
114 if ($line =~ m!^(?://)?\s*#define\s*$name\b!) {
115 $line = "#define $name";
116 $line .= " $value" if defined $value && $value ne "";
117 $line .= "\n";
118 $done = 1;
119 }
120 }
121
122 print $config_write $line;
123}
124
125close $config_write;
126
127die "configuration section not found" if ($action eq "full" && !$done);
128die "$name not found" if ($action ne "full" && !$done);
129
130__END__
Note: See TracBrowser for help on using the repository browser.