diff --git a/scripts/generate_errors.pl b/scripts/generate_errors.pl index 0c1f7e16ec..2fe202e8d4 100755 --- a/scripts/generate_errors.pl +++ b/scripts/generate_errors.pl @@ -3,15 +3,17 @@ # Generate error.c # # Usage: ./generate_errors.pl or scripts/generate_errors.pl without arguments, -# or generate_errors.pl include_dir data_dir error_file +# or generate_errors.pl include_dir data_dir error_file include_crypto +# include_crypto can be either 0 (don't include) or 1 (include). On by default. use strict; -my ($include_dir, $data_dir, $error_file); +my ($include_dir, $data_dir, $error_file, $include_crypto); +my $crypto_dir = "crypto"; if( @ARGV ) { - die "Invalid number of arguments" if scalar @ARGV != 3; - ($include_dir, $data_dir, $error_file) = @ARGV; + die "Invalid number of arguments" if scalar @ARGV != 4; + ($include_dir, $data_dir, $error_file, $include_crypto) = @ARGV; -d $include_dir or die "No such directory: $include_dir\n"; -d $data_dir or die "No such directory: $data_dir\n"; @@ -19,6 +21,7 @@ if( @ARGV ) { $include_dir = 'include/mbedtls'; $data_dir = 'scripts/data_files'; $error_file = 'library/error.c'; + $include_crypto = 1; unless( -d $include_dir && -d $data_dir ) { chdir '..' or die; @@ -27,6 +30,10 @@ if( @ARGV ) { } } +if( $include_crypto ) { + -d $crypto_dir or die "Crypto submodule not present\n"; +} + my $error_format_file = $data_dir.'/error.fmt'; my @low_level_modules = qw( AES ARC4 ARIA ASN1 BASE64 BIGNUM BLOWFISH @@ -47,9 +54,19 @@ close(FORMAT_FILE); $/ = $line_separator; -my @files = <$include_dir/*.h>; +my @headers = (); +if ($include_crypto) { + @headers = <$crypto_dir/$include_dir/*.h>; + foreach my $header (<$include_dir/*.h>) { + my $basename = $header; $basename =~ s!.*/!!; + push @headers, $header unless -e "$crypto_dir/$include_dir/$basename"; + } +} else { + @headers = <$include_dir/*.h>; +} + my @matches; -foreach my $file (@files) { +foreach my $file (@headers) { open(FILE, "$file"); my @grep_res = grep(/^\s*#define\s+MBEDTLS_ERR_\w+\s+\-0x[0-9A-Fa-f]+/, ); push(@matches, @grep_res); @@ -73,8 +90,9 @@ foreach my $line (@matches) my ($error_name, $error_code) = $line =~ /(MBEDTLS_ERR_\w+)\s+\-(0x\w+)/; my ($description) = $line =~ /\/\*\*< (.*?)\.? \*\//; - die "Duplicated error code: $error_code ($error_name)\n" - if( $error_codes_seen{$error_code}++ ); + if( $error_codes_seen{$error_code}++ ) { + die "Duplicated error code: $error_code ($error_name)\n"; + } $description =~ s/\\/\\\\/g; if ($description eq "") { diff --git a/scripts/generate_visualc_files.pl b/scripts/generate_visualc_files.pl index 9913976749..e6545bc3ad 100755 --- a/scripts/generate_visualc_files.pl +++ b/scripts/generate_visualc_files.pl @@ -4,7 +4,8 @@ # 2010 # # Must be run from mbedTLS root or scripts directory. -# Takes no argument. +# Takes "include_crypto" as an argument that can be either 0 (don't include) or +# 1 (include). Off by default. use warnings; use strict; @@ -18,9 +19,16 @@ my $vsx_main_file = "$vsx_dir/mbedTLS.$vsx_ext"; my $vsx_sln_tpl_file = "scripts/data_files/vs2010-sln-template.sln"; my $vsx_sln_file = "$vsx_dir/mbedTLS.sln"; +my $include_crypto = 0; +if( @ARGV ) { + die "Invalid number of arguments" if scalar @ARGV != 1; + ($include_crypto) = @ARGV; +} + my $programs_dir = 'programs'; my $header_dir = 'include/mbedtls'; my $source_dir = 'library'; +my $crypto_dir = 'crypto'; # Need windows line endings! my $vsx_hdr_tpl = <; - my @sources = <$source_dir/*.c>; + + my @sources = (); + if ($include_crypto) { + @sources = <$crypto_dir/$source_dir/*.c>; + foreach my $file (<$source_dir/*.c>) { + my $basename = $file; $basename =~ s!.*/!!; + push @sources, $file unless -e "$crypto_dir/$source_dir/$basename"; + } + } else { + @sources = <$source_dir/*.c>; + } + map { s!/!\\!g } @headers; map { s!/!\\!g } @sources;