6 my ($include_dir, $data_dir, $feature_file);
9 die "Invalid number of arguments" if scalar @ARGV != 3;
10 ($include_dir, $data_dir, $feature_file) = @ARGV;
12 -d $include_dir or die "No such directory: $include_dir\n";
13 -d $data_dir or die "No such directory: $data_dir\n";
15 $include_dir = 'include/mbedtls';
16 $data_dir = 'scripts/data_files';
17 $feature_file = 'library/version_features.c';
19 unless( -d $include_dir && -d $data_dir ) {
21 -d $include_dir && -d $data_dir
22 or die "Without arguments, must be run from root or scripts\n"
26 my $feature_format_file = $data_dir.'/version_features.fmt';
28 my @sections = ( "System support", "mbed TLS modules",
29 "mbed TLS feature support" );
31 my $line_separator = $/;
34 open(FORMAT_FILE, "$feature_format_file") or die "Opening feature format file '$feature_format_file': $!";
35 my $feature_format = <FORMAT_FILE>;
40 open(CONFIG_H, "$include_dir/config.h") || die("Failure when opening config.h: $!");
42 my $feature_defines = "";
45 while (my $line = <CONFIG_H>)
47 next if ($in_section && $line !~ /#define/ && $line !~ /SECTION/);
48 next if (!$in_section && $line !~ /SECTION/);
51 if ($line =~ /SECTION/) {
56 my ($define) = $line =~ /#define (\w+)/;
57 $feature_defines .= "#if defined(${define})\n";
58 $feature_defines .= " \"${define}\",\n";
59 $feature_defines .= "#endif /* ${define} */\n";
63 my ($section_name) = $line =~ /SECTION: ([\w ]+)/;
64 my $found_section = grep $_ eq $section_name, @sections;
66 $in_section = 1 if ($found_section);
70 $feature_format =~ s/FEATURE_DEFINES\n/$feature_defines/g;
72 open(ERROR_FILE, ">$feature_file") or die "Opening destination file '$feature_file': $!";
73 print ERROR_FILE $feature_format;