No more USE_PGXS=1?

I've become very tired of having to set USE_PGXS=1 every time I build pgTAP outside the contrib directory of a PostgreSQL distribution:

make USE_PGXS=1
make USE_PGXS=1 install
make USE_PGXS=1 installcheck

I am forever forgetting to set it, and it’s just not how one normally expects a build incantation to work. It was required because that’s how the core contrib extensions work: They all have this code in their Makefiles, which those of us who develop third-party modules have borrowed:

ifdef USE_PGXS
PG_CONFIG = pg_config
PGXS := $(shell $(PG_CONFIG) --pgxs)
include $(PGXS)
else
subdir = contrib/citext
top_builddir = ../..
include $(top_builddir)/src/Makefile.global
include $(top_srcdir)/contrib/contrib-global.mk
endif

They generally expect ../../src/Makefile.global to exist, and if it doesn’t, you have to tell it so. I find this annoying, because third-party extensions are almost never built from the contrib directory, so one must always remember to specify USE_PGXS=1.

I'd like to propose, instead, that those of us who maintain third-party extensions like pgTAP, PL/Parrot, and Temporal PostgreSQL not force our users to have to remember this special variable by instead checking to see if it’s needed ourselves. As such, I've just added this code to pgTAP’s Makefile:

ifdef USE_PGXS
PG_CONFIG = pg_config
PGXS := $(shell $(PG_CONFIG) --pgxs)
else
ifeq (exists, $(shell [ -e ../../src/bin/pg_config/pg_config ] && echo exists) ) 
top_builddir = ../..
PG_CONFIG := $(top_builddir)/src/bin/pg_config/pg_config
else
PG_CONFIG = pg_config
PGXS := $(shell $(PG_CONFIG) --pgxs)
endif
endif

So it still respects USE_PGXS=1, but if it’s not set, it looks to see if it can find pg_config where it would expect it to be if built from the contrib directory. If it’s not there, it simply uses pg_config as if USE_PGXS=1 was set. This makes building from the contrib directory or from anywhere else the same process:

make
make install
make installcheck

Much better, much easier to remember.

Is there any reason why third-party PostgreSQL extensions should not adopt this pattern? I don’t think it makes sense for contrib extensions in core to do it, but for those that will never be in core, I think it makes a lot of sense.

Comments?

Backtalk

dim wrote:

In the prefix and preprepare extensions I'm only including the PGXS bits, not the contrib/ one, because, well, the extension's not part of contrib and I'll know about it when it gets there.

Oh and we plan to deprecate contrib in its current form, together, remember? :)

Tom Lane wrote:

My own recommendation for third-party extensions is that they just not bother with support for being built under contrib, ie just do

PG_CONFIG = pg_config
PGXS := $(shell $(PG_CONFIG) --pgxs)
include $(PGXS)

The file existence test proposed above seems pretty fragile.

Aidan Van Dyk wrote:

Make it simple:

   PG_CONFIG = pg_config
   [.....]
   PGXS := $(shell $(PG_CONFIG) --pgxs)
   include $(PGXS)

Then if they want a specific pg_config version:

   make PG_CONFIG=../../../../pg-master/.../bin/pg_config

a.

David Fetter wrote:

Aiden,

Your construct is a thing of beauty. It should be in the PostgreSQL docs. :)

Theory wrote:

Tom, Aidan,

Thanks, that does indeed seem to be the correct approach. However, I've just made this change to pgTAP and it works very nicely.

—Theory

Peter Eisentraut wrote:

What Tom said. The fact that people are copying build code from contrib without change is a bug that should be fixed, not enhanced.

alvherre wrote:

I still do not get why we don't remove the no-pgxs build path from contrib as well.