Manuel Pégourié-Gonnard | 1b57878 | 2013-09-16 13:33:42 +0200 | [diff] [blame] | 1 | #!/usr/bin/perl |
| 2 | |
| 3 | use warnings; |
| 4 | use strict; |
| 5 | |
| 6 | my $vs6_dir = "../visualc/VS6"; |
| 7 | my $vs6_ext = "dsp"; |
| 8 | my $vs6_template_file = "data_files/vs6-app-template.$vs6_ext"; |
| 9 | |
| 10 | my $vsx_dir = "../visualc/VS2010"; |
| 11 | my $vsx_ext = "vcxproj"; |
| 12 | my $vsx_template_file = "data_files/vs2010-app-template.$vsx_ext"; |
| 13 | |
| 14 | exit( main() ); |
| 15 | |
| 16 | sub slurp_file { |
| 17 | my ($filename) = @_; |
| 18 | |
| 19 | local $/ = undef; |
| 20 | open my $fh, '<', $filename or die "Could not read $filename\n"; |
| 21 | my $content = <$fh>; |
| 22 | close $fh; |
| 23 | |
| 24 | return $content; |
| 25 | } |
| 26 | |
| 27 | sub gen_app { |
| 28 | my ($path, $template, $dir, $ext) = @_; |
| 29 | |
| 30 | $path =~ s!/!\\!g; |
| 31 | (my $appname = $path) =~ s/.*\\//; |
| 32 | |
| 33 | my $content = $template; |
| 34 | $content =~ s/<PATHNAME>/$path/g; |
| 35 | $content =~ s/<APPNAME>/$appname/g; |
| 36 | |
| 37 | open my $app_fh, '>', "$dir/$appname.$ext"; |
| 38 | print $app_fh $content; |
| 39 | close $app_fh; |
| 40 | } |
| 41 | |
| 42 | sub get_app_list { |
| 43 | my $app_list = `cd ../programs && make list`; |
| 44 | die "make list failed: $!\n" if $?; |
| 45 | |
| 46 | return split /\s+/, $app_list; |
| 47 | } |
| 48 | |
| 49 | sub main { |
| 50 | -d $vs6_dir || die "VS6 directory not found: $vs6_dir\n"; |
| 51 | -d $vsx_dir || die "VS2010 directory not found: $vsx_dir\n"; |
| 52 | |
| 53 | my $vs6_tpl = slurp_file( $vs6_template_file ); |
| 54 | my $vsx_tpl = slurp_file( $vsx_template_file ); |
| 55 | |
| 56 | for my $app ( get_app_list() ) { |
| 57 | printf "$app\n"; |
| 58 | gen_app( $app, $vs6_tpl, $vs6_dir, $vs6_ext ); |
| 59 | gen_app( $app, $vsx_tpl, $vsx_dir, $vsx_ext ); |
| 60 | } |
| 61 | |
| 62 | return 0; |
| 63 | } |