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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
|
package ExtUtils::Builder::Compiler;
$ExtUtils::Builder::Compiler::VERSION = '0.035';
use strict;
use warnings;
use ExtUtils::Builder::Util qw/command require_module/;
use ExtUtils::Builder::Node;
use parent qw/ExtUtils::Builder::ArgumentCollector ExtUtils::Builder::Binary/;
sub new {
my ($class, %args) = @_;
my $cc = $args{cc};
$cc = [ $cc ] if not ref $cc;
my $self = bless {
cc => $cc,
include_dirs => [],
defines => [],
standard => $args{standard},
}, $class;
$self->_init(%args);
return $self;
}
sub _init {
my ($self, %args) = @_;
$self->ExtUtils::Builder::ArgumentCollector::_init(%args);
$self->ExtUtils::Builder::Binary::_init(%args);
return;
}
sub compile_flags;
sub cc {
my $self = shift;
return @{ $self->{cc} };
}
sub add_include_dirs {
my ($self, $dirs, %opts) = @_;
my $ranking = $self->fix_ranking($self->default_include_ranking, $opts{ranking});
push @{ $self->{include_dirs} }, map { { ranking => $ranking, value => $_ } } @{ $dirs };
return;
}
sub default_include_ranking {
return 30;
}
sub add_defines {
my ($self, $defines, %opts) = @_;
my $ranking = $self->fix_ranking($self->default_define_ranking, $opts{ranking});
push @{ $self->{defines} }, map { { key => $_, ranking => $ranking, value => $defines->{$_} } } keys %{ $defines };
return;
}
sub add_profile {
my ($self, $profile, %args) = @_;
if (not ref($profile)) {
$profile =~ s/ \A @ /ExtUtils::Builder::Profile::/xms;
require_module($profile);
}
return $profile->process_compiler($self, \%args);
}
sub default_define_ranking {
return 40;
}
sub set_standard {
my ($self, $version) = @_;
$self->{standard} = $version;
return;
}
sub collect_arguments {
my ($self, @args) = @_;
return ($self->SUPER::collect_arguments, $self->compile_flags(@args));
}
sub compile {
my ($self, $from, $to, %opts) = @_;
my @actions ;
push @actions, $self->_mkdir_for($to) if $opts{mkdir};
my @argv = $self->arguments($from, $to, %opts);
push @actions, command($self->cc, @argv);
my $deps = [ $from, @{ $opts{dependencies} // [] } ];
return ExtUtils::Builder::Node->new(target => $to, dependencies => $deps, actions => \@actions);
}
1;
# ABSTRACT: An interface around different compilers.
__END__
=pod
=encoding UTF-8
=head1 NAME
ExtUtils::Builder::Compiler - An interface around different compilers.
=head1 VERSION
version 0.035
=head1 DESCRIPTION
This is an interface wrapping around different compilers. It's usually not used directly but by a portability layer like L<ExtUtils::Builder::Autodetect::C>.
=head1 METHODS
=head2 add_include_dirs($dirs, %options)
Add dirs the the include list.
=head2 add_defines($defines, %options)
Add defines (as a hash) to the define list.
=head2 compile($source, $target, %options)
Compile a C<$source> to C<$destination>.
=head1 AUTHOR
Leon Timmermans <fawaka@gmail.com>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2012 by Leon Timmermans.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
|