2 eval '(exit $?0)' && eval 'exec perl -w -S $0 ${1+"$@"}'
3 & eval 'exec perl -w -S $0 $argv:q'
6 # ******************************************************************
9 # Description: Visual Studio doesn't support a post clean build step,
10 # so this script will do it.
12 # ******************************************************************
14 # ******************************************************************
16 # ******************************************************************
23 # ******************************************************************
25 # ******************************************************************
29 # ******************************************************************
31 # ******************************************************************
35 my $fh = new FileHandle
();
38 if (open($fh, $file)) {
43 ## Locate the start of a Configuration section
44 if (/<Configuration\s*$/) {
47 ## Next, find the configuration name
48 elsif ($next_name && /Name="(.+)"/) {
49 $cfg_ok = ($1 eq $cfg);
52 ## Next, find the post clean event
53 elsif ($cfg_ok && /Name="VCPostCleanEventTool"/) {
56 ## And finally, get the postclean command line
57 elsif ($next_command && /CommandLine="(.+)"/) {
65 ## Convert frequently used XML sequences to plain characters.
67 $cmd =~ s/"/\"/g;
71 ## Return the command line (undef if there was no postclean)
78 ## Read the postclean command from the project
79 my $cmd = read_proj
($cfg, $file);
81 ## Move to the directory of the project and run the command
83 my $current_dir = getcwd
();
84 if (chdir(dirname
($file))) {
89 ## We'll only warn about files that we can't deal with.
90 print "WARNING: Unable to postclean $file\n";
97 my $fh = new FileHandle
();
99 ## For a solution, just read in and clean each project file we find.
100 if (open($fh, $file)) {
102 if (/^Project\([^)]+\)\s*=\s*"[^\"]+",\s*"([^\"]+)"/) {
103 clean_proj
($cfg, $1);
110 # ******************************************************************
112 # ******************************************************************
115 print "PostClean v$version\n",
116 "Usage: ", basename
($0), " [CFG=<configuration>] <project or solution files>\n\n",
117 "Executes the MPC generated VCPostCleanEventTool commands in a project.\n",
118 "These events are ignored by VisualStudio and must be handled by an outside\n",
119 "tool (i.e., this script).\n";
123 ## Determine the project or solution configuration (defaulting to the
124 ## default created by MPC).
125 my $cfg = 'Debug|Win32';
126 if ($ARGV[0] =~ /^CFG=(.+)/) {
131 foreach my $file (@ARGV) {
132 if ($file =~ /\.sln$/) {
133 clean_sln
($cfg, $file);
136 ## It's not a solution file, we'll assume it's a project
137 clean_proj
($cfg, $file);