From 1d0151d4f66912805d9b6d79527c587ab881f5aa Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 10 Nov 2019 20:24:06 +0000 Subject: [PATCH 1/1] WIP --- NOTES | 9 ++-- build-aux/subdirmk-setup | 99 +++++++++++++++++++++++----------------- 2 files changed, 64 insertions(+), 44 deletions(-) diff --git a/NOTES b/NOTES index e5cdd0a..5d57e99 100644 --- a/NOTES +++ b/NOTES @@ -8,20 +8,23 @@ &^ => $(top_srcdir)/subdir or $(top_srcdir) &~ => $(abs_top_srcdir)/subdir or $(abs_top_srcdir) -&& => & +&& => && +\& => & & thing thing... & => each thing prefixed by &/ &^ &~ resp & ^ thing thing... & each thing is any non-ws & ~ thing thing... & & may be omitted before EOL or before \EOL + other &'s not recognised CAPS is [A-Z][0-9_A-Z]*(?!\w) lc is [a-z][-+,0-9_a-z]*(?!\w) -&! spc disables & *until* EOL +&! disables & *until* EOL (and disappears) &!STUFF STUFF is recognised instead of & (beyond EOL) - STUFF is either all punct or all alphanum (incl _) + STUFF is either all ASCII punct or all ASCII alphanum (incl _) any lwsp after STUFF is discarded too + eg notably STUFF!& now & is recognised instead (ie back to normal) STUFFSTUFF STUFF diff --git a/build-aux/subdirmk-setup b/build-aux/subdirmk-setup index 1de8830..f721621 100644 --- a/build-aux/subdirmk-setup +++ b/build-aux/subdirmk-setup @@ -27,68 +27,87 @@ sub build_tree () { } sub write_makefile ($$) { - my ($subdir,$depth) = @_; - start_output_file("$subdir/Makefile"); + my ($dir_prefix,$depth) = @_; + start_output_file("${dir_prefix}Makefile"); my $cd = $depth ? join('/', ('..',) x $depth) : '.'; o <) { for (;;) { - s{^(.*?)(?=$esc)}{}; + unless (s{^(.*?)(\\)?(?=$esc)}{}) { o $_; last; } o $1; - last if m{^\n}; + if ($2) { o $esclit; next; } s{^$esc}{} or die "$_ ?"; - if (s{^$esc}{}) { - o $esclit; + if (s{^$esc}{}) { o "$esclit$esclit" } + elsif (m{^TARGETS(?:_[0-9a-zA-Z_]+)?(?=\W)}{}) { + my $t = $2 // 'all'; + o target_varname($varname_prefix, $t); + $targets->{$t}=1; } - elsif (m{^(?=$caps_re)}) { o "${for_var}_" } + elsif (m{^(?=$caps_re)}) { o "${var_prefix}_" } elsif (m{^(?=$lc_re)}) { o $dir_prefix } - elsif (s{^_}{}) { o "${for_var}_" } + elsif (s{^_}{}) { o "${var_prefix}_" } elsif (s{^/}{}) { o $dir_prefix } - elsif (s{^=_}{}) { o $for_var } + elsif (s{^=_}{}) { o $var_prefix } elsif (s{^=/}{}) { o $dir_name } elsif (s{^\^}{}) { o "\$(top_srcdir)${dir_suffix}" } elsif (s{^\}}{}) { o "\$(abs_top_srcdir)${dir_suffix}" } - elsif (m{^[ \t]}) { - for (;;) { - if (s{^[ \t]+($caps_re)}{}) { - o " - - s{^ - } else - } - s{^~}{$dir_name} || - - -[A-Z][0-9A-Z_](?!\w -(=?)([/.~])}{}) { - my ($val, - o $subdir; - } elsif (s{^[_/]}{}) { - o + elsif (s{^(?:[ \t]+([~^]))?(?=[ \t]){}}{}) { + my $prefix = + !$1 ? $dir_prefix : + $1 eq '~' ? '$(abs_top_srcdir)'.$dir_suffix : + $1 eq '~' ? '$(abs_top_srcdir)'.$dir_suffix : + die; + my $after=''; + if (m{([ \t])$esc}) { ($_,$after) = ($`, $1.$'); } + s{(?<=[ \t])(?=\S)(?!\\\s*$)}{$prefix}g; + o $_; + $_ = $after; + } elsif (s{^![ \t]+}{}) { + o $_; + $_ = ''; + } elsif (s{^!(\pPosixWord+|\pPosixPunct+)[ \t]*}{}) { + $esclit = $1; + $esc = $esclit; + $esc =~ s/\W/\\$&/g; + } else { + die "bad escape $esclit$_ "; + } + } } } +sub target_varname ($$) { + my ($var_prefix, $target) = @_; + return $vprefix.'TARGETS'.($target eq 'all' ? '' : "_$target"); +} + sub process_subtree ($$) { # => list of descendants (in form SUBDIR/) # recursive, children first my ($node, $path); - my $dprefix = join '', map { "${_}/" } @$path; - my $vprefix = join '', map { "${_}_" } @$path; - my $subdir = @$path ? (join '/', @$path) : '.'; + + my $dir_prefix = join '', map { "$_/" } @$path; + my $dir_suffix = join '', map { "/$_" } @$path; + my $dir_name = join '/', @$path ? @$path : '.'; + my $var_prefix = map { "${_}_" } @$path ? @$path : qw(TOP); + write_makefile($subdir, scalar @$path); my %targets = qw(all 1); @@ -101,16 +120,14 @@ sub process_subtree ($$) { } start_output_file("$subdir/Subdir.mk.tmp"); - filter_subdir_mk(); - - $targets{$_}++ foreach - write_subdir($child); + filter_subdir_mk($dir_prefix, $dir_suffix, $dir_name, + $var_prefix, \%targets); my @targets = sort keys %targets; foreach my $target (@targets) { - $vsuffix = $target eq 'all' ? '' : "_$target"; + my $target_varname = target_varname($var_prefix, target); print O <