PostgreSQL src/Makefile.global中的小坑

less than 1 minute read

背景

在编译一个插件时发现PostgreSQL的src/Makefile.global可能有一些坑你会踩到,

我们来看看坑是什么?

src/Makefile.global

datadir := ${datarootdir}  
ifeq "$(findstring pgsql, $(datadir))" ""  
ifeq "$(findstring postgres, $(datadir))" ""  
override datadir := $(datadir)/postgresql  
endif  
endif  
  
sysconfdir := ${prefix}/etc  
ifeq "$(findstring pgsql, $(sysconfdir))" ""  
ifeq "$(findstring postgres, $(sysconfdir))" ""  
override sysconfdir := $(sysconfdir)/postgresql  
endif  
endif  
  
libdir := ${exec_prefix}/lib  
  
pkglibdir = $(libdir)  
ifeq "$(findstring pgsql, $(pkglibdir))" ""  
ifeq "$(findstring postgres, $(pkglibdir))" ""  
override pkglibdir := $(pkglibdir)/postgresql  
endif  
endif  
  
includedir := ${prefix}/include  
  
pkgincludedir = $(includedir)  
ifeq "$(findstring pgsql, $(pkgincludedir))" ""  
ifeq "$(findstring postgres, $(pkgincludedir))" ""  
override pkgincludedir := $(pkgincludedir)/postgresql  
endif  
endif  
  
mandir := ${datarootdir}/man  
  
docdir := ${datarootdir}/doc/${PACKAGE_TARNAME}  
ifeq "$(findstring pgsql, $(docdir))" ""  
ifeq "$(findstring postgres, $(docdir))" ""  
override docdir := $(docdir)/postgresql  
endif  
endif  

注意,当这些目录中没有出现pgsql, postgres时,自动会在原有目录下新增一个postgresql目录。

这点可能酿成大错,例如你的环境变量,或者代码中有这种强依赖的话,在更换主目录后就可能出现问题。

例如原来是/opt/pgsql/lib

更换主目录后,你的lib可能会放到/opt/pg/lib/postgresql这里去。

这个最容易出问题的在extension中。例如:

src/contrib/pg_stat_statements/Makefile

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

Flag Counter

digoal’s 大量PostgreSQL文章入口