1 # subdirmk - rules for regenerating makefiles etc.
2 # Copyright 2019 Mark Wooding
3 # Copyright 2019 Ian Jackson
4 # SPDX-License-Identifier: LGPL-2.0-or-later
5 # There is NO WARRANTY.
8 # include subdirmk/regen.mk
9 # (probably in toplevel Dir.sd.mk)
11 # Arranges that config.status is automatically rerun to update
12 # makefiles from templates, whenever a template *.sd.mk or *.mk.in is
13 # edited; and that autoconf is rerun if configure's inputs are edited.
15 # If you add includes to configure.ac, add them to CONFIGURE_ACS.
17 # Makefiles updated by config.status and passed to SUBDIRMK_MAKEFILES
18 # in configure.ac are automatically handled too. If you have other
19 # files updated by config.status (eg, the output of autoheader) you
20 # need to put them in CONFIG_STATUS_OUTPUTS (before your inclusion
23 # Also provides a `realclean::' target at the toplevel which deletes
24 # the autoconf output. (This is suitable for being part of a recursive
25 # target creaed by setting &TARGETS_realclean in appropriate .sd.mk.)
27 CONFIGURE ?= configure
28 CONFIGURE_AC ?= $(CONFIGURE).ac
29 CONFIG_STATUS ?= config.status
31 CONFIGURE_ACS += $(CONFIGURE_AC)
32 CONFIGURE_ACS += subdirmk/subdirmk.ac
34 # To turn on debugging here, export SUBDIRMK_REGEN_NDEBUG=''
35 SUBDIRMK_REGEN_NDEBUG ?= @
37 $(top_srcdir)/$(CONFIGURE): $(addprefix $(top_srcdir)/,$(CONFIGURE_ACS))
38 cd $(top_srcdir) && autoconf
40 $(CONFIG_STATUS): $(top_srcdir)/$(CONFIGURE)
41 ./$(CONFIG_STATUS) --recheck
43 # generate will add all its own inputs and outputs to these variables
44 SUBDIRMK_MAKEFILES += @_SUBDIRMK_MAKEFILES@
45 MAKEFILE_TEMPLATES += $(addprefix $(top_srcdir)/, $(addsuffix .in, \
46 @_SUBDIRMK_MAKEFILES@ \
49 main.mk $(SUBDIRMK_MAKEFILES) $(CONFIG_STATUS_OUTPUTS): .makefiles.stamp
50 $(SUBDIRMK_REGEN_NDEBUG): REGEN STAMP CAUSES TARGET=$@
53 $(top_srcdir)/subdirmk/generate \
56 # This filtering arranges that we can often run config.status to
57 # generate only particular output files. We look for *inputs* that
58 # have changed. If the only inputs that have changed are ones that we
59 # know affect only one output (Dir.sd.mk, Final.sd.mk and *.mk.in),
60 # we pass config.status the corresponding output file names.
61 # Otherwise we pass nothing and config.status does them all. We need
62 # to mention Dir.sd.mk twice because if $(top_srcdir) is `.', make
63 # elides the directory part from $?. Similarly but not identically
65 $(SUBDIRMK_REGEN_NDEBUG): REGEN STAMP WANTS DEPS=$?
66 ./$(CONFIG_STATUS) $(if \
67 $(filter-out Dir.sd.mk %/Dir.sd.mk \
68 Final.sd.mk $(top_srcdir)/Final.sd.mk \
71 $(patsubst $(top_srcdir)/%,%, $(sort \
72 $(patsubst %.sd.mk,%.mk,$(filter %.sd.mk,$?)) \
73 $(patsubst %.mk.in,%.mk,$(filter %.mk.in,$?)))))
77 $(RM) config.status config.log
78 $(RM) main.mk $(SUBDIRMK_MAKEFILES) @_SUBDIRMK_MAKEFILES@
79 $(RM) $(addsuffix Makefile,$(dir $(SUBDIRMK_MAKEFILES)))
81 -include $(ALL_DEPFILES)