PERL   82
multiconf pl
Guest on 13th March 2023 12:11:42 AM


  1. #!/usr/bin/env perl
  2.  
  3. require 5.005;
  4. use strict;
  5. use Cwd;
  6.  
  7. # --with-multiconf[=<conf_options>] : enables selected confs
  8. # --with-multiconf-file=conffile : selects multiconf.conf input file (defaults to multiconf.conf.in)
  9. # --with-multiconf-force=name : asserts $opt{name} to allow use w/o passing that arg explicitly
  10. # --reboot : force a Bootstrap before configures are run
  11.  
  12. # new configure options:
  13. # --without-multiconf : legacy behavior
  14. # --with-multiconf-magic=confname : used by multiconf for sub-configures
  15.  
  16. my $top_builddir = getcwd();
  17. chdir($top_builddir) or die "Failed to chdir($top_builddir): $!";
  18. my $top_srcdir = $0;
  19. $top_srcdir =~ s@/[^/]*$@@;
  20. chdir($top_srcdir) or die "Failed to chdir($top_srcdir): $!";
  21. $top_srcdir = getcwd();
  22. chdir($top_srcdir) or die "Failed to chdir($top_srcdir): $!";
  23. push @INC, $top_srcdir;  # set up search path for our perl includes
  24. chdir($top_builddir) or die "Failed to chdir($top_builddir): $!";
  25.  
  26. my $config_shell = '';
  27. if (defined($ENV{'CONFIG_SHELL'})) {
  28.   $config_shell = $ENV{'CONFIG_SHELL'};
  29.   die "If set, environment variable CONFIG_SHELL must be " .
  30.       "the full path to a Bourne-compatible shell.\n"
  31.         unless ($config_shell =~ m:^/:);
  32.   $config_shell .= ' ';
  33. }
  34.  
  35. # bug 3153 - we cannot let SuSE (et al.) set ${libdir} to ${prefix}/lib64
  36. $ENV{'CONFIG_SITE'} = '/dev/null' if defined $ENV{'CONFIG_SITE'};
  37.  
  38. # establish a global configure warning summary file
  39. my $configure_warn_file =  "$top_builddir/.multiconf_configure_warnings.tmp";
  40. $ENV{'GASNET_CONFIGURE_WARNING_GLOBAL'} = $configure_warn_file;
  41. open CONFWARN,">$configure_warn_file" or die "failed to create $configure_warn_file: $!";
  42. close CONFWARN;
  43. # suppress a confusing warning when using multiconf
  44. $ENV{'GASNET_SUPPRESS_DEBUG_WARNING'} = 1;
  45. $| = 1; # autoflush output to ensure correct behavior with forks and output piped to files
  46.  
  47. # shared functions
  48. use vars qw($debug $disable_upcc *debuglog);
  49. $disable_upcc = 1;
  50. my $debuglog_file = "$top_builddir/config.log";
  51. open DEBUGLOG,">$debuglog_file" or die "failed to create $debuglog_file: $!";
  52. *debuglog = *DEBUGLOG{IO}; # bug 2476 - old perl requires this nastiness, avert your eyes...
  53. require "upcc_multi.pl";
  54.  
  55. my %opt;
  56. my %cond_opt;
  57. my %cond_env;
  58. my %cond_confs;
  59. my @sub_ARGV;
  60.  
  61.  
  62. debugmsg("top_srcdir=$top_srcdir");
  63. debugmsg("top_builddir=$top_builddir");
  64.  
  65. ### parse arguments ###
  66. # avoid getopt here, to eliminate the complication of finding a non-buggy version of that module
  67. my $lastopt = '';
  68. foreach my $arg (@ARGV) {
  69.   my $skip;
  70.   if ($arg =~ m/^--?([A-Za-z0-9-_]+)(=(.*))?$/) {
  71.     my ($argb, $set, $argv) = ($1,$2,$3);
  72.     $skip = 1 if ($argb eq "prefix"); # avoid redundant prefix arg to subconfigure
  73.     if ($set) {
  74.       $opt{$argb} = $argv;
  75.       $lastopt = undef;
  76.     } else {
  77.       $opt{$argb} = "yes";
  78.       $lastopt = $argb;
  79.     }
  80.     if ($argb =~ m/^(reboot)|(dry-run)$/) # strip non-autoconf compliant arg names that make it barf
  81.       { $skip = 1; $lastopt = undef; }
  82.     if ($argb =~ m/^with-(.+)$/) { delete $opt{"without-$1"}; $lastopt = undef; }
  83.     if ($argb =~ m/^without-(.+)$/) { delete $opt{"with-$1"}; $lastopt = undef; }
  84.     if ($argb =~ m/^enable-(.+)$/) { delete $opt{"disable-$1"}; $lastopt = undef; }
  85.     if ($argb =~ m/^disable-(.+)$/) { delete $opt{"enable-$1"}; $lastopt = undef; }
  86.   } elsif ($lastopt) { # assume it's an argument to last arg
  87.     $skip = 1 if ($lastopt eq "prefix"); # avoid redundant prefix arg to subconfigure
  88.     $opt{$lastopt} = $arg;
  89.     $lastopt = undef;
  90.   } elsif ($arg =~ m/^([A-Za-z0-9-_]+)=(.*)$/) { # detect command-line environment variables
  91.     my ($var,$val) = ($1,$2);
  92.     $ENV{$var} = $val;
  93.     print "Setting from command-line: $var=".$ENV{$var}."\n";
  94.     $skip = 1;
  95.   } elsif ($arg =~ m/^([A-Za-z0-9-_,]+):(.*)$/) { # conditional (subconfig-specific) argument
  96.     my @confs = split ',', $1;
  97.     my $subarg = $2;
  98.     if ($subarg =~ m/^--?([A-Za-z0-9-_]+)(=.*)?$/) { # conditional --argument
  99.       foreach my $subconf (@confs) {
  100.         $cond_opt{$subconf} .= ' ' . $subarg;
  101.         $cond_confs{$subconf} = 1;
  102.       }
  103.       $skip = 1;
  104.     } elsif ($subarg =~ m/^([A-Za-z0-9-_]+)=(.*)$/) { # conditional VAR=VAL
  105.       foreach my $subconf (@confs) {
  106.         $cond_env{$subconf}->{$1} = $2;
  107.         $cond_confs{$subconf} = 1;
  108.       }
  109.       $skip = 1;
  110.     } else {
  111.       debugmsg("ignoring strange conditional argument:".$arg);
  112.     }
  113.   } else {
  114.     debugmsg("ignoring strange argument:".$arg);
  115.   }
  116.   push @sub_ARGV, "'$arg'" unless ($skip);
  117. }
  118. debugmsg("args: ".join(' ', map { ($opt{$_} eq "yes" ? "--$_" : "--$_=$opt{$_}") } keys %opt));
  119.  
  120. my $top_prefix = $opt{prefix} || "/usr/local/berkeley_upc";
  121. $debug = 1 if ($opt{'dry-run'});
  122.  
  123. if ($opt{h} || $opt{help}) {
  124.   run_command("$config_shell$top_srcdir/configure --with-multiconf-magic=help ".join(' ',@sub_ARGV),"configure help",1);
  125.   print STDERR <<EOF;
  126.  
  127. multiconf options:
  128.  
  129.   --with-multiconf[=<conf_options>]  
  130.          Enable use of multiconf build configuration manager.  The optional
  131.          <conf_options> can be used to modify the default ENABLED_CONFS setting
  132.          in the multiconf config file, using one of the following syntaxes:
  133.           conf1,conf2,conf3      set ENABLED_CONFS=conf1,conf2,conf3
  134.           +conf1,+conf2,-conf3   modify default ENABLED_CONFS, appending conf1,conf2
  135.                                  and removing conf3
  136.  
  137.   --with-multiconf-file=<conf_file>
  138.          Enable use of multiconf, with given config file (defaults to multiconf.conf.in)
  139.                                  
  140.   --with-multiconf-force=<opt>
  141.          Comma-delimited list of multi-conf specific upcc options to assert.
  142.          Typically used to configure for sole use of a non-Berkeley translator.
  143.                                  
  144.   --without-multiconf   Disable use of multiconf - legacy configure behavior
  145.   --prefix=pathname     Use pathname as base prefix for multiconf installation
  146.   --reboot[=<args>]     Bootstrap the source directory before invoking configure
  147.   --verbose             Show operations verbosely
  148.   --dry-run             Skip actual configure invocations, to debug configurations
  149.   --help                This help screen
  150.  
  151.   [[confs:]arg]         Other arguments are passed through to configure
  152.   [[confs:]var=val]     Environment variables will be set when running configure
  153.       Where "confs:" is an optional comma-seprated, colon-terminated list of
  154.       configurations (default is to pass arg, or set var, for all configurations)
  155.  
  156. EOF
  157.   # dont leave junk laying around for a --help invocation
  158.   close *debuglog;
  159.   unlink $debuglog_file;
  160.   unlink $configure_warn_file;
  161.   exit 0;
  162. }
  163.  
  164. if ($opt{reboot}) {
  165.   my $bootstrap_args = ($opt{reboot} eq 'yes') ? '' : $opt{reboot};
  166.   run_command("cd $top_srcdir && ./Bootstrap $bootstrap_args","reboot Bootstrap");
  167. }
  168.  
  169. if ($opt{'without-multiconf'}) { # used for non-multiconf reboot
  170.   my @args = grep !/^-?-reboot/, @ARGV;
  171.   close *debuglog;
  172.   unlink $debuglog_file;
  173.   unlink $configure_warn_file;
  174.   undef $ENV{'GASNET_CONFIGURE_WARNING_GLOBAL'};
  175.   run_command("$config_shell$top_srcdir/configure ".join(' ',@args),"configure");
  176.   exit 0;
  177. }
  178.  
  179. # parse conffile
  180. my @interesting_vars;
  181. delete $opt{'with-multiconf'} if ($opt{'with-multiconf'} eq "yes");
  182. delete $opt{'with-multiconf-file'} if ($opt{'with-multiconf-file'} eq "yes");
  183. delete $opt{'with-multiconf-force'} if ($opt{'with-multiconf-force'} eq "yes");
  184. my $multiconf_confmods = $opt{'with-multiconf'};
  185. my $multiconf_spec = $opt{'with-multiconf-file'} || "multiconf.conf.in";
  186. my $multiconf_forced = $opt{'with-multiconf-force'};
  187. $multiconf_spec = "$top_srcdir/$multiconf_spec" if (! -f $multiconf_spec && -f "$top_srcdir/$multiconf_spec");
  188. my @confs = parse_multiconf_spec($multiconf_spec, $multiconf_confmods, \@interesting_vars);
  189. my @conf_names = grep { $_ ne 'error' } map { $$_{name} } @confs;
  190. my $conf_names = join(' ', @conf_names);
  191. my $default_conf_name = $confs[$#confs]{name};
  192. my $numconfs = $#conf_names+1;
  193. debugmsg("Enabled confs ($numconfs): $conf_names\nDefault conf: $default_conf_name");
  194.  
  195. # copy conffile to builddir with substitutions
  196. copy_file($multiconf_spec, "$top_builddir/multiconf.conf",
  197.           sub { s/^\s*ENABLED_CONFS=.*$/ENABLED_CONFS=$conf_names/;
  198.                 s/^\s*FORCED_OPTIONS=.*$/FORCED_OPTIONS=$multiconf_forced/;
  199.               });
  200.  
  201. my @badopts;
  202. foreach my $badopt ( ( map { ("enable-$_","disable-$_") } split(/,/,$ENV{PROHIBITED_ENABLE_OPTIONS}) ),
  203.                      ( map { ("with-$_","without-$_") }   split(/,/,$ENV{PROHIBITED_WITH_OPTIONS}  ) ) ) {
  204.   push(@badopts, "--$badopt") if ($opt{$badopt});
  205. }
  206. if (@badopts && !$opt{"enable-prohibited-options"}) {
  207.   die "multiconf error: You passed the following configure options which are " .
  208.       "prohibited by the current multiconf configuration script:\n" .
  209.       "  " . join(" ",@badopts) . "\n" .
  210.       "These options are incorporated by the multiplexing nature of the config script " .
  211.       "and should be handled using --with-multiconf= options appropriate to the script. " .
  212.       "See the section 'PROHIBITED TOP-LEVEL CONFIGURE OPTIONS' in $multiconf_spec for " .
  213.       "more detailed usage information to solve this problem.\n";
  214. }
  215.  
  216.  
  217. # create top-level Makefile in builddir
  218. my $makefile = "Makefile";
  219. debugmsg("Writing makefile [$makefile] with confs: $conf_names");
  220. open MAKEFILE, ">$makefile";
  221. print MAKEFILE <<'EOF';
  222. # Berkeley UPC top-level multiconf Makefile driver
  223. ifneq (1,1)
  224.         GNU Make is required, but you're not using it: try 'gmake'
  225. endif
  226.  
  227. # Supported multiconf configurations:
  228. EOF
  229. print MAKEFILE "CONFS=$conf_names\n";
  230. print MAKEFILE <<EOF;
  231.  
  232. DEFAULT_CONF=$default_conf_name
  233. top_srcdir=$top_srcdir
  234. top_builddir=$top_builddir
  235. prefix=$top_prefix
  236. PERL=$^X
  237. EOF
  238.  
  239. open MAKEFILE_IN, "<$top_srcdir/Makefile.multiconf";
  240. my $oldslash = $/;
  241. undef $/;
  242. print MAKEFILE <MAKEFILE_IN>; # slurp
  243. $/ = $oldslash;
  244. close MAKEFILE_IN;
  245.  
  246. exit 0 if ($opt{'regen-makefile'});
  247.  
  248. foreach my $conf (@confs) {
  249.   my $conf_name = $$conf{name};
  250.   next if ($conf_name eq 'error');
  251.  
  252.   # Merge in CONF:... options & vars
  253.   $$conf{options} .= $cond_opt{$conf_name};
  254.   foreach my $var (keys %{$cond_env{$conf_name}}) {
  255.     my $val = $cond_env{$conf_name}->{$var};
  256.     $$conf{env}->{$var} = $val;
  257.     print "Setting from command-line: $var=$val\n";
  258.   }
  259.   delete $cond_confs{$conf_name};
  260.  
  261.   print <<EOF;
  262. --------------------------------------------------------------------
  263.            === Multiconf configuring: $conf_name ===
  264. --------------------------------------------------------------------
  265. EOF
  266.  
  267.   # Create conf dir
  268.   debugmsg("Creating directory: $conf_name");
  269.   if ( ! -d $conf_name ) {
  270.     mkdir($conf_name,0777) || die "Failed to create directory '$conf_name': $!";
  271.   }
  272.  
  273.   # set conf_env
  274.   my $conf_env = $$conf{env};
  275.   %ENV = %$conf_env;
  276.   if ($debug) {
  277.     foreach my $var (@interesting_vars) {
  278.       print "$var=".$ENV{$var}."\n" if (defined $ENV{$var});
  279.     }
  280.   }
  281.  
  282.   my $conf_options;
  283.   $conf_options .= " " . $ENV{CONFIGURE_OPTIONS} if ($ENV{CONFIGURE_OPTIONS}); # conf file general options -- lowest priority
  284.   $conf_options .= " " . $$conf{options}; # per-config options, medium priority
  285.   $conf_options .= " " . join(' ',@sub_ARGV); # command-line pass-thru configure options -- highest priority
  286.  
  287.   # run configure for this conf
  288.   my $cmd = "cd $conf_name && $config_shell$top_srcdir/configure $conf_options --prefix='$top_prefix/$conf_name' --with-multiconf-magic=$conf_name";
  289.   if ($opt{'dry-run'}) {
  290.     debugmsg("Skipping $conf_name configure:\n$cmd");
  291.     system("cd $conf_name && touch config.status && mkdir -p gasnet/other");
  292.     copy_file("$top_srcdir/gasnet/other/perlstart.in", "$conf_name/gasnet/other/perlstart");
  293.     open MAKEFILE,">$conf_name/Makefile";
  294.     print MAKEFILE <<EOF;
  295. %:
  296.         \@echo "MULTICONF DRY RUN: $conf_name conf skipping \$@..."
  297. EOF
  298.     close MAKEFILE;
  299.   } else {
  300.     run_command($cmd, "$conf_name configure");
  301.   }
  302. }
  303.  
  304. if (-s $configure_warn_file) { # non-empty warning file
  305.   for my $FH (*debuglog, *STDOUT) {
  306.     print $FH <<EOF;
  307. --------------------------------------------------------------------
  308.            === Multiconf configure warning summary ===
  309. --------------------------------------------------------------------
  310. EOF
  311.     open CONFWARN,"$configure_warn_file";
  312.     while (<CONFWARN>) { print $FH $_; }
  313.     close CONFWARN;
  314.     print $FH <<EOF;
  315. --------------------------------------------------------------------
  316. EOF
  317.   }
  318. }
  319. unlink $configure_warn_file;
  320. foreach my $conf_name (keys %cond_confs) {
  321.   for my $FH (*debuglog, *STDOUT) {
  322.     print $FH "WARNING: conf-specific command-line options unused for conf=$conf_name\n";
  323.   }
  324. }
  325. close *debuglog;
  326.  
  327. print "\n\nSUCCESS! The configure step is now complete. You should now proceed with:\n gmake ; gmake install\n";
  328. exit 0;

Raw Paste

Login or Register to edit or fork this paste. It's free.