[t/spec] Minor improvements to the series tests.
[pugs.git] / util / config_h.pl
blob09ddedf4ffe4b34d6ea17e4db70d55719bdf567c
1 #!/usr/bin/perl -w
2 use strict;
3 use warnings;
4 use Cwd;
5 use File::Spec;
6 use File::Temp qw(tempdir);
8 =pod
10 =head1 DOCUMENTATION
12 This file seems to determine some configuration.
14 util/config_h.pl GHC BASEDIR
16 GHC - Location and flags of the ghc executable
17 (defaults to 'ghc')
18 BASEDIR - Base directory of the Pugs installation
19 (defaults to current directory)
21 =cut
23 my ($ghc_line, $base) = @ARGV or exit;
25 $ghc_line ||= $ENV{GHC} || 'ghc';
26 $base ||= Cwd::cwd();
28 my ($ghc, @ghc_args) = split /\s+/, $ghc_line;
30 open IN, "< $base/lib/Perl6/Pugs.pm" or die $!;
31 open OUT, "> $base/src/Pugs/pugs_config.h" or die $!;
33 while (<IN>) {
34 /version (\S+) .*\breleased (.*)\./ or next;
35 print OUT << ".";
37 #ifdef PUGS_VERSION
38 #undef PUGS_VERSION
39 #endif
40 #define PUGS_VERSION "$1"
42 #ifdef PUGS_DATE
43 #undef PUGS_DATE
44 #endif
45 #define PUGS_DATE "$2"
48 last;
51 # FIXME: we assume if you have cywin, you're still using ghc-msys
52 if ($^O =~ /MSWin32|mingw|msys|cygwin/i) {
53 print OUT "#undef PUGS_HAVE_POSIX\n";
55 else {
56 print OUT "#define PUGS_HAVE_POSIX 1\n";
59 my $has_readline = try_compile(<< '.');
60 import System.Console.Readline
61 main :: IO ()
62 main = readline "" >> return ()
66 my $has_th = try_compile(<< '.');
67 {-# OPTIONS_GHC -fth #-}
68 main :: (Monad m) => m ()
69 main = $([| return () |])
72 if ($has_th) {
73 print OUT "#define PUGS_HAVE_TH 1\n";
75 else {
76 print OUT "#undef PUGS_HAVE_TH\n";
77 warn << '.';
79 *** Template Haskell compiler backends disabled. If you want
80 Template Haskell support, please compile your GHC with the
81 GHCi option.
86 close OUT;
88 sub try_compile {
89 my $code = shift;
90 my $temp = "pugs-tmp-$$";
92 eval {
93 open TMP, "> $temp.hs";
94 print TMP $code;
95 close TMP;
96 system(
97 $ghc, @ghc_args,
98 "--make", "-v0",
99 -o => "$temp.exe",
100 "$temp.hs"
105 my $ok = -s "$temp.exe";
107 unlink("$temp.exe");
108 unlink("$temp.hs");
109 unlink("$temp.hi");
110 unlink("$temp.o");
112 return $ok;