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; |
| 11 | |
Manuel Pégourié-Gonnard | 2d34fe3 | 2014-05-07 17:51:20 +0200 | [diff] [blame] | 12 | my $vs6_dir = "visualc/VS6"; |
Manuel Pégourié-Gonnard | 1b57878 | 2013-09-16 13:33:42 +0200 | [diff] [blame] | 13 | my $vs6_ext = "dsp"; |
Manuel Pégourié-Gonnard | 2d34fe3 | 2014-05-07 17:51:20 +0200 | [diff] [blame] | 14 | 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] | 15 | my $vs6_main_tpl_file = "scripts/data_files/vs6-main-template.$vs6_ext"; |
| 16 | my $vs6_main_file = "$vs6_dir/polarssl.$vs6_ext"; |
Manuel Pégourié-Gonnard | cd8f844 | 2014-05-08 12:53:58 +0200 | [diff] [blame^] | 17 | my $vs6_wsp_tpl_file = "scripts/data_files/vs6-workspace-template.dsw"; |
| 18 | my $vs6_wsp_file = "$vs6_dir/polarssl.dsw"; |
Manuel Pégourié-Gonnard | 1b57878 | 2013-09-16 13:33:42 +0200 | [diff] [blame] | 19 | |
Manuel Pégourié-Gonnard | 2d34fe3 | 2014-05-07 17:51:20 +0200 | [diff] [blame] | 20 | my $vsx_dir = "visualc/VS2010"; |
Manuel Pégourié-Gonnard | 1b57878 | 2013-09-16 13:33:42 +0200 | [diff] [blame] | 21 | my $vsx_ext = "vcxproj"; |
Manuel Pégourié-Gonnard | 2d34fe3 | 2014-05-07 17:51:20 +0200 | [diff] [blame] | 22 | 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] | 23 | my $vsx_main_tpl_file = "scripts/data_files/vs2010-main-template.$vsx_ext"; |
| 24 | my $vsx_main_file = "$vsx_dir/PolarSSL.$vsx_ext"; |
Manuel Pégourié-Gonnard | 2d34fe3 | 2014-05-07 17:51:20 +0200 | [diff] [blame] | 25 | |
| 26 | my $programs_dir = 'programs'; |
Manuel Pégourié-Gonnard | 0aafa5c | 2014-05-08 11:33:30 +0200 | [diff] [blame] | 27 | my $header_dir = 'include/polarssl'; |
| 28 | my $source_dir = 'library'; |
| 29 | |
| 30 | # Need windows line endings! |
| 31 | my $vs6_file_tpl = <<EOT; |
| 32 | # Begin Source File\r |
| 33 | \r |
Manuel Pégourié-Gonnard | cd8f844 | 2014-05-08 12:53:58 +0200 | [diff] [blame^] | 34 | SOURCE=..\\..\\{NAME}\r |
Manuel Pégourié-Gonnard | 0aafa5c | 2014-05-08 11:33:30 +0200 | [diff] [blame] | 35 | # End Source File\r |
| 36 | EOT |
| 37 | |
Manuel Pégourié-Gonnard | cd8f844 | 2014-05-08 12:53:58 +0200 | [diff] [blame^] | 38 | my $vs6_wsp_entry_tpl = <<EOT; |
| 39 | ###############################################################################\r |
| 40 | \r |
| 41 | Project: "{NAME}"=.\\{NAME}.dsp - Package Owner=<4>\r |
| 42 | \r |
| 43 | Package=<5>\r |
| 44 | {{{\r |
| 45 | }}}\r |
| 46 | \r |
| 47 | Package=<4>\r |
| 48 | {{{\r |
| 49 | Begin Project Dependency\r |
| 50 | Project_Dep_Name polarssl\r |
| 51 | End Project Dependency\r |
| 52 | }}}\r |
| 53 | \r |
| 54 | EOT |
| 55 | |
Manuel Pégourié-Gonnard | 0aafa5c | 2014-05-08 11:33:30 +0200 | [diff] [blame] | 56 | my $vsx_hdr_tpl = <<EOT; |
Manuel Pégourié-Gonnard | cd8f844 | 2014-05-08 12:53:58 +0200 | [diff] [blame^] | 57 | <ClInclude Include="..\\..\\{NAME}" />\r |
Manuel Pégourié-Gonnard | 0aafa5c | 2014-05-08 11:33:30 +0200 | [diff] [blame] | 58 | EOT |
| 59 | my $vsx_src_tpl = <<EOT; |
Manuel Pégourié-Gonnard | cd8f844 | 2014-05-08 12:53:58 +0200 | [diff] [blame^] | 60 | <ClCompile Include="..\\..\\{NAME}" />\r |
Manuel Pégourié-Gonnard | 0aafa5c | 2014-05-08 11:33:30 +0200 | [diff] [blame] | 61 | EOT |
Manuel Pégourié-Gonnard | 1b57878 | 2013-09-16 13:33:42 +0200 | [diff] [blame] | 62 | |
| 63 | exit( main() ); |
| 64 | |
Manuel Pégourié-Gonnard | 2d34fe3 | 2014-05-07 17:51:20 +0200 | [diff] [blame] | 65 | sub check_dirs { |
| 66 | return -d $vs6_dir |
| 67 | && -d $vsx_dir |
Manuel Pégourié-Gonnard | 0aafa5c | 2014-05-08 11:33:30 +0200 | [diff] [blame] | 68 | && -d $header_dir |
| 69 | && -d $source_dir |
Manuel Pégourié-Gonnard | 2d34fe3 | 2014-05-07 17:51:20 +0200 | [diff] [blame] | 70 | && -d $programs_dir; |
| 71 | } |
| 72 | |
Manuel Pégourié-Gonnard | 1b57878 | 2013-09-16 13:33:42 +0200 | [diff] [blame] | 73 | sub slurp_file { |
| 74 | my ($filename) = @_; |
| 75 | |
| 76 | local $/ = undef; |
| 77 | open my $fh, '<', $filename or die "Could not read $filename\n"; |
| 78 | my $content = <$fh>; |
| 79 | close $fh; |
| 80 | |
| 81 | return $content; |
| 82 | } |
| 83 | |
| 84 | sub gen_app { |
| 85 | my ($path, $template, $dir, $ext) = @_; |
| 86 | |
| 87 | $path =~ s!/!\\!g; |
| 88 | (my $appname = $path) =~ s/.*\\//; |
| 89 | |
| 90 | my $content = $template; |
| 91 | $content =~ s/<PATHNAME>/$path/g; |
| 92 | $content =~ s/<APPNAME>/$appname/g; |
| 93 | |
| 94 | open my $app_fh, '>', "$dir/$appname.$ext"; |
| 95 | print $app_fh $content; |
| 96 | close $app_fh; |
| 97 | } |
| 98 | |
| 99 | sub get_app_list { |
Manuel Pégourié-Gonnard | 2d34fe3 | 2014-05-07 17:51:20 +0200 | [diff] [blame] | 100 | my $app_list = `cd $programs_dir && make list`; |
Manuel Pégourié-Gonnard | 1b57878 | 2013-09-16 13:33:42 +0200 | [diff] [blame] | 101 | die "make list failed: $!\n" if $?; |
| 102 | |
| 103 | return split /\s+/, $app_list; |
| 104 | } |
| 105 | |
Manuel Pégourié-Gonnard | 2d34fe3 | 2014-05-07 17:51:20 +0200 | [diff] [blame] | 106 | sub gen_app_files { |
Manuel Pégourié-Gonnard | 0aafa5c | 2014-05-08 11:33:30 +0200 | [diff] [blame] | 107 | my @app_list = @_; |
| 108 | |
Manuel Pégourié-Gonnard | 2d34fe3 | 2014-05-07 17:51:20 +0200 | [diff] [blame] | 109 | my $vs6_tpl = slurp_file( $vs6_app_tpl_file ); |
| 110 | my $vsx_tpl = slurp_file( $vsx_app_tpl_file ); |
Manuel Pégourié-Gonnard | 1b57878 | 2013-09-16 13:33:42 +0200 | [diff] [blame] | 111 | |
Manuel Pégourié-Gonnard | 0aafa5c | 2014-05-08 11:33:30 +0200 | [diff] [blame] | 112 | for my $app ( @app_list ) { |
Manuel Pégourié-Gonnard | 1b57878 | 2013-09-16 13:33:42 +0200 | [diff] [blame] | 113 | gen_app( $app, $vs6_tpl, $vs6_dir, $vs6_ext ); |
| 114 | gen_app( $app, $vsx_tpl, $vsx_dir, $vsx_ext ); |
| 115 | } |
Manuel Pégourié-Gonnard | 2d34fe3 | 2014-05-07 17:51:20 +0200 | [diff] [blame] | 116 | } |
| 117 | |
Manuel Pégourié-Gonnard | 0aafa5c | 2014-05-08 11:33:30 +0200 | [diff] [blame] | 118 | sub gen_entry_list { |
Manuel Pégourié-Gonnard | cd8f844 | 2014-05-08 12:53:58 +0200 | [diff] [blame^] | 119 | my ($tpl, @names) = @_; |
Manuel Pégourié-Gonnard | 0aafa5c | 2014-05-08 11:33:30 +0200 | [diff] [blame] | 120 | |
| 121 | my $entries; |
Manuel Pégourié-Gonnard | cd8f844 | 2014-05-08 12:53:58 +0200 | [diff] [blame^] | 122 | for my $name (@names) { |
| 123 | (my $entry = $tpl) =~ s/{NAME}/$name/g; |
Manuel Pégourié-Gonnard | 0aafa5c | 2014-05-08 11:33:30 +0200 | [diff] [blame] | 124 | $entries .= $entry; |
| 125 | } |
| 126 | |
| 127 | return $entries; |
| 128 | } |
| 129 | |
| 130 | sub gen_main_file { |
| 131 | my ($headers, $sources, $hdr_tpl, $src_tpl, $main_tpl, $main_out) = @_; |
| 132 | |
| 133 | my $header_entries = gen_entry_list( $hdr_tpl, @$headers ); |
| 134 | my $source_entries = gen_entry_list( $src_tpl, @$sources ); |
| 135 | |
| 136 | my $out = slurp_file( $main_tpl ); |
| 137 | $out =~ s/SOURCE_ENTRIES\r\n/$source_entries/m; |
| 138 | $out =~ s/HEADER_ENTRIES\r\n/$header_entries/m; |
| 139 | |
| 140 | open my $fh, '>', $main_out or die; |
| 141 | print $fh $out; |
| 142 | close $fh; |
| 143 | } |
| 144 | |
Manuel Pégourié-Gonnard | cd8f844 | 2014-05-08 12:53:58 +0200 | [diff] [blame^] | 145 | sub gen_vs6_workspace { |
| 146 | my (@app_names) = @_; |
| 147 | |
| 148 | map { s!.*/!! } @app_names; |
| 149 | my $entries = gen_entry_list( $vs6_wsp_entry_tpl, @app_names ); |
| 150 | |
| 151 | my $out = slurp_file( $vs6_wsp_tpl_file ); |
| 152 | $out =~ s/APP_ENTRIES\r\n/$entries/m; |
| 153 | |
| 154 | open my $fh, '>', $vs6_wsp_file or die; |
| 155 | print $fh $out; |
| 156 | close $fh; |
| 157 | } |
| 158 | |
Manuel Pégourié-Gonnard | 2d34fe3 | 2014-05-07 17:51:20 +0200 | [diff] [blame] | 159 | sub main { |
| 160 | if( ! check_dirs() ) { |
| 161 | chdir '..' or die; |
| 162 | check_dirs or die "Must but run from PolarSSL root or scripts dir\n"; |
| 163 | } |
| 164 | |
Manuel Pégourié-Gonnard | 0aafa5c | 2014-05-08 11:33:30 +0200 | [diff] [blame] | 165 | my @app_list = get_app_list(); |
| 166 | my @headers = <$header_dir/*.h>; |
| 167 | my @sources = <$source_dir/*.c>; |
| 168 | map { s!/!\\!g } @headers; |
| 169 | map { s!/!\\!g } @sources; |
| 170 | |
| 171 | print "Generating apps files... "; |
| 172 | gen_app_files( @app_list ); |
| 173 | print "done.\n"; |
| 174 | |
| 175 | print "Generating main files... "; |
| 176 | gen_main_file( \@headers, \@sources, |
| 177 | $vs6_file_tpl, $vs6_file_tpl, |
| 178 | $vs6_main_tpl_file, $vs6_main_file ); |
| 179 | gen_main_file( \@headers, \@sources, |
| 180 | $vsx_hdr_tpl, $vsx_src_tpl, |
| 181 | $vsx_main_tpl_file, $vsx_main_file ); |
Manuel Pégourié-Gonnard | 2d34fe3 | 2014-05-07 17:51:20 +0200 | [diff] [blame] | 182 | print "done.\n"; |
Manuel Pégourié-Gonnard | 1b57878 | 2013-09-16 13:33:42 +0200 | [diff] [blame] | 183 | |
Manuel Pégourié-Gonnard | cd8f844 | 2014-05-08 12:53:58 +0200 | [diff] [blame^] | 184 | print "Generating VS6 workspace file... "; |
| 185 | gen_vs6_workspace( @app_list ); |
| 186 | print "done.\n"; |
| 187 | |
| 188 | |
Manuel Pégourié-Gonnard | 1b57878 | 2013-09-16 13:33:42 +0200 | [diff] [blame] | 189 | return 0; |
| 190 | } |