chiark / gitweb /
tests/filter/check: Capture generate's stderr
[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 Dir.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 # Makefiles updated by config.status and passed to SUBDIRMK_MAKEFILES
17 # in configure.ac are automatically handled too.  If you have other
18 # files updated by config.status (eg, the output of autoheader) you
19 # need to put them in CONFIG_STATUS_OUTPUTS (before your inclusion
20 # of regen.mk).
21 #
22 # Also provides a `realclean::' target at the toplevel which deletes
23 # the autoconf output.  (This is suitable for being part of a recursive
24 # target creaed by setting &TARGETS_realclean in appropriate .sd.mk.)
25
26 CONFIGURE       ?= configure
27 CONFIGURE_AC    ?= $(CONFIGURE).ac
28 CONFIG_STATUS   ?= config.status
29
30 CONFIGURE_ACS   += $(CONFIGURE_AC)
31 CONFIGURE_ACS   += subdirmk/subdirmk.ac
32
33 # To turn on debugging here, export SUBDIRMK_REGEN_NDEBUG=''
34 SUBDIRMK_REGEN_NDEBUG ?= @
35
36 $(top_srcdir)/$(CONFIGURE): $(addprefix $(top_srcdir)/,$(CONFIGURE_ACS))
37         cd $(top_srcdir) && autoconf
38
39 $(CONFIG_STATUS): $(top_srcdir)/$(CONFIGURE)
40         ./$(CONFIG_STATUS) --recheck
41
42 # generate will add all its own inputs and outputs to these variables
43 SUBDIRMK_MAKEFILES += @_SUBDIRMK_MAKEFILES@
44 MAKEFILE_TEMPLATES += $(addprefix $(top_srcdir)/, $(addsuffix .in, \
45         @_SUBDIRMK_MAKEFILES@ \
46         ))
47
48 main.mk $(SUBDIRMK_MAKEFILES) $(CONFIG_STATUS_OUTPUTS): .makefiles.stamp
49         $(SUBDIRMK_REGEN_NDEBUG): REGEN STAMP CAUSES TARGET=$@
50
51 .makefiles.stamp:                                               \
52                 $(top_srcdir)/subdirmk/generate                 \
53                 $(CONFIG_STATUS)                                \
54                 $(MAKEFILE_TEMPLATES)
55 # This filtering arranges that we can often run config.status to
56 # generate only particular output files.  We look for *inputs* that
57 # have changed.  If the only inputs that have changed are ones that we
58 # know affect only one output (Dir.sd.mk, Final.sd.mk and *.mk.in),
59 # we pass config.status the corresponding output file names.
60 # Otherwise we pass nothing and config.status does them all.  We need
61 # to mention Dir.sd.mk twice because if $(top_srcdir) is `.', make
62 # elides the directory part from $?.  Similarly but not identically
63 # Final.sd.mk.
64         $(SUBDIRMK_REGEN_NDEBUG): REGEN STAMP WANTS DEPS=$?
65         ./$(CONFIG_STATUS) $(if                                 \
66                 $(filter-out Dir.sd.mk %/Dir.sd.mk              \
67                              Final.sd.mk $(top_srcdir)/Final.sd.mk \
68                              %.mk.in                            \
69                         , $?),,                                 \
70                 $(patsubst $(top_srcdir)/%,%, $(sort            \
71                         $(patsubst %.sd.mk,%.mk,$(filter %.sd.mk,$?)) \
72                         $(patsubst %.mk.in,%.mk,$(filter %.mk.in,$?)))))
73         touch $@
74
75 realclean:: clean
76         $(RM) config.status config.log
77         $(RM) main.mk $(SUBDIRMK_MAKEFILES) @_SUBDIRMK_MAKEFILES@
78         $(RM) $(addsuffix Makefile,$(dir $(SUBDIRMK_MAKEFILES)))
79
80 -include $(ALL_DEPFILES)