Paul Bakker | 0f90d7d | 2014-04-30 11:49:44 +0200 | [diff] [blame] | 1 | #!/usr/bin/perl |
| 2 | # |
| 3 | |
| 4 | use strict; |
| 5 | |
| 6 | my $include_dir = shift or die "Missing include directory"; |
| 7 | my $data_dir = shift or die "Missing data directory"; |
| 8 | my $feature_file = shift or die "Missing destination file"; |
| 9 | my $feature_format_file = $data_dir.'/version_features.fmt'; |
| 10 | |
| 11 | my @sections = ( "System support", "PolarSSL modules", |
| 12 | "PolarSSL feature support" ); |
| 13 | |
| 14 | my $line_separator = $/; |
| 15 | undef $/; |
| 16 | |
| 17 | open(FORMAT_FILE, "$feature_format_file") or die "Opening feature format file '$feature_format_file': $!"; |
| 18 | my $feature_format = <FORMAT_FILE>; |
| 19 | close(FORMAT_FILE); |
| 20 | |
| 21 | $/ = $line_separator; |
| 22 | |
| 23 | open(CONFIG_H, "$include_dir/config.h") || die("Failure when opening config.h: $!"); |
| 24 | |
| 25 | my $feature_defines = ""; |
| 26 | my $in_section = 0; |
| 27 | |
| 28 | while (my $line = <CONFIG_H>) |
| 29 | { |
| 30 | next if ($in_section && $line !~ /#define/ && $line !~ /SECTION/); |
| 31 | next if (!$in_section && $line !~ /SECTION/); |
| 32 | |
| 33 | if ($in_section) { |
| 34 | if ($line =~ /SECTION/) { |
| 35 | $in_section = 0; |
| 36 | next; |
| 37 | } |
| 38 | |
| 39 | my ($define) = $line =~ /#define (\w+)/; |
| 40 | $feature_defines .= "#if defined(${define})\n"; |
| 41 | $feature_defines .= " \"${define}\",\n"; |
| 42 | $feature_defines .= "#endif /* ${define} */\n"; |
| 43 | } |
| 44 | |
| 45 | if (!$in_section) { |
| 46 | my ($section_name) = $line =~ /SECTION: ([\w ]+)/; |
| 47 | my $found_section = grep $_ eq $section_name, @sections; |
| 48 | |
| 49 | $in_section = 1 if ($found_section); |
| 50 | } |
| 51 | }; |
| 52 | |
| 53 | $feature_format =~ s/FEATURE_DEFINES\n/$feature_defines/g; |
| 54 | |
| 55 | open(ERROR_FILE, ">$feature_file") or die "Opening destination file '$feature_file': $!"; |
| 56 | print ERROR_FILE $feature_format; |
| 57 | close(ERROR_FILE); |