sub write_makefile ($$) {
my ($dir_prefix,$depth) = @_;
- print STDERR "write_makefile @_\n";
+ #print STDERR "write_makefile @_\n";
start_output_file("${dir_prefix}Makefile");
my $cd = $depth ? join('/', ('..',) x $depth) : '.';
o <<END;
default: all
%:
- \$(MAKE) -C $cd ${dir_prefix}$@
+ \$(MAKE) -C $cd -f subdirs.mk ${dir_prefix}\$@
END
}
my ($dir_prefix, $dir_suffix, $dir_name,
$var_prefix, $targets) = @_;
- use Data::Dumper;
- print STDERR "filter @_\n";
+ #use Data::Dumper;
+ #print STDERR "filter @_\n";
my $in = "${srcdir}/${dir_prefix}Subdir.mk.in";
open I, '<', $in or die "open $in: $!\n";
if ($2) { o $esclit; next; }
s{^$esc}{} or die "$_ ?";
if (s{^$esc}{}) { o "$esclit$esclit" }
- elsif (s{^TARGETS(?:_[0-9a-zA-Z_]+)?(?=\W)}{}) {
- my $t = $2 // 'all';
+ elsif (s{^TARGETS(?:_([0-9a-zA-Z_]+))?(?=\W)}{}) {
+ my $t = $1 // 'all';
o target_varname($var_prefix, $t);
$targets->{$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 :
# recursive, children first
my ($node, $path) = @_;
- use Data::Dumper;
- print STDERR Dumper(\@_);
+ #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);
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 <<END;
-${dir_prefix}${target}: \$($target_varname)
-END
- if (@child_subdirs) {
- print O "${dir_prefix}${target}:";
- foreach my $child_subdir (@child_subdirs) {
- print O " $child_subdir/$target";
- }
- print O "\n";
+ print O "${dir_prefix}${target}: \$($target_varname)";
+ foreach my $child_subdir (@child_subdirs) {
+ print O " $child_subdir/$target";
}
+ print O "\n";
}
return @targets;
sub process_tree() {
process_subtree($root, [ ]);
- start_output_file("subdirs.mk");
+ start_output_file("subdirs.mk.tmp");
+ foreach my $v (qw(top_srcdir abs_top_srcdir)) {
+ o "$v=\@$v@\n";
+ }
o "include Subdir.mk\n";
foreach my $subdir (@subdirs) {
o "include $subdir/Subdir.mk\n";