3939# SCRIPTS_built -- script files (not binaries) to install into $PREFIX/bin,
4040# which need to be built first
4141# HEADERS -- files to install into $(includedir_server)/$MODULEDIR/$MODULE_big
42+ # HEADERS_built -- as above but built first
4243# HEADERS_$(MODULE) -- files to install into
4344# $(includedir_server)/$MODULEDIR/$MODULE; the value of $MODULE must be
4445# listed in MODULES or MODULE_big
46+ # HEADERS_built_$(MODULE) -- as above but built first
4547# REGRESS -- list of regression test cases (without suffix)
4648# REGRESS_OPTS -- additional switches to pass to pg_regress
4749# NO_INSTALLCHECK -- don't define an installcheck target, useful e.g. if
@@ -115,34 +117,62 @@ ifdef PG_CPPFLAGS
115117override CPPFLAGS := $(PG_CPPFLAGS ) $(CPPFLAGS )
116118endif
117119
120+ # get list of all names used with or without built_ prefix
121+ # note that use of HEADERS_built_foo will get both "foo" and "built_foo",
122+ # we cope with that later when filtering this list against MODULES.
123+ # If someone wants to name a module "built_foo", they can do that and it
124+ # works, but if they have MODULES = foo built_foo then they will need to
125+ # force building of all headers and use HEADERS_built_foo and
126+ # HEADERS_built_built_foo.
118127HEADER_alldirs := $(patsubst HEADERS_% ,% ,$(filter HEADERS_% , $(.VARIABLES ) ) )
128+ HEADER_alldirs += $(patsubst HEADERS_built_% ,% ,$(filter HEADERS_built_% , $(.VARIABLES ) ) )
129+
130+ # collect all names of built headers to use as a dependency
131+ HEADER_allbuilt =
119132
120133# HEADERS is an error in the absence of MODULE_big to provide a dir name
121134ifdef MODULE_big
122135ifdef HEADERS
123136HEADER_dirs := $(MODULE_big )
124- HEADERS_$(MODULE_big) = $(HEADERS )
137+ HEADER_unbuilt_$(MODULE_big) = $(HEADERS )
138+ HEADER_built_$(MODULE_big) = $(HEADERS_built )
139+ HEADER_allbuilt += $(HEADERS_built )
140+ else ifdef HEADERS_built
141+ HEADER_dirs := $(MODULE_big )
142+ HEADER_built_$(MODULE_big) = $(HEADERS_built )
143+ HEADER_allbuilt += $(HEADERS_built )
125144else
126- HEADER_dirs := $(filter $(MODULE_big ) ,$(HEADER_alldirs ) )
145+ # file might have used HEADERS_foo or HEADERS_built_foo, so check for those
146+ HEADER_dirs := $(if $(filter $(MODULE_big ) built_$(MODULE_big ) ,$(HEADER_alldirs ) ) ,$(MODULE_big ) )
147+ HEADER_unbuilt_$(MODULE_big) = $(HEADERS_$(MODULE_big ) )
148+ HEADER_built_$(MODULE_big) = $(HEADERS_built_$(MODULE_big ) )
149+ HEADER_allbuilt += $(HEADERS_built_$(MODULE_big ) )
127150endif
128151else
129152ifdef HEADERS
130153$(error HEADERS requires MODULE_big to be set)
131154endif
132- HEADER_dirs := $(filter $(MODULES ) ,$(HEADER_alldirs ) )
155+ # make list of modules that have either HEADERS_foo or HEADERS_built_foo
156+ HEADER_dirs := $(foreach m,$(MODULES ) ,$(if $(filter $(m ) built_$(m ) ,$(HEADER_alldirs ) ) ,$(m ) ) )
157+ # assign HEADER_unbuilt_foo and HEADER_built_foo, but make sure
158+ # that "built" takes precedence in the case of conflict, by removing
159+ # conflicting module names when matching the unbuilt name
160+ $(foreach m,$(filter-out $(addprefix built_,$(MODULES)),$(MODULES)),$(eval HEADER_unbuilt_$(m) = $$(HEADERS_$(m))))
161+ $(foreach m,$(MODULES),$(eval HEADER_built_$(m) = $$(HEADERS_built_$(m))))
162+ $(foreach m,$(MODULES),$(eval HEADER_allbuilt += $$(HEADERS_built_$(m))))
133163endif
134164
135165# HEADERS_foo requires that "foo" is in MODULES as a sanity check
136- ifneq ($(filter-out $(HEADER_dirs ) ,$(HEADER_alldirs ) ) ,)
137- $(error $(patsubst %,HEADERS_%,$(filter-out $(HEADER_dirs),$(HEADER_alldirs))) defined with no module)
166+ ifneq ($(filter-out $(HEADER_dirs ) $( addprefix built_, $( HEADER_dirs ) ) ,$(HEADER_alldirs ) ) ,)
167+ $(error $(patsubst %,HEADERS_%,$(filter-out $(HEADER_dirs) $(addprefix built_,$(HEADER_dirs)) ,$(HEADER_alldirs))) defined with no module)
138168endif
139169
140170# Functions for generating install/uninstall commands; the blank lines
141171# before the "endef" are required, don't lose them
142172# $(call install_headers,dir,headers)
143173define install_headers
144174$(MKDIR_P ) '$(DESTDIR )$(includedir_server ) /$(incmoduledir ) /$(1 ) /'
145- $(INSTALL_DATA ) $(addprefix $( srcdir ) /, $( 2 ) ) '$(DESTDIR )$(includedir_server ) /$(incmoduledir ) /$(1 ) /'
175+ $(INSTALL_DATA ) $(2 ) '$(DESTDIR )$(includedir_server ) /$(incmoduledir ) /$(1 ) /'
146176
147177endef
148178# $(call uninstall_headers,dir,headers)
@@ -152,7 +182,7 @@ rm -f $(addprefix '$(DESTDIR)$(includedir_server)/$(incmoduledir)/$(1)'/, $(notd
152182endef
153183
154184
155- all : $(PROGRAM ) $(DATA_built ) $(SCRIPTS_built ) $(addsuffix $(DLSUFFIX ) , $(MODULES ) ) $(addsuffix .control, $(EXTENSION ) )
185+ all : $(PROGRAM ) $(DATA_built ) $(HEADER_allbuilt ) $( SCRIPTS_built ) $(addsuffix $(DLSUFFIX ) , $(MODULES ) ) $(addsuffix .control, $(EXTENSION ) )
156186
157187ifeq ($(with_llvm ) , yes)
158188all : $(addsuffix .bc, $(MODULES ) ) $(patsubst % .o,% .bc, $(OBJS ) )
@@ -199,7 +229,8 @@ ifdef SCRIPTS_built
199229 $(INSTALL_SCRIPT) $(SCRIPTS_built) '$(DESTDIR)$(bindir)/'
200230endif # SCRIPTS_built
201231ifneq ($(strip $(HEADER_dirs ) ) ,)
202- $(foreach dir,$(HEADER_dirs),$(if $(HEADERS_$(dir)),$(call install_headers,$(dir),$(HEADERS_$(dir)))))
232+ $(foreach dir,$(HEADER_dirs),$(if $(HEADER_unbuilt_$(dir)),$(call install_headers,$(dir),$(addprefix $(srcdir)/, $(HEADER_unbuilt_$(dir))))))
233+ $(foreach dir,$(HEADER_dirs),$(if $(HEADER_built_$(dir)),$(call install_headers,$(dir),$(HEADER_built_$(dir)))))
203234endif # HEADERS
204235ifdef MODULE_big
205236ifeq ($(with_llvm ) , yes)
@@ -266,7 +297,7 @@ ifdef SCRIPTS_built
266297 rm -f $(addprefix '$(DESTDIR)$(bindir)'/, $(SCRIPTS_built))
267298endif
268299ifneq ($(strip $(HEADER_dirs ) ) ,)
269- $(foreach dir,$(HEADER_dirs),$(if $(HEADERS_$( dir)) ,$(call uninstall_headers, $(dir),$(HEADERS_ $(dir) ))))
300+ $(foreach dir,$(HEADER_dirs),$(call uninstall_headers,$( dir),$(HEADER_unbuilt_ $(dir)) $(HEADER_built_ $(dir))))
270301endif # HEADERS
271302
272303ifdef MODULE_big
0 commit comments