Manuel Pégourié-Gonnard | bb3a7f2 | 2014-07-12 02:11:29 +0200 | [diff] [blame^] | 1 | #!/usr/bin/perl |
| 2 | |
| 3 | use warnings; |
| 4 | use 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 |
| 11 | my @excluded = qw( |
| 12 | POLARSSL_HAVE_INT8 |
| 13 | POLARSSL_HAVE_INT16 |
| 14 | POLARSSL_HAVE_SSE2 |
| 15 | POLARSSL_PLATFORM_NO_STD_FUNCTIONS |
| 16 | POLARSSL_ECP_DP_M221_ENABLED |
| 17 | POLARSSL_ECP_DP_M383_ENABLED |
| 18 | POLARSSL_ECP_DP_M511_ENABLED |
| 19 | POLARSSL_NO_DEFAULT_ENTROPY_SOURCES |
| 20 | POLARSSL_NO_PLATFORM_ENTROPY |
| 21 | POLARSSL_SSL_HW_RECORD_ACCEL |
| 22 | POLARSSL_X509_ALLOW_EXTENSIONS_NON_V3 |
| 23 | POLARSSL_X509_ALLOW_UNSUPPORTED_CRITICAL_EXTENSION |
| 24 | POLARSSL_ZLIB_SUPPORT |
| 25 | POLARSSL_PKCS11_C |
| 26 | _ALT\s*$ |
| 27 | ); |
| 28 | |
| 29 | my $include_dir; |
| 30 | |
| 31 | if( @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 | |
| 46 | my $config_file = "$include_dir/config.h"; |
| 47 | |
| 48 | open my $config_read, '<', $config_file or die "read $config_file: $!\n"; |
| 49 | my @config_lines = <$config_read>; |
| 50 | close $config_read; |
| 51 | |
| 52 | my $exclude_re = join '|', @excluded; |
| 53 | |
| 54 | open my $config_write, '>', $config_file or die "write $config_file: $!\n"; |
| 55 | |
| 56 | my $done; |
| 57 | for 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 | |
| 69 | close $config_write; |
| 70 | |
| 71 | __END__ |