Commit | Line | Data |
3a42a9c3 |
1 | use strict; |
9aaf3646 |
2 | use warnings; |
3 | |
8801e4f5 |
4 | require 5.006000; |
3a42a9c3 |
5 | |
6 | use ExtUtils::MakeMaker; |
9aaf3646 |
7 | BEGIN { if ( $^O eq 'cygwin' ) { |
8 | require ExtUtils::MM_Cygwin; |
9 | require ExtUtils::MM_Win32; |
10 | if ( ! defined(&ExtUtils::MM_Cygwin::maybe_command) ) { |
11 | *ExtUtils::MM_Cygwin::maybe_command = sub { |
12 | my ($self, $file) = @_; |
13 | if ($file =~ m{^/cygdrive/}i and ExtUtils::MM_Win32->can('maybe_command')) { |
14 | ExtUtils::MM_Win32->maybe_command($file); |
15 | } else { |
16 | ExtUtils::MM_Unix->maybe_command($file); |
17 | } |
18 | } |
19 | } |
20 | }} |
21 | |
22 | my $mymeta_works = eval { ExtUtils::MakeMaker->VERSION('6.5707'); 1 }; |
23 | my $mymeta = $mymeta_works || eval { ExtUtils::MakeMaker->VERSION('6.5702'); 1 }; |
24 | |
25 | my %META_BITS = ( |
26 | ); |
27 | my %RUN_DEPS = ( |
28 | 'Sub::Exporter' => 0, |
29 | ); |
3a42a9c3 |
30 | |
9aaf3646 |
31 | my %WriteMakefileArgs = ( |
32 | NAME => 'Devel::GlobalDestruction', |
33 | VERSION_FROM => 'lib/Devel/GlobalDestruction.pm', |
34 | LICENSE => 'perl', |
35 | INSTALLDIRS => 'site', |
36 | PL_FILES => { }, |
37 | MIN_PERL_VERSION => '5.006000', |
38 | PREREQ_PM => \%RUN_DEPS, |
39 | CONFIGURE_REQUIRES => { 'ExtUtils::CBuilder' => 0.27 }, |
40 | META_ADD => { |
41 | resources => { |
0e762ade |
42 | homepage => 'http://search.cpan.org/dist/Devel-GlobalDestruction', |
43 | repository => 'git://git.shadowcat.co.uk/p5sagit/Devel-GlobalDestruction.git', |
44 | bugtracker => 'http://rt.cpan.org/Public/Dist/Display.html?Name=Devel-GlobalDestruction', |
3790e928 |
45 | }, |
9aaf3646 |
46 | requires => \%RUN_DEPS, |
47 | }, |
48 | ($mymeta and !$mymeta_works) ? ( 'NO_MYMETA' => 1 ) : (), |
49 | ( (defined ${^GLOBAL_PHASE} or !can_xs() ) |
50 | ? (XS => {}, C => []) |
51 | : () |
52 | ), |
3a42a9c3 |
53 | ); |
54 | |
9aaf3646 |
55 | unless ( eval { ExtUtils::MakeMaker->VERSION('6.56') } ) { |
56 | my $br = delete $WriteMakefileArgs{BUILD_REQUIRES}; |
57 | my $pp = $WriteMakefileArgs{PREREQ_PM}; |
58 | for my $mod ( keys %$br ) { |
59 | if ( exists $pp->{$mod} ) { |
60 | $pp->{$mod} = $br->{$mod} if $br->{$mod} > $pp->{$mod}; |
61 | } |
62 | else { |
63 | $pp->{$mod} = $br->{$mod}; |
64 | } |
65 | } |
66 | } |
67 | |
68 | delete $WriteMakefileArgs{CONFIGURE_REQUIRES} |
69 | unless eval { ExtUtils::MakeMaker->VERSION('6.52') }; |
70 | |
71 | WriteMakefile(%WriteMakefileArgs); |
72 | |
73 | # can we locate a (the) C compiler |
74 | sub can_cc { |
75 | my @chunks = split(/ /, $Config::Config{cc}) or return; |
76 | |
77 | # $Config{cc} may contain args; try to find out the program part |
78 | while (@chunks) { |
79 | return can_run("@chunks") || (pop(@chunks), next); |
80 | } |
81 | |
82 | return; |
83 | } |
84 | |
85 | # check if we can run some command |
86 | sub can_run { |
87 | my ($cmd) = @_; |
88 | |
89 | return $cmd if -x $cmd; |
90 | if (my $found_cmd = MM->maybe_command($cmd)) { |
91 | return $found_cmd; |
92 | } |
93 | |
94 | require File::Spec; |
95 | for my $dir ((split /$Config::Config{path_sep}/, $ENV{PATH}), '.') { |
96 | next if $dir eq ''; |
97 | my $abs = File::Spec->catfile($dir, $cmd); |
98 | return $abs if (-x $abs or $abs = MM->maybe_command($abs)); |
99 | } |
100 | |
101 | return; |
102 | } |
103 | |
104 | # Can our C compiler environment build XS files |
105 | sub can_xs { |
106 | # Do we have the configure_requires checker? |
107 | local $@; |
108 | eval "require ExtUtils::CBuilder; ExtUtils::CBuilder->VERSION(0.27)"; |
109 | if ( $@ ) { |
110 | # They don't obey configure_requires, so it is |
111 | # someone old and delicate. Try to avoid hurting |
112 | # them by falling back to an older simpler test. |
113 | return can_cc(); |
114 | } |
115 | |
116 | # Do we have a working C compiler |
117 | my $builder = ExtUtils::CBuilder->new( |
118 | quiet => 1, |
119 | ); |
120 | unless ( $builder->have_compiler ) { |
121 | # No working C compiler |
122 | return 0; |
123 | } |
124 | |
125 | # Write a C file representative of what XS becomes |
126 | require File::Temp; |
127 | my ( $FH, $tmpfile ) = File::Temp::tempfile( |
128 | "compilexs-XXXXX", |
129 | SUFFIX => '.c', |
130 | ); |
131 | binmode $FH; |
132 | print $FH <<'END_C'; |
133 | #include "EXTERN.h" |
134 | #include "perl.h" |
135 | #include "XSUB.h" |
136 | |
137 | int main(int argc, char **argv) { |
138 | return 0; |
139 | } |
140 | |
141 | int boot_sanexs() { |
142 | return 1; |
143 | } |
144 | |
145 | END_C |
146 | close $FH; |
147 | |
148 | # Can the C compiler access the same headers XS does |
149 | my @libs = (); |
150 | my $object = undef; |
151 | eval { |
152 | local $^W = 0; |
153 | $object = $builder->compile( |
154 | source => $tmpfile, |
155 | ); |
156 | @libs = $builder->link( |
157 | objects => $object, |
158 | module_name => 'sanexs', |
159 | ); |
160 | }; |
161 | my $result = $@ ? 0 : 1; |
162 | |
163 | # Clean up all the build files |
164 | foreach ( $tmpfile, $object, @libs ) { |
165 | next unless defined $_; |
166 | 1 while unlink; |
167 | } |
168 | |
169 | return $result; |
170 | } |