summaryrefslogtreecommitdiff
path: root/bin/mwc.pl
diff options
context:
space:
mode:
Diffstat (limited to 'bin/mwc.pl')
-rwxr-xr-xbin/mwc.pl75
1 files changed, 62 insertions, 13 deletions
diff --git a/bin/mwc.pl b/bin/mwc.pl
index 13dd157f7ef..688d278b513 100755
--- a/bin/mwc.pl
+++ b/bin/mwc.pl
@@ -13,17 +13,16 @@ eval '(exit $?0)' && eval 'exec perl -w -S $0 ${1+"$@"}'
# ******************************************************************
use strict;
+use Cwd;
use Config;
-use FindBin;
-use File::Spec;
use File::Basename;
-my($basePath) = $FindBin::Bin;
-if ($^O eq 'VMS') {
- $basePath = File::Spec->rel2abs(dirname($0)) if ($basePath eq '');
- $basePath = VMS::Filespec::unixify($basePath);
+if ( $^O eq 'VMS' ) {
+ require VMS::Filespec;
+ import VMS::Filespec qw(unixpath);
}
-$basePath .= '/MakeProjectCreator';
+
+my($basePath) = getExecutePath($0) . '/MakeProjectCreator';
unshift(@INC, $basePath . '/modules');
my($mpcroot) = $ENV{MPC_ROOT};
@@ -66,6 +65,58 @@ sub getBasePath {
return $mpcpath;
}
+
+sub which {
+ my($prog) = shift;
+ my($exec) = $prog;
+
+ if (defined $ENV{'PATH'}) {
+ my($part) = '';
+ my($envSep) = $Config{'path_sep'};
+ foreach $part (split(/$envSep/, $ENV{'PATH'})) {
+ $part .= "/$prog";
+ if ( -x $part ) {
+ $exec = $part;
+ last;
+ }
+ }
+ }
+
+ return $exec;
+}
+
+
+sub getExecutePath {
+ my($prog) = shift;
+ my($loc) = '';
+
+ if ($prog ne basename($prog)) {
+ my($dir) = ($^O eq 'VMS' ? unixpath(dirname($prog)) : dirname($prog));
+ if ($prog =~ /^[\/\\]/ ||
+ $prog =~ /^[A-Za-z]:[\/\\]?/) {
+ $loc = $dir;
+ }
+ else {
+ $loc = ($^O eq 'VMS' ? unixpath(getcwd()) : getcwd()) . '/' . $dir;
+ }
+ }
+ else {
+ $loc = dirname(which($prog));
+ if ($^O eq 'VMS') {
+ $loc = unixpath($loc);
+ }
+ }
+
+ $loc =~ s/\/\.$//;
+
+ if ($loc eq '.') {
+ $loc = ($^O eq 'VMS' ? unixpath(getcwd()) : getcwd());
+ }
+
+ return $loc;
+}
+
+
# ************************************************************
# Main Section
# ************************************************************
@@ -77,11 +128,9 @@ my($driver) = new MWC();
my($creators) = $driver->getCreatorList();
unshift(@$creators, @creators);
-## Add the mpc path to the include paths, but preserve
-## the original @ARGV as it is included in the output of
-## most of the workspace creators.
-my(@args) = ('-include', "$mpcpath/config",
- '-include', "$mpcpath/templates", @ARGV);
+## Add the mpc path to the include paths
+unshift(@ARGV, '-include', "$mpcpath/config",
+ '-include', "$mpcpath/templates");
## Execute the driver
-exit($driver->execute($basePath, basename($0), \@args));
+exit($driver->execute($basePath, basename($0), \@ARGV));