Makefile-Update
view release on metacpan or search on metacpan
lib/Makefile/Update/Makefile.pm view on Meta::CPAN
package Makefile::Update::Makefile;
# ABSTRACT: Update lists of files in makefile variables.
use Exporter qw(import);
our @EXPORT = qw(update_makefile);
use strict;
use warnings;
our $VERSION = '0.4'; # VERSION
sub update_makefile
{
my ($in, $out, $vars) = @_;
# Variable whose contents is being currently replaced and its original
# name in the makefile.
my ($var, $makevar);
# Hash with files defined for the specified variable as keys and 0 or 1
# depending on whether we have seen them in the input file as values.
my %files;
# Array of lines in the existing makefile.
my @values;
# True if the values are in alphabetical order: we use this to add new
# entries in alphabetical order too if the existing ones use it, otherwise
# we just append them at the end.
my $sorted = 1;
# Extensions of the files in the files list (they're keys of this hash,
# the values are not used), there can be more than one (e.g. ".c" and
# ".cpp").
my %src_exts;
# Extension of the files in the makefiles: here there can also be more
# than one, but in this case we just give up and don't perform any
# extensions translation because we don't have enough information to do it
# (e.g. which extension should be used for the new files in the makefile?).
# Such case is indicated by make_ext being empty (as opposed to its
# initial undefined value).
my $make_ext;
# Helper to get the extension. Note that the "extension" may be a make
# variable, e.g. the file could be something like "foo.$(obj)", so don't
# restrict it to just word characters.
sub _get_ext { $_[0] =~ /(\.\S+)$/ ? $1 : undef }
# Indent and the part after the value (typically some amount of spaces and
# a backslash) for normal lines and, separately, for the last one, as it
# may or not have backslash after it.
my ($indent, $tail, $last_tail);
# We can't use the usual check for EOF inside while itself because this
# wouldn't work for files with no new line after the last line, so check
# for the EOF manually.
my $eof = 0;
# Set to 1 if we made any changes.
my $changed = 0;
while (1) {
my $line = <$in>;
if (defined $line) {
chomp $line;
} else {
$line = '';
$eof = 1;
}
# If we're inside the variable definition, parse the current line as
# another file name,
( run in 0.827 second using v1.01-cache-2.11-cpan-39bf76dae61 )