Skip to content

Commit be54b37

Browse files
committed
Allow extensions to install built as well as unbuilt headers.
Commit df16323 overlooked the case that an out-of-tree extension might need to build its header files (e.g. via ./configure). If it is also doing a VPATH build, the HEADERS_* rules in the original commit would then fail to find the files, since they would be looking only under $(srcdir) and not in the build directory. Fix by adding HEADERS_built and HEADERS_built_$(MODULE) which behave like DATA_built in that they look in the build dir rather than the source dir (and also make the files dependencies of the "all" target). No Windows support appears to be needed for this, since it is only relevant to out-of-tree builds (no support exists in Mkvcbuild.pm to build extension header files in any case).
1 parent 54b01b9 commit be54b37

File tree

2 files changed

+53
-12
lines changed

2 files changed

+53
-12
lines changed

doc/src/sgml/extend.sgml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1224,22 +1224,32 @@ include $(PGXS)
12241224

12251225
<varlistentry>
12261226
<term><varname>HEADERS</varname></term>
1227+
<term><varname>HEADERS_built</varname></term>
12271228
<listitem>
12281229
<para>
1229-
files to install under
1230+
files to (optionally build and) install under
12301231
<literal><replaceable>prefix</replaceable>/include/server/$MODULEDIR/$MODULE_big</literal>
12311232
</para>
12321233
</listitem>
12331234
</varlistentry>
12341235

12351236
<varlistentry>
12361237
<term><varname>HEADERS_$MODULE</varname></term>
1238+
<term><varname>HEADERS_built_$MODULE</varname></term>
12371239
<listitem>
12381240
<para>
1239-
files to install under
1241+
Files to install (after building if specified) under
12401242
<literal><replaceable>prefix</replaceable>/include/server/$MODULEDIR/$MODULE</literal>,
12411243
where <literal>$MODULE</literal> must be a module name used
1242-
in <literal>MODULES</literal> or <literal>MODULE_big</literal>
1244+
in <literal>MODULES</literal> or <literal>MODULE_big</literal>.
1245+
</para>
1246+
<para>
1247+
It is legal to use both variables for the same module, or any
1248+
combination, unless you have two module names in the
1249+
<literal>MODULES</literal> list that differ only by the presence of a
1250+
prefix <literal>built_</literal>, which would cause ambiguity. In
1251+
that (hopefully unlikely) case, you should use only the
1252+
<literal>HEADERS_built_$MODULE</literal> variables.
12431253
</para>
12441254
</listitem>
12451255
</varlistentry>

src/makefiles/pgxs.mk

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,11 @@
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
115117
override CPPFLAGS := $(PG_CPPFLAGS) $(CPPFLAGS)
116118
endif
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.
118127
HEADER_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
121134
ifdef MODULE_big
122135
ifdef HEADERS
123136
HEADER_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)
125144
else
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))
127150
endif
128151
else
129152
ifdef HEADERS
130153
$(error HEADERS requires MODULE_big to be set)
131154
endif
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))))
133163
endif
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)
138168
endif
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)
143173
define 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

147177
endef
148178
# $(call uninstall_headers,dir,headers)
@@ -152,7 +182,7 @@ rm -f $(addprefix '$(DESTDIR)$(includedir_server)/$(incmoduledir)/$(1)'/, $(notd
152182
endef
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

157187
ifeq ($(with_llvm), yes)
158188
all: $(addsuffix .bc, $(MODULES)) $(patsubst %.o,%.bc, $(OBJS))
@@ -199,7 +229,8 @@ ifdef SCRIPTS_built
199229
$(INSTALL_SCRIPT) $(SCRIPTS_built) '$(DESTDIR)$(bindir)/'
200230
endif # SCRIPTS_built
201231
ifneq ($(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)))))
203234
endif # HEADERS
204235
ifdef MODULE_big
205236
ifeq ($(with_llvm), yes)
@@ -266,7 +297,7 @@ ifdef SCRIPTS_built
266297
rm -f $(addprefix '$(DESTDIR)$(bindir)'/, $(SCRIPTS_built))
267298
endif
268299
ifneq ($(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))))
270301
endif # HEADERS
271302

272303
ifdef MODULE_big

0 commit comments

Comments
 (0)