This Trac instance is not used for development anymore!

We migrated our development workflow to git and Gitea.
To test the future redirection, replace trac by ariadne in the page URL.

source: ps/trunk/build/premake/premake5/contrib/mbedtls/scripts/generate_visualc_files.pl

Last change on this file was 20366, checked in by Itms, 7 years ago

Alpha 12 version of Premake 5, including prebuilt binary for Windows.
Directly taken from https://premake.github.io/.

Refs #3729.

File size: 4.8 KB
Line 
1#!/usr/bin/perl
2
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
6#
7# Must be run from mbedTLS root or scripts directory.
8# Takes no argument.
9
10use warnings;
11use strict;
12use Digest::MD5 'md5_hex';
13
14my $vsx_dir = "visualc/VS2010";
15my $vsx_ext = "vcxproj";
16my $vsx_app_tpl_file = "scripts/data_files/vs2010-app-template.$vsx_ext";
17my $vsx_main_tpl_file = "scripts/data_files/vs2010-main-template.$vsx_ext";
18my $vsx_main_file = "$vsx_dir/mbedTLS.$vsx_ext";
19my $vsx_sln_tpl_file = "scripts/data_files/vs2010-sln-template.sln";
20my $vsx_sln_file = "$vsx_dir/mbedTLS.sln";
21
22my $programs_dir = 'programs';
23my $header_dir = 'include/mbedtls';
24my $source_dir = 'library';
25
26# Need windows line endings!
27my $vsx_hdr_tpl = <<EOT;
28 <ClInclude Include="..\\..\\{NAME}" />\r
29EOT
30my $vsx_src_tpl = <<EOT;
31 <ClCompile Include="..\\..\\{NAME}" />\r
32EOT
33
34my $vsx_sln_app_entry_tpl = <<EOT;
35Project("{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
38 EndProjectSection\r
39EndProject\r
40EOT
41
42my $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
51EOT
52
53exit( main() );
54
55sub check_dirs {
56 return -d $vsx_dir
57 && -d $header_dir
58 && -d $source_dir
59 && -d $programs_dir;
60}
61
62sub slurp_file {
63 my ($filename) = @_;
64
65 local $/ = undef;
66 open my $fh, '<', $filename or die "Could not read $filename\n";
67 my $content = <$fh>;
68 close $fh;
69
70 return $content;
71}
72
73sub content_to_file {
74 my ($content, $filename) = @_;
75
76 open my $fh, '>', $filename or die "Could not write to $filename\n";
77 print $fh $content;
78 close $fh;
79}
80
81sub gen_app_guid {
82 my ($path) = @_;
83
84 my $guid = md5_hex( "mbedTLS:$path" );
85 $guid =~ s/(.{8})(.{4})(.{4})(.{4})(.{12})/\U{$1-$2-$3-$4-$5}/;
86
87 return $guid;
88}
89
90sub gen_app {
91 my ($path, $template, $dir, $ext) = @_;
92
93 my $guid = gen_app_guid( $path );
94 $path =~ s!/!\\!g;
95 (my $appname = $path) =~ s/.*\\//;
96
97 my $content = $template;
98 $content =~ s/<PATHNAME>/$path/g;
99 $content =~ s/<APPNAME>/$appname/g;
100 $content =~ s/<GUID>/$guid/g;
101
102 content_to_file( $content, "$dir/$appname.$ext" );
103}
104
105sub get_app_list {
106 my $app_list = `cd $programs_dir && make list`;
107 die "make list failed: $!\n" if $?;
108
109 return split /\s+/, $app_list;
110}
111
112sub gen_app_files {
113 my @app_list = @_;
114
115 my $vsx_tpl = slurp_file( $vsx_app_tpl_file );
116
117 for my $app ( @app_list ) {
118 gen_app( $app, $vsx_tpl, $vsx_dir, $vsx_ext );
119 }
120}
121
122sub gen_entry_list {
123 my ($tpl, @names) = @_;
124
125 my $entries;
126 for my $name (@names) {
127 (my $entry = $tpl) =~ s/{NAME}/$name/g;
128 $entries .= $entry;
129 }
130
131 return $entries;
132}
133
134sub gen_main_file {
135 my ($headers, $sources, $hdr_tpl, $src_tpl, $main_tpl, $main_out) = @_;
136
137 my $header_entries = gen_entry_list( $hdr_tpl, @$headers );
138 my $source_entries = gen_entry_list( $src_tpl, @$sources );
139
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;
143
144 content_to_file( $out, $main_out );
145}
146
147sub gen_vsx_solution {
148 my (@app_names) = @_;
149
150 my ($app_entries, $conf_entries);
151 for my $path (@app_names) {
152 my $guid = gen_app_guid( $path );
153 (my $appname = $path) =~ s!.*/!!;
154
155 my $app_entry = $vsx_sln_app_entry_tpl;
156 $app_entry =~ s/{APPNAME}/$appname/g;
157 $app_entry =~ s/{GUID}/$guid/g;
158
159 $app_entries .= $app_entry;
160
161 my $conf_entry = $vsx_sln_conf_entry_tpl;
162 $conf_entry =~ s/{GUID}/$guid/g;
163
164 $conf_entries .= $conf_entry;
165 }
166
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;
170
171 content_to_file( $out, $vsx_sln_file );
172}
173
174sub main {
175 if( ! check_dirs() ) {
176 chdir '..' or die;
177 check_dirs or die "Must but run from mbedTLS root or scripts dir\n";
178 }
179
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;
185
186 gen_app_files( @app_list );
187
188 gen_main_file( \@headers, \@sources,
189 $vsx_hdr_tpl, $vsx_src_tpl,
190 $vsx_main_tpl_file, $vsx_main_file );
191
192 gen_vsx_solution( @app_list );
193
194 return 0;
195}
Note: See TracBrowser for help on using the repository browser.