Manuel Pégourié-Gonnard | 1b57878 | 2013-09-16 13:33:42 +0200 | [diff] [blame] | 1 | #!/usr/bin/perl |
| 2 | |
Manuel Pégourié-Gonnard | 684e9dc | 2013-09-20 15:11:44 +0200 | [diff] [blame] | 3 | # create individual project files for example programs |
| 4 | # for VS6 and VS2010 |
Manuel Pégourié-Gonnard | 2d34fe3 | 2014-05-07 17:51:20 +0200 | [diff] [blame] | 5 | # |
| 6 | # Must be run from PolarSSL root or scripts directory. |
| 7 | # Takes no argument. |
Manuel Pégourié-Gonnard | 684e9dc | 2013-09-20 15:11:44 +0200 | [diff] [blame] | 8 | |
Manuel Pégourié-Gonnard | 1b57878 | 2013-09-16 13:33:42 +0200 | [diff] [blame] | 9 | use warnings; |
| 10 | use strict; |
Manuel Pégourié-Gonnard | 41e8b62 | 2014-05-09 12:27:49 +0200 | [diff] [blame] | 11 | use Digest::MD5 'md5_hex'; |
Manuel Pégourié-Gonnard | 1b57878 | 2013-09-16 13:33:42 +0200 | [diff] [blame] | 12 | |
Manuel Pégourié-Gonnard | 2d34fe3 | 2014-05-07 17:51:20 +0200 | [diff] [blame] | 13 | my $vs6_dir = "visualc/VS6"; |
Manuel Pégourié-Gonnard | 1b57878 | 2013-09-16 13:33:42 +0200 | [diff] [blame] | 14 | my $vs6_ext = "dsp"; |
Manuel Pégourié-Gonnard | 2d34fe3 | 2014-05-07 17:51:20 +0200 | [diff] [blame] | 15 | my $vs6_app_tpl_file = "scripts/data_files/vs6-app-template.$vs6_ext"; |
Manuel Pégourié-Gonnard | 0aafa5c | 2014-05-08 11:33:30 +0200 | [diff] [blame] | 16 | my $vs6_main_tpl_file = "scripts/data_files/vs6-main-template.$vs6_ext"; |
| 17 | my $vs6_main_file = "$vs6_dir/polarssl.$vs6_ext"; |
Manuel Pégourié-Gonnard | cd8f844 | 2014-05-08 12:53:58 +0200 | [diff] [blame] | 18 | my $vs6_wsp_tpl_file = "scripts/data_files/vs6-workspace-template.dsw"; |
| 19 | my $vs6_wsp_file = "$vs6_dir/polarssl.dsw"; |
Manuel Pégourié-Gonnard | 1b57878 | 2013-09-16 13:33:42 +0200 | [diff] [blame] | 20 | |
Manuel Pégourié-Gonnard | 2d34fe3 | 2014-05-07 17:51:20 +0200 | [diff] [blame] | 21 | my $vsx_dir = "visualc/VS2010"; |
Manuel Pégourié-Gonnard | 1b57878 | 2013-09-16 13:33:42 +0200 | [diff] [blame] | 22 | my $vsx_ext = "vcxproj"; |
Manuel Pégourié-Gonnard | 2d34fe3 | 2014-05-07 17:51:20 +0200 | [diff] [blame] | 23 | my $vsx_app_tpl_file = "scripts/data_files/vs2010-app-template.$vsx_ext"; |
Manuel Pégourié-Gonnard | 0aafa5c | 2014-05-08 11:33:30 +0200 | [diff] [blame] | 24 | my $vsx_main_tpl_file = "scripts/data_files/vs2010-main-template.$vsx_ext"; |
| 25 | my $vsx_main_file = "$vsx_dir/PolarSSL.$vsx_ext"; |
Manuel Pégourié-Gonnard | 0598faf | 2014-05-09 12:56:03 +0200 | [diff] [blame^] | 26 | my $vsx_sln_tpl_file = "scripts/data_files/vs2010-sln-template.sln"; |
| 27 | my $vsx_sln_file = "$vsx_dir/PolarSSL.sln"; |
Manuel Pégourié-Gonnard | 2d34fe3 | 2014-05-07 17:51:20 +0200 | [diff] [blame] | 28 | |
| 29 | my $programs_dir = 'programs'; |
Manuel Pégourié-Gonnard | 0aafa5c | 2014-05-08 11:33:30 +0200 | [diff] [blame] | 30 | my $header_dir = 'include/polarssl'; |
| 31 | my $source_dir = 'library'; |
| 32 | |
| 33 | # Need windows line endings! |
| 34 | my $vs6_file_tpl = <<EOT; |
| 35 | # Begin Source File\r |
| 36 | \r |
Manuel Pégourié-Gonnard | cd8f844 | 2014-05-08 12:53:58 +0200 | [diff] [blame] | 37 | SOURCE=..\\..\\{NAME}\r |
Manuel Pégourié-Gonnard | 0aafa5c | 2014-05-08 11:33:30 +0200 | [diff] [blame] | 38 | # End Source File\r |
| 39 | EOT |
| 40 | |
Manuel Pégourié-Gonnard | cd8f844 | 2014-05-08 12:53:58 +0200 | [diff] [blame] | 41 | my $vs6_wsp_entry_tpl = <<EOT; |
| 42 | ###############################################################################\r |
| 43 | \r |
| 44 | Project: "{NAME}"=.\\{NAME}.dsp - Package Owner=<4>\r |
| 45 | \r |
| 46 | Package=<5>\r |
| 47 | {{{\r |
| 48 | }}}\r |
| 49 | \r |
| 50 | Package=<4>\r |
| 51 | {{{\r |
| 52 | Begin Project Dependency\r |
| 53 | Project_Dep_Name polarssl\r |
| 54 | End Project Dependency\r |
| 55 | }}}\r |
| 56 | \r |
| 57 | EOT |
| 58 | |
Manuel Pégourié-Gonnard | 0aafa5c | 2014-05-08 11:33:30 +0200 | [diff] [blame] | 59 | my $vsx_hdr_tpl = <<EOT; |
Manuel Pégourié-Gonnard | cd8f844 | 2014-05-08 12:53:58 +0200 | [diff] [blame] | 60 | <ClInclude Include="..\\..\\{NAME}" />\r |
Manuel Pégourié-Gonnard | 0aafa5c | 2014-05-08 11:33:30 +0200 | [diff] [blame] | 61 | EOT |
| 62 | my $vsx_src_tpl = <<EOT; |
Manuel Pégourié-Gonnard | cd8f844 | 2014-05-08 12:53:58 +0200 | [diff] [blame] | 63 | <ClCompile Include="..\\..\\{NAME}" />\r |
Manuel Pégourié-Gonnard | 0aafa5c | 2014-05-08 11:33:30 +0200 | [diff] [blame] | 64 | EOT |
Manuel Pégourié-Gonnard | 1b57878 | 2013-09-16 13:33:42 +0200 | [diff] [blame] | 65 | |
Manuel Pégourié-Gonnard | 0598faf | 2014-05-09 12:56:03 +0200 | [diff] [blame^] | 66 | my $vsx_sln_app_entry_tpl = <<EOT; |
| 67 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "{APPNAME}", "{APPNAME}.vcxproj", "{GUID}"\r |
| 68 | ProjectSection(ProjectDependencies) = postProject\r |
| 69 | {46CF2D25-6A36-4189-B59C-E4815388E554} = {46CF2D25-6A36-4189-B59C-E4815388E554}\r |
| 70 | EndProjectSection\r |
| 71 | EndProject\r |
| 72 | EOT |
| 73 | |
| 74 | my $vsx_sln_conf_entry_tpl = <<EOT; |
| 75 | {GUID}.Debug|Win32.ActiveCfg = Debug|Win32\r |
| 76 | {GUID}.Debug|Win32.Build.0 = Debug|Win32\r |
| 77 | {GUID}.Debug|x64.ActiveCfg = Debug|x64\r |
| 78 | {GUID}.Debug|x64.Build.0 = Debug|x64\r |
| 79 | {GUID}.Release|Win32.ActiveCfg = Release|Win32\r |
| 80 | {GUID}.Release|Win32.Build.0 = Release|Win32\r |
| 81 | {GUID}.Release|x64.ActiveCfg = Release|x64\r |
| 82 | {GUID}.Release|x64.Build.0 = Release|x64\r |
| 83 | EOT |
| 84 | |
Manuel Pégourié-Gonnard | 1b57878 | 2013-09-16 13:33:42 +0200 | [diff] [blame] | 85 | exit( main() ); |
| 86 | |
Manuel Pégourié-Gonnard | 2d34fe3 | 2014-05-07 17:51:20 +0200 | [diff] [blame] | 87 | sub check_dirs { |
| 88 | return -d $vs6_dir |
| 89 | && -d $vsx_dir |
Manuel Pégourié-Gonnard | 0aafa5c | 2014-05-08 11:33:30 +0200 | [diff] [blame] | 90 | && -d $header_dir |
| 91 | && -d $source_dir |
Manuel Pégourié-Gonnard | 2d34fe3 | 2014-05-07 17:51:20 +0200 | [diff] [blame] | 92 | && -d $programs_dir; |
| 93 | } |
| 94 | |
Manuel Pégourié-Gonnard | 1b57878 | 2013-09-16 13:33:42 +0200 | [diff] [blame] | 95 | sub slurp_file { |
| 96 | my ($filename) = @_; |
| 97 | |
| 98 | local $/ = undef; |
| 99 | open my $fh, '<', $filename or die "Could not read $filename\n"; |
| 100 | my $content = <$fh>; |
| 101 | close $fh; |
| 102 | |
| 103 | return $content; |
| 104 | } |
| 105 | |
Manuel Pégourié-Gonnard | 41e8b62 | 2014-05-09 12:27:49 +0200 | [diff] [blame] | 106 | sub gen_app_guid { |
| 107 | my ($path) = @_; |
| 108 | |
| 109 | my $guid = md5_hex( "PolarSSL:$path" ); |
| 110 | $guid =~ s/(.{8})(.{4})(.{4})(.{4})(.{12})/\U{$1-$2-$3-$4-$5}/; |
| 111 | |
| 112 | return $guid; |
| 113 | } |
| 114 | |
Manuel Pégourié-Gonnard | 1b57878 | 2013-09-16 13:33:42 +0200 | [diff] [blame] | 115 | sub gen_app { |
| 116 | my ($path, $template, $dir, $ext) = @_; |
| 117 | |
Manuel Pégourié-Gonnard | 41e8b62 | 2014-05-09 12:27:49 +0200 | [diff] [blame] | 118 | my $guid = gen_app_guid( $path ); |
Manuel Pégourié-Gonnard | 1b57878 | 2013-09-16 13:33:42 +0200 | [diff] [blame] | 119 | $path =~ s!/!\\!g; |
| 120 | (my $appname = $path) =~ s/.*\\//; |
| 121 | |
| 122 | my $content = $template; |
| 123 | $content =~ s/<PATHNAME>/$path/g; |
| 124 | $content =~ s/<APPNAME>/$appname/g; |
Manuel Pégourié-Gonnard | 41e8b62 | 2014-05-09 12:27:49 +0200 | [diff] [blame] | 125 | $content =~ s/<GUID>/$guid/g; |
Manuel Pégourié-Gonnard | 1b57878 | 2013-09-16 13:33:42 +0200 | [diff] [blame] | 126 | |
| 127 | open my $app_fh, '>', "$dir/$appname.$ext"; |
| 128 | print $app_fh $content; |
| 129 | close $app_fh; |
| 130 | } |
| 131 | |
| 132 | sub get_app_list { |
Manuel Pégourié-Gonnard | 2d34fe3 | 2014-05-07 17:51:20 +0200 | [diff] [blame] | 133 | my $app_list = `cd $programs_dir && make list`; |
Manuel Pégourié-Gonnard | 1b57878 | 2013-09-16 13:33:42 +0200 | [diff] [blame] | 134 | die "make list failed: $!\n" if $?; |
| 135 | |
| 136 | return split /\s+/, $app_list; |
| 137 | } |
| 138 | |
Manuel Pégourié-Gonnard | 2d34fe3 | 2014-05-07 17:51:20 +0200 | [diff] [blame] | 139 | sub gen_app_files { |
Manuel Pégourié-Gonnard | 0aafa5c | 2014-05-08 11:33:30 +0200 | [diff] [blame] | 140 | my @app_list = @_; |
| 141 | |
Manuel Pégourié-Gonnard | 2d34fe3 | 2014-05-07 17:51:20 +0200 | [diff] [blame] | 142 | my $vs6_tpl = slurp_file( $vs6_app_tpl_file ); |
| 143 | my $vsx_tpl = slurp_file( $vsx_app_tpl_file ); |
Manuel Pégourié-Gonnard | 1b57878 | 2013-09-16 13:33:42 +0200 | [diff] [blame] | 144 | |
Manuel Pégourié-Gonnard | 0aafa5c | 2014-05-08 11:33:30 +0200 | [diff] [blame] | 145 | for my $app ( @app_list ) { |
Manuel Pégourié-Gonnard | 1b57878 | 2013-09-16 13:33:42 +0200 | [diff] [blame] | 146 | gen_app( $app, $vs6_tpl, $vs6_dir, $vs6_ext ); |
| 147 | gen_app( $app, $vsx_tpl, $vsx_dir, $vsx_ext ); |
| 148 | } |
Manuel Pégourié-Gonnard | 2d34fe3 | 2014-05-07 17:51:20 +0200 | [diff] [blame] | 149 | } |
| 150 | |
Manuel Pégourié-Gonnard | 0aafa5c | 2014-05-08 11:33:30 +0200 | [diff] [blame] | 151 | sub gen_entry_list { |
Manuel Pégourié-Gonnard | cd8f844 | 2014-05-08 12:53:58 +0200 | [diff] [blame] | 152 | my ($tpl, @names) = @_; |
Manuel Pégourié-Gonnard | 0aafa5c | 2014-05-08 11:33:30 +0200 | [diff] [blame] | 153 | |
| 154 | my $entries; |
Manuel Pégourié-Gonnard | cd8f844 | 2014-05-08 12:53:58 +0200 | [diff] [blame] | 155 | for my $name (@names) { |
| 156 | (my $entry = $tpl) =~ s/{NAME}/$name/g; |
Manuel Pégourié-Gonnard | 0aafa5c | 2014-05-08 11:33:30 +0200 | [diff] [blame] | 157 | $entries .= $entry; |
| 158 | } |
| 159 | |
| 160 | return $entries; |
| 161 | } |
| 162 | |
| 163 | sub gen_main_file { |
| 164 | my ($headers, $sources, $hdr_tpl, $src_tpl, $main_tpl, $main_out) = @_; |
| 165 | |
| 166 | my $header_entries = gen_entry_list( $hdr_tpl, @$headers ); |
| 167 | my $source_entries = gen_entry_list( $src_tpl, @$sources ); |
| 168 | |
| 169 | my $out = slurp_file( $main_tpl ); |
| 170 | $out =~ s/SOURCE_ENTRIES\r\n/$source_entries/m; |
| 171 | $out =~ s/HEADER_ENTRIES\r\n/$header_entries/m; |
| 172 | |
| 173 | open my $fh, '>', $main_out or die; |
| 174 | print $fh $out; |
| 175 | close $fh; |
| 176 | } |
| 177 | |
Manuel Pégourié-Gonnard | cd8f844 | 2014-05-08 12:53:58 +0200 | [diff] [blame] | 178 | sub gen_vs6_workspace { |
| 179 | my (@app_names) = @_; |
| 180 | |
| 181 | map { s!.*/!! } @app_names; |
| 182 | my $entries = gen_entry_list( $vs6_wsp_entry_tpl, @app_names ); |
| 183 | |
| 184 | my $out = slurp_file( $vs6_wsp_tpl_file ); |
| 185 | $out =~ s/APP_ENTRIES\r\n/$entries/m; |
| 186 | |
| 187 | open my $fh, '>', $vs6_wsp_file or die; |
| 188 | print $fh $out; |
| 189 | close $fh; |
| 190 | } |
| 191 | |
Manuel Pégourié-Gonnard | 0598faf | 2014-05-09 12:56:03 +0200 | [diff] [blame^] | 192 | sub gen_vsx_solution { |
| 193 | my (@app_names) = @_; |
| 194 | |
| 195 | my ($app_entries, $conf_entries); |
| 196 | for my $path (@app_names) { |
| 197 | my $guid = gen_app_guid( $path ); |
| 198 | (my $appname = $path) =~ s!.*/!!; |
| 199 | |
| 200 | my $app_entry = $vsx_sln_app_entry_tpl; |
| 201 | $app_entry =~ s/{APPNAME}/$appname/g; |
| 202 | $app_entry =~ s/{GUID}/$guid/g; |
| 203 | |
| 204 | $app_entries .= $app_entry; |
| 205 | |
| 206 | my $conf_entry = $vsx_sln_conf_entry_tpl; |
| 207 | $conf_entry =~ s/{GUID}/$guid/g; |
| 208 | |
| 209 | $conf_entries .= $conf_entry; |
| 210 | } |
| 211 | |
| 212 | my $out = slurp_file( $vsx_sln_tpl_file ); |
| 213 | $out =~ s/APP_ENTRIES\r\n/$app_entries/m; |
| 214 | $out =~ s/CONF_ENTRIES\r\n/$conf_entries/m; |
| 215 | |
| 216 | open my $fh, '>', $vsx_sln_file or die; |
| 217 | print $fh $out; |
| 218 | close $fh; |
| 219 | } |
| 220 | |
Manuel Pégourié-Gonnard | 2d34fe3 | 2014-05-07 17:51:20 +0200 | [diff] [blame] | 221 | sub main { |
| 222 | if( ! check_dirs() ) { |
| 223 | chdir '..' or die; |
| 224 | check_dirs or die "Must but run from PolarSSL root or scripts dir\n"; |
| 225 | } |
| 226 | |
Manuel Pégourié-Gonnard | 0aafa5c | 2014-05-08 11:33:30 +0200 | [diff] [blame] | 227 | my @app_list = get_app_list(); |
| 228 | my @headers = <$header_dir/*.h>; |
| 229 | my @sources = <$source_dir/*.c>; |
| 230 | map { s!/!\\!g } @headers; |
| 231 | map { s!/!\\!g } @sources; |
| 232 | |
| 233 | print "Generating apps files... "; |
| 234 | gen_app_files( @app_list ); |
| 235 | print "done.\n"; |
| 236 | |
| 237 | print "Generating main files... "; |
| 238 | gen_main_file( \@headers, \@sources, |
| 239 | $vs6_file_tpl, $vs6_file_tpl, |
| 240 | $vs6_main_tpl_file, $vs6_main_file ); |
| 241 | gen_main_file( \@headers, \@sources, |
| 242 | $vsx_hdr_tpl, $vsx_src_tpl, |
| 243 | $vsx_main_tpl_file, $vsx_main_file ); |
Manuel Pégourié-Gonnard | 2d34fe3 | 2014-05-07 17:51:20 +0200 | [diff] [blame] | 244 | print "done.\n"; |
Manuel Pégourié-Gonnard | 1b57878 | 2013-09-16 13:33:42 +0200 | [diff] [blame] | 245 | |
Manuel Pégourié-Gonnard | cd8f844 | 2014-05-08 12:53:58 +0200 | [diff] [blame] | 246 | print "Generating VS6 workspace file... "; |
| 247 | gen_vs6_workspace( @app_list ); |
| 248 | print "done.\n"; |
| 249 | |
Manuel Pégourié-Gonnard | 0598faf | 2014-05-09 12:56:03 +0200 | [diff] [blame^] | 250 | print "Generating VS2010 solution file... "; |
| 251 | gen_vsx_solution( @app_list ); |
| 252 | print "done.\n"; |
Manuel Pégourié-Gonnard | cd8f844 | 2014-05-08 12:53:58 +0200 | [diff] [blame] | 253 | |
Manuel Pégourié-Gonnard | 1b57878 | 2013-09-16 13:33:42 +0200 | [diff] [blame] | 254 | return 0; |
| 255 | } |