Move MakeMaker customizations to a module in inc that can be used for dzil and the...
[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 $root = shift;
12
13     my $ccflags = ( $Config::Config{ccflags} || '' ) . ' -I.';
14     $ccflags .= ' -Wall -Wdeclaration-after-statement';
15
16     my %mm = ( CCFLAGS => $ccflags );
17
18     my ( @object, %xs );
19
20     for my $xs ( glob "$root/xs/*.xs" ) {
21         ( my $c = $xs ) =~ s/\.xs$/.c/i;
22         ( my $o = $xs ) =~ s/\.xs$/\$(OBJ_EXT)/i;
23
24         $xs{$xs} = $c;
25         push @object, $o;
26     }
27
28     for my $c ( glob "$root/*.c" ) {
29         ( my $o = $c ) =~ s/\.c$/\$(OBJ_EXT)/i;
30         push @object, $o;
31     }
32
33     return (
34         CCFLAGS => $ccflags,
35         clean   => { FILES => join( q{ }, @object ) },
36         OBJECT => join( q{ }, @object ),
37         XS     => \%xs,
38     );
39 }
40
41 sub my_package_subs {
42     return <<'EOP';
43 package MY;
44
45 use Config;
46
47 sub const_cccmd {
48     my $ret = shift->SUPER::const_cccmd(@_);
49     return q{} unless $ret;
50
51     if ($Config{cc} =~ /^cl\b/i) {
52         warn 'you are using MSVC... my condolences.';
53         $ret .= ' /Fo$@';
54     }
55     else {
56         $ret .= ' -o $@';
57     }
58
59     return $ret;
60 }
61
62 sub postamble {
63     return <<'EOF';
64 $(OBJECT) : mop.h
65 EOF
66 }
67 EOP
68 }
69
70 1;