Currently the configure script uses the presence of a perl module
(Term::ReadLine::Gnu) and a hard coded list of platforms to decide if
ghc has Readline and Posix support.  This is fragile and often wrong.

This patch asks ghc-pkg which packages are supported and passes that
down to the script that generates config.h.

For now I'm passing the packages available to ghc on
util/config_h.pl's command line, but it probably makes more sense to
kill util/config_h.pl and move its functionality into Makefile.PL
since the new %ghc_packages hash is only easily available there.

With the following, Readline is now correctly detected on my machine.
It should work on other platforms, but I haven't tested them.

-Jim

Also, there seem to be a divergent copy of assert_ghc() in

  ext/Pugs-MakeMaker/lib/Pugs/MakeMaker.pm

which I didn't patch.

Index: Makefile.PL
===================================================================
--- Makefile.PL (revision 1312)
+++ Makefile.PL (working copy)
@@ -47,7 +47,7 @@
     my @srcfiles = grep !/MainCC/, map glob("$_/*.*hs"), @srcdirs;
 
     # turning off unused imports and deprecations for GHC6.4.
-    my ($ghc, $ghc_version, $ghc_flags) = assert_ghc();
+    my ($ghc, $ghc_version, $ghc_flags, $ghc_packages) = assert_ghc();
     my $ghc_output = "-o pugs$Config{_exe} src/Main.hs";
 
     my $pcre = "src/pcre/pcre.o";
@@ -62,7 +62,7 @@
 
     postamble(fixpaths(<< "."));
 $config_h : lib/Perl6/Pugs.pm util/config_h.pl
-       \$(PERL) util/config_h.pl
+       \$(PERL) util/config_h.pl @{[keys %$ghc_packages]}
 
 $version_h : .svn/entries util/version_h.pl
        \$(PERL) util/version_h.pl
Index: inc/Module/Install/Pugs.pm
===================================================================
--- inc/Module/Install/Pugs.pm  (revision 1312)
+++ inc/Module/Install/Pugs.pm  (working copy)
@@ -156,7 +156,13 @@
       if $ENV{PUGS_EMBED} and $ENV{PUGS_EMBED} =~ /perl5/i;
     $ghc_flags .= " -fno-warn-deprecations -fno-warn-orphans"
       if $ghc_version ge '6.4';
-    return ($ghc, $ghc_version, $ghc_flags);
+
+    my $packages = `$ghc-pkg --list-packages`;
+    $packages =~ s/^.*://g; # remove the config filename:
+    $packages =~ s/[\n\s]+//g; # simplify for the split RE
+    my %ghc_packages = map { $_ => 1 } split /,/, $packages;
+
+    return ($ghc, $ghc_version, $ghc_flags, \%ghc_packages);
 }
 
 sub fixpaths {
Index: util/config_h.pl
===================================================================
--- util/config_h.pl    (revision 1312)
+++ util/config_h.pl    (working copy)
@@ -3,7 +3,8 @@
 use warnings;
 use Cwd;
 
-my $base = shift || Cwd::cwd();
+my $base = Cwd::cwd();
+my @packages = @ARGV;
 
 open IN, "< $base/lib/Perl6/Pugs.pm" or die $!;
 open OUT, "> $base/src/pugs_config.h" or die $!;
@@ -39,30 +40,22 @@
 .
 }
 
-if ($^O =~ /MSWin32|mingw|msys/i) {
-    print OUT "#undef PUGS_HAVE_POSIX\n";
+if (grep /^unix$/, @packages) {
+    print OUT "#define PUGS_HAVE_POSIX 1\n";
 }
 else {
-    print OUT "#define PUGS_HAVE_POSIX 1\n";
+    print OUT "#undef PUGS_HAVE_POSIX\n";
 }
 
-my $has_readline = eval {
-    require Term::ReadLine;
-    require Term::ReadLine::Gnu;
-    1;
-};
-
-if ($has_readline) {
+if (grep /^readline$/, @packages) {
     print OUT "#define PUGS_HAVE_READLINE 1\n";
 }
 else {
     print OUT "#undef PUGS_HAVE_READLINE\n";
     warn << '.';
 
-*** Readline support disabled.  If you want readline support,
-    please install Term::ReadLine::Gnu from CPAN, as well as
-    the GNU Readline headers and shared library.
-
+*** Readline support disabled.  ghc does not have
+    System.Console.Readline.
 .
 }
 close OUT;

Reply via email to