Changeset 21782 for Configure.PL

Show
Ignore:
Timestamp:
08/04/08 18:03:16 (5 months ago)
Author:
audreyt
Message:

* Configure.PL: Probe for GHC's -threaded flag.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • Configure.PL

    r21727 r21782  
    33use 5.006; 
    44use strict; 
     5use FindBin; 
     6BEGIN { chdir $FindBin::RealBin }; 
     7use inc::Module::Install; 
     8use lib 'inc'; 
    59use Cwd; 
    610use Config; 
    711use ExtUtils::Embed; 
     12use Carp; 
     13 
     14my ($ghc, $ghc_version, $ghc_flags, $ghc_pkg) = assert_ghc(); 
     15my $threaded = (try_compile_and_run("main :: IO ()\nmain = return ()", $ghc, "-threaded")) ? '-threaded' : ''; 
     16if ($threaded && $ENV{PUGS_NO_THREADS}) { 
     17    warn << '.'; 
     18*** Thread support disabled due to explicit request in PUGS_NO_THREADS. 
     19 
     20. 
     21    $threaded = ''; 
     22} 
    823 
    924my $embed_flags = "-I" . cwd(); 
     
    7893my $info = << "."; 
    7994executable: pugs 
    80 ghc-options: $embed_flags $ccdlflags 
     95ghc-options: $embed_flags $ccdlflags $threaded 
    8196include-dirs: @include_dirs 
    8297cc-options: @cc_options 
     
    87102print INFO $info; 
    88103close INFO; 
     104 
     105our $do_run; 
     106sub try_compile_and_run { 
     107    local $do_run = 1; 
     108    try_compile(@_); 
     109} 
     110 
     111sub try_compile { 
     112    my $code = shift; 
     113    my $temp = "pugs-tmp-$$"; 
     114    my $ghc  = shift or croak "try_compile called without path to ghc"; 
     115 
     116    eval { 
     117        open TMP, "> $temp.hs"; 
     118        print TMP $code; 
     119        close TMP; 
     120        system( 
     121            $ghc, @_, 
     122            "--make", "-v0", 
     123            -o => "$temp.exe", 
     124            "$temp.hs" 
     125        ); 
     126 
     127    }; 
     128 
     129    my $ok = -s "$temp.exe"; 
     130 
     131    if ($do_run) { 
     132        $ok = 0 unless system(Cwd::abs_path("$temp.exe")) == 0; 
     133    } 
     134 
     135    unlink("$temp.exe"); 
     136    unlink("$temp.hs"); 
     137    unlink("$temp.hi"); 
     138    unlink("$temp.o"); 
     139 
     140    return $ok; 
     141}