| 1 | # App::hopen::T::MSCL::C::LinkCmd - link object files using the GNU toolset | ||
| 2 | package App::hopen::T::MSCL::C::LinkCmd; | ||
| 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::Cmd'; | ||
| 10 | use Class::Tiny qw(dest linker); | ||
| 11 | |||
| 12 | use App::hopen::BuildSystemGlobals; # For $DestDir. | ||
| 13 | # TODO make the dirs available to nodes through the context. | ||
| 14 | use App::hopen::Util::BasedPath; | ||
| 15 | use Data::Hopen qw(getparameters); | ||
| 16 | use Data::Hopen::Util::Filename; | ||
| 17 | use Path::Class; | ||
| 18 | |||
| 19 | # Docs {{{1 | ||
| 20 | |||
| 21 | =head1 NAME | ||
| 22 | |||
| 23 | App::hopen::T::MSCL::C::LinkCmd - link object files using the GNU toolset | ||
| 24 | |||
| 25 | =head1 SYNOPSIS | ||
| 26 | |||
| 27 | In a hopen file: | ||
| 28 | |||
| 29 | my $cmd = App::hopen::T::MSCL::C::LinkCmd->new( | ||
| 30 | linker => 'gcc', | ||
| 31 | dest => 'foo.exe', | ||
| 32 | name => 'some linker node', # optional | ||
| 33 | ); | ||
| 34 | |||
| 35 | The inputs come from earlier in the build graph. | ||
| 36 | TODO support specifying linker arguments. | ||
| 37 | |||
| 38 | =head1 ATTRIBUTES | ||
| 39 | |||
| 40 | =head2 linker | ||
| 41 | |||
| 42 | The linker to use. TODO is this a full path or just a name? | ||
| 43 | |||
| 44 | =head2 dest | ||
| 45 | |||
| 46 | The destination file to produce, as an L<App::hopen::Util::BasedPath> instance. | ||
| 47 | TODO? accept string or L<Path::Class::File> instance? | ||
| 48 | |||
| 49 | =head1 MEMBER FUNCTIONS | ||
| 50 | |||
| 51 | =cut | ||
| 52 | |||
| 53 | # }}}1 | ||
| 54 | |||
| 55 | =head2 _run | ||
| 56 | |||
| 57 | Create the link command line. | ||
| 58 | |||
| 59 | =cut | ||
| 60 | |||
| 61 | sub _run { | ||
| 62 | my ($self, %args) = getparameters('self', [qw(phase visitor ; *)], @_); | ||
| 63 | |||
| 64 | # Currently we only do things at gen time. | ||
| 65 | return $self->passthrough(-nocontext=>1) if $args{phase} ne 'Gen'; | ||
| 66 | |||
| 67 | # Pull the inputs | ||
| 68 | my $lrObjFiles = $self->input_assets; | ||
| 69 | hlog { 'found object files', Dumper($lrObjFiles) } 2; | ||
| 70 | |||
| 71 | my $exe = App::hopen::Asset->new( | ||
| 72 | target => $self->dest, | ||
| 73 | made_by => $self, | ||
| 74 | ); | ||
| 75 | $args{visitor}->asset($exe, | ||
| 76 | -how => '"' . $self->linker . '" "/Fe#out" #all', | ||
| 77 | # TODO permit escaping #out and #all - see comments in | ||
| 78 | # App::hopen::T::MSCL::C::CompileCmd. | ||
| 79 | ); # TODO refactor out common code with T::Gnu::C::LinkCmd | ||
| 80 | |||
| 81 | foreach my $obj (@$lrObjFiles) { | ||
| 82 | die "Cannot link non-file $obj" unless $obj->isdisk; | ||
| 83 | $args{visitor}->connect($obj, $exe); | ||
| 84 | } | ||
| 85 | |||
| 86 | $self->make($exe); | ||
| 87 | return {}; | ||
| 88 | } #_run() | ||
| 89 | |||
| 90 | 1; | ||
| 91 | __END__ | ||
| 92 | # vi: set fdm=marker: # |