# subdirmk - &-filter (makefile generation program)
# Copyright 2019 Ian Jackson
# SPDX-License-Identifier: LGPL-2.0-or-later
+# There is NO WARRANTY.
#
# $(srcdir)/subdirmk/generate [--srcdir=SRCDIR] [--] SUBDIR...
#
}
our %varref;
+our %varref_exp;
our ($dir_prefix, $dir_suffix, $dir_name,
$var_prefix, $var_prefix_name);
local+global
single-char-var
unknown-warning
+ broken-var-ref
);
our %warn_ena = @warn_ena_dfl;
sub err ($) {
my ($m) = @_;
- die "subdirmk: ${err_file}:$.: $m\n";
+ die defined $err_file
+ ? "subdirmk: ${err_file}:$.: $m\n"
+ : "subdirmk: $m\n";
}
sub wrncore ($$) {
local $err_file=$f;
my %srcdirmap = (
- '^' => "\$(top_srcdir)${dir_suffix}",
- '~' => "\$(top_srcdir)",
+ '^' => "\${top_srcdir}${dir_suffix}",
+ '~' => "\${top_srcdir}",
);
my %pfxmap = (
'' => $dir_prefix,
# accurate, since it is only going to be used for advice to the user.
my $note_varref = sub {
my ($vn,$amp) = @_;
- $varref{$vn}{$amp}{"$f:$."} = 1;
+ my $exp = !!$varref_exp{$vn}{$amp};
+ $varref{$vn}{$exp}{$amp}{"$f:$."} = 1;
};
while (<$input>) {
next;
} elsif (s#^\s*$esc\:local\+global\s+(\S.*)$##) {
foreach my $vn (split /\s+/, $1) {
- $vn =~ s{^$esc}{};
- $varref{$vn}{NoWarn} = 1;
+ my $pos = !($vn =~ s{^!}{});
+ my $amp = $vn =~ s{^$esc}{};
+ $varref_exp{$vn}{!!$amp} = $pos;
}
next;
} elsif (s#^\s*$esc\:(?=(-?)include|macro)##) {
wrn 'single-char-var',
'possibly confusing unbracketed single-char $-expansion';
}
+ elsif (m{^$esc}) {
+ wrn 'broken-var-ref',
+ 'broken $&... expansion; you probably meant &$';
+ }
elsif (m{^\(($esc)?([^()\$]+)\)} ||
m{^\{($esc)?([^{}\$]+)\}}) {
$note_varref->($2,!!$1);
elsif (m{^(?=$caps_re)}) { od $var_prefix }
elsif (s{^\$([A-Za-z]\w+)}{}) {
$note_varref->($1,1);
- od "\$(${var_prefix}$1)";
+ od "\${${var_prefix}$1}";
}
elsif (s{^([~^]?)(?=$lc_re)}{}) { od $pfxmap{$1} }
elsif (s{^_}{}) { od $var_prefix }
elsif (s{^\$\-}{}) { $ddbl=undef; }
elsif (s{^\$\+}{}) { $ddbl=1; }
elsif (s{^\$\(}{}) {
- ddbl_only($&); oud "\$(";
+ ddbl_only($&); oud "\${";
$note_varref->($2,!!$1) if m{^($esc)?([^()\$]+\))};
}
- elsif (s{^\$(\d+)}{}) { ddbl_only($&); oud "\$($1)"; }
+ elsif (s{^\$(\d+)}{}) { ddbl_only($&); oud "\${$1}"; }
elsif (s{^\$\{}{}) {
err 'macro invocation cannot be re-$-doubled' if $ddbl;
od '${eval ${call ';
#use Data::Dumper;
#print STDERR Dumper(\@_);
+ local %varref_exp;
+
my $dir_prefix = dir_prefix($path);
# ^ this is the only var which we need before we come back from
# the recursion.
sub print_varref_warnings () {
foreach my $vn (sort keys %varref) {
my $vv = $varref{$vn};
- next unless $vv->{''} && $vv->{1};
- next if $vv->{NoWarn};
+ next unless $vv->{''}{''} && $vv->{''}{1};
wrncore 'local+global', "saw both $vn and &$vn" or return;
+ foreach my $exp ('', 1) {
foreach my $amp ('', 1) {
- printf STDERR " saw %s%s at %s\n",
+ printf STDERR
+ ($exp
+ ? " expectedly saw %s%s at %s\n"
+ : " saw %s%s at %s\n"),
($amp ? '&' : ''), $vn, $_
foreach
sort { flmap($a) cmp flmap($b) }
- keys %{ $vv->{$amp} };
+ keys %{ $vv->{$exp}{$amp} };
}
+ }
}
}