#!/usr/bin/perl
$nproc=4;
print "Using $nproc threads\n";
$n=0;
$top=`pwd`; chop $top;
@subdirs = ( "apps/fgr", "apps/rodent-fgr", "apps/rodent-diff", "apps/rodent-iconmgr",  "apps/rodent-fm","apps/rodent-pkg", "./");
BEGIN { $| = 1 }
$j=0;
foreach $subdir (@subdirs){
    $child = fork;
    if ($child) {
        $j++;
	$n++;
       print "Configuring $subdir ($child)\n";
       if ($n <= $nproc){next}
       wait; $n--; 
#print "Wait complete\n";
       chdir $top;
    } else {
	chdir $subdir;
	$pwd=`pwd`; chop $pwd;
	if ($subdir =~ m/\.\//g){
	    $cmd = "./a_configure";
	} else {
	    $cmd = "./configure";
	}
	for ($i=0; $i <= $#ARGV; $i++){
	    $cmd .= " ";
	    $cmd .= $ARGV[$i];
	}
	print "Entering $pwd\n";
	print "$cmd\n";
	$_ = `$cmd`;
	print;
#if ($j = $#subdirs){print}
	print `cat *.settings`;
	print "Leaving $pwd\n";
	exit (123);
    }
}
while ($n){wait; $n--}

