summaryrefslogtreecommitdiff
path: root/vs_postclean.pl
diff options
context:
space:
mode:
authorelliott_c <ocielliottc@users.noreply.github.com>2008-07-10 22:35:52 +0000
committerelliott_c <ocielliottc@users.noreply.github.com>2008-07-10 22:35:52 +0000
commit060d2b96c28992008fd42cfd2cd7b0591be7023b (patch)
treebdd3f309652d944c8763e179b1b04b51938ce599 /vs_postclean.pl
parentf170498f782e82c1c79f8553fc94770820733085 (diff)
downloadMPC-060d2b96c28992008fd42cfd2cd7b0591be7023b.tar.gz
ChangeLogTag: Thu Jul 10 22:34:12 UTC 2008 Chad Elliott <elliott_c@ociweb.com>
Diffstat (limited to 'vs_postclean.pl')
-rwxr-xr-xvs_postclean.pl102
1 files changed, 102 insertions, 0 deletions
diff --git a/vs_postclean.pl b/vs_postclean.pl
new file mode 100755
index 00000000..c8923938
--- /dev/null
+++ b/vs_postclean.pl
@@ -0,0 +1,102 @@
+eval '(exit $?0)' && eval 'exec perl -w -S $0 ${1+"$@"}'
+ & eval 'exec perl -w -S $0 $argv:q'
+ if 0;
+
+# ******************************************************************
+# Author: Chad Elliott
+# Date: 7/10/2008
+# Description: Visual Studio doesn't support a post clean build step,
+# so this script will do it.
+# $Id$
+# ******************************************************************
+
+# ******************************************************************
+# Pragma Section
+# ******************************************************************
+
+use strict;
+use FileHandle;
+use File::Basename;
+
+# ******************************************************************
+# Data Section
+# ******************************************************************
+
+my $version = '1.0';
+
+# ******************************************************************
+# Subroutine Section
+# ******************************************************************
+
+sub read_proj {
+ my($cfg, $file) = @_;
+ my $fh = new FileHandle();
+ my $cmd;
+
+ if (open($fh, $file)) {
+ my $cfg_ok;
+ my $next_name;
+ my $next_command;
+ while(<$fh>) {
+ ## Locate the start of a Configuration section
+ if (/<Configuration\s*$/) {
+ $next_name = 1;
+ }
+ ## Next, find the configuration name
+ elsif ($next_name && /Name="(.+)"/) {
+ $cfg_ok = ($1 eq $cfg);
+ $next_name = undef;
+ }
+ ## Next, find the post clean event
+ elsif ($cfg_ok && /Name="VCPostCleanEventTool"/) {
+ $next_command = 1;
+ }
+ ## And finally, get the postclean command line
+ elsif ($next_command && /CommandLine="(.+)"/) {
+ $cmd = $1;
+ last;
+ }
+ }
+ close($fh);
+ }
+
+ ## Return the command line (undef if there was no postclean)
+ return $cmd;
+}
+
+sub clean_proj {
+ my($cfg, $file) = @_;
+
+ ## Read the postclean command from the project
+ my $cmd = read_proj($cfg, $file);
+
+ ## Move to the directory of the project and run the command
+ if (defined $cmd) {
+ if (chdir(dirname($file))) {
+ system($cmd);
+ }
+ else {
+ print "WARNING: Unable to postclean $file\n";
+ }
+ }
+}
+
+# ******************************************************************
+# Main Section
+# ******************************************************************
+
+if ($#ARGV == -1) {
+ print "PostClean v$version\n",
+ "Usage: ", basename($0), " [CFG=<configuration>] <project files>\n";
+ exit(0);
+}
+
+my $cfg = 'Debug|Win32';
+if ($ARGV[0] =~ /^CFG=(.+)/) {
+ $cfg = $1;
+ shift(@ARGV);
+}
+
+foreach my $file (@ARGV) {
+ clean_proj($cfg, $file);
+}