blob: 4781a1476b511f18fd8f4be246f7ef2c6a0b3586 [file] [log] [blame]
Manuel Pégourié-Gonnardbb3a7f22014-07-12 02:11:29 +02001#!/usr/bin/perl
2
3use warnings;
4use strict;
5
6# Things that shouldn't be enabled.
7# Notes:
8# - POLARSSL_X509_ALLOW_EXTENSIONS_NON_V3 and
9# POLARSSL_X509_ALLOW_UNSUPPORTED_CRITICAL_EXTENSION could be enabled if the
10# respective tests were adapted
11my @excluded = qw(
12POLARSSL_HAVE_INT8
13POLARSSL_HAVE_INT16
14POLARSSL_HAVE_SSE2
15POLARSSL_PLATFORM_NO_STD_FUNCTIONS
16POLARSSL_ECP_DP_M221_ENABLED
17POLARSSL_ECP_DP_M383_ENABLED
18POLARSSL_ECP_DP_M511_ENABLED
19POLARSSL_NO_DEFAULT_ENTROPY_SOURCES
20POLARSSL_NO_PLATFORM_ENTROPY
21POLARSSL_SSL_HW_RECORD_ACCEL
22POLARSSL_X509_ALLOW_EXTENSIONS_NON_V3
23POLARSSL_X509_ALLOW_UNSUPPORTED_CRITICAL_EXTENSION
24POLARSSL_ZLIB_SUPPORT
25POLARSSL_PKCS11_C
26_ALT\s*$
27);
28
29my $include_dir;
30
31if( @ARGV ) {
32 die "Invalid number of arguments" if scalar @ARGV != 1;
33 ($include_dir) = @ARGV;
34
35 -d $include_dir or die "No such directory: $include_dir\n";
36} else {
37 $include_dir = 'include/polarssl';
38
39 unless( -d $include_dir ) {
40 chdir '..' or die;
41 -d $include_dir
42 or die "Without arguments, must be run from root or scripts\n"
43 }
44}
45
46my $config_file = "$include_dir/config.h";
47
48open my $config_read, '<', $config_file or die "read $config_file: $!\n";
49my @config_lines = <$config_read>;
50close $config_read;
51
52my $exclude_re = join '|', @excluded;
53
54open my $config_write, '>', $config_file or die "write $config_file: $!\n";
55
56my $done;
57for my $line (@config_lines) {
58 if ($line =~ /name SECTION: Module configuration options/) {
59 $done = 1;
60 }
61
62 if (!$done && $line =~ m!^//\s?#define! && $line !~ /$exclude_re/) {
63 $line =~ s!^//!!;
64 }
65
66 print $config_write $line;
67}
68
69close $config_write;
70
71__END__