root/juggler/tags/2.0.0/configure.pl

Revision 16519, 25.2 kB (checked in by patrickh, 4 years ago)

Copyright update.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
Line 
1 #!/usr/bin/env perl
2
3 # ************** <auto-copyright.pl BEGIN do not edit this line> **************
4 #
5 # VR Juggler is (C) Copyright 1998-2005 by Iowa State University
6 #
7 # Original Authors:
8 #   Allen Bierbaum, Christopher Just,
9 #   Patrick Hartling, Kevin Meinert,
10 #   Carolina Cruz-Neira, Albert Baker
11 #
12 # This library is free software; you can redistribute it and/or
13 # modify it under the terms of the GNU Library General Public
14 # License as published by the Free Software Foundation; either
15 # version 2 of the License, or (at your option) any later version.
16 #
17 # This library is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20 # Library General Public License for more details.
21 #
22 # You should have received a copy of the GNU Library General Public
23 # License along with this library; if not, write to the
24 # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 # Boston, MA 02111-1307, USA.
26 #
27 # -----------------------------------------------------------------
28 # File:          $RCSfile$
29 # Date modified: $Date$
30 # Version:       $Revision$
31 # -----------------------------------------------------------------
32 #
33 # *************** <auto-copyright.pl END do not edit this line> ***************
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 # Subroutine prototypes.
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 # Print the help output and exit if --help was on the command line.
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 # On Windows, the command-line arguments can confuse the Cygwin shell.  For
123 # example, the character used to separate paths is ';', but the shell sees
124 # that as a statement separator.  We can deal with this by ensuring that the
125 # shell interprets command-line arguments as literal strings (i.e., by
126 # putting quotes around each argument).
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    # Unless the user passed --noargs, try to find default argument values.
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       # Figure out what argument file to load, if any.  If the user specified
168       # a file name on the command line, it will be in $user_args.  Otherwise,
169       # we fall back on $base_dir/$args_file.
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    # Configure the module named on the command line.
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    # If no module was named on the command line but we do have a default
206    # module, configure it.
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    # If neither of the above will do, just configure every module we know
215    # about from the input file.
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    # Do a quick check to try to find GNU make.  If we don't find it, then we
231    # will just assume that GNU make is 'gmake' and that the user knows what
232    # he or she is doing.
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 # Subroutines follow.
273 # =============================================================================
274
275 sub mergeArgArrays ($$)
276 {
277    my $dest_list   = shift;
278    my $source_list = shift;
279
280    foreach ( @$source_list )
281    {
282       # Strip leading and trailing whitespace.
283       s/^\s+//;
284       s/\s+$//;
285       next if /^$/;   # Just to be safe...
286       
287       # Only add the argument if it is not already on the command line.
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/#.*$//;           # Strip comments
305          next if /^\s*$/;    # Skip blank lines
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          # Read in the arguments for all platforms.
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          # Skip a platform that does not match $platform.
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       # Do not try to proceed with $dependency unless we can chdir to
439       # $mod_path.
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    # Use ksh to run configure if we are on Solaris.  Otherwise, use the default
478    # shell.
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    # Print the command to run this script again.  The actual output will be
530    # the exec shell command followed by the full path to the Perl
531    # interpreter used to run this script; the same path to the script that
532    # the user entered; and the full argument list given on the command line.
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 #      if ( $#{$MODULES{"$mod_name"}} != -1 )
546 #      {
547 #         print " (Requires:";
548 #
549 #         my $dep_ref;
550 #         foreach $dep_ref ( @{$MODULES{"$mod_name"}} )
551 #         {
552 #            print " ${$dep_ref}{'path'}";
553 #         }
554 #
555 #         print ")";
556 #      }
557
558       print "\n";
559    }
560
561    return 1;
562 }
563
564 sub printHelp ()
565 {
566    my @help_output = ();
567
568    # Initialize the references that are contained within @help_output.
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       # Match everything up to the list of optional features.  This forms the
678       # prelude of the help output.
679       if ( $string =~ /^(Usage:.*)(Optional Features:)/s )
680       {
681          $string = "$2$'";
682          ${$$arg_arr_ref[$PRELUDE]}{'all'} = "$1";
683       }
684       # Handle the --enable and --disable list of options.
685       elsif ( $string =~ /^(Optional Features:.*)(Optional Packages:)/s )
686       {
687          $string = "$2$'";
688
689          my @param_list = split(/\n/, "$1");
690
691          # Loop over all the lines of output in the "Optional Features" block.
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                # If $param does not exist in the hash of feature arguments,
700                # we need to add it.
701                if ( ! exists(${$$arg_arr_ref[$FEATURE_ARGS]}{"$param"}) )
702                {
703                   # Add the first line of information for $param.
704                   my $param_info = "$param_list[$i]\n";
705
706                   # If the following lines are a continuation of the info for
707                   # $param, add them to $param_info as well.
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                   # Store the complete information block for $param.
716                   ${$$arg_arr_ref[$FEATURE_ARGS]}{"$param"} = "$param_info";
717                }
718             }
719          }
720       }
721       # Handle the --with and --without list of options.
722       elsif ( $string =~ /^(Optional Packages:.*)(Some influential)/s )
723       {
724          $string = "$2$'";
725
726          my @param_list = split(/\n/, "$1");
727
728          # Loop over all the lines of output in the "Optional Packages" block.
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                # If $param does not exist in the hash of package arguments,
737                # we need to add it.
738                if ( ! exists(${$$arg_arr_ref[$PACKAGE_ARGS]}{"$param"}) )
739                {
740                   # Add the first line of information for $param.
741                   my $param_info = "$param_list[$i]\n";
742
743                   # If the following lines are a continuation of the info for
744                   # $param, add them to $param_info as well.
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                   # Store the complete information block for $param.
753                   ${$$arg_arr_ref[$PACKAGE_ARGS]}{"$param"} = "$param_info";
754                }
755             }
756          }
757       }
758       # We'll keep everything after the line beginning with "Some influential"
759       # to form the prologue of the help output.
760       elsif ( $string =~ /^(Some influential.*)$/s )
761       {
762          $string = "$'";   # This should be the empty string.
763          ${$$arg_arr_ref[$PROLOGUE]}{'all'} = "$1";
764       }
765       # Match anything else and strip it from the output.
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 configure script.