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