| 1 | # App::hopen::T::MSCL::C::CompileCmd - compile C source using the GNU toolset | ||
| 2 | package App::hopen::T::MSCL::C::CompileCmd; | ||
| 3 | use Data::Hopen; | ||
| 4 | use strict; use warnings; | ||
| 5 | use Data::Hopen::Base; | ||
| 6 | |||
| 7 | our $VERSION = '0.000013'; # TRIAL | ||
| 8 | |||
| 9 | use parent 'App::hopen::G::OutputPerFileCmd'; | ||
| 10 | use Class::Tiny qw(compiler); | ||
| 11 | |||
| 12 | use App::hopen::Asset; | ||
| 13 | use App::hopen::BuildSystemGlobals; # For $DestDir. | ||
| 14 | # TODO make the dirs available to nodes through the context. | ||
| 15 | use App::hopen::Util::BasedPath; | ||
| 16 | use Data::Hopen qw(getparameters); | ||
| 17 | use Data::Hopen::Util::Filename; | ||
| 18 | use Path::Class; | ||
| 19 | |||
| 20 | my $_FN = Data::Hopen::Util::Filename->new; # for brevity | ||
| 21 | |||
| 22 | # Docs {{{1 | ||
| 23 | |||
| 24 | =head1 NAME | ||
| 25 | |||
| 26 | App::hopen::T::MSCL::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::MSCL::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 | my ($self, %args) = getparameters('self', [qw(asset phase visitor ; *)], @_); | ||
| 60 | my $src = $args{asset}; | ||
| 61 | |||
| 62 | die "Cannot compile non-file $src" unless $src->isdisk; | ||
| 63 | |||
| 64 | my $to = based_path(path => file($_FN->obj($src->target->path)), | ||
| 65 | base => $DestDir); | ||
| 66 | my $how = '"' . $self->compiler . '" /c "#first" "/Fo#out"'; | ||
| 67 | # TODO? escape quotes in #first and #out? | ||
| 68 | # => No, instead permit the asset node to carry the compiler ID | ||
| 69 | # in its scope, so that the generator can quote appropriately | ||
| 70 | # for the platform. | ||
| 71 | |||
| 72 | # TODO better: T::MSCL::C should put the compiler name in the | ||
| 73 | # global Scope of the DAG. Then this node can set how to, e.g., | ||
| 74 | # '#compiler /c #first /Fo#out', and let the generator escape | ||
| 75 | # appropriately for the platform. If a particular node needs a | ||
| 76 | # different compiler, that compiler can be added to the Scope of | ||
| 77 | # that particular node to override what the generator sees. | ||
| 78 | |||
| 79 | my $obj = App::hopen::Asset->new( | ||
| 80 | target => $to, | ||
| 81 | made_by => $self, | ||
| 82 | ); | ||
| 83 | |||
| 84 | return [$obj, $how]; | ||
| 85 | } #_process_input() | ||
| 86 | |||
| 87 | =head2 _should_act | ||
| 88 | |||
| 89 | Returns truthy if L</_process_input> should be called. | ||
| 90 | |||
| 91 | =cut | ||
| 92 | |||
| 93 | sub _should_act { | ||
| 94 | my ($self, %args) = getparameters('self', [qw(phase visitor ; *)], @_); | ||
| 95 | return ($args{phase} eq 'Gen'); | ||
| 96 | } #_should_act() | ||
| 97 | |||
| 98 | 1; | ||
| 99 | __END__ | ||
| 100 | # vi: set fdm=marker: # |