Generalize everest support to generic 3rdparty support

Other third-party components can now be added by just adding lines to
the definitions of @thirdparty_header_dirs and
@thirdparty_source_dirs.

No semantic change. The output does not change at all.
This commit is contained in:
Gilles Peskine 2020-02-12 20:34:22 +01:00
parent 9ab9621511
commit 13fac98aca

View File

@ -22,8 +22,18 @@ my $programs_dir = 'programs';
my $mbedtls_header_dir = 'include/mbedtls'; my $mbedtls_header_dir = 'include/mbedtls';
my $psa_header_dir = 'include/psa'; my $psa_header_dir = 'include/psa';
my $source_dir = 'library'; my $source_dir = 'library';
my $everest_header_dir = '3rdparty/everest/include/everest';
my @everest_source_dirs = ('3rdparty/everest/library', '3rdparty/everest/library/kremlib', '3rdparty/everest/library/legacy'); my @thirdparty_header_dirs = qw(
3rdparty/everest/include/everest
);
my @thirdparty_source_dirs = qw(
3rdparty/everest/library
3rdparty/everest/library/kremlib
3rdparty/everest/library/legacy
);
my @thirdparty_excluded = qw(
3rdparty/everest/library/Hacl_Curve25519.c
);
# Need windows line endings! # Need windows line endings!
my $vsx_hdr_tpl = <<EOT; my $vsx_hdr_tpl = <<EOT;
@ -55,11 +65,12 @@ EOT
exit( main() ); exit( main() );
sub check_dirs { sub check_dirs {
foreach my $d (@everest_source_dirs) { if (not (-d $d)) { return 0; } } foreach my $d (@thirdparty_header_dirs, @thirdparty_source_dirs) {
if (not (-d $d)) { return 0; }
}
return -d $vsx_dir return -d $vsx_dir
&& -d $mbedtls_header_dir && -d $mbedtls_header_dir
&& -d $psa_header_dir && -d $psa_header_dir
&& -d $everest_header_dir
&& -d $source_dir && -d $source_dir
&& -d $programs_dir; && -d $programs_dir;
} }
@ -92,6 +103,11 @@ sub gen_app_guid {
return $guid; return $guid;
} }
sub is_thirdparty_excluded {
my ($path) = @_;
return grep { $path eq $_ } @thirdparty_excluded;
}
sub gen_app { sub gen_app {
my ($path, $template, $dir, $ext) = @_; my ($path, $template, $dir, $ext) = @_;
@ -143,14 +159,14 @@ sub gen_entry_list {
} }
sub gen_main_file { sub gen_main_file {
my ($mbedtls_headers, $psa_headers, $source_headers, $everest_headers, $sources, $everest_sources, $hdr_tpl, $src_tpl, $main_tpl, $main_out) = @_; my ($mbedtls_headers, $psa_headers, $source_headers, $thirdparty_headers, $sources, $thirdparty_sources, $hdr_tpl, $src_tpl, $main_tpl, $main_out) = @_;
my $header_entries = gen_entry_list( $hdr_tpl, @$mbedtls_headers ); my $header_entries = gen_entry_list( $hdr_tpl, @$mbedtls_headers );
$header_entries .= gen_entry_list( $hdr_tpl, @$psa_headers ); $header_entries .= gen_entry_list( $hdr_tpl, @$psa_headers );
$header_entries .= gen_entry_list( $hdr_tpl, @$source_headers ); $header_entries .= gen_entry_list( $hdr_tpl, @$source_headers );
$header_entries .= gen_entry_list( $hdr_tpl, @$everest_headers ); $header_entries .= gen_entry_list( $hdr_tpl, @$thirdparty_headers );
my $source_entries = gen_entry_list( $src_tpl, @$sources ); my $source_entries = gen_entry_list( $src_tpl, @$sources );
$source_entries .= gen_entry_list( $src_tpl, @$everest_sources ); $source_entries .= gen_entry_list( $src_tpl, @$thirdparty_sources );
my $out = slurp_file( $main_tpl ); my $out = slurp_file( $main_tpl );
$out =~ s/SOURCE_ENTRIES\r\n/$source_entries/m; $out =~ s/SOURCE_ENTRIES\r\n/$source_entries/m;
@ -211,17 +227,16 @@ sub main {
map { s!/!\\!g } @psa_headers; map { s!/!\\!g } @psa_headers;
map { s!/!\\!g } @sources; map { s!/!\\!g } @sources;
my @everest_headers = <$everest_header_dir/*.h>; my @thirdparty_headers = map { <$_/*.h> } @thirdparty_header_dirs;
my @everest_sources = (); my @thirdparty_sources = map { <$_/*.c> } @thirdparty_source_dirs;
foreach my $d (@everest_source_dirs) { push @everest_sources, <$d/*.c>; } @thirdparty_sources = grep { ! is_thirdparty_excluded($_) } @thirdparty_sources;
@everest_sources = grep !/3rdparty\/everest\/library\/Hacl_Curve25519.c/, @everest_sources; map { s!/!\\!g } @thirdparty_headers;
map { s!/!\\!g } @everest_headers; map { s!/!\\!g } @thirdparty_sources;
map { s!/!\\!g } @everest_sources;
gen_app_files( @app_list ); gen_app_files( @app_list );
gen_main_file( \@mbedtls_headers, \@psa_headers, \@source_headers, gen_main_file( \@mbedtls_headers, \@psa_headers, \@source_headers,
\@everest_headers, \@sources, \@everest_sources, $vsx_hdr_tpl, \@thirdparty_headers, \@sources, \@thirdparty_sources, $vsx_hdr_tpl,
$vsx_src_tpl, $vsx_main_tpl_file, $vsx_main_file ); $vsx_src_tpl, $vsx_main_tpl_file, $vsx_main_file );
gen_vsx_solution( @app_list ); gen_vsx_solution( @app_list );