@@ -9,93 +9,10 @@ our $VERSION = '0.003';
9
9
use Carp ' croak' ;
10
10
use Config;
11
11
use File::Basename qw/ basename dirname/ ;
12
- use File::Spec::Functions qw/ catfile catdir splitdir/ ;
12
+ use File::Spec::Functions qw/ catfile splitdir/ ;
13
13
use Pod::Man;
14
14
15
- my $compiler = $Config {cc } eq ' cl' ? ' msvc' : ' gcc' ;
16
-
17
- sub _compiler_flags {
18
- return ($compiler eq ' gcc' ) ? [ qw/ --std=gnu++0x -ggdb3 -DDEBUG -Wall -Wshadow -Wnon-virtual-dtor -Wsign-promo -Wextra -Winvalid-pch/ ] :
19
- ($compiler eq ' msvc' ) ? [ qw{ /TP /EHsc /Wall} ] :
20
- [];
21
- }
22
-
23
- sub _get_input_files {
24
- my ($input_files , $input_dir ) = @_ ;
25
- if ($input_files ) {
26
- if (ref $input_files ) {
27
- return @{$input_files };
28
- }
29
- else {
30
- return $input_files ;
31
- }
32
- }
33
- elsif ($input_dir ) {
34
- opendir my ($dh ), $input_dir or croak " Can't open input directory '$input_dir ': $! " ;
35
- my @ret = grep { / ^ .+ \. C $ /xsm } readdir $dh ;
36
- closedir $dh ;
37
- return @ret ;
38
- }
39
- croak ' Can\' t establish source files' ;
40
- }
41
-
42
- sub _linker_flags {
43
- my ($libs , $libdirs , %options ) = @_ ;
44
- my @elements ;
45
- if ($compiler eq ' gcc' ) {
46
- push @elements , map { " -l$_ " } @{$libs };
47
- push @elements , map { " -L$_ " } @{$libdirs };
48
- if ($options {' C++' }) {
49
- push @elements , ' -lstdc++' ;
50
- }
51
- }
52
- elsif ($compiler eq ' msvc' ) {
53
- push @elements , map { " $_ .dll" } @{$libs };
54
- push @elements , map { qq{ -libpath:"$_ "} } @{$libdirs };
55
- if ($options {' C++' }) {
56
- push @elements , ' msvcprt.lib' ;
57
- }
58
- }
59
- push @elements , $options {append } if defined $options {append };
60
- return join ' ' , @elements ;
61
- }
62
-
63
- *my_system = $^O eq ' MSWin32'
64
- ? sub {
65
- my ($self , $exec , $input , $output ) = @_ ;
66
- my $call = join ' ' , @{$exec }, $input , ' >' , $output ;
67
- print " $call \n " if $self -> stash(' verbose' ) >= 0;
68
- system $call and croak " Couldn't call system(): $! " ;
69
- return ;
70
- }
71
- : sub {
72
- my ($self , $exec , $input , $output ) = @_ ;
73
- my @call = (@{$exec }, $input );
74
- print " @call > $output \n " if $self -> stash(' verbose' ) >= 0;
75
- my $pid = fork ;
76
- if ($pid ) {
77
- waitpid $pid , 0;
78
- }
79
- else {
80
- open STDOUT , ' >' , $output or croak " Can't write to file '$output ': $! " ;
81
- exec @call or croak " Couldn't exec: $! " ;
82
- }
83
- return ;
84
- };
85
-
86
15
my %build_methods = (
87
- cbuilder => sub {
88
- my $self = shift ;
89
- require ExtUtils::CBuilder;
90
- return $self -> {builder } ||= ExtUtils::CBuilder-> new(quiet => $self -> stash(' verbose' ) < 0)
91
- },
92
- create_by_system => sub {
93
- my ($self , $exec , $input , $output ) = @_ ;
94
- if (not -e $output or -M $input < -M $output ) {
95
- my_system($self , $exec , $input , $output );
96
- }
97
- return ;
98
- },
99
16
pod2man => sub {
100
17
my ($self , $source , $dest ) = @_ ;
101
18
return if -e $dest and -M $source > -M $dest ;
@@ -105,70 +22,6 @@ my %build_methods = (
105
22
$self -> {pod_parser }-> parse_from_file($source , $dest );
106
23
return ;
107
24
},
108
- build_objects => sub {
109
- my ($self , %args ) = @_ ;
110
-
111
- my $input_dir = $args {input_dir } || ' .' ;
112
- my $tempdir = $args {temp_dir } || ' _build' ;
113
- my @raw_files = _get_input_files(@args {qw/ input_files input_dir/ });
114
- my %object_for = map { (catfile($input_dir , $_ ) => catfile($tempdir , $self -> cbuilder-> object_file($_ ))) } @raw_files ;
115
- my @input_dirs = ( (defined $self -> stash(' include_dir' ) ? @{ $self -> stash(' include_dir' ) } : ()), (defined $args {include_dirs } ? @{ $args {include_dirs } } : ()));
116
-
117
- for my $source_file (sort keys %object_for ) {
118
- my $object_file = $object_for {$source_file };
119
- next if -e $object_file and -M $source_file > -M $object_file ;
120
- $self -> create_dir(dirname($object_file ));
121
- $self -> cbuilder-> compile(
122
- source => $source_file ,
123
- object_file => $object_file ,
124
- ' C++' => $args {' C++' },
125
- include_dirs => \@input_dirs ,
126
- extra_compiler_flags => $args {cc_flags } || _compiler_flags(),
127
- );
128
- }
129
- return values %object_for ;
130
- },
131
- build_library => sub {
132
- my ($self , %args ) = @_ ;
133
-
134
- my @objects = $self -> build_objects(%args );
135
-
136
- my $output_dir = $args {output_dir } || ' blib' ;
137
- my $library_file = $args {libfile } || catfile($output_dir , ' so' , ' lib' . $self -> cbuilder-> lib_file($args {name }));
138
- my $linker_flags = _linker_flags($args {libs }, $args {libdirs }, append => $args {linker_append }, ' C++' => $args {' C++' });
139
- $self -> create_dir(dirname($library_file ));
140
- $self -> cbuilder-> link (
141
- lib_file => $library_file ,
142
- objects => \@objects ,
143
- extra_linker_flags => $linker_flags ,
144
- module_name => $args {name },
145
- ) if not -e $library_file or grep { (-M $_ < -M $library_file ) } @objects ;
146
- return ;
147
- },
148
- build_executable => sub {
149
- my ($self , %args ) = @_ ;
150
-
151
- my @objects = $self -> build_objects(%args );
152
- my $linker_flags = _linker_flags($args {libs }, $args {libdirs }, append => $args {linker_append }, ' C++' => $args {' C++' });
153
- $self -> create_dir(dirname($args {output }));
154
- $self -> cbuilder-> link_executable(
155
- objects => \@objects ,
156
- exe_file => $args {output },
157
- extra_linker_flags => $linker_flags ,
158
- ' C++' => $args {' C++' },
159
- ) if not -e $args {output } or grep { (-M $_ < -M $args {output }) } @objects ;
160
- return ;
161
- },
162
- process_cpp => sub {
163
- my ($self , $input , $output ) = @_ ;
164
- $self -> create_by_system([ $Config {cpp }, split (/ / , $Config {ccflags }), ' -I' . catdir($Config {archlibexp }, ' CORE' ) ], $input , $output );
165
- return ;
166
- },
167
- process_perl => sub {
168
- my ($self , $input , $output ) = @_ ;
169
- $self -> create_by_system([ $^X, ' -T' ], $input , $output );
170
- return ;
171
- },
172
25
);
173
26
174
27
my %build_actions = (
@@ -195,12 +48,7 @@ sub mixin {
195
48
196
49
$builder -> inject_roles({ build => \%build_methods });
197
50
$builder -> register_actions(%build_actions );
198
- $builder -> register_dirty(binary => [qw/ blib _build/ ]);
199
- $builder -> register_argument(include_dir => 2);
200
- $builder -> register_paths(
201
- ' so' => (split ' ' , $Config {libpth })[0],
202
- ' headers' => $Config {usrinc },
203
- );
51
+ $builder -> register_dirty(binary => [qw/ blib/ ]);
204
52
return ;
205
53
}
206
54
0 commit comments