redirect 'make dist' and 'make install' to dzil
[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 ccflags_dyn {
11     my $is_dev = shift;
12
13     my $ccflags = q<( $Config::Config{ccflags} || '' ) . ' -I.'>;
14     $ccflags .= q< . ' -Wall -Wdeclaration-after-statement'>
15         if $is_dev;
16
17     return $ccflags;
18 }
19
20 sub ccflags_static {
21     my $is_dev = shift;
22
23     return eval(ccflags_dyn($is_dev));
24 }
25
26 sub mm_args {
27     my ( @object, %xs );
28
29     for my $xs ( glob "xs/*.xs" ) {
30         ( my $c = $xs ) =~ s/\.xs$/.c/i;
31         ( my $o = $xs ) =~ s/\.xs$/\$(OBJ_EXT)/i;
32
33         $xs{$xs} = $c;
34         push @object, $o;
35     }
36
37     for my $c ( glob "*.c" ) {
38         ( my $o = $c ) =~ s/\.c$/\$(OBJ_EXT)/i;
39         push @object, $o;
40     }
41
42     return (
43         clean   => { FILES => join( q{ }, @object ) },
44         OBJECT => join( q{ }, @object ),
45         XS     => \%xs,
46     );
47 }
48
49 sub my_package_subs {
50     return <<'EOP';
51 {
52 package MY;
53
54 use Config;
55
56 my $message;
57 BEGIN {
58 $message = <<'MESSAGE';
59
60   ********************************* ERROR ************************************
61
62   This module uses Dist::Zilla for development. This Makefile.PL will let you
63   run the tests, but should not be used for installation or building dists.
64   Building a dist should be done with 'dzil build', installation should be
65   done with 'dzil install', and releasing should be done with 'dzil release'.
66
67   ****************************************************************************
68
69 MESSAGE
70 $message =~ s/^(.*)$/\t\$(NOECHO) echo "$1";/mg;
71 }
72
73 sub const_cccmd {
74     my $ret = shift->SUPER::const_cccmd(@_);
75     return q{} unless $ret;
76
77     if ($Config{cc} =~ /^cl\b/i) {
78         warn 'you are using MSVC... my condolences.';
79         $ret .= ' /Fo$@';
80     }
81     else {
82         $ret .= ' -o $@';
83     }
84
85     return $ret;
86 }
87
88 sub postamble {
89     return <<'EOF';
90 $(OBJECT) : mop.h
91 EOF
92 }
93
94 sub install {
95     return <<EOF;
96 install:
97 $message
98         \$(NOECHO) echo "Running dzil install for you...";
99         \$(NOECHO) dzil install
100 EOF
101 }
102
103 sub dist_core {
104     return <<EOF;
105 dist:
106 $message
107         \$(NOECHO) echo "Running dzil build for you...";
108         \$(NOECHO) dzil build
109 EOF
110 }
111 EOP
112 }
113
114 1;