3 # Generate files for MS Visual Studio:
4 # - for VS6: main project (library) file, individual app files, workspace
5 # - for VS2010: main file, individual apps, solution file
7 # Must be run from mbedTLS root or scripts directory.
12 use Digest::MD5 'md5_hex';
14 my $vsx_dir = "visualc/VS2010";
15 my $vsx_ext = "vcxproj";
16 my $vsx_app_tpl_file = "scripts/data_files/vs2010-app-template.$vsx_ext";
17 my $vsx_main_tpl_file = "scripts/data_files/vs2010-main-template.$vsx_ext";
18 my $vsx_main_file = "$vsx_dir/mbedTLS.$vsx_ext";
19 my $vsx_sln_tpl_file = "scripts/data_files/vs2010-sln-template.sln";
20 my $vsx_sln_file = "$vsx_dir/mbedTLS.sln";
22 my $programs_dir = 'programs';
23 my $header_dir = 'include/mbedtls';
24 my $source_dir = 'library';
26 # Need windows line endings!
27 my $vsx_hdr_tpl = <<EOT;
28 <ClInclude Include="..\\..\\{NAME}" />\r
30 my $vsx_src_tpl = <<EOT;
31 <ClCompile Include="..\\..\\{NAME}" />\r
34 my $vsx_sln_app_entry_tpl = <<EOT;
35 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "{APPNAME}", "{APPNAME}.vcxproj", "{GUID}"\r
36 ProjectSection(ProjectDependencies) = postProject\r
37 {46CF2D25-6A36-4189-B59C-E4815388E554} = {46CF2D25-6A36-4189-B59C-E4815388E554}\r
42 my $vsx_sln_conf_entry_tpl = <<EOT;
43 {GUID}.Debug|Win32.ActiveCfg = Debug|Win32\r
44 {GUID}.Debug|Win32.Build.0 = Debug|Win32\r
45 {GUID}.Debug|x64.ActiveCfg = Debug|x64\r
46 {GUID}.Debug|x64.Build.0 = Debug|x64\r
47 {GUID}.Release|Win32.ActiveCfg = Release|Win32\r
48 {GUID}.Release|Win32.Build.0 = Release|Win32\r
49 {GUID}.Release|x64.ActiveCfg = Release|x64\r
50 {GUID}.Release|x64.Build.0 = Release|x64\r
66 open my $fh, '<', $filename or die "Could not read $filename\n";
74 my ($content, $filename) = @_;
76 open my $fh, '>', $filename or die "Could not write to $filename\n";
84 my $guid = md5_hex( "mbedTLS:$path" );
85 $guid =~ s/(.{8})(.{4})(.{4})(.{4})(.{12})/\U{$1-$2-$3-$4-$5}/;
91 my ($path, $template, $dir, $ext) = @_;
93 my $guid = gen_app_guid( $path );
95 (my $appname = $path) =~ s/.*\\//;
97 my $content = $template;
98 $content =~ s/<PATHNAME>/$path/g;
99 $content =~ s/<APPNAME>/$appname/g;
100 $content =~ s/<GUID>/$guid/g;
102 content_to_file( $content, "$dir/$appname.$ext" );
106 my $app_list = `cd $programs_dir && make list`;
107 die "make list failed: $!\n" if $?;
109 return split /\s+/, $app_list;
115 my $vsx_tpl = slurp_file( $vsx_app_tpl_file );
117 for my $app ( @app_list ) {
118 gen_app( $app, $vsx_tpl, $vsx_dir, $vsx_ext );
123 my ($tpl, @names) = @_;
126 for my $name (@names) {
127 (my $entry = $tpl) =~ s/{NAME}/$name/g;
135 my ($headers, $sources, $hdr_tpl, $src_tpl, $main_tpl, $main_out) = @_;
137 my $header_entries = gen_entry_list( $hdr_tpl, @$headers );
138 my $source_entries = gen_entry_list( $src_tpl, @$sources );
140 my $out = slurp_file( $main_tpl );
141 $out =~ s/SOURCE_ENTRIES\r\n/$source_entries/m;
142 $out =~ s/HEADER_ENTRIES\r\n/$header_entries/m;
144 content_to_file( $out, $main_out );
147 sub gen_vsx_solution {
148 my (@app_names) = @_;
150 my ($app_entries, $conf_entries);
151 for my $path (@app_names) {
152 my $guid = gen_app_guid( $path );
153 (my $appname = $path) =~ s!.*/!!;
155 my $app_entry = $vsx_sln_app_entry_tpl;
156 $app_entry =~ s/{APPNAME}/$appname/g;
157 $app_entry =~ s/{GUID}/$guid/g;
159 $app_entries .= $app_entry;
161 my $conf_entry = $vsx_sln_conf_entry_tpl;
162 $conf_entry =~ s/{GUID}/$guid/g;
164 $conf_entries .= $conf_entry;
167 my $out = slurp_file( $vsx_sln_tpl_file );
168 $out =~ s/APP_ENTRIES\r\n/$app_entries/m;
169 $out =~ s/CONF_ENTRIES\r\n/$conf_entries/m;
171 content_to_file( $out, $vsx_sln_file );
175 if( ! check_dirs() ) {
177 check_dirs or die "Must but run from mbedTLS root or scripts dir\n";
180 my @app_list = get_app_list();
181 my @headers = <$header_dir/*.h>;
182 my @sources = <$source_dir/*.c>;
183 map { s!/!\\!g } @headers;
184 map { s!/!\\!g } @sources;
186 gen_app_files( @app_list );
188 gen_main_file( \@headers, \@sources,
189 $vsx_hdr_tpl, $vsx_src_tpl,
190 $vsx_main_tpl_file, $vsx_main_file );
192 gen_vsx_solution( @app_list );