chiark / gitweb /
generate: Add missing final newline to main.mk
[subdirmk.git] / generate
index dd22146339b130fc6ffbb7efdd9ab3ce0ccc8515..fe3e3f5866674bcf17fa69ea6addaba1225cb3bb 100755 (executable)
--- a/generate
+++ b/generate
@@ -97,12 +97,16 @@ sub write_makefile ($$) {
     #print STDERR "write_makefile @_\n";
     start_output_file("${dir_prefix}Makefile");
     my $cd = $depth ? join('/', ('..',) x $depth) : '.';
     #print STDERR "write_makefile @_\n";
     start_output_file("${dir_prefix}Makefile");
     my $cd = $depth ? join('/', ('..',) x $depth) : '.';
+    my $suppress_templates=
+       '$(if $(filter-out clean real-clean, $(subdirmk_targets)),,'.
+       ' MAKEFILE_TEMPLATES=)';
     o <<END;
 default: all
     o <<END;
 default: all
-\$(MAKECMDGOALS) all: run-main.mk
+\$(filter-out all,\$(MAKECMDGOALS)) all: run-main.mk
        \@:
        \@:
+subdirmk_targets:=\$(or \$(MAKECMDGOALS),all)
 Makefile run-main.mk:
 Makefile run-main.mk:
-       \$(MAKE) -C $cd -f main.mk \$(addprefix ${dir_prefix},\$(or \$(MAKECMDGOALS),all))
+       \$(MAKE) -C $cd -f main.mk \$(addprefix ${dir_prefix},\$(subdirmk_targets))$suppress_templates
 .SUFFIXES:
 .PHONY:        run-main.mk
 END
 .SUFFIXES:
 .PHONY:        run-main.mk
 END
@@ -254,6 +258,11 @@ sub process_subtree ($$) {
        }
        print O "\n";
     }
        }
        print O "\n";
     }
+    if (@targets) {
+       print O ".PHONY:";
+       print O " ${dir_prefix}${_}" foreach @targets;
+       print O "\n";
+    }
 
     return @targets;
 }
 
     return @targets;
 }
@@ -273,7 +282,7 @@ sub process_tree() {
     foreach my $input (sort keys %input_files) {
        o "MAKEFILE_TEMPLATES += $input\n";
     }
     foreach my $input (sort keys %input_files) {
        o "MAKEFILE_TEMPLATES += $input\n";
     }
-    o "include \$(SUBDIRMK_MAKEFILES)";
+    o "include \$(SUBDIRMK_MAKEFILES)\n";
 }
 
 build_tree();
 }
 
 build_tree();