Implement a XS constructor generator
[gitmo/Class-MOP.git] / Makefile.PL
1 use strict;
2 use warnings;
3 use inc::Module::Install;
4 use 5.008001;
5
6 check_conflicts();
7
8 name 'Class-MOP';
9 perl_version '5.008001';
10 all_from 'lib/Class/MOP.pm';
11 license 'perl';
12
13 require Config;
14 my $ccflags = ( $Config::Config{ccflags} || '' ) . ' -I.';
15 $ccflags .= ' -Wall' if -d '.svn' || -d '.git' || $ENV{MAINTAINER_MODE};
16
17 requires 'Carp';
18 requires 'Devel::GlobalDestruction';
19 requires 'MRO::Compat'  => '0.05';
20 requires 'Scalar::Util' => '1.18';
21 requires 'Sub::Name'    => '0.04';
22 requires 'Task::Weaken';
23
24 test_requires 'File::Spec';
25 test_requires 'Test::More'      => '0.88';
26 test_requires 'Test::Exception' => '0.27';
27
28 install_headers('mop.h'); # need Module::Install::XSUtil
29
30 #extra_tests();
31
32 makemaker_args( CCFLAGS => $ccflags );
33
34 {
35     my (@clean, @OBJECT, %XS);
36
37     for my $xs (<xs/*.xs>) {
38         (my $c = $xs) =~ s/\.xs$/.c/i;
39         (my $o = $xs) =~ s/\.xs$/\$(OBJ_EXT)/i;
40
41         $XS{$xs} = $c;
42         push @OBJECT, $o;
43         push @clean, $o;
44     }
45
46     for my $c (<*.c>) {
47         (my $o = $c) =~ s/\.c$/\$(OBJ_EXT)/i;
48         push @OBJECT, $o;
49         push @clean, $o;
50     }
51
52     makemaker_args(
53         clean  => { FILES => join(q{ }, @clean) },
54         OBJECT => join (q{ }, @OBJECT),
55         XS     => \%XS,
56     );
57 }
58
59 postamble(<<'EOM');
60 $(OBJECT) : mop.h
61 EOM
62
63 WriteAll();
64
65 # Use the cpan-smolder-stable script in the Moose svn root to figure
66 # out what on CPAN will break with the latest Moose, then update this
67 # before a release.
68 sub check_conflicts {
69     my %conflicts = (
70         'Moose' => '0.85',
71     );
72
73     my $has_module_info = eval{ require Module::Info };
74     my $get_version     = $has_module_info
75         ? sub{ Module::Info->new_from_module($_[0])->version }
76         : sub{ eval qq{ require $_[0] } ? $_[0]->VERSION : undef };
77
78     my $found = 0;
79     for my $mod ( sort keys %conflicts ) {
80         my $installed = $get_version->($mod);
81
82         if ( defined($installed) && $installed le $conflicts{$mod} ) {
83
84             print <<"EOF";
85
86 ***
87     This version of Class::MOP conflicts with the version of
88     $mod ($installed) you have installed.
89
90     You will need to upgrade $mod after installing
91     this version of Class::MOP.
92 ***
93
94 EOF
95
96             $found = 1;
97         }
98     }
99
100     return unless $found;
101
102     # More or less copied from Module::Build
103     return if $ENV{PERL_MM_USE_DEFAULT};
104     return unless -t STDIN && ( -t STDOUT || !( -f STDOUT || -c STDOUT ) );
105
106     sleep 4;
107 }
108
109 package MY;
110
111 use Config;
112
113 sub const_cccmd {
114     my $ret = shift->SUPER::const_cccmd(@_);
115     return q{} unless $ret;
116
117     if ($Config{cc} =~ /^cl\b/i) {
118         warn 'you are using MSVC... my condolences.';
119         $ret .= ' /Fo$@';
120     }
121     else {
122         $ret .= ' -o $@';
123     }
124
125     return $ret;
126 }