| 1 | # App::hopen::Gen::Make - generator for a generic make(1). | ||||||||||
| 2 | package App::hopen::Gen::Make; | ||||||||||
| 3 | 1 | ▶ | use strict; use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use Data::Hopen::Base; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 1 | our $VERSION = '0.000013'; # TRIAL | |||||||||
| 7 | |||||||||||
| 8 | 1 | ▶ | use parent 'App::hopen::Gen'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 1 | ▶ | use Class::Tiny; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 1 | ▶ | use App::hopen::BuildSystemGlobals; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 1 | ▶ | use App::hopen::Phases qw(is_last_phase); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 1 | ▶ | use Data::Hopen qw(:default getparameters *QUIET); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 1 | ▶ | use Data::Hopen::Scope::Hash; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | 1 | ▶ | use Data::Hopen::Util::Data qw(forward_opts); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | 1 | ▶ | use File::Which; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | 1 | ▶ | use Quote::Code; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 18 | |||||||||||
| 19 | 1 | ▶ | use App::hopen::Gen::Make::AssetGraphNode; # for $OUTPUT | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 20 | |||||||||||
| 21 | # Docs {{{1 | ||||||||||
| 22 | |||||||||||
| 23 | =head1 NAME | ||||||||||
| 24 | |||||||||||
| 25 | App::hopen::Gen::Make - hopen generator for simple Makefiles | ||||||||||
| 26 | |||||||||||
| 27 | =head1 SYNOPSIS | ||||||||||
| 28 | |||||||||||
| 29 | This generator makes a Makefile that does its best to run on cmd.exe or sh(1). | ||||||||||
| 30 | |||||||||||
| 31 | =head1 FUNCTIONS | ||||||||||
| 32 | |||||||||||
| 33 | =cut | ||||||||||
| 34 | |||||||||||
| 35 | # }}}1 | ||||||||||
| 36 | |||||||||||
| 37 | =head2 finalize | ||||||||||
| 38 | |||||||||||
| 39 | Write out the Makefile. Usage: | ||||||||||
| 40 | |||||||||||
| 41 | $Generator->finalize($dag); # $data parameter unused | ||||||||||
| 42 | |||||||||||
| 43 | C<$dag> is the build graph. | ||||||||||
| 44 | |||||||||||
| 45 | =cut | ||||||||||
| 46 | |||||||||||
| 47 | sub finalize { | ||||||||||
| 48 | 2 | ▶ | my ($self, %args) = getparameters('self', [qw(dag; data)], @_); | ||||||||
|
Subroutine
finalize: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||
| 49 | 2 | ▶ | hlog { Finalizing => __PACKAGE__ , '- phase', $Phase }; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||
| 50 | 2 | ▶ | return unless is_last_phase $Phase; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 51 | |||||||||||
| 52 | 1 | ▶ | hlog { __PACKAGE__, 'Asset graph', '' . $self->_assets->_graph } 3; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||
| 53 | |||||||||||
| 54 | # During the Gen phase, create the Makefile | ||||||||||
| 55 | 1 | ▶ | open my $fh, '>', $self->dest_dir->file('Makefile') or die "Couldn't create Makefile"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 56 | 1 | print $fh <<EOT; | |||||||||
| 57 | # Makefile generated by hopen (https://github.com/hopenbuild/App-hopen) | ||||||||||
| 58 | 1 | # at @{[scalar gmtime]} GMT | |||||||||
| 59 | 1 | # From ``@{[$self->proj_dir->absolute]}'' into ``@{[$self->dest_dir->absolute]}'' | |||||||||
| 60 | |||||||||||
| 61 | .PHONY: first__goal__ | ||||||||||
| 62 | EOT | ||||||||||
| 63 | |||||||||||
| 64 | # Make sure the first goal is 'all' regardless of order. | ||||||||||
| 65 | 1 | say $fh qc'first__goal__: {$args{dag}->default_goal->name}\n'; | |||||||||
| 66 | |||||||||||
| 67 | 1 | my $context = Data::Hopen::Scope::Hash->new; | |||||||||
| 68 | 1 | $context->put(App::hopen::Gen::Make::AssetGraphNode::OUTPUT, $fh); | |||||||||
| 69 | |||||||||||
| 70 | # Write the Makefile. TODO flip the order. | ||||||||||
| 71 | |||||||||||
| 72 | 1 | $self->_assets->run(-context => $context); | |||||||||
| 73 | |||||||||||
| 74 | 1 | close $fh; | |||||||||
| 75 | } #finalize() | ||||||||||
| 76 | |||||||||||
| 77 | =head2 default_toolset | ||||||||||
| 78 | |||||||||||
| 79 | Returns the package name of the default toolset for this generator, | ||||||||||
| 80 | which is C<Gnu> (i.e., L<App::hopen::T::Gnu>). | ||||||||||
| 81 | |||||||||||
| 82 | =cut | ||||||||||
| 83 | |||||||||||
| 84 | 2 | ▶ | sub default_toolset { 'Gnu' } | ||||||||
|
Subroutine
default_toolset: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 85 | |||||||||||
| 86 | =head2 _assetop_class | ||||||||||
| 87 | |||||||||||
| 88 | The class of asset-graph operations, which in this case is | ||||||||||
| 89 | L<App::hopen::Gen::Make::AssetGraphNode>. | ||||||||||
| 90 | |||||||||||
| 91 | =cut | ||||||||||
| 92 | |||||||||||
| 93 | 4 | ▶ | sub _assetop_class { 'App::hopen::Gen::Make::AssetGraphNode' } | ||||||||
|
Subroutine
_assetop_class: called CC=1 SCAR=0.0
| |||||||||||
| 94 | |||||||||||
| 95 | =head2 _run_build | ||||||||||
| 96 | |||||||||||
| 97 | Implementation of L<App::hopen::Gen/run_build>. | ||||||||||
| 98 | |||||||||||
| 99 | =cut | ||||||||||
| 100 | |||||||||||
| 101 | sub _run_build { | ||||||||||
| 102 | # Look for the make(1) executable. Listing make before gmake since a | ||||||||||
| 103 | # system with both Cygwin and Strawberry Perl installed has cygwin's | ||||||||||
| 104 | # make(1) and Strawberry's gmake(1). | ||||||||||
| 105 | 0 | ▶ | foreach my $candidate (qw[make gmake mingw32-make dmake]) { | ||||||||
|
Subroutine
_run_build: not called CC=3 SCAR=24.8
| |||||||||||
| 106 | 0 | my $path = File::Which::which($candidate); | |||||||||
| 107 | 0 | ▶ | next unless defined $path; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 108 | 0 | ▶ | hlog { Running => $path }; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 109 | 0 | system $path, (); | |||||||||
| 110 | 0 | return; | |||||||||
| 111 | } | ||||||||||
| 112 | 0 | warn "Could not find a 'make' program to run"; | |||||||||
| 113 | } #_run_build() | ||||||||||
| 114 | |||||||||||
| 115 | 1 | 1; | |||||||||
| 116 | __END__ | ||||||||||
| 117 | # vi: set fdm=marker: # | ||||||||||