open-src/util/build-tools/xmake
changeset 851 d428083dbbdd
parent 810 6f94d3da0552
child 907 3c35d611cdaa
--- a/open-src/util/build-tools/xmake	Wed Dec 02 21:38:00 2009 -0800
+++ b/open-src/util/build-tools/xmake	Sat Dec 05 22:13:03 2009 -0800
@@ -29,7 +29,7 @@
 # or other dealings in this Software without prior written authorization
 # of the copyright holder.
 #
-# ident	"@(#)xmake	1.2	09/10/13 SMI"
+# ident	"@(#)xmake	1.3	09/12/05 SMI"
 #
 
 require 5.005;				# minimal Perl version required
@@ -46,6 +46,8 @@
   $verbose = 1;
 }
 
+my @makeargs = ();
+
 # Arguments: (envvar, defval)
 # If environment variable 'envvar' is not set, set it to 'defval'
 sub setenv_default {
@@ -62,6 +64,16 @@
   return $ENV{$envvar};
 }
 
+sub exec_verbose {
+  my $program = shift @_;
+
+  if ($verbose > 0) {
+    print join(' ', $program, @_), "\n";
+  }
+  exec($program, @_)
+    or die "$0: exec of $program failed: $OS_ERROR";
+}
+
 # save full path to current directory
 my $startdir = File::Spec->rel2abs(File::Spec->curdir());
 
@@ -98,8 +110,21 @@
   setenv_default('DMAKE_MODE', 'parallel');
   setenv_default('DMAKE_OUTPUT_MODE', 'TXT2');
 
-  if (!exists $ENV{'DMAKE_MAX_JOBS'}) {
-    my $max_jobs;
+  my $max_jobs;
+
+  foreach my $i ( 0..($#ARGV - 1) ) {
+    if ($ARGV[$i] eq '-j') {
+      $max_jobs = $ARGV[$i+1];
+      $ARGV[$i] = '';
+      $ARGV[$i+1] = '';
+    }
+  }
+
+  if (!defined($max_jobs) && exists $ENV{'DMAKE_MAX_JOBS'}) {
+    $max_jobs = $ENV{'DMAKE_MAX_JOBS'};
+  }
+
+  if (!defined($max_jobs)) {
     my $machlist = join('/', $ENV{'HOME'}, '.make.machines');
     if ( -f $machlist ) {
       my $nodename = (POSIX::uname())[1];
@@ -135,9 +160,10 @@
 	close $PSRINFO;
       }
     }
-    setenv_default('DMAKE_MAX_JOBS', $max_jobs);
   }
 
+  push @makeargs, '-j', $max_jobs;
+
   my $dmake_odir =
     setenv_default('DMAKE_ODIR', File::Spec->catfile(@dirtree[0..($osdepth-1)],
 						     'log', '.dmake'));
@@ -146,9 +172,8 @@
 
 # if in top two levels, just run make
 if ($osdepth >= ($#dirtree - 2)) {
-  print join(' ', $make_cmd, @ARGV), "\n";
-  exec($make_cmd, @ARGV)
-    or die "$0: exec of $make_cmd failed: $OS_ERROR";
+  print join(' ', $make_cmd, @makeargs, @ARGV), "\n";
+  exec_verbose($make_cmd, @makeargs, @ARGV);
 }
 
 my $subdir_target = 'build-in-subdir';
@@ -161,7 +186,7 @@
 # Otherwise get info from the module makefile
 my $moduledir = File::Spec->catdir( @dirtree[0..($osdepth+2)] );
 
-my @makeargs = ($subdir_target, qq{subdir='$startdir'});
+push @makeargs, $subdir_target, qq{subdir='$startdir'};
 if (scalar(@ARGV) > 0) {
   push @makeargs, join(q{ }, q{subdir_cmd=}, @ARGV);
 }
@@ -169,8 +194,7 @@
 print join(' ', "(cd $moduledir ;\\\n", $make_cmd, @makeargs), ")\n";
 chdir $moduledir
   or die "$0: Can't chdir $moduledir: $OS_ERROR";
-exec($make_cmd, @makeargs)
-    or die "$0: exec of $make_cmd failed: $OS_ERROR";
+exec_verbose($make_cmd, @makeargs);
 
 __END__