Perl6-Pugs

 view release on metacpan or  search on metacpan

Makefile.PL  view on Meta::CPAN

    compile_hs($ghc, 'Setup', $setup);
    compile_hs($ghc, File::Spec->catfile('util', 'ghc-pkg-wrapper'), $ghc_pkg_wrapper);
    compile_hs($ghc, File::Spec->catfile('util', 'runcompiler'), $ghc_wrapper);

    # Add GHC to PATH
    local $ENV{PATH} = dirname($ghc) . $Config{path_sep} . $ENV{PATH};

    if (not try_compile
        ( "import Control.Monad.RWS\n"
        . "main = let (x, (), ()) = runRWS (return ()) () () in return x\n"
        , $ghc, qw(-hide-all-packages -package mtl -package base)
        ),
    ) {
        # We are missing mtl somehow, likely because GHC 6.6's extra pkg is not there
        die <<'EOD';
*** Could not load the "mtl" package in your GHC installation.

    This is likely because the "extralibs" of GHC 6.6 was not built along
    with the base GHC distribution.

    To install extra libraries, extract both "-src" and "-src-extralibs"
    distributions from http://haskell.org/ghc/download_ghc_66.html in the
    same directory, then cd into ghc-6.6/ and build GHC from there.
EOD
    }

    my $native_fps;

    if (try_compile("import Data.ByteString (useAsCStringLen)\n"
            ."main :: IO ()\n"
            ."main = main\n", $ghc, qw(-hide-all-packages -package base))) {
        # We have native ByteString; dummy the fps out
        $native_fps = 1;
        copy "third-party/fps/fps.cabal.dummy" => "third-party/fps/pugs-fps.cabal";
        unlink "third-party/fps/fps.cabal"; # legacy
    } else {
        # Use bundled ByteString - unregister user-fps installed by earlier Pugs
        system($ghc_pkg, qw( --user unregister fps ));
        copy "third-party/fps/fps.cabal.in" => "third-party/fps/pugs-fps.cabal";
        unlink "third-party/fps/fps.cabal"; # legacy
    }

    $ghc = $ghc_wrapper;
    $ghc_pkg = $ghc_pkg_wrapper;

    my $heap;

    # Win32 GHC is a memory hog.  We need to provide it with a memory sty.
    # We still use the option from config.yml if available.

    # XXX - This is no longer needed for GHC 6.6!
    if ($Config{osname} eq 'cygwin' or $Config{osname} eq 'MSWin32') {
        $heap = WIN32_GHC_HEAPSIZE;
    }

    $heap = PugsBuild::Config->lookup('ghc_heap_size') || $heap;
    $ghc_flags .= " +RTS -M$heap -RTS" if $heap;
    # $ghc_flags .= ' -dcore-lint';
    # $ghc_flags .= " -keep-tmp-files";

    if ($ENV{PUGS_EMBED} and $ENV{PUGS_EMBED} =~ /\bhaskell\b/i) {
        if (has_ghc_package('plugins')
            and  try_compile("import System.Eval\n"
                            ."main :: IO ()\n"
                            .'main = (eval_ "return ()" [] [] [] [] :: IO (Either [String] (Maybe ()))) >> return ()', $ghc, '-package', 'plugins')) {
            $ghc_flags .= ' -package plugins -DPUGS_HAVE_HSPLUGINS ';
        }
        else {
            push @warn, << '.';
*** Inline Haskell support disabled.  If you want dynamic loading
    of haskell modules, please install the hs-plugins library:
        http://www.cse.unsw.edu.au/~dons/hs-plugins/
    Remember to "make register" after "make install" for hs-plugins!

.
        }
    }

    if (has_ghc_package('readline') 
        and  try_compile("import System.Console.Readline\n"
                        ."main :: IO ()\n"
                        ."main = do\n"
                        ."  setCatchSignals False\n"
                        ."  setCatchSigwinch False\n"
                        .'  _ <- readline "" '."\n"
                        .'  return ()', $ghc)) {
      $ghc_flags .= ' -DPUGS_HAVE_READLINE '; # -package readline';
    }
    else {
      push @warn, << '.';
*** Readline support disabled.  If you want readline support,
    please install the GNU readline library.

.
    }

    my $ghc_output = ''; # "-o pugs$Config{_exe} src/Main.hs";
    my $hasktags = $ENV{HASKTAGS} || 'hasktags';

    # map a bunch of .c files to a bunch of expected .o files
    my $o = sub { map { substr($_, 0, -1) . 'o' } @_ };

    my $pcre_c    = "src/pcre/pcre.c";
    my ($pcre)    = $o->($pcre_c);

    my @prereqs = ($pcre);
    my @derived_srcfiles = qw< src/Pugs/Embed/Parrot.hs src/Pugs/pugs_config.h src/Pugs/pugs_version.h src/Pugs/Config.hs src/Pugs/Prelude.hs src/Pugs/CodeGen/PIR/Prelude.hs >;

    my $embed_flags = "";
    my $hsc2hs_flags = "";
    my $ccdlflags = "";

    # [-!]perl5 does not work with the \bFLAG\b convention used in this file.
    # It should be removed, or the convention, and code, fixed.
    # Went in 2006-08-30.  Depreciated 2006-09-11.
    if ($ENV{PUGS_EMBED} and $ENV{PUGS_EMBED} =~ /[-!]perl5\b/i) {
        push @warn,  << '.';
*** PUGS_EMBED flags "-perl5" and "!perl5" are depreciated and buggy.
    Please use "noperl5" instead.

.
    }
    if (!$ENV{PUGS_EMBED} or $ENV{PUGS_EMBED} !~ /(?:[-!]|\bno)perl5\b/i) {
        $ENV{PUGS_EMBED} .= " perl5 ";
        #push @prereqs, "src/perl5/p5embed.o"; # XXX
        # $ghc_output .= " src/perl5/p5embed.o ";
        $embed_flags .= " -DPUGS_HAVE_PERL5 -isrc/perl5 ";
        my $flags = "$Config{ccflags} $Config{ccdlflags} ";
        if ($flags =~ /\S/) {
            $flags =~ s{([\\"'])}{\\$1}g;
            my @flags = grep { length $_ } split /\s+/, $flags;
            if ($^O eq 'MSWin32') {
                if ($Config{libperl} =~ /lib(\w+)\.a/) {
                    $embed_flags .= " -optl-l$1 ";
                }
                elsif (defined &Win32::BuildNumber) {
                    # We are on ActivePerl -- Kluge massively!

                    no warnings 'once';
                    our %MY_CONFIG = %Config;
                    *Config = *MY_CONFIG;
                    *Config::Config = *MY_CONFIG;
                    *ExtUtils::MM_Win32::Config = *MY_CONFIG;
                    *ExtUtils::MM_Unix::Config = *MY_CONFIG;

                    $Config{ccflags} =~ s/-libpath:"?(.*?)"? //g;
                    $Config{ccdlflags} =~ s/-libpath:"?(.*?)"? //g;
                    $Config{lddlflags} =~ s/-libpath:"?(.*?)"? //g;
                    $Config{ldflags} =~ s/-libpath:"?(.*?)"? //g or die "ldflags: $Config{ldflags} does not contain -libpath:";

                    my $lib = "$1/$Config{libperl}";
                    $embed_flags .= " -optl\"$lib\" ";

                    $flags = "$Config{ccflags} $Config{ccdlflags}";
                    $flags =~ s{([\\"'])}{\\$1}g;
                    @flags = grep { length $_ } split /\s+/, $flags;
                }
                else {
                    warn "Unrecognized libperl shared library: $Config{libperl}, proceeding anyway...\n";
                }

                $ccdlflags .= (/^-[DIL]/ ? ' -optc' : ' -optl') . qq["$_" ] for @flags;
                $embed_flags .= " -optc-Ddirent=DIRENT";
            }
            else {
                $embed_flags .= " -optc$_" for grep length, split(/\s+/, ccopts());
                $embed_flags .= " -optl$_" for grep length, split(/\s+/, ldopts());

            }

            $embed_flags .= " $_" for grep { /-[DIL]/ } split(/\s+/, ccopts());
            $embed_flags .= " $_" for grep { /-[DIL]/ } split(/\s+/, ldopts());

            if ($Config{osname} eq 'cygwin') {
                my $cygpath = sub {
                    my $path = `cygpath @_`;
                    chomp $path;
                    $path =~ s{\\}{/}g;
                    return $path;
                };
                $embed_flags =~ s{(/usr/\S+)}{$cygpath->($1)}eg;
                $embed_flags =~ s{/cygdrive/(\w)/}{$1:/}g;
                #warn "** Cygwin embedding flags: embed_flags\n";
            }
        }
    }
    else {
        push @warn, << '.';
*** Perl 5 embedding disabled.  If you want Perl 5 support, please set the
    PUGS_EMBED environment variable to not contain "noperl5".

.
    }
    
    if ($ENV{PUGS_EMBED} and $ENV{PUGS_EMBED} =~ /\bparrot\b/i and $Config{cc} eq 'cl') {
        push @warn, << '.';
*** Parrot linking not supported with MSVC.  Parrot linking will be disabled.

.
        $ENV{PUGS_EMBED} =~ s/\bparrot\b//g;
    }

    # Respect CC setting
    my $cc = $ENV{CC} || 'gcc';
    $ghc_flags .= " -pgmc $cc " unless $cc eq 'gcc';

    if ($Config{cf_by} eq 'Debian Project' and $ENV{PUGS_EMBED} and $ENV{PUGS_EMBED} =~ /\bperl5\b/i) {
        # Is it safe to remove 'Debian Project' above, to test on all platforms?
        my $need_path = 1;
        my $libperlpath = '';
        my $libperl = $Config{libperl};
        foreach my $path (split(/\s/, $Config{libpth} . ' ' . $Config{libsdirs})) {
            if (-e "$path/libperl.so") {
                $need_path = 0;
                last;
            } elsif (-e "$path/$libperl") {
                $libperlpath ||= $path;
            }
        }
        if ($need_path) {
            my $message = '';
            $message .= qq[        * Symlink $libperlpath/$libperl to libperl.so\n] if ($libperlpath and $libperl);
            $message .= qq[        * Install libperl-dev package\n] if ($Config{cf_by} eq 'Debian Project');
            die <<EOD;
*** Could not find libperl.so in: $Config{libpth} $Config{libsdirs}
    Solutions include:
        * Add noperl5 to PUGS_EMBED
$message
EOD
        }
    }

    if ($ENV{PUGS_EMBED} and $ENV{PUGS_EMBED} =~ /\bparrot\b/i) {
        my $base = $ENV{PARROT_PATH};
        my $parrot_config = which('parrot-config.imc') || which('parrot-config.pir') || which('parrot-config') || '';
        if (!$base && -e $parrot_config) {
            $base = (File::Spec->splitpath($parrot_config))[1];
        }
        if (!$base) {
            $parrot_config = which('parrot-config') || '';
            $base = (File::Spec->splitpath($parrot_config))[1] if -e $parrot_config;
        }
        if (!$base and -d File::Spec->catdir(File::Spec->updir, 'parrot')) {
            $base = abs_path(File::Spec->catdir(File::Spec->updir, 'parrot'));
        }
        if (!$base and -d File::Spec->catdir(File::Spec->updir, 'parrot-trunk')) {
            $base = abs_path(File::Spec->catdir(File::Spec->updir, 'parrot-trunk'));
        }

        my $temp = File::Spec->catfile($base, 'parrot-config.imc');
        if (!$parrot_config && -e $temp) {
          $parrot_config = $temp;
        }
        
        $temp = File::Spec->catfile($base, 'parrot-config.pir');
        if (!$parrot_config && -e $temp) {
          $parrot_config = $temp;
        }
        
        $temp = File::Spec->catfile($base, 'parrot-config');
        if (!$parrot_config && -e $temp) {
          $parrot_config = $temp;
        }

        $base =~ s/bin\/*$//;
        
        (-d $base and -e $parrot_config)
            or die "*** Please set \$ENV{PARROT_PATH} to the base path with a built parrot tree.\n";
        my $ldflags = parrot_config($base, $parrot_config, 'ldflags');
        my $libs = parrot_config($base, $parrot_config, 'libs');
        my $icuflags = parrot_config($base, $parrot_config, 'icu_shared');
        my $include_path = parrot_config($base, $parrot_config, 'prefix') . parrot_config($base, $parrot_config, 'inc');
        my $rpath_blib = parrot_config($base, $parrot_config, 'rpath_blib');
        my $build_dir = parrot_config($base, $parrot_config, 'top_builddir', 'build_dir');
        my $is_shared = parrot_config($base, $parrot_config, 'parrot_is_shared');
        my $parrot_libdir = parrot_config($base, $parrot_config, 'lib_dir');

        # Convert flags to -optc-*,etc, to pass through ghc. c/ompiler l/inker
        $ldflags =~ s/(^|\s)-/$1-optl-/g;
        $libs =~ s/(^|\s)-/$1-optl-/g;
        $icuflags =~ s/(^|\s)-/$1-optl-/g;
        $include_path =~ s/(^|\s)-/$1-optc-/g;
        $embed_flags .= " -I$include_path" if $include_path =~ /\S/;
        $rpath_blib =~ s/(^|\s)-/$1-optl-/g;

        $embed_flags .= " -I$base/include -L$base/lib -L$base/blib/lib -DPUGS_HAVE_PARROT -L/usr/local/lib $ldflags ";
        $embed_flags .= " -lparrot $libs $icuflags ";
        my $config = $parrot_libdir."/parrot/config/install_config$Config{_o}";
        $config = $parrot_libdir."/parrot/config/parrot_config$Config{_o}" unless -e $config;
        $config = $parrot_libdir."/parrot/config/null_config$Config{_o}" unless -e $config;
        $config = "$build_dir/src/install_config$Config{_o}" unless -e $config;
        $config = "$build_dir/src/parrot_config$Config{_o}" unless -e $config;
        $config = "$build_dir/src/null_config$Config{_o}" unless -e $config;

        die <<"EOD" unless -e $config or $is_shared; 
*** Could not find src/null_config.o in $build_dir.
    Solutions include:
        * Remove parrot from PUGS_EMBED
        * Place a built Parrot source tree under $build_dir.
EOD

        $embed_flags .= " $config ";
        $embed_flags .= " $rpath_blib " if -d $build_dir;

        # parrot include paths for hsc2hs
        $hsc2hs_flags .= " -DPUGS_HAVE_PARROT -I$base/include ";

        push @warn, << ".";
*** Embedded 'parrot' enabled.  You can use it for Perl 6 regex support by
    setting the PUGS_REGEX_ENGINE environment variable to "PGE" at runtime.
.
    }
    else {
        my $whichparrot = can_run('parrot');

        if ($whichparrot) {
            push @warn, << ".";
*** External 'parrot' executable found in your PATH at:

        $whichparrot

    You can use it for Perl 6 regex support by setting the
    PUGS_REGEX_ENGINE environment variable to "PGE" at runtime.

    If you want to link against Parrot, set the PUGS_EMBED environment
    variable to contain 'parrot', the PARROT_PATH environment variable to
    the path of a built parrot tree, then run Makefile.PL again.

.
        }
    }

    my $config = get_pugs_config();
    my $is_win32 = ($^O =~ /MSWin|mingw|cygwin/i);
    my $threaded = (try_compile_and_run("main :: IO ()\nmain = return ()", $ghc, "-threaded")) ? '-threaded' : '';

    if ($threaded and $ENV{PUGS_EMBED} and $ENV{PUGS_EMBED} =~ /\bperl5\b/ and !$Config{usethreads}) {
        push @warn, << '.';
*** Thread support disabled because you are building with embedded perl5 and
    your perl5 is not threaded.

.

        $threaded = '';
    }
    if ($threaded && $ENV{PUGS_NO_THREADS}) {
        push @warn, << '.';
*** Thread support disabled due to explicit request in PUGS_NO_THREADS.

.
        $threaded = '';
    }

    # As of now, Test::TAP::HTMLMatrix is the key dependency for smokes,
    # so we need only check for that.
    eval { require Test::TAP::HTMLMatrix } or push @warn, << '.';
*** You do not appear to have a Smoke Kit installed. You can still build
    Pugs and even run `make test', but you won't be able to run the more
    modern `make smoke' target to produce nice graphs and send them to the
    public smoke server. Installing Task::Smoke from CPAN will bring in
    the necessary dependencies.

.
    # XXX - hsplugins doesn't build with profiles
    my $profiled_flags = $ghc_flags;
    $profiled_flags =~ s{-DPUGS_HAVE_HSPLUGINS}{};
    $profiled_flags =~ s{-package plugins}{};

    my $emit = sub {
        my $o = shift;
        my $c = substr($o, 0, -1) . 'c';
        return "$o : $c\n\t$ghc $threaded $embed_flags $ghc_flags -no-link -no-hs-main -O -o $o $c\n";
    };

    mkdir 'dist';
    mkdir 'dist/build';
    mkdir 'dist/build/src';

    # Using the Win32 Haskell compiler results in a setup program that
    # doesn't grok cygwin paths.  This kludge takes any /cygdrive/
    # style paths and rewrites them.  This really should be factored
    # out to a common module.  Better still, we should make a Cygwin-native
    # GHC.

    if ($Config{osname} eq 'cygwin') {

        # NB.  We're exploiting for's aliasing of variables.
        foreach my $path ($ghc_pkg, $hsc2hs, $ghc) {
            $path =~ s{^/cygdrive/(\w)/}{$1:/};
        }
    }

    my $setup_flags = "--prefix=\$(DESTDIR) --with-hc-pkg=$ghc_pkg --with-hsc2hs=$hsc2hs --ghc --with-compiler=$ghc";

    my $svn_entries = '';

    if (-d '.svn') {



( run in 0.595 second using v1.01-cache-2.11-cpan-71847e10f99 )