xtra: Allow manually specifying packed array name.
[dxcommon.git] / snippet / glconfig.mk
blob42d024eed3ba9673d24bf2206a4cf2275b595520
1 # Copyright © 2011-2013, 2019, 2021-2023 Nick Bowler
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:
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.
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.
16 GLCONFIG = @GLSRC@/glconfig.h
17 GLCAT = cat /dev/null
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 ' $<;
23 gnulib_headers += $(GLCONFIG)
25 # This suffix rule triggers symbol generation only on demand. Dependencies are
26 # not tracked directly, so it must remain phony and thus not create the target.
27 .c.glsym:
28 $(GLSYM_V) $(MKDIR_P) $(@D)/.syms
29 $(AM_V_at) depfile=$(@D)/.syms/$(*F).deps \
30 source=$< object=$(GLCONFIG) $(CCDEPMODE) \
31 $(depcomp) $(COMPILE) -DNO_GLCONFIG \
32 -c -o $(@D)/.syms/$(*F).o $<
33 $(AM_V_at) $(SHELL) $(top_builddir)/exported.sh \
34 $(@D)/.syms/$(*F).o > $(@D)/.syms/$(*F).sym
36 clean-local: clean-glconfig
37 clean-glconfig:
38 @for sym in $(libgnu_la_SOURCES) $(EXTRA_libgnu_la_SOURCES); do \
39 symdir=`expr "$$sym" : '\(.*/\)'`.syms; \
40 if test -d "$$symdir"; then \
41 echo "rm -rf $$symdir"; rm -rf "$$symdir"; \
42 fi; \
43 done
44 .PHONY: clean-glconfig
46 # Produce the list of all currently-enabled gnulib object files to assist with
47 # external build helpers.
48 GLCONFIG_OBJECTS = &1
49 glconfig-objects:
50 @:; { \
51 for f in $(gnulib_objects); do echo "$$f"; done; \
52 } >$(GLCONFIG_OBJECTS)
53 .PHONY: glconfig-objects
55 # The config header requires compilation of all gnulib object files via the
56 # .glsym rule above. However, it cannot depend on those build products
57 # directly because they are phony, and would make this header never up-to-date.
59 # Thus, we use a recursive make call to regenerate the header, which avoids
60 # the need to list prerequisites.
62 # Since GNU make does not appear to allow the target of a suffix rule to be
63 # marked .PHONY, we also delete the .glsym files here just in case they were
64 # created for some reason (e.g., make -t).
65 $(GLCONFIG): $(gnulib_core_headers)
66 -$(AM_V_at) rm -f $(gnulib_symfiles)
67 $(AM_V_at) $(MAKE) $(AM_MAKEFLAGS) glconfig-gen
68 $(AM_V_GEN) mv -f $@.tmp $@
69 CLEANFILES += $(GLCONFIG)
71 # The glconfig-gen target is intended only for use in recursive make
72 # invocations.
73 glconfig-gen: $(gnulib_symfiles)
74 $(AM_V_at) $(MKDIR_P) @GLSRC@
75 $(AM_V_at) depfiles=; symfiles=; \
76 for sym in $(gnulib_symfiles); do \
77 symdir=`expr "$$sym" : '\(.*/\)'`; \
78 symfile=`expr "$$sym" : '.*/\(.*\)' || printf '%s\n' "$$sym"`; \
79 symbase=$$symdir.syms/`expr "$$symfile" : '\(.*\)\..*'`; \
80 test -f "$$symbase.deps" && \
81 depfiles="$$depfiles $$symbase.deps"; \
82 symfiles="$$symfiles $$symbase.sym"; \
83 done; \
84 $(glconfig_nodeps) \
85 || $(GLCAT) $$depfiles > @GLSRC@/$(DEPDIR)/glconfig.Ph || exit; \
86 $(GLCAT) $$symfiles | sed 's/.*/#define & $(GLSYM_PREFIX)&/' \
87 >$(GLCONFIG).tmp
88 .PHONY: glconfig-gen
90 if AMDEP
91 glconfig_nodeps = false
92 @am__include@ @am__quote@@GLSRC@/$(DEPDIR)/glconfig.Ph@am__quote@@dx_include_marker@
93 else
94 glconfig_nodeps = true
95 endif
97 # Automake 1.16 and newer use make rules to generate the dependency stubs.
98 # we must hook those which is kind of annoying to do. This should be harmless
99 # on previous versions which generate the stubs directly in config.status.
100 @dx_depfiles_target@: @GLSRC@/$(DEPDIR)/glconfig.Ph
101 @GLSRC@/$(DEPDIR)/glconfig.Ph:
102 @$(MKDIR_P) $(@D)
103 @echo '# dummy' >$@-t && mv -f $@-t $@
104 DISTCLEANFILES += @GLSRC@/$(DEPDIR)/glconfig.Ph