6 BEGIN { chdir $FindBin::RealBin
};
7 use inc
::Module
::Install
;
14 my ($ghc, $ghc_version, $ghc_flags, $ghc_pkg) = assert_ghc
();
15 my $threaded = (try_compile_and_run
("main :: IO ()\nmain = return ()", $ghc, "-threaded")) ?
'-threaded' : '';
16 if ($threaded && $ENV{PUGS_NO_THREADS
}) {
18 *** Thread support disabled due to explicit request
in PUGS_NO_THREADS
.
24 my $embed_flags = "-I" . cwd
();
26 my $flags = "$Config{ccflags} $Config{ccdlflags} ";
29 $flags =~ s{([\\"'])}{\\$1}g;
30 my @flags = grep { length $_ } split /\s+/, $flags;
32 if ($^O
eq 'MSWin32') {
33 if ($Config{libperl
} =~ /lib(\w+)\.a/) {
34 $embed_flags .= " -optl-l$1 ";
36 elsif (defined &Win32
::BuildNumber
) {
37 # We are on ActivePerl -- Kluge massively!
40 our %MY_CONFIG = %Config;
42 *Config
::Config
= *MY_CONFIG
;
43 *ExtUtils
::MM_Win32
::Config
= *MY_CONFIG
;
44 *ExtUtils
::MM_Unix
::Config
= *MY_CONFIG
;
46 $Config{ccflags
} =~ s/-libpath:"?(.*?)"? //g;
47 $Config{ccdlflags
} =~ s/-libpath:"?(.*?)"? //g;
48 $Config{lddlflags
} =~ s/-libpath:"?(.*?)"? //g;
49 $Config{ldflags
} =~ s/-libpath:"?(.*?)"? //g
50 or die "ldflags: $Config{ldflags} does not contain -libpath:";
52 my $lib = "$1/$Config{libperl}";
53 $embed_flags .= " -optl\"$lib\" ";
55 $flags = "$Config{ccflags} $Config{ccdlflags}";
56 $flags =~ s{([\\"'])}{\\$1}g;
57 @flags = grep { length $_ } split /\s+/, $flags;
60 warn "Unrecognized libperl shared library: $Config{libperl}, proceeding anyway...\n";
63 $ccdlflags .= (/^-[DIL]/ ?
' -optc' : ' -optl') . qq["$_" ] for @flags;
64 $embed_flags .= " -optc-Ddirent=DIRENT";
67 $embed_flags .= " -optc$_" for grep length, split(/\s+/, ccopts
());
68 $embed_flags .= " -optl$_" for grep length, split(/\s+/, ldopts
());
71 $embed_flags .= " $_" for grep { /-[DIL]/ } split(/\s+/, ccopts
());
72 $embed_flags .= " $_" for grep { /-[DIL]/ } split(/\s+/, ldopts
());
74 if ($Config{osname
} eq 'cygwin') {
76 my $path = `cygpath -m @_`;
80 $embed_flags =~ s{(/usr/\S+)}{$cygpath->($1)}eg;
81 $embed_flags =~ s{/cygdrive/(\w)/}{$1:/}g;
82 #warn "** Cygwin embedding flags: embed_flags\n";
86 my @include_dirs = split(/\s+/, perl_inc
());
87 s/^-I// for @include_dirs;
89 my @cc_options = map { /^-optc(.+)/ ?
$1 : () } (split(/\s+/, $embed_flags), split(/\s+/, $ccdlflags));
90 my @ld_options = grep { not /,/ } map { /^-optl(.+)/ ?
$1 : () } (split(/\s+/, $embed_flags), split(/\s+/, $ccdlflags));
92 open INFO
, ">Pugs.buildinfo" or die "Cannot write build info: $!";
95 ghc
-options
: $embed_flags $ccdlflags $threaded
96 include
-dirs
: @include_dirs
97 cc
-options
: @cc_options
98 ld
-options
: @ld_options
100 $info =~ s/-arch\s+\w+\s*//g;
101 $info =~ s/-opt[lc]-arch\s+-opt[lc]\w+\s*//g;
106 sub try_compile_and_run
{
113 my $temp = "pugs-tmp-$$";
114 my $ghc = shift or croak
"try_compile called without path to ghc";
117 open TMP
, "> $temp.hs";
129 my $ok = -s
"$temp.exe";
132 $ok = 0 unless system(Cwd
::abs_path
("$temp.exe")) == 0;