chiark / gitweb /
WIP
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 12 Nov 2019 17:51:40 +0000 (17:51 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 12 Nov 2019 17:51:40 +0000 (17:51 +0000)
.gitignore
Subdir.mk.in
subdirmk/autogen.sh [new file with mode: 0755]
subdirmk/generate
subdirmk/regen.mk.in
subdirmk/subdirmk.ac

index 0e76771..60b28ff 100644 (file)
@@ -7,12 +7,15 @@
 /src/toy
 
 ## Autoconf cruft.
-Makefile
-Subdir.mk
-/subdirs.mk
-*.tmp
 
 /autom4te.cache/
 /config.log
 /config.status
 /configure
+
+## subdirmk-generated
+/main.mk
+/subdirmk/regen.mk
+Makefile
+Subdir.mk
+*.tmp
index ef34280..79249db 100644 (file)
@@ -22,3 +22,5 @@ COMPILE               ?= $(CC) -c -o$@ -MD $(DEFS) $(INCLUDES) $(CFLAGS)
 
 %.o: %.c
        $(COMPILE) $<
+
+include &^/subdirmk/regen.mk
diff --git a/subdirmk/autogen.sh b/subdirmk/autogen.sh
new file mode 100755 (executable)
index 0000000..5658c0a
--- /dev/null
@@ -0,0 +1,3 @@
+#!/bin/sh
+set -e
+autoconf
index 857e768..312b488 100755 (executable)
@@ -115,7 +115,7 @@ sub filter_subdir_mk ($$$$$) {
            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 }
@@ -168,12 +168,11 @@ sub process_subtree ($$) {
 
     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");
@@ -187,7 +186,7 @@ sub process_subtree ($$) {
     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";
index 0e8bb6a..81739b9 100644 (file)
@@ -2,16 +2,19 @@
 CONFIGURE      ?= configure
 CONFIGURE_AC   ?= $(CONFIGURE).ac
 CONFIG_STATUS  ?= config.status
-SUBDIRMK       ?= subdirmk
 
-&^/$(CONFIGURE): &^/$(CONFIGURE_AC)
+$(top_srcdir)/$(CONFIGURE): $(top_srcdir)/$(CONFIGURE_AC)
        cd &^ && autoconf
 
-$(CONFIG_STATUS): &^/$(CONFIGURE)
+$(CONFIG_STATUS): $(top_srcdir)/$(CONFIGURE)
        ./$(CONFIG_STATUS) --recheck
 
-all-subdirs.mk $(MAKFILES): makefiles.phantom
+MAKEFILES += subdirmk/regen.mk
+
+main.mk $(MAKFILES): makefiles.phantom
 .INTERMEDIATE: makefiles.phantom
-makefiles.phantom: $(addprefix &^/,$(addsuffix .in,$(MAKEFILES)))      \
-               $(CONFIG_STATUS) &^/$(SUBDIRMK)/generate
+makefiles.phantom:                                             \
+               $(top_srcdir)/subdirmk/generate                 \
+               $(CONFIG_STATUS)                                \
+               $(foreach m,$(MAKEFILES),$(top_srcdir)/$(m).in)
        ./$(CONFIG_STATUS)
index 43963df..24e6d14 100644 (file)
@@ -3,7 +3,11 @@ AC_DEFUN([SUBDIRMK_SUBDIRS],
 [m4_map_args_w([$1],[_SUBDIRMK_SUBDIR(],[/)])])dnl
 
 AC_DEFUN_ONCE([_SUBDIRMK_INIT],[
-  AC_CONFIG_FILES([main.mk:main.mk.tmp Subdir.mk:Subdir.mk.tmp],[],[
+  AC_CONFIG_FILES([
+       main.mk:main.mk.tmp
+       Subdir.mk:Subdir.mk.tmp
+       subdirmk/regen.mk
+       ],[],[
     subdirsmk_need_prep=false
     AS_IF([\$ac_need_defaults],[
       subdirsmk_need_prep=true],[