/
MyBuild.pm
executable file
·70 lines (54 loc) · 1.93 KB
/
MyBuild.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package MyBuild;
use base 'Module::Build';
# Override default 'code' action
# to allow compilation of perl5i.c
sub ACTION_code {
my $self = shift;
# This has to be run first so the PL files are run to generate
# the C code for us to compile.
$self->process_PL_files;
if ( $self->is_windowsish ) {
# Writing a C wrapper is too hard on Windows
# Don't need it as there's no #! anyway
# Just do a bat file
$self->script_files("bin/perl5i.bat");
}
elsif ( $self->have_c_compiler() ) {
my $b = $self->cbuilder();
my $obj_file = $b->compile(
source => 'bin/perl5i.c',
);
my $exe_file = $b->link_executable(objects => $obj_file);
# script_files is set here as the resulting compiled
# executable name varies based on operating system
$self->script_files($exe_file);
# Cleanup files from compilation
$self->add_to_cleanup($obj_file, $exe_file);
}
else {
# No C compiler, Unix style operating system.
# Just use the Perl wrapper.
File::Copy::copy("bin/perl5i.plx", "bin/perl5i");
$self->script_files("bin/perl5i");
$self->add_to_cleanup("bin/perl5i");
}
return $self->SUPER::ACTION_code;
}
# Run perltidy over all the Perl code
# Borrowed from Test::Harness
sub ACTION_tidy {
my $self = shift;
my %found_files = map { %$_ } $self->find_pm_files,
$self->_find_file_by_type( 'pm', 't' ),
$self->_find_file_by_type( 'pm', 'inc' ),
$self->_find_file_by_type( 't', 't' ),
$self->_find_file_by_type( 'PL', '.' );
my @files = ( keys %found_files, map { $self->localize_file_path($_) } @extra );
print "Running perltidy on @{[ scalar @files ]} files...\n";
for my $file ( sort { $a cmp $b } @files ) {
print " $file\n";
system( 'perltidy', '-b', $file );
unlink("$file.bak") if $? == 0;
}
}
1;