chiark / gitweb /
subdirmk: Go back to ^ and ~
[subdirmk.git] / regen.mk.in
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
6 # Usage:
7 #   include subdirmk/regen.mk
8 # (probably in toplevel Subdir.sd.mk)
9 #
10 # Arranges that config.status is automatically rerun to update
11 # makefiles from templates, whenever a template *.sd.mk or *.mk.in is
12 # edited; and that autoconf is rerun if configure's inputs are edited.
13 #
14 # If you add includes to configure.ac, add them to CONFIGURE_ACS.
15 #
16 # Also provides a `realclean::' target at the toplevel which deletes
17 # the autoconf output.  This may be made into a recursive target
18 # by mentioning &TARGETS_realclean in appropriate .sd.mk.
19
20 CONFIGURE       ?= configure
21 CONFIGURE_AC    ?= $(CONFIGURE).ac
22 CONFIG_STATUS   ?= config.status
23
24 CONFIGURE_ACS   += $(CONFIGURE_AC)
25 CONFIGURE_ACS   += subdirmk/subdirmk.ac
26
27 $(top_srcdir)/$(CONFIGURE): $(addprefix $(top_srcdir)/,$(CONFIGURE_ACS))
28         cd $(top_srcdir) && autoconf
29
30 $(CONFIG_STATUS): $(top_srcdir)/$(CONFIGURE)
31         ./$(CONFIG_STATUS) --recheck
32
33 # Normally, generate will add all the inputs to MAKEFILE_TEMPLATES.
34 MAKEFILE_TEMPLATES += $(addprefix $(top_srcdir)/, $(addsuffix .in, \
35         @_SUBDIRMK_MAKEFILES@ \
36         ))
37
38 main.mk $(SUBDIRMK_MAKEFILES) $(CONFIG_STATUS_OUTPUTS): .makefiles.stamp ;
39 .makefiles.stamp:                                               \
40                 $(top_srcdir)/subdirmk/generate                 \
41                 $(CONFIG_STATUS)                                \
42                 $(MAKEFILE_TEMPLATES)
43 # This filtering arranges that we can often run config.status to
44 # generate only particular output files.  We look for *inputs* that
45 # have changed.  If the only inputs that have changed are ones that we
46 # know affect only one output (Subdir.mk.in and regen.mk.in), we pass
47 # config.status the corresponding output file names.  Otherwise we
48 # pass nothing and config.status does them all.  We need to mention
49 # regen.mk.in twice because if $(top_srcdir) is `.', make elides the
50 # directory part from $?.
51         ./$(CONFIG_STATUS) $(if                                 \
52                 $(filter-out Subdir.sd.mk %/Subdir.sd.mk        \
53                              %.mk.in                            \
54                         , $?),,                                 \
55                 $(patsubst $(top_srcdir)/%,%, $(sort            \
56                         $(patsubst %.sd.mk,%.mk,$(filter %.sd.mk,$?)) \
57                         $(patsubst %.mk.in,%.mk,$(filter %.mk.in,$?)))))
58         touch $@
59
60 realclean:: clean
61         $(RM) config.status config.log
62         $(RM) main.mk $(SUBDIRMK_MAKEFILES) @_SUBDIRMK_MAKEFILES@
63         $(RM) $(addsuffix Makefile,$(dir $(SUBDIRMK_MAKEFILES)))
64
65 -include $(ALL_DEPFILES)