Okay, this makes Configure generate a Parrot::Config module in the
current directory.  This is analogous to Config.pm, except this exports
a %PConfig hash (to avoid collisions).  I'm using Data::Dumper to create
the hash, so it'll make sure you have it and just not generate the file
(and tell the user) if Data::Dumper isn't available.  Patches after my
sig.  Someone suggested that we use .whatever_in instead of .whatever.in
for portability reasons; this does so on the new file but leaves the old
files as they are.  It also adds "or die ..." to all openings and
closings of files.

Note that this patch *replaces* my last patch, sent earlier today.  Do
*not* apply my last patch--apply this one instead.

--Brent Dax
[EMAIL PROTECTED]

They *will* pay for what they've done.


--- c:\old_parrot\Configure.pl  Tue Sep 11 02:44:00 2001
+++ Configure.pl        Thu Sep 13 23:32:26 2001
@@ -1,11 +1,18 @@
 #!/usr/bin/perl -w
 #so we get -w

-#Configre.pl, written by Brent Dax
+#Configure.pl, written by Brent Dax

 use strict;
 use Config;

+my($DDOK)=undef;
+eval {
+       require Data::Dumper;
+       Data::Dumper->import();
+       $DDOK=1;
+};
+
 #print the header
 print <<"END";
 Parrot Configure
@@ -22,11 +29,17 @@
 #defaults for them.
 #XXX Figure out better defaults
 my(%c)=(
-       iv => ($Config{ivtype}||'long'),
-       nv => ($Config{nvtype}||'long double')
+       iv =>           ($Config{ivtype}||'long'),
+       nv =>           ($Config{nvtype}||'long double'),
+       cc =>           $Config{cc},
+       ccflags =>      '-Wall -o $@',
+       libs =>         $Config{libs}
 );

-#inquire about numeric sizes
+#ask questions
+prompt("What C compiler do you want to use?", 'cc');
+prompt("What flags would you like passed to your C compiler?",
'ccflags');
+prompt("Which libraries would you like your C compiler to include?" ,
'libs');
 prompt("How big would you like integers to be?", 'iv');
 prompt("How about your floats?", 'nv');

@@ -40,25 +53,22 @@

 #set up HAS_HEADER_
 foreach(grep {/^i_/} keys %Config) {
+       $c{$_}=$Config{$_};
        $c{headers}.=defineifdef((/^i_(.*)$/));
 }

-#now let's assemble the config.h file
-my $config_h;
-{
-       local $/;
-       open(CONFIG_HT, "<config.h.in") or die $!;
-       $config_h=<CONFIG_HT>;
-       close CONFIG_HT;
-}
+print <<"END";

-# ${field} is replaced with $c{field}
-$config_h =~ s/\$\{(\w+)\}/$c{$1}/g;
+Okay, that's finished.  I'm now going to write your very
+own Makefile, config.h, and Parrot::Config to disk.
+END

-#write out the config.h file
-open(CONFIG_H, ">config.h");
-print CONFIG_H $config_h;
-close CONFIG_H;
+#now let's assemble the config.h file
+buildfile("config.h");
+#and the makefile
+buildfile("Makefile");
+#and Parrot::Config
+buildconfigpm();

 print <<"END";

@@ -91,3 +101,47 @@
        $c{$field}=$input||$c{$field};
 }

+sub buildfile {
+       my($filename)=shift;
+
+       local $/;
+       open(IN, "<$filename.in") or die "Can't open $filename.in: $!";
+       my $text=<IN>;
+       close(IN) or die "Can't close $filename.in: $!";
+
+       $text =~ s/\$\{(\w+)\}/$c{$1}/g;
+
+       open(OUT, ">$filename") or die "Can't open $filename: $!";
+       print OUT $text;
+       close(OUT) or die "Can't close $filename: $!";
+}
+
+sub buildconfigpm {
+       unless($DDOK) {
+               print <<"END";
+
+Your system doesn't have Data::Dumper installed, so I couldn't
+build Parrot::Config.  If you want Parrot::Config installed,
+use CPAN.pm to install Data::Dumper and run this script again.
+END
+
+               return;
+       }
+
+       my %C=%c;
+       delete $C{headers};
+       my $dd=new Data::Dumper([\%C]);
+       $dd->Names(['*PConfig']);
+
+       local $/;
+       open(IN, "<Config.pm_in") or die "Can't open Config.pm_in: $!";
+       my $text=<IN>;
+       close(IN) or die "Can't close Config.pm_in: $!";
+
+       $text =~ s/#DUMPER OUTPUT HERE/$dd->Dump()/eg;
+
+       mkdir("Parrot") or ( $! =~ /File exists/i or die "Can't make
directory ./Parrot: $!");
+       open(OUT, ">Parrot/Config.pm") or die "Can't open file
Parrot/Config.pm: $!";
+       print OUT $text;
+       close(OUT) or die "Can't close file Parrot/Config.pm: $!";
+}

--- /dev/null   Wed Dec 31 16:00:00 1969
+++ Config.pm_in        Thu Sep 13 23:40:00 2001
@@ -0,0 +1,14 @@
+package Parrot::Config;
+
+use strict;
+use warnings;
+use Exporter;
+
+use vars qw(@ISA @EXPORT %PConfig);
+@ISA=qw(Exporter);
+
+@EXPORT=qw(%PConfig);
+
+#DUMPER OUTPUT HERE
+
+1;

Reply via email to