Centralize MakeMaker customizations so they can be shared between dzil and dev-only...
[gitmo/Moose.git] / inc / MMHelper.pm
1 package MMHelper;
2
3 use strict;
4 use warnings;
5
6 use Config;
7 use Cwd qw( abs_path );
8 use File::Basename qw( dirname );
9
10 sub mm_args {
11     my $is_dev = shift;
12
13     my $ccflags = ( $Config::Config{ccflags} || '' ) . ' -I.';
14     $ccflags .= ' -Wall -Wdeclaration-after-statement'
15         if $is_dev;
16
17     my %mm = ( CCFLAGS => $ccflags );
18
19     my ( @object, %xs );
20
21     for my $xs ( glob "xs/*.xs" ) {
22         ( my $c = $xs ) =~ s/\.xs$/.c/i;
23         ( my $o = $xs ) =~ s/\.xs$/\$(OBJ_EXT)/i;
24
25         $xs{$xs} = $c;
26         push @object, $o;
27     }
28
29     for my $c ( glob "*.c" ) {
30         ( my $o = $c ) =~ s/\.c$/\$(OBJ_EXT)/i;
31         push @object, $o;
32     }
33
34     return (
35         CCFLAGS => $ccflags,
36         clean   => { FILES => join( q{ }, @object ) },
37         OBJECT => join( q{ }, @object ),
38         XS     => \%xs,
39     );
40 }
41
42 sub my_package_subs {
43     return <<'EOP';
44 {
45 package MY;
46
47 use Config;
48
49 sub const_cccmd {
50     my $ret = shift->SUPER::const_cccmd(@_);
51     return q{} unless $ret;
52
53     if ($Config{cc} =~ /^cl\b/i) {
54         warn 'you are using MSVC... my condolences.';
55         $ret .= ' /Fo$@';
56     }
57     else {
58         $ret .= ' -o $@';
59     }
60
61     return $ret;
62 }
63
64 sub postamble {
65     return <<'EOF';
66 $(OBJECT) : mop.h
67 EOF
68 }
69 }
70 EOP
71 }
72
73 1;