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