#!/usr/bin/perl -w
#
-# $(srcdir)/build-aux/subdirmk-setup SUBDIR...
+# $(srcdir)/subdirmk/generate [--srcdir=SRCDIR] [--] SUBDIR...
#
-# generates
-# main.mk.tmp
-# and in each subdirectory
+# generates in each subdirectory
# Subdir.mk.tmp
# Makefile
+# and in toplevel
+# main.mk.tmp
+# from in each subdirectory
+# Subdir.mk.in
+# and at toplevel
+# Perdir.mk.in
use strict;
-our $srcdir;
-our @subdirs = @ARGV;
+print "$0 @ARGV\n" or die $!;
+
+our $srcdir='.';
-die unless $ARGV[0] eq '--srcdir';
-die unless @ARGV>=2;
-shift @ARGV;
-($srcdir, @subdirs) = @ARGV;
+while (@ARGV && $ARGV[0] =~ m/^-/) {
+ $_ = shift @ARGV;
+ last if $_ eq '--';
+ if (s/^--srcdir=//) {
+ $srcdir=$';
+ } else {
+ die "$0: unknown option \`$_'\n";
+ }
+}
+our @subdirs = @ARGV;
s{/+$}{} foreach @subdirs;
elsif (s{^TARGETS(?:_([0-9a-zA-Z_]+))?(?=\W)}{}) {
my $t = $1 // 'all';
o target_varname($var_prefix, $t);
- $targets->{$t}=1;
+ $targets->{$t} //= [ ];
}
elsif (m{^(?=$caps_re)}) { o $var_prefix }
elsif (m{^(?=$lc_re)}) { o $dir_prefix }
write_makefile($dir_prefix, scalar @$path);
- my %targets = qw(all 1);
- my @child_subdirs;
+ my %targets = (all => []);
foreach my $child (@{ $node->[1] }) {
my @childpath = (@$path, $child->[0]);
- push @child_subdirs, join '/', @childpath;
- $targets{$_}++ foreach
+ my $child_subdir = join '/', @childpath;
+ push @{ $targets{$_} }, $child_subdir foreach
process_subtree($child, \@childpath);
}
start_output_file("${dir_prefix}Subdir.mk.tmp");
foreach my $target (@targets) {
my $target_varname = target_varname($var_prefix, $target);
print O "${dir_prefix}${target}: \$($target_varname)";
- foreach my $child_subdir (@child_subdirs) {
+ foreach my $child_subdir (@{ $targets{$target} }) {
print O " $child_subdir/$target";
}
print O "\n";