From 033421585dfa781211b558d7acc310b8540ba60e Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 28 Dec 2019 22:45:50 +0000 Subject: [PATCH] Interface: Rename Perdir to Suffix; provide Prefix We want to be able to specify something that appears at the top of every per-directory segment, principally to provide for-every-directory variable settings. A more sophisticated scheme akin to m4 diversions would be possible in principle, but it would make organising the output files (which must be processed by autoconf) really awkward - let alone the depenency management for regenerating the makefiles. So instead, simply provide a Prefix too. Additionally, soon we are going to introduce a Final.sd.mk which is processed right at the end. I think this new scheme will be sufficient in principle to do anything that might be needed. Sadly it will continue to require that &:include's are done in the right order. "Suffix" and "Subdir" tab-complete really badly. In a forthcoming commit we will rename Subdir.sd.mk to Dir.sd.mk. Incompatible change. We must update the tests right away. Signed-off-by: Ian Jackson --- README | 19 ++++++++++--------- cdeps.sd.mk | 2 +- clean.sd.mk | 2 +- example/{Perdir.sd.mk => Suffix.sd.mk} | 0 generate | 3 ++- tests/filter/Perdir.sd.mk | 1 - tests/filter/Prefix.sd.mk | 1 + tests/filter/Subdir.mk.expected | 3 ++- tests/filter/Suffix.sd.mk | 1 + tests/filter/main.mk.expected | 3 ++- tests/filter/sub/dir/Subdir.mk.expected | 3 ++- 11 files changed, 22 insertions(+), 16 deletions(-) rename example/{Perdir.sd.mk => Suffix.sd.mk} (100%) delete mode 100644 tests/filter/Perdir.sd.mk create mode 100644 tests/filter/Prefix.sd.mk create mode 100644 tests/filter/Suffix.sd.mk diff --git a/README b/README index 360afbd..e3259c0 100644 --- a/README +++ b/README @@ -90,20 +90,21 @@ Unlike `all', these other targets only exist in areas of the project where at least something mentions them. So for example, if &TARGETS_zonk is mentioned in src but not lib, `make zonk' in lib will fail. If you want to make a target exist everywhere, -mention its name in Perdir.sd.mk (see below). +mention its name in Prefix.sd.mk or Suffix.sd.mk (see below). -Perdir.sd.mk, inclusion ------------------------ +Prefix.sd.mk, Suffix.sd.mk, inclusion +------------------------------------- -The file Perdir.sd.mk in the toplevel of the source is automatically -processed after each individual directory's Subdir.sd.mk, and the -&-substituted contents therefore appear once for each subdirectory. +The files Prefix.sd.mk and Suffix.sd.mk in the toplevel of the source +are automatically processed before and after each individual +directory's Subdir.sd.mk, and the &-substituted contents therefore +appear once for each subdirectory. This lets you do per-directory boilerplate. Some useful boilerplate is already provided in subdirmk, for you to reference like this: &:include subdirmk/cdeps.sd.mk &:include subdirmk/clean.sd.mk -For example you could put that in Perdir.sd.mk. +For example you could put that in Suffix.sd.mk. The top-level Subdir.sd.mk is the first makefile included after the autogenerated `main.mk' which merely has some basic settings and @@ -147,7 +148,7 @@ There are two kinds of template files. How to include `&:include foo.sd.mk' `include foo.mk' in all relevant .sd.mk in only one (but not needed for Subdir.sd.mk - Subdir and Perdir) + Prefix, Suffix) If you `include subdirmk/regen.mk', dependency management and automatic regeneration for all of this template substitution, and for @@ -354,7 +355,7 @@ probably contain: include subdirmk/usual.mk include subdirmk/regen.mk -Write a Perdir.sd.mk in the toplevel, if you want. It should probably +Write a Suffix.sd.mk in the toplevel, if you want. It should probably have: &:include subdirmk/cdeps.sd.mk diff --git a/cdeps.sd.mk b/cdeps.sd.mk index 5a2bfb2..3743830 100644 --- a/cdeps.sd.mk +++ b/cdeps.sd.mk @@ -5,7 +5,7 @@ &# Usage: &# &:include subdirmk/cdeps.sd.mk -&# (probably in Perdir.sd.mk) +&# (probably in Suffix.sd.mk) &# &# Arranges for automatic #include dependency tracking for &# C compilation. The compiler is asked to write the dependencies to diff --git a/clean.sd.mk b/clean.sd.mk index 80c40bc..b145442 100644 --- a/clean.sd.mk +++ b/clean.sd.mk @@ -5,7 +5,7 @@ &# Usage: &# &:include subdirmk/clean.sd.mk -&# (probably in Perdir.sd.mk) +&# (probably in Suffix.sd.mk) &# &# Provides a per-directory `clean' target, which deletes all the files &# in &CLEAN. &OBJECTS, &DEPFILES and &TARGETS are automatically deleted. diff --git a/example/Perdir.sd.mk b/example/Suffix.sd.mk similarity index 100% rename from example/Perdir.sd.mk rename to example/Suffix.sd.mk diff --git a/generate b/generate index a3c8b4f..5273e15 100755 --- a/generate +++ b/generate @@ -234,8 +234,9 @@ sub filter_subdir_mk ($) { my ($f, $enoentok) = @_; process_input_mk($targets, "${srcdir}/$f", \$esclit, $enoentok); }; + $pi->("Prefix.sd.mk", 1); $pi->("${dir_prefix}Subdir.sd.mk", 0); - $pi->("Perdir.sd.mk", 1); + $pi->("Suffix.sd.mk", 1); } sub process_subtree ($$); diff --git a/tests/filter/Perdir.sd.mk b/tests/filter/Perdir.sd.mk deleted file mode 100644 index 0bc254d..0000000 --- a/tests/filter/Perdir.sd.mk +++ /dev/null @@ -1 +0,0 @@ -# Perdir in &. diff --git a/tests/filter/Prefix.sd.mk b/tests/filter/Prefix.sd.mk new file mode 100644 index 0000000..da3a735 --- /dev/null +++ b/tests/filter/Prefix.sd.mk @@ -0,0 +1 @@ +# Prefix in &. diff --git a/tests/filter/Subdir.mk.expected b/tests/filter/Subdir.mk.expected index b112441..cf4841a 100644 --- a/tests/filter/Subdir.mk.expected +++ b/tests/filter/Subdir.mk.expected @@ -1,7 +1,8 @@ # autogenerated - do not edit +# Prefix in . # test cases for generate script # doctests: -# Perdir in . +# Suffix in . all:: $(TOP_TARGETS) sub/all sometarget1:: $(TOP_TARGETS_sometarget1) sub/sometarget1 diff --git a/tests/filter/Suffix.sd.mk b/tests/filter/Suffix.sd.mk new file mode 100644 index 0000000..453de60 --- /dev/null +++ b/tests/filter/Suffix.sd.mk @@ -0,0 +1 @@ +# Suffix in &. diff --git a/tests/filter/main.mk.expected b/tests/filter/main.mk.expected index 4a4779f..95cae48 100644 --- a/tests/filter/main.mk.expected +++ b/tests/filter/main.mk.expected @@ -6,8 +6,9 @@ MAKEFILE_TEMPLATES := SUBDIRMK_MAKEFILES += Subdir.mk SUBDIRMK_MAKEFILES += sub/Subdir.mk SUBDIRMK_MAKEFILES += sub/dir/Subdir.mk -MAKEFILE_TEMPLATES += ./Perdir.sd.mk +MAKEFILE_TEMPLATES += ./Prefix.sd.mk MAKEFILE_TEMPLATES += ./Subdir.sd.mk +MAKEFILE_TEMPLATES += ./Suffix.sd.mk MAKEFILE_TEMPLATES += ./doctest.sd.mk MAKEFILE_TEMPLATES += ./sub/dir/Subdir.sd.mk MAKEFILE_TEMPLATES += ./sub/dir/doctest.sd.mk diff --git a/tests/filter/sub/dir/Subdir.mk.expected b/tests/filter/sub/dir/Subdir.mk.expected index e5aadc2..6748cdc 100644 --- a/tests/filter/sub/dir/Subdir.mk.expected +++ b/tests/filter/sub/dir/Subdir.mk.expected @@ -1,4 +1,5 @@ # autogenerated - do not edit +# Prefix in sub/dir # subdirectory test cases sub/dir/ @@ -10,7 +11,7 @@ sub_dir_TARGETS_sometarget2 line joining # doctests: -# Perdir in sub/dir +# Suffix in sub/dir sub/dir/all:: $(sub_dir_TARGETS) sub/dir/sometarget1:: $(sub_dir_TARGETS_sometarget1) -- 2.30.2