2013-09-16 13:33:42 +02:00
|
|
|
#!/usr/bin/perl
|
|
|
|
|
2013-09-20 15:11:44 +02:00
|
|
|
# create individual project files for example programs
|
|
|
|
# for VS6 and VS2010
|
2014-05-07 17:51:20 +02:00
|
|
|
#
|
|
|
|
# Must be run from PolarSSL root or scripts directory.
|
|
|
|
# Takes no argument.
|
2013-09-20 15:11:44 +02:00
|
|
|
|
2013-09-16 13:33:42 +02:00
|
|
|
use warnings;
|
|
|
|
use strict;
|
|
|
|
|
2014-05-07 17:51:20 +02:00
|
|
|
my $vs6_dir = "visualc/VS6";
|
2013-09-16 13:33:42 +02:00
|
|
|
my $vs6_ext = "dsp";
|
2014-05-07 17:51:20 +02:00
|
|
|
my $vs6_app_tpl_file = "scripts/data_files/vs6-app-template.$vs6_ext";
|
2014-05-08 11:33:30 +02:00
|
|
|
my $vs6_main_tpl_file = "scripts/data_files/vs6-main-template.$vs6_ext";
|
|
|
|
my $vs6_main_file = "$vs6_dir/polarssl.$vs6_ext";
|
2013-09-16 13:33:42 +02:00
|
|
|
|
2014-05-07 17:51:20 +02:00
|
|
|
my $vsx_dir = "visualc/VS2010";
|
2013-09-16 13:33:42 +02:00
|
|
|
my $vsx_ext = "vcxproj";
|
2014-05-07 17:51:20 +02:00
|
|
|
my $vsx_app_tpl_file = "scripts/data_files/vs2010-app-template.$vsx_ext";
|
2014-05-08 11:33:30 +02:00
|
|
|
my $vsx_main_tpl_file = "scripts/data_files/vs2010-main-template.$vsx_ext";
|
|
|
|
my $vsx_main_file = "$vsx_dir/PolarSSL.$vsx_ext";
|
2014-05-07 17:51:20 +02:00
|
|
|
|
|
|
|
my $programs_dir = 'programs';
|
2014-05-08 11:33:30 +02:00
|
|
|
my $header_dir = 'include/polarssl';
|
|
|
|
my $source_dir = 'library';
|
|
|
|
|
|
|
|
# Need windows line endings!
|
|
|
|
my $vs6_file_tpl = <<EOT;
|
|
|
|
# Begin Source File\r
|
|
|
|
\r
|
|
|
|
SOURCE=..\\..\\{FILE}\r
|
|
|
|
# End Source File\r
|
|
|
|
EOT
|
|
|
|
|
|
|
|
my $vsx_hdr_tpl = <<EOT;
|
|
|
|
<ClInclude Include="..\\..\\{FILE}" />\r
|
|
|
|
EOT
|
|
|
|
my $vsx_src_tpl = <<EOT;
|
|
|
|
<ClCompile Include="..\\..\\{FILE}" />\r
|
|
|
|
EOT
|
2013-09-16 13:33:42 +02:00
|
|
|
|
|
|
|
exit( main() );
|
|
|
|
|
2014-05-07 17:51:20 +02:00
|
|
|
sub check_dirs {
|
|
|
|
return -d $vs6_dir
|
|
|
|
&& -d $vsx_dir
|
2014-05-08 11:33:30 +02:00
|
|
|
&& -d $header_dir
|
|
|
|
&& -d $source_dir
|
2014-05-07 17:51:20 +02:00
|
|
|
&& -d $programs_dir;
|
|
|
|
}
|
|
|
|
|
2013-09-16 13:33:42 +02:00
|
|
|
sub slurp_file {
|
|
|
|
my ($filename) = @_;
|
|
|
|
|
|
|
|
local $/ = undef;
|
|
|
|
open my $fh, '<', $filename or die "Could not read $filename\n";
|
|
|
|
my $content = <$fh>;
|
|
|
|
close $fh;
|
|
|
|
|
|
|
|
return $content;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub gen_app {
|
|
|
|
my ($path, $template, $dir, $ext) = @_;
|
|
|
|
|
|
|
|
$path =~ s!/!\\!g;
|
|
|
|
(my $appname = $path) =~ s/.*\\//;
|
|
|
|
|
|
|
|
my $content = $template;
|
|
|
|
$content =~ s/<PATHNAME>/$path/g;
|
|
|
|
$content =~ s/<APPNAME>/$appname/g;
|
|
|
|
|
|
|
|
open my $app_fh, '>', "$dir/$appname.$ext";
|
|
|
|
print $app_fh $content;
|
|
|
|
close $app_fh;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub get_app_list {
|
2014-05-07 17:51:20 +02:00
|
|
|
my $app_list = `cd $programs_dir && make list`;
|
2013-09-16 13:33:42 +02:00
|
|
|
die "make list failed: $!\n" if $?;
|
|
|
|
|
|
|
|
return split /\s+/, $app_list;
|
|
|
|
}
|
|
|
|
|
2014-05-07 17:51:20 +02:00
|
|
|
sub gen_app_files {
|
2014-05-08 11:33:30 +02:00
|
|
|
my @app_list = @_;
|
|
|
|
|
2014-05-07 17:51:20 +02:00
|
|
|
my $vs6_tpl = slurp_file( $vs6_app_tpl_file );
|
|
|
|
my $vsx_tpl = slurp_file( $vsx_app_tpl_file );
|
2013-09-16 13:33:42 +02:00
|
|
|
|
2014-05-08 11:33:30 +02:00
|
|
|
for my $app ( @app_list ) {
|
2013-09-16 13:33:42 +02:00
|
|
|
gen_app( $app, $vs6_tpl, $vs6_dir, $vs6_ext );
|
|
|
|
gen_app( $app, $vsx_tpl, $vsx_dir, $vsx_ext );
|
|
|
|
}
|
2014-05-07 17:51:20 +02:00
|
|
|
}
|
|
|
|
|
2014-05-08 11:33:30 +02:00
|
|
|
sub gen_entry_list {
|
|
|
|
my ($tpl, @files) = @_;
|
|
|
|
|
|
|
|
my $entries;
|
|
|
|
for my $file (@files) {
|
|
|
|
(my $entry = $tpl) =~ s/{FILE}/$file/;
|
|
|
|
$entries .= $entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $entries;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub gen_main_file {
|
|
|
|
my ($headers, $sources, $hdr_tpl, $src_tpl, $main_tpl, $main_out) = @_;
|
|
|
|
|
|
|
|
my $header_entries = gen_entry_list( $hdr_tpl, @$headers );
|
|
|
|
my $source_entries = gen_entry_list( $src_tpl, @$sources );
|
|
|
|
|
|
|
|
my $out = slurp_file( $main_tpl );
|
|
|
|
$out =~ s/SOURCE_ENTRIES\r\n/$source_entries/m;
|
|
|
|
$out =~ s/HEADER_ENTRIES\r\n/$header_entries/m;
|
|
|
|
|
|
|
|
open my $fh, '>', $main_out or die;
|
|
|
|
print $fh $out;
|
|
|
|
close $fh;
|
|
|
|
}
|
|
|
|
|
2014-05-07 17:51:20 +02:00
|
|
|
sub main {
|
|
|
|
if( ! check_dirs() ) {
|
|
|
|
chdir '..' or die;
|
|
|
|
check_dirs or die "Must but run from PolarSSL root or scripts dir\n";
|
|
|
|
}
|
|
|
|
|
2014-05-08 11:33:30 +02:00
|
|
|
my @app_list = get_app_list();
|
|
|
|
my @headers = <$header_dir/*.h>;
|
|
|
|
my @sources = <$source_dir/*.c>;
|
|
|
|
map { s!/!\\!g } @headers;
|
|
|
|
map { s!/!\\!g } @sources;
|
|
|
|
|
|
|
|
print "Generating apps files... ";
|
|
|
|
gen_app_files( @app_list );
|
|
|
|
print "done.\n";
|
|
|
|
|
|
|
|
print "Generating main files... ";
|
|
|
|
gen_main_file( \@headers, \@sources,
|
|
|
|
$vs6_file_tpl, $vs6_file_tpl,
|
|
|
|
$vs6_main_tpl_file, $vs6_main_file );
|
|
|
|
gen_main_file( \@headers, \@sources,
|
|
|
|
$vsx_hdr_tpl, $vsx_src_tpl,
|
|
|
|
$vsx_main_tpl_file, $vsx_main_file );
|
2014-05-07 17:51:20 +02:00
|
|
|
print "done.\n";
|
2013-09-16 13:33:42 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|