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.
11 # ******************************************************************
13 # ******************************************************************
15 # ******************************************************************
22 # ******************************************************************
24 # ******************************************************************
28 # ******************************************************************
30 # ******************************************************************
34 my $fh = new FileHandle
();
37 if (open($fh, $file)) {
42 ## Locate the start of a Configuration section
43 if (/<Configuration\s*$/) {
46 ## Next, find the configuration name
47 elsif ($next_name && /Name="(.+)"/) {
48 $cfg_ok = ($1 eq $cfg);
51 ## Next, find the post clean event
52 elsif ($cfg_ok && /Name="VCPostCleanEventTool"/) {
55 ## And finally, get the postclean command line
56 elsif ($next_command && /CommandLine="(.+)"/) {
64 ## Convert frequently used XML sequences to plain characters.
66 $cmd =~ s/"/\"/g;
70 ## Return the command line (undef if there was no postclean)
77 ## Read the postclean command from the project
78 my $cmd = read_proj
($cfg, $file);
80 ## Move to the directory of the project and run the command
82 my $current_dir = getcwd
();
83 if (chdir(dirname
($file))) {
88 ## We'll only warn about files that we can't deal with.
89 print "WARNING: Unable to postclean $file\n";
96 my $fh = new FileHandle
();
98 ## For a solution, just read in and clean each project file we find.
99 if (open($fh, $file)) {
101 if (/^Project\([^)]+\)\s*=\s*"[^\"]+",\s*"([^\"]+)"/) {
102 clean_proj
($cfg, $1);
109 # ******************************************************************
111 # ******************************************************************
114 print "PostClean v$version\n",
115 "Usage: ", basename
($0), " [CFG=<configuration>] <project or solution files>\n\n",
116 "Executes the MPC generated VCPostCleanEventTool commands in a project.\n",
117 "These events are ignored by VisualStudio and must be handled by an outside\n",
118 "tool (i.e., this script).\n";
122 ## Determine the project or solution configuration (defaulting to the
123 ## default created by MPC).
124 my $cfg = 'Debug|Win32';
125 if ($ARGV[0] =~ /^CFG=(.+)/) {
130 foreach my $file (@ARGV) {
131 if ($file =~ /\.sln$/) {
132 clean_sln
($cfg, $file);
135 ## It's not a solution file, we'll assume it's a project
136 clean_proj
($cfg, $file);