| 1 | # App::hopen::T::Gnu::C::CompileCmd - compile C source using the GNU toolset | ||||||||||
| 2 | package App::hopen::T::Gnu::C::CompileCmd; | ||||||||||
| 3 | 1 | ▶ | use Data::Hopen; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use strict; use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use Data::Hopen::Base; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 1 | our $VERSION = '0.000013'; # TRIAL | |||||||||
| 8 | |||||||||||
| 9 | 1 | ▶ | use parent 'App::hopen::G::OutputPerFileCmd'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 1 | ▶ | use Class::Tiny qw(compiler); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 1 | ▶ | use App::hopen::Asset; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 1 | ▶ | use App::hopen::BuildSystemGlobals; # For $DestDir. | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | # TODO make the dirs available to nodes through the context. | ||||||||||
| 15 | 1 | ▶ | use App::hopen::Util::BasedPath; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | 1 | ▶ | use Data::Hopen qw(getparameters); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | 1 | ▶ | use Data::Hopen::Util::Filename; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 18 | 1 | ▶ | use Path::Class; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 19 | |||||||||||
| 20 | 1 | my $_FN = Data::Hopen::Util::Filename->new; # for brevity | |||||||||
| 21 | |||||||||||
| 22 | # Docs {{{1 | ||||||||||
| 23 | |||||||||||
| 24 | =head1 NAME | ||||||||||
| 25 | |||||||||||
| 26 | App::hopen::T::Gnu::C::CompileCmd - compile C source using the GNU toolset | ||||||||||
| 27 | |||||||||||
| 28 | =head1 SYNOPSIS | ||||||||||
| 29 | |||||||||||
| 30 | In a hopen file: | ||||||||||
| 31 | |||||||||||
| 32 | my $cmd = App::hopen::T::Gnu::C::CompileCmd->new( | ||||||||||
| 33 | compiler => '/usr/bin/gcc', | ||||||||||
| 34 | name => 'compilation command' # optional | ||||||||||
| 35 | ); | ||||||||||
| 36 | |||||||||||
| 37 | The inputs come from earlier in the build graph. | ||||||||||
| 38 | TODO support specifying compiler arguments. | ||||||||||
| 39 | |||||||||||
| 40 | =head1 ATTRIBUTES | ||||||||||
| 41 | |||||||||||
| 42 | =head2 compiler | ||||||||||
| 43 | |||||||||||
| 44 | The compiler to use. TODO is this a full path or just a name? | ||||||||||
| 45 | |||||||||||
| 46 | =head1 MEMBER FUNCTIONS | ||||||||||
| 47 | |||||||||||
| 48 | =cut | ||||||||||
| 49 | |||||||||||
| 50 | # }}}1 | ||||||||||
| 51 | |||||||||||
| 52 | =head2 _process_input | ||||||||||
| 53 | |||||||||||
| 54 | Create the compile command line for a given asset. | ||||||||||
| 55 | |||||||||||
| 56 | =cut | ||||||||||
| 57 | |||||||||||
| 58 | sub _process_input { | ||||||||||
| 59 | 3 | ▶ | my ($self, %args) = getparameters('self', [qw(asset visitor ; *)], @_); | ||||||||
|
Subroutine
_process_input: called CC=2 SCAR=7.0
| |||||||||||
| 60 | 3 | my $src = $args{asset}; | |||||||||
| 61 | |||||||||||
| 62 | 3 | ▶ | die "Cannot compile non-file $src" unless $src->isdisk; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 63 | |||||||||||
| 64 | 3 | my $to = based_path(path => file($_FN->obj($src->target->path)), | |||||||||
| 65 | base => $DestDir); | ||||||||||
| 66 | 3 | my $how = $self->compiler . " -c #first -o #out"; | |||||||||
| 67 | 3 | my $obj = App::hopen::Asset->new( | |||||||||
| 68 | target => $to, | ||||||||||
| 69 | made_by => $self, | ||||||||||
| 70 | ); | ||||||||||
| 71 | |||||||||||
| 72 | 3 | return [$obj, $how]; | |||||||||
| 73 | } #_process_input() | ||||||||||
| 74 | |||||||||||
| 75 | =head2 _should_act | ||||||||||
| 76 | |||||||||||
| 77 | Returns truthy if L</_process_input> should be called. | ||||||||||
| 78 | |||||||||||
| 79 | =cut | ||||||||||
| 80 | |||||||||||
| 81 | sub _should_act { | ||||||||||
| 82 | 3 | ▶ | my ($self, %args) = getparameters('self', [qw(visitor ; *)], @_); | ||||||||
|
Subroutine
_should_act: called CC=1 SCAR=0.0
| |||||||||||
| 83 | 3 | return ($Phase eq 'Gen'); | |||||||||
| 84 | } #_should_act() | ||||||||||
| 85 | |||||||||||
| 86 | 1 | 1; | |||||||||
| 87 | __END__ | ||||||||||
| 88 | # vi: set fdm=marker: # | ||||||||||