blob: a72247da40b06db843e3c64e2a5f5816ebc5377f [file] [log] [blame]
Paul Bakker0f90d7d2014-04-30 11:49:44 +02001#!/usr/bin/perl
2#
3
4use strict;
5
6my $include_dir = shift or die "Missing include directory";
7my $data_dir = shift or die "Missing data directory";
8my $feature_file = shift or die "Missing destination file";
9my $feature_format_file = $data_dir.'/version_features.fmt';
10
11my @sections = ( "System support", "PolarSSL modules",
12 "PolarSSL feature support" );
13
14my $line_separator = $/;
15undef $/;
16
17open(FORMAT_FILE, "$feature_format_file") or die "Opening feature format file '$feature_format_file': $!";
18my $feature_format = <FORMAT_FILE>;
19close(FORMAT_FILE);
20
21$/ = $line_separator;
22
23open(CONFIG_H, "$include_dir/config.h") || die("Failure when opening config.h: $!");
24
25my $feature_defines = "";
26my $in_section = 0;
27
28while (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
55open(ERROR_FILE, ">$feature_file") or die "Opening destination file '$feature_file': $!";
56print ERROR_FILE $feature_format;
57close(ERROR_FILE);