From 3452ae1eb73cdb736765fd0d60e225ec2179c237 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Wed, 13 Nov 2019 17:55:46 +0000 Subject: [PATCH 01/16] abbreviate some copyright notices No change to legal effect. Signed-off-by: Ian Jackson --- configure.ac | 26 ++++---------------------- lib/Subdir.sd.mk | 28 ++++------------------------ lib/t/Subdir.sd.mk | 28 ++++------------------------ src/Subdir.sd.mk | 28 ++++------------------------ 4 files changed, 16 insertions(+), 94 deletions(-) diff --git a/configure.ac b/configure.ac index acd7f47..88516fb 100644 --- a/configure.ac +++ b/configure.ac @@ -1,26 +1,8 @@ dnl -*-autoconf-*- -dnl -dnl Configuration script for toy project -dnl -dnl (c) 2019 Mark Wooding -dnl - -dnl----- Licensing notice --------------------------------------------------- -dnl -dnl This program is free software; you can redistribute it and/or modify -dnl it under the terms of the GNU Library General Public License as -dnl published by the Free Software Foundation; either version 2 of the -dnl License, or (at your option) any later version. -dnl -dnl This program is distributed in the hope that it will be useful, -dnl but WITHOUT ANY WARRANTY; without even the implied warranty of -dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -dnl GNU Library General Public License for more details. -dnl -dnl You should have received a copy of the GNU Library General Public -dnl License along with this program; if not, write to the Free -dnl Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -dnl MA 02111-1307, USA. +dnl subdirmk example - configuration script +dnl Copyright 2019 Mark Wooding +dnl Copyright 2019 Ian Jackson +dnl SPDX-License-Identifier: LGPL-2.0-or-later AC_INIT([mktoy], [0.9.0], [mdw@distorted.org.uk]) AC_CONFIG_SRCDIR([src/toy.c]) diff --git a/lib/Subdir.sd.mk b/lib/Subdir.sd.mk index 03d1359..fa40cfd 100644 --- a/lib/Subdir.sd.mk +++ b/lib/Subdir.sd.mk @@ -1,27 +1,7 @@ -### -*-makefile-gmake-*- -### -### Build script for library -### -### (c) 2019 Mark Wooding -### (c) 2019 Ian Jackson -### - -###----- Licensing notice --------------------------------------------------- -### -### This program is free software; you can redistribute it and/or modify -### it under the terms of the GNU Library General Public License as -### published by the Free Software Foundation; either version 2 of the -### License, or (at your option) any later version. -### -### This program is distributed in the hope that it will be useful, -### but WITHOUT ANY WARRANTY; without even the implied warranty of -### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -### GNU Library General Public License for more details. -### -### You should have received a copy of the GNU Library General Public -### License along with this program; if not, write to the Free -### Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -### MA 02111-1307, USA. +# subdirmk example - subdirectory rules +# Copyright 2019 Mark Wooding +# Copyright 2019 Ian Jackson +# SPDX-License-Identifier: LGPL-2.0-or-later &TARGETS += & libtoy.a diff --git a/lib/t/Subdir.sd.mk b/lib/t/Subdir.sd.mk index a957397..ae11cd0 100644 --- a/lib/t/Subdir.sd.mk +++ b/lib/t/Subdir.sd.mk @@ -1,27 +1,7 @@ -### -*-makefile-gmake-*- -### -### Build script for library test -### -### (c) 2019 Mark Wooding -### (c) 2019 Ian Jackson -### - -###----- Licensing notice --------------------------------------------------- -### -### This program is free software; you can redistribute it and/or modify -### it under the terms of the GNU Library General Public License as -### published by the Free Software Foundation; either version 2 of the -### License, or (at your option) any later version. -### -### This program is distributed in the hope that it will be useful, -### but WITHOUT ANY WARRANTY; without even the implied warranty of -### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -### GNU Library General Public License for more details. -### -### You should have received a copy of the GNU Library General Public -### License along with this program; if not, write to the Free -### Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -### MA 02111-1307, USA. +# subdirmk example - subdirectory rules +# Copyright 2019 Mark Wooding +# Copyright 2019 Ian Jackson +# SPDX-License-Identifier: LGPL-2.0-or-later &TARGETS_check += & toytest.stamp diff --git a/src/Subdir.sd.mk b/src/Subdir.sd.mk index 4995739..69ac190 100644 --- a/src/Subdir.sd.mk +++ b/src/Subdir.sd.mk @@ -1,27 +1,7 @@ -### -*-makefile-gmake-*- -### -### Build script for main program -### -### (c) 2019 Mark Wooding -### (c) 2019 Ian Jackson -### - -###----- Licensing notice --------------------------------------------------- -### -### This program is free software; you can redistribute it and/or modify -### it under the terms of the GNU Library General Public License as -### published by the Free Software Foundation; either version 2 of the -### License, or (at your option) any later version. -### -### This program is distributed in the hope that it will be useful, -### but WITHOUT ANY WARRANTY; without even the implied warranty of -### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -### GNU Library General Public License for more details. -### -### You should have received a copy of the GNU Library General Public -### License along with this program; if not, write to the Free -### Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, -### MA 02111-1307, USA. +# subdirmk example - subdirectory rules +# Copyright 2019 Mark Wooding +# Copyright 2019 Ian Jackson +# SPDX-License-Identifier: LGPL-2.0-or-later &TARGETS += & toy -- 2.30.2 From 96ef3343f7effb47f94e60309198c57f9e2b228b Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Wed, 13 Nov 2019 17:56:08 +0000 Subject: [PATCH 02/16] minor docs change Signed-off-by: Ian Jackson --- subdirmk/generate | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subdirmk/generate b/subdirmk/generate index 0ad0eb8..8669864 100755 --- a/subdirmk/generate +++ b/subdirmk/generate @@ -8,7 +8,7 @@ # # generates in each subdirectory from in each subdirectory # Subdir.mk.tmp Subdir.sd.mk -# Makefile +# Makefile and included files # and in toplevel and in toplevel # main.mk.tmp Perdir.sd.mk -- 2.30.2 From 58859755f916bd326f2bbbbac12654a92c47328f Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Wed, 13 Nov 2019 18:00:18 +0000 Subject: [PATCH 03/16] more docs Signed-off-by: Ian Jackson --- subdirmk/README | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/subdirmk/README b/subdirmk/README index d2b3c46..d43c04b 100644 --- a/subdirmk/README +++ b/subdirmk/README @@ -239,6 +239,33 @@ project) are best avoided. If you name your variables in ALL CAPS and your subdirectories in lower case with `-' rather than `_', there will be no confusion. +Incorporating this into your project +------------------------------------ + +Use `git-subtree' to merge the subdirmk/ directory. You may find it +useful to symlink the DEVELOPER-CERTIFICATE file (git can store +symlinks as symlinks - just `git add' the link). And you probably +want to mention the situation in your top-level COPYING. + +Symlink autogen.sh into your project toplevel. + +In your configure.ac, say + + m4_include([subdirmk/subdirmk.ac]) + SUBDIRMK_SUBDIRS([...list of subdirectories in relative syntax...]) + +Write a Subdir.sd.mk in each directory. The toplevel one should +probably contain: + + include subdirmk/usual.mk + include subdirmk/regen.mk + +Write a Perdir.sd.mk in the toplevel, if you want. It should probably +have: + + &:include subdirmk/cdeps.sd.mk + &:include subdirmk/clean.sd.mk + Legal information ----------------- -- 2.30.2 From 3feffa3257a111e37dafd9684092726845d34f42 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Wed, 13 Nov 2019 18:05:11 +0000 Subject: [PATCH 04/16] more docs fixes Signed-off-by: Ian Jackson --- subdirmk/README | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/subdirmk/README b/subdirmk/README index d43c04b..10117be 100644 --- a/subdirmk/README +++ b/subdirmk/README @@ -189,8 +189,8 @@ empty string). &!STUFF changes the escape sequence from & to literally STUFF STUFF may be any series of of non-whitespace characters, - and is terminated by EOL or lwsp. STUFF and the lwsp - is discarded. + and is terminated by EOL or lwsp. &!STUFF and the lwsp + are discarded. After this, write STUFF instead of &, everywhere. The effect is global and lasts until the next setting. @@ -198,7 +198,7 @@ empty string). it back before using &:include. Notably - STUFFSTUFF => STUFF + STUFFSTUFF => STUFFSTUFF \STUFF => STUFF STUFF!& set escape back to & -- 2.30.2 From 1c1948504ec808f30a0fd631d6cbc11ebd7ab371 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Wed, 13 Nov 2019 18:08:18 +0000 Subject: [PATCH 05/16] more docs changes Signed-off-by: Ian Jackson --- subdirmk/README | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/subdirmk/README b/subdirmk/README index 10117be..95cdd69 100644 --- a/subdirmk/README +++ b/subdirmk/README @@ -203,9 +203,8 @@ empty string). STUFF!& set escape back to & &TARGETS_things - Handled specially. If mentioned, declares that - this subdirectory ought to have a target `things'. - (`all' if not specified). The rule will be + Handled specially. If mentioned, declares that this + subdir ought to have a target `things'. The rule will be &/things:: $(&TARGETS_things) You may extend it by adding more :: rules for the target, @@ -213,13 +212,14 @@ empty string). &TARGETS_check += & test-passed.stamp It is important to mention &TARGETS_things at least once in - the context of each applicable directory, because it arranges - that the *parent* will also have a `things' target which - recursively implies this directory's `things'. + the context of each applicable directory, because doing so + arranges that the *parent* will also have a `things' target + which recursively implies this directory's `things'. Must be spelled exactly &TARGETS_things. &_TARGETS_things, - for example, does not work. But mentioning it in a #-comment - *does* work because the & filter does not care about comments. + for example, is not magic. But mentioning &TARGETS_things in + a #-comment *does* work because the & filter does not care + about comments. `all' is extra special: every directory has an `all' target, which corresponds to &TARGETS. -- 2.30.2 From 53819b44e7c74b0a991d41fd96d706861051799d Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Wed, 13 Nov 2019 18:48:42 +0000 Subject: [PATCH 06/16] subdirmk/autogen.sh: Remove myself as copyright holder I had nothing to do with this. My original proof-of-concept suggested that developers use `autoreconf' to bootstrap the working tree. Signed-off-by: Mark Wooding --- subdirmk/autogen.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/subdirmk/autogen.sh b/subdirmk/autogen.sh index 4e361fc..e28e80e 100755 --- a/subdirmk/autogen.sh +++ b/subdirmk/autogen.sh @@ -1,6 +1,5 @@ #!/bin/sh # subdirmk, autogen.sh (conventional autoconf invocation script) -# Copyright 2019 Mark Wooding # Copyright 2019 Ian Jackson # SPDX-License-Identifier: LGPL-2.0-or-later set -e -- 2.30.2 From 32f2d681625cb2d4bde2d155e5b95ec12d0e753d Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Wed, 13 Nov 2019 18:42:18 +0000 Subject: [PATCH 07/16] subdirmk/generate: Supply default target if none given in command line If you just run `make' then `$(MAKECMDGOALS)' is empty, so we get the default target of `main.mk'. Nothing is set up by `usual.mk', so we end up with `$(srcdir)/configure' established by `regen.mk'. Instead, propagate `all' to the `main.mk' makefile. Maybe this should be configurable, though I don't think that'll be very useful in real life. Signed-off-by: Mark Wooding --- subdirmk/generate | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subdirmk/generate b/subdirmk/generate index 8669864..fbf07d4 100755 --- a/subdirmk/generate +++ b/subdirmk/generate @@ -102,7 +102,7 @@ default: all %: FORCE-ALWAYS-RUN \@: Makefile FORCE-ALWAYS-RUN: - \$(MAKE) -C $cd -f main.mk \$(addprefix ${dir_prefix},\$(MAKECMDGOALS)) + \$(MAKE) -C $cd -f main.mk \$(addprefix ${dir_prefix},\$(or \$(MAKECMDGOALS),all)) .SUFFIXES: END } -- 2.30.2 From 9bad147b1a52bbef3021fb3f9100b4fa52d0dce6 Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Wed, 13 Nov 2019 19:00:23 +0000 Subject: [PATCH 08/16] subdirmk/regen.mk.in: Trim `$(srcdir)/' prefix from output makefile names This doesn't make a difference if you're doing in-tree builds, of course. Signed-off-by: Mark Wooding --- subdirmk/regen.mk.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/subdirmk/regen.mk.in b/subdirmk/regen.mk.in index 65d75c2..948ef4e 100644 --- a/subdirmk/regen.mk.in +++ b/subdirmk/regen.mk.in @@ -38,9 +38,9 @@ main.mk $(MAKEFILES): .makefiles.stamp ; $(filter-out Subdir.sd.mk %/Subdir.sd.mk \ %.mk.in \ , $?),, \ - $(sort \ + $(patsubst $(top_srcdir)/%,%, $(sort \ $(patsubst %.sd.mk,%.mk,$(filter %.sd.mk,$?)) \ - $(patsubst %.mk.in,%.mk,$(filter %.mk.in,$?)))) + $(patsubst %.mk.in,%.mk,$(filter %.mk.in,$?))))) touch $@ realclean:: clean -- 2.30.2 From b549db60e5f03a7b3e4a3631bd9112e77a7eab4f Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Wed, 13 Nov 2019 19:08:46 +0000 Subject: [PATCH 09/16] subdirmk/usual.mk.in: Fix `VPATH' setting This file isn't processed through `generate', so `&' doesn't mean anything special. Use `$(top_srcdir)' here because we can rely on that being established by `main.mk'. Signed-off-by: Mark Wooding --- subdirmk/usual.mk.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subdirmk/usual.mk.in b/subdirmk/usual.mk.in index 00c48fe..97f99e7 100644 --- a/subdirmk/usual.mk.in +++ b/subdirmk/usual.mk.in @@ -3,7 +3,7 @@ # Copyright 2019 Ian Jackson # SPDX-License-Identifier: LGPL-2.0-or-later -VPATH = &^ +VPATH = $(top_srcdir) prefix = @prefix@ exec_prefix = @exec_prefix@ -- 2.30.2 From b0ec8ee72de621b16191b1a06612c60156ec667e Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Wed, 13 Nov 2019 19:24:41 +0000 Subject: [PATCH 10/16] subdirmk/generate: Make `FORCE-ALWAYS-RUN' be `.PHONY' Otherwise `touch FORCE-ALWAYS-RUN' stops your build from working, which seems a shame, even though nobody should ever want to do this. Signed-off-by: Mark Wooding --- subdirmk/generate | 1 + 1 file changed, 1 insertion(+) diff --git a/subdirmk/generate b/subdirmk/generate index fbf07d4..7fc3809 100755 --- a/subdirmk/generate +++ b/subdirmk/generate @@ -104,6 +104,7 @@ default: all Makefile FORCE-ALWAYS-RUN: \$(MAKE) -C $cd -f main.mk \$(addprefix ${dir_prefix},\$(or \$(MAKECMDGOALS),all)) .SUFFIXES: +.PHONY: FORCE-ALWAYS-RUN END } -- 2.30.2 From 51d204f72e2c292c0c6751109e54c4546d1ab41f Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Wed, 13 Nov 2019 19:17:40 +0000 Subject: [PATCH 11/16] subdirmk/*: Some simple whitespace cleanups Zap trailing whitespace, and spaces-followed-by-tabs. This commit is empty in `git show -b'. Signed-off-by: Mark Wooding --- subdirmk/README | 6 +++--- subdirmk/generate | 2 +- subdirmk/regen.mk.in | 10 +++++----- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/subdirmk/README b/subdirmk/README index d43c04b..9a53f93 100644 --- a/subdirmk/README +++ b/subdirmk/README @@ -14,7 +14,7 @@ style is not very ergonomic. The main difficulties are: - constantly having to write out long file and directory names - the lack of a per-directory make variable namespace means long make variables (or namespace clashes) - - it is difficult to arrange that one can cd to a subdirectory + - it is difficult to arrange that one can cd to a subdirectory and say `make all' and have something reasonable happen (to wit, build an appropriate subset) @@ -151,8 +151,8 @@ we describe the expansion at the top level, which is often a special case (in general in variable names we call that TOP rather than the empty string). -&CAPS => sub_dir_CAPS or TOP_CAPS -&lc => sub/dir/lc or lc +&CAPS => sub_dir_CAPS or TOP_CAPS +&lc => sub/dir/lc or lc Here CAPS is any ASCII letter A-Z and lc is a-z. The assumption is that filenames are usually lowercase and variables usually uppercase. Otherwise, use another syntax: diff --git a/subdirmk/generate b/subdirmk/generate index 7fc3809..8a5daa6 100755 --- a/subdirmk/generate +++ b/subdirmk/generate @@ -252,7 +252,7 @@ sub process_subtree ($$) { } print O "\n"; } - + return @targets; } diff --git a/subdirmk/regen.mk.in b/subdirmk/regen.mk.in index 948ef4e..bd56a24 100644 --- a/subdirmk/regen.mk.in +++ b/subdirmk/regen.mk.in @@ -4,11 +4,11 @@ # SPDX-License-Identifier: LGPL-2.0-or-later CONFIGURE ?= configure -CONFIGURE_AC ?= $(CONFIGURE).ac -CONFIG_STATUS ?= config.status +CONFIGURE_AC ?= $(CONFIGURE).ac +CONFIG_STATUS ?= config.status -CONFIGURE_ACS += $(CONFIGURE_AC) -CONFIGURE_ACS += subdirmk/subdirmk.ac +CONFIGURE_ACS += $(CONFIGURE_AC) +CONFIGURE_ACS += subdirmk/subdirmk.ac $(top_srcdir)/$(CONFIGURE): $(addprefix $(top_srcdir)/,$(CONFIGURE_ACS)) cd $(top_srcdir) && autoconf @@ -22,7 +22,7 @@ MAKEFILE_TEMPLATES += $(addprefix $(top_srcdir)/, $(addsuffix .in, \ )) main.mk $(MAKEFILES): .makefiles.stamp ; -.makefiles.stamp: \ +.makefiles.stamp: \ $(top_srcdir)/subdirmk/generate \ $(CONFIG_STATUS) \ $(MAKEFILE_TEMPLATES) -- 2.30.2 From 1aa5fc43e51f61b1b5ca50f9e21e1909f3c716bf Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Wed, 13 Nov 2019 22:02:55 +0000 Subject: [PATCH 12/16] More docs updates Signed-off-by: Ian Jackson --- subdirmk/README | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/subdirmk/README b/subdirmk/README index 1b249fd..8dfebc6 100644 --- a/subdirmk/README +++ b/subdirmk/README @@ -5,7 +5,7 @@ Introduction ------------ Peter Miller's 1997 essay _Recursive Make Considered Harmful_ -persuasively argues that it is better to arrannge to have a single +persuasively argues that it is better to arrange to have a single make invocation with the project's complete dependency tree, rather than the currently conventional `$(MAKE) -C subdirectory' approach. @@ -42,9 +42,9 @@ The Subdir.sd.mk's are filtered, fed through autoconf in the usual way (for @..@-substitutions) and included by one autogenerated toplevel makefile. -So all of the input is combined and passed to one make invocation. (A -corollary is that there is no enforcement of the namespacing: -discipline is required to prefix relevant variable names with &, etc. +So all of the input is combined and passed to one make invocation. +(A corollary is that there is no enforcement of the namespacing: +discipline is required to prefix relevant variable names with &, etc.) Each subdirectory is also provided with an autogenerated `Makefile' which exists purely to capture ordinary make invocations and arrange @@ -67,7 +67,7 @@ Each subdirectory has its own `all' target. For example a subdirectory `src' has a target `src/all'. The rules for these are automatically generated from the settings of the per-directory &TARGETS variables. &TARGETS is magic in this way. (In -src/Subdir.sd.mk, &TARGES of course refers to a make variable called +src/Subdir.sd.mk, &TARGETS of course refers to a make variable called src_TARGETS.) The `all' target in a parent directory is taken to imply the `all' @@ -77,8 +77,9 @@ just type `make' in the toplevel, you are asking for `&all' (/all) for every directory in the project. In a parallel build, the rules for all these various subdirectory -targets may be in run in parallel: there is only one `make' -invocation at a time. +targets may be in run in parallel: there is only one `make' invocation +at a time. There is no sequencing between subdirectories, only been +individual targets (as specified according to their dependencies). You can define other per-directory recursive targets too: simply mention (usually, by setting) the variable &TARGETS_zonk, or whatever. @@ -109,6 +110,10 @@ If want to set global variables, such as CC, that should only be done once. You can put them in your top-level Subdir.sd.mk, or a separate file you `include' and declare using SUBDIRMK_MAKEFILES. +If you need different settings of variables like CC for different +subdirectories, you should probably do that with target-specific +variable settings. See the info node `(make) Target-specific'. + Subdirectory templates `.sd.mk' vs plain autoconf templates `.mk.in' -------------------------------------------------------------------- @@ -174,7 +179,7 @@ empty string). Introduced by & followed by lwsp (space or tab). Each lwsp-separated non-ws word is prefixed by &/ &^/ &~/ respectively. No other & escapes are recognised. - This processing continues until a & preceded by lwsp, + This processing continues until & preceded by lwsp, or until EOL (the end of the line), or \ then EOL. &: .... @@ -183,6 +188,7 @@ empty string). &:include filename filename should usually be foo.sd.mk &:-include filename tolerate nonexistent file + filenames are relative to $(top_srcdir) &! disables & until EOL (and then disappears) -- 2.30.2 From 975c0d74cb53a3c26850329274c9e533827c495d Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Wed, 13 Nov 2019 22:03:57 +0000 Subject: [PATCH 13/16] New &# feature Signed-off-by: Ian Jackson --- subdirmk/README | 3 +++ subdirmk/generate | 2 ++ 2 files changed, 5 insertions(+) diff --git a/subdirmk/README b/subdirmk/README index 8dfebc6..cc309f6 100644 --- a/subdirmk/README +++ b/subdirmk/README @@ -192,6 +192,9 @@ empty string). &! disables & until EOL (and then disappears) +&# delete everything to end of line + (useful if the RHS contains unrecognise & constructions) + &!STUFF changes the escape sequence from & to literally STUFF STUFF may be any series of of non-whitespace characters, diff --git a/subdirmk/generate b/subdirmk/generate index 8a5daa6..486bdc5 100755 --- a/subdirmk/generate +++ b/subdirmk/generate @@ -165,6 +165,8 @@ sub process_input_mk ($$$$$$$$) { s{(?<=[ \t])(?=\S)(?!\\\s*$)}{$prefix}g; o $_; $_ = $after; + } elsif (s{^\#}{}) { + $_ = ''; } elsif (s{^![ \t]+}{}) { o $_; $_ = ''; -- 2.30.2 From 6600b10418c5c38d43bf6c732724123ed34779b6 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Wed, 13 Nov 2019 22:04:32 +0000 Subject: [PATCH 14/16] Introduce CDEPS_CFLAGS so without cdeps.sd.mk you don't get .*.d Signed-off-by: Ian Jackson --- subdirmk/cdeps.sd.mk | 2 ++ subdirmk/usual.mk.in | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/subdirmk/cdeps.sd.mk b/subdirmk/cdeps.sd.mk index c898cc0..6ba0bbb 100644 --- a/subdirmk/cdeps.sd.mk +++ b/subdirmk/cdeps.sd.mk @@ -3,6 +3,8 @@ # Copyright 2019 Ian Jackson # SPDX-License-Identifier: LGPL-2.0-or-later +CDEPS_CFLAGS ?= -MD -MF $(*D)/.$(*F).d + &DEPFILES += $(foreach b,$(patsubst %.o,%,$(&OBJECTS)), \ $(dir $b).$(notdir $b).d) -include $(&DEPFILES) diff --git a/subdirmk/usual.mk.in b/subdirmk/usual.mk.in index 97f99e7..c40a18f 100644 --- a/subdirmk/usual.mk.in +++ b/subdirmk/usual.mk.in @@ -19,7 +19,7 @@ LIBS ?= @LIBS@ LINK ?= $(CC) -o$@ $(CFLAGS) $(LDFLAGS) AR ?= ar -COMPILE ?= $(CC) -c -o$@ -MD -MF $(*D)/.$(*F).d $(DEFS) $(INCLUDES) $(CFLAGS) +COMPILE ?= $(CC) -c -o$@ $(CDEPS_CFLAGS) $(DEFS) $(INCLUDES) $(CFLAGS) %.o: %.c $(COMPILE) $< -- 2.30.2 From a2d0da0b0b2f40319d8787b98f5198f78303f85d Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Wed, 13 Nov 2019 22:11:47 +0000 Subject: [PATCH 15/16] Move knowledge of DEPFILES into cdeps.sd.mk No overall functional change. Signed-off-by: Ian Jackson --- subdirmk/cdeps.sd.mk | 1 + subdirmk/clean.sd.mk | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/subdirmk/cdeps.sd.mk b/subdirmk/cdeps.sd.mk index 6ba0bbb..5d58b6b 100644 --- a/subdirmk/cdeps.sd.mk +++ b/subdirmk/cdeps.sd.mk @@ -9,3 +9,4 @@ CDEPS_CFLAGS ?= -MD -MF $(*D)/.$(*F).d $(dir $b).$(notdir $b).d) -include $(&DEPFILES) +&CLEAN += $(&DEPFILES) diff --git a/subdirmk/clean.sd.mk b/subdirmk/clean.sd.mk index 7df2e21..e235fcd 100644 --- a/subdirmk/clean.sd.mk +++ b/subdirmk/clean.sd.mk @@ -5,7 +5,6 @@ &CLEAN += & *~ *.tmp &CLEAN += $(&OBJECTS) -&CLEAN += $(&DEPFILES) &CLEAN += $(&TARGETS) # &TARGETS_clean -- 2.30.2 From 5c99a7202fe6895190cbc7e3fdc0948e04ab73d1 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Wed, 13 Nov 2019 22:12:10 +0000 Subject: [PATCH 16/16] Documentation for clean.sd.mk and cdeps.sd.mk Signed-off-by: Ian Jackson --- subdirmk/cdeps.sd.mk | 12 ++++++++++++ subdirmk/clean.sd.mk | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/subdirmk/cdeps.sd.mk b/subdirmk/cdeps.sd.mk index 5d58b6b..402e687 100644 --- a/subdirmk/cdeps.sd.mk +++ b/subdirmk/cdeps.sd.mk @@ -3,6 +3,18 @@ # Copyright 2019 Ian Jackson # SPDX-License-Identifier: LGPL-2.0-or-later +&# Usage: +&# &:include subdirmk/cdeps.sd.mk +&# (probably in Perdir.sd.mk) +&# +&# Arranges for automatic #include dependency tracking for +&# C compilation. The compiler is asked to write the dependencies to +&# .*.d and these are automatically included. +&# +&# There is a bug: if a #included file is deleted and all references +&# in .c files to it removed, `make' will complain that it is needed +&# and can't be built. `make clean' will fix this. + CDEPS_CFLAGS ?= -MD -MF $(*D)/.$(*F).d &DEPFILES += $(foreach b,$(patsubst %.o,%,$(&OBJECTS)), \ diff --git a/subdirmk/clean.sd.mk b/subdirmk/clean.sd.mk index e235fcd..08f8dcc 100644 --- a/subdirmk/clean.sd.mk +++ b/subdirmk/clean.sd.mk @@ -3,6 +3,18 @@ # Copyright 2019 Ian Jackson # SPDX-License-Identifier: LGPL-2.0-or-later +&# Usage: +&# &:include subdirmk/clean.sd.mk +&# (probably in Perdir.sd.mk) +&# +&# Provides a per-directory `clean' target, which deletes all the files +&# in &CLEAN. &OBJECTS, &DEPFILES and &TARGETS are automatically deleted. +&# +&# If you want to delete a directory, extend the target with +&# &/clean:: +&# $(RM) -r somethingn +&# ($(RM) conventionally contains `-f'.) + &CLEAN += & *~ *.tmp &CLEAN += $(&OBJECTS) &CLEAN += $(&TARGETS) -- 2.30.2