| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
use 5.005; |
|---|
| 36 |
|
|---|
| 37 |
use strict 'vars'; |
|---|
| 38 |
use vars qw($base_dir $module $PRELUDE $FEATURE_ARGS $PACKAGE_ARGS $PROLOGUE |
|---|
| 39 |
$LAST_ARG_GROUP $OS $Win32 $CFG_LOAD_FUNC); |
|---|
| 40 |
use vars qw(%MODULES); |
|---|
| 41 |
|
|---|
| 42 |
use Cwd qw(chdir getcwd); |
|---|
| 43 |
use File::Basename; |
|---|
| 44 |
use File::Path; |
|---|
| 45 |
use Getopt::Long; |
|---|
| 46 |
use Pod::Usage; |
|---|
| 47 |
|
|---|
| 48 |
BEGIN |
|---|
| 49 |
{ |
|---|
| 50 |
$base_dir = (fileparse("$0"))[1]; |
|---|
| 51 |
$base_dir =~ s|/+$||; |
|---|
| 52 |
} |
|---|
| 53 |
|
|---|
| 54 |
use lib("$base_dir"); |
|---|
| 55 |
use JugglerConfigure; |
|---|
| 56 |
|
|---|
| 57 |
|
|---|
| 58 |
sub mergeArgArrays($$); |
|---|
| 59 |
sub loadDefaultArgs($); |
|---|
| 60 |
sub generateTopLevelMakefile(;$); |
|---|
| 61 |
sub generateModuleMakefiles($); |
|---|
| 62 |
sub generatePreMakefile($); |
|---|
| 63 |
sub generateReconfig($@); |
|---|
| 64 |
sub listModules(); |
|---|
| 65 |
sub printHelp(); |
|---|
| 66 |
sub getConfigureHelp($$); |
|---|
| 67 |
sub parseOutput($$); |
|---|
| 68 |
sub getPlatform(); |
|---|
| 69 |
|
|---|
| 70 |
%MODULES = (); |
|---|
| 71 |
|
|---|
| 72 |
my $all_help = 0; |
|---|
| 73 |
my $cfg = "juggler.cfg"; |
|---|
| 74 |
my $user_cfg = ''; |
|---|
| 75 |
$module = ''; |
|---|
| 76 |
my $script_help = 0; |
|---|
| 77 |
my $manual = 0; |
|---|
| 78 |
my $mod_list = 0; |
|---|
| 79 |
my $args_file = 'acdefaults.cfg'; |
|---|
| 80 |
my $args_mod_file = 'acdefaults.pl'; |
|---|
| 81 |
my $user_args = ''; |
|---|
| 82 |
my $user_args_mod = ''; |
|---|
| 83 |
my $no_user_args = 0; |
|---|
| 84 |
|
|---|
| 85 |
$PRELUDE = 0; |
|---|
| 86 |
$FEATURE_ARGS = 1; |
|---|
| 87 |
$PACKAGE_ARGS = 2; |
|---|
| 88 |
$PROLOGUE = 3; |
|---|
| 89 |
$LAST_ARG_GROUP = 4; |
|---|
| 90 |
|
|---|
| 91 |
$CFG_LOAD_FUNC = undef; |
|---|
| 92 |
$OS = ''; |
|---|
| 93 |
|
|---|
| 94 |
my @save_argv = @ARGV; |
|---|
| 95 |
|
|---|
| 96 |
Getopt::Long::Configure('pass_through'); |
|---|
| 97 |
GetOptions('help|?' => \$script_help, 'cfg=s' => \$user_cfg, |
|---|
| 98 |
'module=s' => \$module, 'all-help' => \$all_help, |
|---|
| 99 |
'manual' => \$manual, 'modlist' => \$mod_list, |
|---|
| 100 |
'args=s' => \$user_args, 'argsmod=s' => \$user_args_mod, |
|---|
| 101 |
'noargs' => \$no_user_args, 'os=s' => \$OS) |
|---|
| 102 |
or pod2usage(2); |
|---|
| 103 |
|
|---|
| 104 |
|
|---|
| 105 |
pod2usage(1) if $script_help; |
|---|
| 106 |
pod2usage(-exitstatus => 0, -verbose => 2) if $manual; |
|---|
| 107 |
|
|---|
| 108 |
die "ERROR: No configuration given\n" unless $cfg || $user_cfg; |
|---|
| 109 |
|
|---|
| 110 |
my $inst_prefix = '/usr/local'; |
|---|
| 111 |
my $arg; |
|---|
| 112 |
foreach $arg ( @ARGV ) |
|---|
| 113 |
{ |
|---|
| 114 |
if ( $arg =~ /--prefix=(.*)$/ ) |
|---|
| 115 |
{ |
|---|
| 116 |
$inst_prefix = "$1"; |
|---|
| 117 |
} |
|---|
| 118 |
} |
|---|
| 119 |
|
|---|
| 120 |
$Win32 = 1 if $ENV{'OS'} && $ENV{'OS'} =~ /Windows/; |
|---|
| 121 |
|
|---|
| 122 |
|
|---|
| 123 |
|
|---|
| 124 |
|
|---|
| 125 |
|
|---|
| 126 |
|
|---|
| 127 |
if ( $Win32 ) |
|---|
| 128 |
{ |
|---|
| 129 |
die "Absolute Cygwin paths confuse Visual C++. Use a relative path.\n" |
|---|
| 130 |
if $0 =~ /^\//; |
|---|
| 131 |
|
|---|
| 132 |
for ( my $i = 0; $i <= $#save_argv; $i++ ) |
|---|
| 133 |
{ |
|---|
| 134 |
$save_argv[$i] = "\"$save_argv[$i]\""; |
|---|
| 135 |
} |
|---|
| 136 |
|
|---|
| 137 |
for ( my $i = 0; $i <= $#ARGV; $i++ ) |
|---|
| 138 |
{ |
|---|
| 139 |
$ARGV[$i] = "\"$ARGV[$i]\""; |
|---|
| 140 |
} |
|---|
| 141 |
} |
|---|
| 142 |
|
|---|
| 143 |
my $cfg_load = ("$user_cfg" eq "") ? "$base_dir/$cfg" : "$user_cfg"; |
|---|
| 144 |
%MODULES = JugglerConfigure::parseConfigFile("$cfg_load"); |
|---|
| 145 |
|
|---|
| 146 |
listModules() && exit(0) if $mod_list; |
|---|
| 147 |
printHelp() && exit(0) if $all_help; |
|---|
| 148 |
|
|---|
| 149 |
{ |
|---|
| 150 |
my $cache_file_set = 0; |
|---|
| 151 |
|
|---|
| 152 |
foreach ( @ARGV ) |
|---|
| 153 |
{ |
|---|
| 154 |
if ( /-cache-f/ ) |
|---|
| 155 |
{ |
|---|
| 156 |
$cache_file_set = 1; |
|---|
| 157 |
last; |
|---|
| 158 |
} |
|---|
| 159 |
} |
|---|
| 160 |
|
|---|
| 161 |
|
|---|
| 162 |
unless ( $no_user_args ) |
|---|
| 163 |
{ |
|---|
| 164 |
my $args_mod = ("$user_args_mod" eq "") ? "$base_dir/$args_mod_file" |
|---|
| 165 |
: "$user_args_mod"; |
|---|
| 166 |
|
|---|
| 167 |
|
|---|
| 168 |
|
|---|
| 169 |
|
|---|
| 170 |
my $args_load = ("$user_args" eq "") ? "$base_dir/$args_file" |
|---|
| 171 |
: "$user_args"; |
|---|
| 172 |
|
|---|
| 173 |
if ( -r "$args_mod" ) |
|---|
| 174 |
{ |
|---|
| 175 |
require "$args_mod"; |
|---|
| 176 |
|
|---|
| 177 |
if ( $CFG_LOAD_FUNC ) |
|---|
| 178 |
{ |
|---|
| 179 |
my @default_args = &$CFG_LOAD_FUNC(); |
|---|
| 180 |
mergeArgArrays(\@ARGV, \@default_args); |
|---|
| 181 |
} |
|---|
| 182 |
} |
|---|
| 183 |
elsif ( -r "$args_load" ) |
|---|
| 184 |
{ |
|---|
| 185 |
loadDefaultArgs("$args_load"); |
|---|
| 186 |
} |
|---|
| 187 |
} |
|---|
| 188 |
|
|---|
| 189 |
if ( ! $cache_file_set ) |
|---|
| 190 |
{ |
|---|
| 191 |
my $cwd = getcwd(); |
|---|
| 192 |
push(@ARGV, "--cache-file=$cwd/config.cache"); |
|---|
| 193 |
} |
|---|
| 194 |
|
|---|
| 195 |
|
|---|
| 196 |
if ( $module ) |
|---|
| 197 |
{ |
|---|
| 198 |
die "ERROR: No such module $module in $cfg!\n" |
|---|
| 199 |
unless defined($MODULES{"$module"}); |
|---|
| 200 |
|
|---|
| 201 |
generateReconfig("$module", @save_argv); |
|---|
| 202 |
generateModuleMakefiles("$module"); |
|---|
| 203 |
generateTopLevelMakefile("$module"); |
|---|
| 204 |
} |
|---|
| 205 |
|
|---|
| 206 |
|
|---|
| 207 |
elsif ( $JugglerConfigure::DEFAULT_MODULE && |
|---|
| 208 |
defined($MODULES{"$JugglerConfigure::DEFAULT_MODULE"}) ) |
|---|
| 209 |
{ |
|---|
| 210 |
generateReconfig("$JugglerConfigure::DEFAULT_MODULE", @save_argv); |
|---|
| 211 |
generateModuleMakefiles("$JugglerConfigure::DEFAULT_MODULE"); |
|---|
| 212 |
generateTopLevelMakefile("$JugglerConfigure::DEFAULT_MODULE"); |
|---|
| 213 |
} |
|---|
| 214 |
|
|---|
| 215 |
|
|---|
| 216 |
else |
|---|
| 217 |
{ |
|---|
| 218 |
generateReconfig('', @save_argv); |
|---|
| 219 |
|
|---|
| 220 |
foreach ( keys(%MODULES) ) |
|---|
| 221 |
{ |
|---|
| 222 |
generateModuleMakefiles("$_"); |
|---|
| 223 |
} |
|---|
| 224 |
|
|---|
| 225 |
generateTopLevelMakefile(); |
|---|
| 226 |
} |
|---|
| 227 |
|
|---|
| 228 |
my $gnu_make = 'gmake'; |
|---|
| 229 |
|
|---|
| 230 |
|
|---|
| 231 |
|
|---|
| 232 |
|
|---|
| 233 |
foreach ( 'make', 'gmake' ) |
|---|
| 234 |
{ |
|---|
| 235 |
my $result = open(MAKE, "$_ -v 2>&1 |"); |
|---|
| 236 |
next unless $result; |
|---|
| 237 |
my @output = <MAKE>; |
|---|
| 238 |
close(MAKE); |
|---|
| 239 |
|
|---|
| 240 |
if ( grep(/GNU Make/, @output) ) |
|---|
| 241 |
{ |
|---|
| 242 |
$gnu_make = $_; |
|---|
| 243 |
last; |
|---|
| 244 |
} |
|---|
| 245 |
} |
|---|
| 246 |
|
|---|
| 247 |
print <<EOF; |
|---|
| 248 |
|
|---|
| 249 |
GNU make is required to build the Juggler Suite. |
|---|
| 250 |
On your system, GNU make is the command $gnu_make. |
|---|
| 251 |
To build and install everything into $inst_prefix, |
|---|
| 252 |
run the following: |
|---|
| 253 |
|
|---|
| 254 |
$gnu_make build install |
|---|
| 255 |
|
|---|
| 256 |
To make a developer build and installation in |
|---|
| 257 |
./instlinks, (debug only), simply run the following: |
|---|
| 258 |
|
|---|
| 259 |
$gnu_make |
|---|
| 260 |
|
|---|
| 261 |
To make an optimized build in ./instlinks, run the |
|---|
| 262 |
following: |
|---|
| 263 |
|
|---|
| 264 |
$gnu_make optim |
|---|
| 265 |
|
|---|
| 266 |
EOF |
|---|
| 267 |
} |
|---|
| 268 |
|
|---|
| 269 |
exit(0); |
|---|
| 270 |
|
|---|
| 271 |
|
|---|
| 272 |
|
|---|
| 273 |
|
|---|
| 274 |
|
|---|
| 275 |
sub mergeArgArrays ($$) |
|---|
| 276 |
{ |
|---|
| 277 |
my $dest_list = shift; |
|---|
| 278 |
my $source_list = shift; |
|---|
| 279 |
|
|---|
| 280 |
foreach ( @$source_list ) |
|---|
| 281 |
{ |
|---|
| 282 |
|
|---|
| 283 |
s/^\s+//; |
|---|
| 284 |
s/\s+$//; |
|---|
| 285 |
next if /^$/; |
|---|
| 286 |
|
|---|
| 287 |
|
|---|
| 288 |
m/^(--[^=]+)/; |
|---|
| 289 |
push(@$dest_list, "$_") unless grep(/$1/, @$dest_list); |
|---|
| 290 |
} |
|---|
| 291 |
} |
|---|
| 292 |
|
|---|
| 293 |
sub loadDefaultArgs ($) |
|---|
| 294 |
{ |
|---|
| 295 |
my $args_load = shift; |
|---|
| 296 |
|
|---|
| 297 |
if ( open(ARGS_FILE, "$args_load") ) |
|---|
| 298 |
{ |
|---|
| 299 |
print "Loading default arguments from $args_load ...\n"; |
|---|
| 300 |
my $args_contents = ''; |
|---|
| 301 |
|
|---|
| 302 |
while ( <ARGS_FILE> ) |
|---|
| 303 |
{ |
|---|
| 304 |
s/ |
|---|
| 305 |
next if /^\s*$/; |
|---|
| 306 |
$args_contents .= "$_"; |
|---|
| 307 |
} |
|---|
| 308 |
|
|---|
| 309 |
close(ARGS_FILE) or warn "WARNING: Could not close $args_load: $!\n"; |
|---|
| 310 |
|
|---|
| 311 |
my $platform = getPlatform(); |
|---|
| 312 |
|
|---|
| 313 |
while ( "$args_contents" ne '' ) |
|---|
| 314 |
{ |
|---|
| 315 |
my @args_list = (); |
|---|
| 316 |
|
|---|
| 317 |
|
|---|
| 318 |
if ( $args_contents =~ /^\s*all\s*{(.+?)}\s*/si ) |
|---|
| 319 |
{ |
|---|
| 320 |
@args_list = split(m|$/|, "$1"); |
|---|
| 321 |
$args_contents = $'; |
|---|
| 322 |
} |
|---|
| 323 |
# Read in the arguments for the current platform. |
|---|
| 324 |
elsif ( $args_contents =~ /^\s*$platform\s*{(.+?)}\s*/sio ) |
|---|
| 325 |
{ |
|---|
| 326 |
@args_list = split(m|$/|, "$1"); |
|---|
| 327 |
$args_contents = $'; |
|---|
| 328 |
} |
|---|
| 329 |
|
|---|
| 330 |
elsif ( $args_contents =~ /^\s*(\S+)\b\s*{(.+?)}\s*/s ) |
|---|
| 331 |
{ |
|---|
| 332 |
print "Skipping $1\n"; |
|---|
| 333 |
$args_contents = $'; |
|---|
| 334 |
} |
|---|
| 335 |
|
|---|
| 336 |
mergeArgArrays(\@ARGV, \@args_list); |
|---|
| 337 |
} |
|---|
| 338 |
} |
|---|
| 339 |
else |
|---|
| 340 |
{ |
|---|
| 341 |
warn "WARNING: Coult not read from $args_load: $!\n"; |
|---|
| 342 |
} |
|---|
| 343 |
} |
|---|
| 344 |
|
|---|
| 345 |
sub generateTopLevelMakefile(;$) |
|---|
| 346 |
{ |
|---|
| 347 |
my $gen_module = shift || ''; |
|---|
| 348 |
|
|---|
| 349 |
open(INPUT, "$base_dir/Makefile.in") |
|---|
| 350 |
or die "ERROR: Could not read from $base_dir/Makefile.in: $!\n"; |
|---|
| 351 |
|
|---|
| 352 |
my $input_file; |
|---|
| 353 |
while ( <INPUT> ) |
|---|
| 354 |
{ |
|---|
| 355 |
$input_file .= "$_"; |
|---|
| 356 |
} |
|---|
| 357 |
|
|---|
| 358 |
close(INPUT); |
|---|
| 359 |
|
|---|
| 360 |
my $modules; |
|---|
| 361 |
my @module_array; |
|---|
| 362 |
|
|---|
| 363 |
if ( $gen_module ) |
|---|
| 364 |
{ |
|---|
| 365 |
foreach ( $MODULES{"$gen_module"}->getDependencies() ) |
|---|
| 366 |
{ |
|---|
| 367 |
$modules .= $_->getPath() . " "; |
|---|
| 368 |
} |
|---|
| 369 |
} |
|---|
| 370 |
else |
|---|
| 371 |
{ |
|---|
| 372 |
my $mod_name; |
|---|
| 373 |
foreach $mod_name ( keys(%MODULES) ) |
|---|
| 374 |
{ |
|---|
| 375 |
my $temp_mod; |
|---|
| 376 |
foreach $temp_mod ( $MODULES{"$mod_name"}->getDependencies() ) |
|---|
| 377 |
{ |
|---|
| 378 |
$modules .= $temp_mod->getPath() . " "; |
|---|
| 379 |
} |
|---|
| 380 |
} |
|---|
| 381 |
} |
|---|
| 382 |
|
|---|
| 383 |
warn "WARNING: No modules defined!\n" unless $modules; |
|---|
| 384 |
|
|---|
| 385 |
my $cwd = getcwd(); |
|---|
| 386 |
chdir("$base_dir"); |
|---|
| 387 |
$input_file =~ s/\@JUGGLER_PROJECTS\@/$modules/g; |
|---|
| 388 |
|
|---|
| 389 |
if ( $Win32 ) |
|---|
| 390 |
{ |
|---|
| 391 |
# Get the Win32-friendly versions of these paths. Then change the \'s |
|---|
| 392 |
# to /'s just to be safe. |
|---|
| 393 |
my $win_pwd = `cygpath -w $ENV{'PWD'}`; |
|---|
| 394 |
my $win_cwd = `cygpath -w $cwd`; |
|---|
| 395 |
chomp($win_pwd); |
|---|
| 396 |
chomp($win_cwd); |
|---|
| 397 |
|
|---|
| 398 |
$win_pwd =~ s/\\/\//g; |
|---|
| 399 |
$win_cwd =~ s/\\/\//g; |
|---|
| 400 |
|
|---|
| 401 |
$input_file =~ s/\@JUGGLERROOT_ABS\@/$win_pwd/g; |
|---|
| 402 |
$input_file =~ s/\@topdir\@/$win_cwd/g; |
|---|
| 403 |
} |
|---|
| 404 |
else |
|---|
| 405 |
{ |
|---|
| 406 |
$input_file =~ s/\@JUGGLERROOT_ABS\@/$ENV{'PWD'}/g; |
|---|
| 407 |
$input_file =~ s/\@topdir\@/$cwd/g; |
|---|
| 408 |
} |
|---|
| 409 |
|
|---|
| 410 |
chdir("$cwd"); |
|---|
| 411 |
|
|---|
| 412 |
print "Generating Makefile\n"; |
|---|
| 413 |
open(OUTPUT, "> Makefile") or die "ERROR: Could not create Makefile: $!\n"; |
|---|
| 414 |
print OUTPUT "$input_file"; |
|---|
| 415 |
close(OUTPUT) or warn "WARNING: Failed to save Makefile: $!\n"; |
|---|
| 416 |
} |
|---|
| 417 |
|
|---|
| 418 |
sub generateModuleMakefiles($) |
|---|
| 419 |
{ |
|---|
| 420 |
my $module_name = shift; |
|---|
| 421 |
|
|---|
| 422 |
die "ERROR: No module $module_name defined\n" |
|---|
| 423 |
unless defined($MODULES{"$module_name"}); |
|---|
| 424 |
|
|---|
| 425 |
my $cwd = getcwd(); |
|---|
| 426 |
|
|---|
| 427 |
chdir("$base_dir"); |
|---|
| 428 |
my $root_srcdir = getcwd(); |
|---|
| 429 |
chdir("$cwd"); |
|---|
| 430 |
|
|---|
| 431 |
my $depencency; |
|---|
| 432 |
foreach $depencency ( $MODULES{"$module_name"}->getDependencies() ) |
|---|
| 433 |
{ |
|---|
| 434 |
my $mod_path = $depencency->getPath(); |
|---|
| 435 |
|
|---|
| 436 |
mkpath("$mod_path", 0, 0755) unless -d "$mod_path"; |
|---|
| 437 |
|
|---|
| 438 |
|
|---|
| 439 |
|
|---|
| 440 |
unless ( -e "$root_srcdir/$mod_path/Makefile.pre.in" ) |
|---|
| 441 |
{ |
|---|
| 442 |
warn "WARNING: Missing $root_srcdir/$mod_path/Makefile.pre.in!\n"; |
|---|
| 443 |
next; |
|---|
| 444 |
} |
|---|
| 445 |
|
|---|
| 446 |
generatePreMakefile("$mod_path/Makefile.pre"); |
|---|
| 447 |
} |
|---|
| 448 |
} |
|---|
| 449 |
|
|---|
| 450 |
sub generatePreMakefile($) |
|---|
| 451 |
{ |
|---|
| 452 |
my $output_file_name = shift; |
|---|
| 453 |
|
|---|
| 454 |
my $cwd = getcwd(); |
|---|
| 455 |
|
|---|
| 456 |
chdir("$base_dir"); |
|---|
| 457 |
my $root_srcdir = getcwd(); |
|---|
| 458 |
my $input_file_name = "$root_srcdir/$output_file_name.in"; |
|---|
| 459 |
chdir("$cwd"); |
|---|
| 460 |
|
|---|
| 461 |
open(INPUT, "$input_file_name") |
|---|
| 462 |
or die "ERROR: Could not read from $input_file_name: $!\n"; |
|---|
| 463 |
|
|---|
| 464 |
my $input_file; |
|---|
| 465 |
while ( <INPUT> ) |
|---|
| 466 |
{ |
|---|
| 467 |
$input_file .= "$_"; |
|---|
| 468 |
} |
|---|
| 469 |
|
|---|
| 470 |
close(INPUT); |
|---|
| 471 |
|
|---|
| 472 |
my $srcdir = (fileparse("$input_file_name"))[1]; |
|---|
| 473 |
$srcdir =~ s|/+$||; |
|---|
| 474 |
|
|---|
| 475 |
my $configure_args = join(" ", @ARGV); |
|---|
| 476 |
|
|---|
| 477 |
|
|---|
| 478 |
|
|---|
| 479 |
my $shell = ((getPlatform() =~ /solaris/i) ? 'ksh' : '$(SHELL)'); |
|---|
| 480 |
|
|---|
| 481 |
$input_file =~ s/\@srcdir\@/$srcdir/g; |
|---|
| 482 |
$input_file =~ s/\@top_srcdir\@/$root_srcdir/g; |
|---|
| 483 |
$input_file =~ s/\@CONFIGURE_ARGS\@/$configure_args/g; |
|---|
| 484 |
$input_file =~ s/\@CFG_SHELL\@/$shell/g; |
|---|
| 485 |
|
|---|
| 486 |
print "Generating $output_file_name\n"; |
|---|
| 487 |
open(OUTPUT, "> $output_file_name") |
|---|
| 488 |
or die "ERROR: Could not create $output_file_name: $!\n"; |
|---|
| 489 |
print OUTPUT "$input_file"; |
|---|
| 490 |
close(OUTPUT) or warn "WARNING: Failed to save $output_file_name: $!\n"; |
|---|
| 491 |
} |
|---|
| 492 |
|
|---|
| 493 |
sub generateReconfig ($@) |
|---|
| 494 |
{ |
|---|
| 495 |
my $gen_module = shift; |
|---|
| 496 |
my @arg_list = @_; |
|---|
| 497 |
|
|---|
| 498 |
my $modules; |
|---|
| 499 |
|
|---|
| 500 |
open(RECONFIG, "> reconfig"); |
|---|
| 501 |
|
|---|
| 502 |
print RECONFIG "#!/bin/sh\n"; |
|---|
| 503 |
print RECONFIG "if [ \"x\$1\" != \"x-q\" ]; then\n"; |
|---|
| 504 |
|
|---|
| 505 |
if ( $gen_module ) |
|---|
| 506 |
{ |
|---|
| 507 |
foreach ( $MODULES{"$gen_module"}->getDependencies() ) |
|---|
| 508 |
{ |
|---|
| 509 |
print RECONFIG " (cd " . $_->getPath() . |
|---|
| 510 |
" && rm -f config.status config.log)\n"; |
|---|
| 511 |
} |
|---|
| 512 |
} |
|---|
| 513 |
else |
|---|
| 514 |
{ |
|---|
| 515 |
my $mod_name; |
|---|
| 516 |
foreach $mod_name ( keys(%MODULES) ) |
|---|
| 517 |
{ |
|---|
| 518 |
foreach ( $MODULES{"$mod_name"}->getDependencies() ) |
|---|
| 519 |
{ |
|---|
| 520 |
print RECONFIG " (cd " . $_->getPath() . |
|---|
| 521 |
" && rm -f config.status config.cache config.log)\n"; |
|---|
| 522 |
} |
|---|
| 523 |
} |
|---|
| 524 |
} |
|---|
| 525 |
|
|---|
| 526 |
print RECONFIG " rm -f config.cache\n"; |
|---|
| 527 |
print RECONFIG "fi\n"; |
|---|
| 528 |
|
|---|
| 529 |
|
|---|
| 530 |
|
|---|
| 531 |
|
|---|
| 532 |
|
|---|
| 533 |
print RECONFIG "exec $^X $0 ", "@arg_list \n"; |
|---|
| 534 |
close(RECONFIG); |
|---|
| 535 |
chmod(0755, "reconfig"); |
|---|
| 536 |
} |
|---|
| 537 |
|
|---|
| 538 |
sub listModules () |
|---|
| 539 |
{ |
|---|
| 540 |
my $mod_name; |
|---|
| 541 |
foreach $mod_name ( keys(%MODULES) ) |
|---|
| 542 |
{ |
|---|
| 543 |
print "$mod_name"; |
|---|
| 544 |
|
|---|
| 545 |
|
|---|
| 546 |
|
|---|
| 547 |
|
|---|
| 548 |
|
|---|
| 549 |
|
|---|
| 550 |
|
|---|
| 551 |
|
|---|
| 552 |
|
|---|
| 553 |
|
|---|
| 554 |
|
|---|
| 555 |
|
|---|
| 556 |
|
|---|
| 557 |
|
|---|
| 558 |
print "\n"; |
|---|
| 559 |
} |
|---|
| 560 |
|
|---|
| 561 |
return 1; |
|---|
| 562 |
} |
|---|
| 563 |
|
|---|
| 564 |
sub printHelp () |
|---|
| 565 |
{ |
|---|
| 566 |
my @help_output = (); |
|---|
| 567 |
|
|---|
| 568 |
|
|---|
| 569 |
my $i; |
|---|
| 570 |
for ( $i = 0; $i < $LAST_ARG_GROUP; $i++ ) |
|---|
| 571 |
{ |
|---|
| 572 |
$help_output[$i] = {}; |
|---|
| 573 |
} |
|---|
| 574 |
|
|---|
| 575 |
if ( $module ) |
|---|
| 576 |
{ |
|---|
| 577 |
getConfigureHelp("$module", \@help_output); |
|---|
| 578 |
} |
|---|
| 579 |
elsif ( $JugglerConfigure::DEFAULT_MODULE && |
|---|
| 580 |
defined($MODULES{"$JugglerConfigure::DEFAULT_MODULE"}) ) |
|---|
| 581 |
{ |
|---|
| 582 |
getConfigureHelp("$JugglerConfigure::DEFAULT_MODULE", \@help_output); |
|---|
| 583 |
} |
|---|
| 584 |
else |
|---|
| 585 |
{ |
|---|
| 586 |
foreach ( keys(%MODULES) ) |
|---|
| 587 |
{ |
|---|
| 588 |
getConfigureHelp("$_", \@help_output); |
|---|
| 589 |
} |
|---|
| 590 |
} |
|---|
| 591 |
|
|---|
| 592 |
for ( $i = 0; $i < $LAST_ARG_GROUP; $i++ ) |
|---|
| 593 |
{ |
|---|
| 594 |
SWITCH: |
|---|
| 595 |
{ |
|---|
| 596 |
if ( $i == $PRELUDE ) |
|---|
| 597 |
{ |
|---|
| 598 |
last SWITCH; |
|---|
| 599 |
} |
|---|
| 600 |
|
|---|
| 601 |
if ( $i == $FEATURE_ARGS ) |
|---|
| 602 |
{ |
|---|
| 603 |
print "Optional Features:\n"; |
|---|
| 604 |
last SWITCH; |
|---|
| 605 |
} |
|---|
| 606 |
|
|---|
| 607 |
if ( $i == $PACKAGE_ARGS ) |
|---|
| 608 |
{ |
|---|
| 609 |
print "\nOptional Packages:\n"; |
|---|
| 610 |
last SWITCH; |
|---|
| 611 |
} |
|---|
| 612 |
|
|---|
| 613 |
if ( $i == $PROLOGUE ) |
|---|
| 614 |
{ |
|---|
| 615 |
print "\n"; |
|---|
| 616 |
last SWITCH; |
|---|
| 617 |
} |
|---|
| 618 |
} |
|---|
| 619 |
|
|---|
| 620 |
foreach ( sort(keys(%{$help_output[$i]})) ) |
|---|
| 621 |
{ |
|---|
| 622 |
print "${$help_output[$i]}{$_}"; |
|---|
| 623 |
} |
|---|
| 624 |
} |
|---|
| 625 |
|
|---|
| 626 |
print "\n"; |
|---|
| 627 |
|
|---|
| 628 |
print "Modules that may be built:\n"; |
|---|
| 629 |
foreach ( keys(%MODULES) ) |
|---|
| 630 |
{ |
|---|
| 631 |
print "\t$_\n"; |
|---|
| 632 |
} |
|---|
| 633 |
|
|---|
| 634 |
print "\nDefault module is $JugglerConfigure::DEFAULT_MODULE\n" |
|---|
| 635 |
if $JugglerConfigure::DEFAULT_MODULE; |
|---|
| 636 |
|
|---|
| 637 |
return 1; |
|---|
| 638 |
} |
|---|
| 639 |
|
|---|
| 640 |
sub getConfigureHelp ($$) |
|---|
| 641 |
{ |
|---|
| 642 |
my $mod_name = shift; |
|---|
| 643 |
my $arg_arr_ref = shift; |
|---|
| 644 |
|
|---|
| 645 |
my $configure_count = 0; |
|---|
| 646 |
|
|---|
| 647 |
foreach ( $MODULES{"$mod_name"}->getDependencies() ) |
|---|
| 648 |
{ |
|---|
| 649 |
next unless -x "$base_dir/$$_{'path'}/configure"; |
|---|
| 650 |
|
|---|
| 651 |
$configure_count++; |
|---|
| 652 |
open(CFG_OUTPUT, "$base_dir/$$_{'path'}/configure --help |"); |
|---|
| 653 |
|
|---|
| 654 |
my $cfg_output; |
|---|
| 655 |
while ( <CFG_OUTPUT> ) |
|---|
| 656 |
{ |
|---|
| 657 |
$cfg_output .= "$_"; |
|---|
| 658 |
} |
|---|
| 659 |
|
|---|
| 660 |
close(CFG_OUTPUT); |
|---|
| 661 |
|
|---|
| 662 |
parseOutput("$cfg_output", $arg_arr_ref); |
|---|
| 663 |
} |
|---|
| 664 |
|
|---|
| 665 |
die "ERROR: No configure scripts found! Please run autogen.sh\n" . |
|---|
| 666 |
" (found in $base_dir) first.\n" |
|---|
| 667 |
if $configure_count == 0; |
|---|
| 668 |
} |
|---|
| 669 |
|
|---|
| 670 |
sub parseOutput ($$) |
|---|
| 671 |
{ |
|---|
| 672 |
my $string = shift; |
|---|
| 673 |
my $arg_arr_ref = shift; |
|---|
| 674 |
|
|---|
| 675 |
while ( $string !~ /^\s*$/s ) |
|---|
| 676 |
{ |
|---|
| 677 |
|
|---|
| 678 |
|
|---|
| 679 |
if ( $string =~ /^(Usage:.*)(Optional Features:)/s ) |
|---|
| 680 |
{ |
|---|
| 681 |
$string = "$2$'"; |
|---|
| 682 |
${$$arg_arr_ref[$PRELUDE]}{'all'} = "$1"; |
|---|
| 683 |
} |
|---|
| 684 |
|
|---|
| 685 |
elsif ( $string =~ /^(Optional Features:.*)(Optional Packages:)/s ) |
|---|
| 686 |
{ |
|---|
| 687 |
$string = "$2$'"; |
|---|
| 688 |
|
|---|
| 689 |
my @param_list = split(/\n/, "$1"); |
|---|
| 690 |
|
|---|
| 691 |
|
|---|
| 692 |
my $i; |
|---|
| 693 |
for ( $i = 0; $i <= $#param_list; $i++ ) |
|---|
| 694 |
{ |
|---|
| 695 |
if ( $param_list[$i] =~ /(--(enable|disable)\S+)/ ) |
|---|
| 696 |
{ |
|---|
| 697 |
my $param = "$1"; |
|---|
| 698 |
|
|---|
| 699 |
|
|---|
| 700 |
|
|---|
| 701 |
if ( ! exists(${$$arg_arr_ref[$FEATURE_ARGS]}{"$param"}) ) |
|---|
| 702 |
{ |
|---|
| 703 |
|
|---|
| 704 |
my $param_info = "$param_list[$i]\n"; |
|---|
| 705 |
|
|---|
| 706 |
|
|---|
| 707 |
|
|---|
| 708 |
while ( $i + 1 <= $#param_list && |
|---|
| 709 |
$param_list[$i + 1] !~ /--(enable|disable)/ ) |
|---|
| 710 |
{ |
|---|
| 711 |
$param_info .= "$param_list[$i + 1]\n"; |
|---|
| 712 |
$i++; |
|---|
| 713 |
} |
|---|
| 714 |
|
|---|
| 715 |
|
|---|
| 716 |
${$$arg_arr_ref[$FEATURE_ARGS]}{"$param"} = "$param_info"; |
|---|
| 717 |
} |
|---|
| 718 |
} |
|---|
| 719 |
} |
|---|
| 720 |
} |
|---|
| 721 |
|
|---|
| 722 |
elsif ( $string =~ /^(Optional Packages:.*)(Some influential)/s ) |
|---|
| 723 |
{ |
|---|
| 724 |
$string = "$2$'"; |
|---|
| 725 |
|
|---|
| 726 |
my @param_list = split(/\n/, "$1"); |
|---|
| 727 |
|
|---|
| 728 |
|
|---|
| 729 |
my $i; |
|---|
| 730 |
for ( $i = 0; $i <= $#param_list; $i++ ) |
|---|
| 731 |
{ |
|---|
| 732 |
if ( $param_list[$i] =~ /(--with\S+)/ ) |
|---|
| 733 |
{ |
|---|
| 734 |
my $param = "$1"; |
|---|
| 735 |
|
|---|
| 736 |
|
|---|
| 737 |
|
|---|
| 738 |
if ( ! exists(${$$arg_arr_ref[$PACKAGE_ARGS]}{"$param"}) ) |
|---|
| 739 |
{ |
|---|
| 740 |
|
|---|
| 741 |
my $param_info = "$param_list[$i]\n"; |
|---|
| 742 |
|
|---|
| 743 |
|
|---|
| 744 |
|
|---|
| 745 |
while ( $i + 1 <= $#param_list && |
|---|
| 746 |
$param_list[$i + 1] !~ /--with/ ) |
|---|
| 747 |
{ |
|---|
| 748 |
$param_info .= "$param_list[$i + 1]\n"; |
|---|
| 749 |
$i++; |
|---|
| 750 |
} |
|---|
| 751 |
|
|---|
| 752 |
|
|---|
| 753 |
${$$arg_arr_ref[$PACKAGE_ARGS]}{"$param"} = "$param_info"; |
|---|
| 754 |
} |
|---|
| 755 |
} |
|---|
| 756 |
} |
|---|
| 757 |
} |
|---|
| 758 |
|
|---|
| 759 |
|
|---|
| 760 |
elsif ( $string =~ /^(Some influential.*)$/s ) |
|---|
| 761 |
{ |
|---|
| 762 |
$string = "$'"; |
|---|
| 763 |
${$$arg_arr_ref[$PROLOGUE]}{'all'} = "$1"; |
|---|
| 764 |
} |
|---|
| 765 |
|
|---|
| 766 |
elsif ( $string =~ /^.*$/m ) |
|---|
| 767 |
{ |
|---|
| 768 |
$string = $'; |
|---|
| 769 |
} |
|---|
| 770 |
|
|---|
| 771 |
$string =~ s/^\s*//s; |
|---|
| 772 |
} |
|---|
| 773 |
} |
|---|
| 774 |
|
|---|
| 775 |
sub getPlatform () |
|---|
| 776 |
{ |
|---|
| 777 |
my $platform = "unknown"; |
|---|
| 778 |
|
|---|
| 779 |
# Prefer the user-defined platform type over any auto-detected value. |
|---|
| 780 |
if ( "$OS" ne '' ) |
|---|
| 781 |
{ |
|---|
| 782 |
$platform = "$OS"; |
|---|
| 783 |
} |
|---|
| 784 |
elsif ( defined($ENV{'OS'}) ) |
|---|
| 785 |
{ |
|---|
| 786 |
$platform = "$ENV{'OS'}"; |
|---|
| 787 |
} |
|---|
| 788 |
elsif ( defined($ENV{'OSTYPE'}) ) |
|---|
| 789 |
{ |
|---|
| 790 |
$platform = "$ENV{'OSTYPE'}"; |
|---|
| 791 |
} |
|---|
| 792 |
elsif ( defined($ENV{'OS_TYPE'}) ) |
|---|
| 793 |
{ |
|---|
| 794 |
$platform = "$ENV{'OS_TYPE'}"; |
|---|
| 795 |
} |
|---|
| 796 |
elsif ( defined($ENV{'HOSTTYPE'}) ) |
|---|
| 797 |
{ |
|---|
| 798 |
$platform = "$ENV{'HOSTTYPE'}"; |
|---|
| 799 |
} |
|---|
| 800 |
# As a last resort, fall back on the use of uname(1). |
|---|
| 801 |
else |
|---|
| 802 |
{ |
|---|
| 803 |
chomp($platform = `uname -s`); |
|---|
| 804 |
} |
|---|
| 805 |
|
|---|
| 806 |
# XXX: This is a hack to deal with weird OS strings such as "linux-gnu". |
|---|
| 807 |
# We just make the platform be "linux" unless the user set the platform |
|---|
| 808 |
# type on the command line. |
|---|
| 809 |
$platform = 'linux' if ! $OS && $platform =~ /linux/i; |
|---|
| 810 |
|
|---|
| 811 |
return $platform; |
|---|
| 812 |
} |
|---|
| 813 |
|
|---|
| 814 |
sub getHostname () |
|---|
| 815 |
{ |
|---|
| 816 |
my $hostname = ''; |
|---|
| 817 |
|
|---|
| 818 |
if ( defined($ENV{'HOSTNAME'}) ) |
|---|
| 819 |
{ |
|---|
| 820 |
$hostname = "$ENV{'HOSTNAME'}"; |
|---|
| 821 |
} |
|---|
| 822 |
else |
|---|
| 823 |
{ |
|---|
| 824 |
chomp($hostname = `hostname`); |
|---|
| 825 |
} |
|---|
| 826 |
|
|---|
| 827 |
return $hostname; |
|---|
| 828 |
} |
|---|
| 829 |
|
|---|
| 830 |
__END__ |
|---|
| 831 |
|
|---|
| 832 |
=head1 NAME |
|---|
| 833 |
|
|---|
| 834 |
configure.pl |
|---|
| 835 |
|
|---|
| 836 |
=head1 SYNOPSIS |
|---|
| 837 |
|
|---|
| 838 |
This script acts as the "glue" for a collection of Autoconf-based configure |
|---|
| 839 |
scripts. Based on a configuration file, it is capable of building a |
|---|
| 840 |
dependency tree and running the configure scripts in the correct order such |
|---|
| 841 |
that the dependencies are satisfied correctly. Note that all modules must |
|---|
| 842 |
be capable of having dependencies satisfied based entirely on the results |
|---|
| 843 |
of running a dependent module's |
|---|