X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?a=blobdiff_plain;f=build-aux%2Fsubdirmk-setup;h=976e3ce0055a74ff4eeb0ae654efca55587c55ba;hb=ad6795dd7d122fa1b3a0613c075e87479980f93f;hp=616f6530f653ddec6e44ad5cb66261feda2f5dfb;hpb=1dec8023efc8ce858935f96a09f84d97e69eba77;p=subdirmk.git diff --git a/build-aux/subdirmk-setup b/build-aux/subdirmk-setup index 616f653..976e3ce 100755 --- a/build-aux/subdirmk-setup +++ b/build-aux/subdirmk-setup @@ -49,12 +49,18 @@ sub close_any_output_file() { $writing_output = undef; } +sub o { + die unless defined $writing_output; + print O @_ or die "error writing $writing_output.tmp: $!\n"; +} + sub start_output_file ($) { close_any_output_file(); ($writing_output) = @_; - die if $output_files{$writing_output}++; + die "$writing_output ?" if $output_files{$writing_output}++; my $tmp = "$writing_output.tmp"; open O, ">", $tmp or die "create $tmp: $!\n"; + o "# autogenerated - do not edit\n"; } sub install_output_files () { @@ -64,19 +70,15 @@ sub install_output_files () { } } -sub o { - die unless defined $writing_output; - print O @_ or die "error writing $writing_output.tmp: $!\n"; -} - sub write_makefile ($$) { my ($dir_prefix,$depth) = @_; + #print STDERR "write_makefile @_\n"; start_output_file("${dir_prefix}Makefile"); my $cd = $depth ? join('/', ('..',) x $depth) : '.'; o <{$t}=1; } - elsif (m{^(?=$caps_re)}) { o "${var_prefix}_" } + elsif (m{^(?=$caps_re)}) { o $var_prefix } elsif (m{^(?=$lc_re)}) { o $dir_prefix } - elsif (s{^_}{}) { o "${var_prefix}_" } + elsif (s{^_}{}) { o $var_prefix } elsif (s{^/}{}) { o $dir_prefix } 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 (s{^(?:[ \t]+([~^]))?(?=[ \t]){}}{}) { + elsif (s{^(?:[ \t]+([~^]))?(?=[ \t])}{}) { my $prefix = !$1 ? $dir_prefix : $1 eq '~' ? '$(abs_top_srcdir)'.$dir_suffix : @@ -140,12 +145,15 @@ sub process_subtree ($$); sub process_subtree ($$) { # => list of descendants (in form SUBDIR/) # recursive, children first - my ($node, $path); + my ($node, $path) = @_; + + #use Data::Dumper; + #print STDERR Dumper(\@_); 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); + my $var_prefix = join '', map { "${_}_" } @$path ? @$path : qw(TOP); write_makefile($dir_prefix, scalar @$path); @@ -155,26 +163,23 @@ sub process_subtree ($$) { my @childpath = (@$path, $child->[0]); push @child_subdirs, join '/', @childpath; $targets{$_}++ foreach - process_subtree($child, [ ]); + process_subtree($child, \@childpath); } start_output_file("${dir_prefix}Subdir.mk.tmp"); filter_subdir_mk($dir_prefix, $dir_suffix, $dir_name, $var_prefix, \%targets); + o "\n"; + my @targets = sort keys %targets; foreach my $target (@targets) { my $target_varname = target_varname($var_prefix, $target); - print O <