]> git.draconx.ca Git - dxcommon.git/blob - snippet/glconfig.mk
Fix depfiles compatibility with modern Automake.
[dxcommon.git] / snippet / glconfig.mk
1 # Copyright © 2011-2013,2019 Nick Bowler
2 #
3 # Automake fragment to generate a Gnulib config header to rewrite exported
4 # symbols.  This fragment relies on the Gnulib makefile postprocessing done by
5 # fix-gnulib.pl.  Furthermore, the following additions to configure.ac may be
6 # required:
7 #
8 #   * Add AM_PROC_CC_C_O to configure.ac
9 #   * Pass the desired symbol prefix to DX_GLSYM_PREFIX in configure.ac,
10 #     after including the fix-gnulib.pl output.
11 #
12 # License WTFPL2: Do What The Fuck You Want To Public License, version 2.
13 # This is free software: you are free to do what the fuck you want to.
14 # There is NO WARRANTY, to the extent permitted by law.
15
16 GLCONFIG = @GLSRC@/glconfig.h
17 GLCAT    = cat /dev/null
18
19 GLSYM_V   = $(GLSYM_V_@AM_V@)
20 GLSYM_V_  = $(GLSYM_V_@AM_DEFAULT_V@)
21 GLSYM_V_0 = @printf '  %$(DX_ALIGN_V)s %s\n' 'GLSYM   ' $<;
22
23 gnulib_symfiles = $(gnulib_lt_objects:.lo=.glsym)
24 gnulib_headers += $(GLCONFIG)
25
26 # This suffix rule triggers symbol generation only on demand.  Dependencies are
27 # not tracked directly, so it must remain phony and thus not create the target.
28 .c.glsym:
29         $(GLSYM_V) $(MKDIR_P) $(@D)/.syms
30         $(AM_V_at) depfile=$(@D)/.syms/$(*F).deps \
31                 source=$< object=$(GLCONFIG) $(CCDEPMODE) \
32                 $(depcomp) $(COMPILE) -DNO_GLCONFIG \
33                 -c -o $(@D)/.syms/$(*F).o $<
34         $(AM_V_at) $(SHELL) $(top_builddir)/exported.sh \
35                 $(@D)/.syms/$(*F).o > $(@D)/.syms/$(*F).sym
36 $(gnulib_symfiles): $(gnulib_core_headers)
37
38 clean-local: clean-glconfig
39 clean-glconfig:
40         @for sym in $(libgnu_la_SOURCES) $(EXTRA_libgnu_la_SOURCES); do \
41                 symdir=`expr "$$sym" : '\(.*/\)'`.syms; \
42                 if test -d "$$symdir"; then \
43                         echo "rm -rf $$symdir"; rm -rf "$$symdir"; \
44                 fi; \
45         done
46 .PHONY: clean-glconfig
47
48 # The config header requires compilation of all gnulib object files via the
49 # .glsym rule above.  However, it cannot depend on those build products
50 # directly because they are phony, and would make this header never up-to-date.
51 #
52 # Thus, we use a recursive make call to regenerate the header, which avoids
53 # the need to list prerequisites.
54 #
55 # Since GNU make does not appear to allow the target of a suffix rule to be
56 # marked .PHONY, we also delete the .glsym files here just in case they were
57 # created for some reason (e.g., make -t).
58 $(GLCONFIG): $(gnulib_core_headers)
59         -$(AM_V_at) rm -f $(gnulib_symfiles)
60         $(AM_V_at) $(MAKE) $(AM_MAKEFLAGS) glconfig-gen
61         $(AM_V_GEN) mv -f $@.tmp $@
62 CLEANFILES += $(GLCONFIG)
63
64 # The glconfig-gen target is intended only for use in recursive make
65 # invocations.
66 glconfig-gen: $(gnulib_symfiles)
67         $(AM_V_at) depfiles=; symfiles=; \
68         for sym in $(gnulib_symfiles); do \
69                 symdir=`expr "$$sym" : '\(.*/\)'`; \
70                 symfile=`expr "$$sym" : '.*/\(.*\)' || printf '%s\n' "$$sym"`; \
71                 symbase=$$symdir.syms/`expr "$$symfile" : '\(.*\)\..*'`; \
72                 test -f "$$symbase.deps" && \
73                         depfiles="$$depfiles $$symbase.deps"; \
74                 symfiles="$$symfiles $$symbase.sym"; \
75         done; \
76                 $(GLCAT) $$depfiles > @GLSRC@/$(DEPDIR)/glconfig.Ph && \
77                 $(GLCAT) $$symfiles | sed 's/.*/#define & $(GLSYM_PREFIX)&/' \
78                         > $(GLCONFIG).tmp
79 .PHONY: glconfig-gen
80
81 @AMDEP_TRUE@@am__include@ @am__quote@@GLSRC@/$(DEPDIR)/glconfig.Ph@am__quote@
82
83 # Automake 1.16 and newer use make rules to generate the dependency stubs.
84 # we must hook those which is kind of annoying to do.  This should be harmless
85 # on previous versions which generate the stubs directly in config.status.
86 _dx_glconfig_depfiles = am--depfiles
87 $(_dx_glconfig_depfiles): @GLSRC@/$(DEPDIR)/glconfig.Ph
88 @GLSRC@/$(DEPDIR)/glconfig.Ph:
89         @$(MKDIR_P) $(@D)
90         @echo '# dummy' >$@-t && mv -f $@-t $@
91 DISTCLEANFILES += @GLSRC@/$(DEPDIR)/glconfig.Ph