summaryrefslogtreecommitdiffstats
path: root/src/makefiles
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-13 13:44:03 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-13 13:44:03 +0000
commit293913568e6a7a86fd1479e1cff8e2ecb58d6568 (patch)
treefc3b469a3ec5ab71b36ea97cc7aaddb838423a0c /src/makefiles
parentInitial commit. (diff)
downloadpostgresql-16-293913568e6a7a86fd1479e1cff8e2ecb58d6568.tar.xz
postgresql-16-293913568e6a7a86fd1479e1cff8e2ecb58d6568.zip
Adding upstream version 16.2.upstream/16.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/makefiles')
-rw-r--r--src/makefiles/Makefile15
-rw-r--r--src/makefiles/Makefile.aix39
-rw-r--r--src/makefiles/Makefile.cygwin50
-rw-r--r--src/makefiles/Makefile.darwin12
-rw-r--r--src/makefiles/Makefile.freebsd14
-rw-r--r--src/makefiles/Makefile.linux8
-rw-r--r--src/makefiles/Makefile.netbsd6
-rw-r--r--src/makefiles/Makefile.openbsd6
-rw-r--r--src/makefiles/Makefile.solaris8
-rw-r--r--src/makefiles/Makefile.win3283
-rw-r--r--src/makefiles/meson.build262
-rw-r--r--src/makefiles/pgxs.mk479
12 files changed, 982 insertions, 0 deletions
diff --git a/src/makefiles/Makefile b/src/makefiles/Makefile
new file mode 100644
index 0000000..417c98b
--- /dev/null
+++ b/src/makefiles/Makefile
@@ -0,0 +1,15 @@
+# src/makefiles/Makefile
+
+subdir = src/makefiles
+top_builddir = ../..
+include $(top_builddir)/src/Makefile.global
+
+
+install: all installdirs
+ $(INSTALL_DATA) $(srcdir)/pgxs.mk '$(DESTDIR)$(pgxsdir)/$(subdir)/'
+
+installdirs:
+ $(MKDIR_P) '$(DESTDIR)$(pgxsdir)/$(subdir)'
+
+uninstall:
+ rm -f '$(DESTDIR)$(pgxsdir)/$(subdir)/pgxs.mk'
diff --git a/src/makefiles/Makefile.aix b/src/makefiles/Makefile.aix
new file mode 100644
index 0000000..dd16a7a
--- /dev/null
+++ b/src/makefiles/Makefile.aix
@@ -0,0 +1,39 @@
+# MAKE_EXPORTS is required for svr4 loaders that want a file of
+# symbol names to tell them what to export/import.
+MAKE_EXPORTS= true
+
+# -blibpath must contain ALL directories where we should look for libraries
+libpath := $(shell echo $(subst -L,:,$(filter -L/%,$(LDFLAGS))) | sed -e's/ //g'):/usr/lib:/lib
+
+# when building with gcc, need to make sure that libgcc can be found
+ifeq ($(GCC), yes)
+libpath := $(libpath):$(dir $(shell gcc -print-libgcc-file-name))
+endif
+
+rpath = -Wl,-blibpath:'$(rpathdir)$(libpath)'
+
+LDFLAGS_SL += -Wl,-bnoentry -Wl,-H512 -Wl,-bM:SRE
+
+# gcc needs to know it's building a shared lib, otherwise it'll not emit
+# correct code / link to the right support libraries
+ifeq ($(GCC), yes)
+LDFLAGS_SL += -shared
+endif
+
+# env var name to use in place of LD_LIBRARY_PATH
+ld_library_path_var = LIBPATH
+
+
+POSTGRES_IMP= postgres.imp
+
+ifdef PGXS
+BE_DLLLIBS= -Wl,-bI:$(pkglibdir)/$(POSTGRES_IMP)
+else
+BE_DLLLIBS= -Wl,-bI:$(top_builddir)/src/backend/$(POSTGRES_IMP)
+endif
+
+MKLDEXPORT_DIR=src/backend/port/aix
+MKLDEXPORT=$(top_srcdir)/$(MKLDEXPORT_DIR)/mkldexport.sh
+
+%$(DLSUFFIX): %.o
+ $(CC) $(CFLAGS) $*.o $(LDFLAGS) $(LDFLAGS_SL) -o $@ $(BE_DLLLIBS)
diff --git a/src/makefiles/Makefile.cygwin b/src/makefiles/Makefile.cygwin
new file mode 100644
index 0000000..7759397
--- /dev/null
+++ b/src/makefiles/Makefile.cygwin
@@ -0,0 +1,50 @@
+# src/makefiles/Makefile.cygwin
+
+ifdef PGXS
+BE_DLLLIBS= -L$(libdir) -lpostgres
+else
+BE_DLLLIBS= -L$(top_builddir)/src/backend -lpostgres
+endif
+
+# linking with -lm or -lc causes program to crash
+# (see http://sources.redhat.com/cygwin/faq/faq.html#SEC110)
+LIBS:=$(filter-out -lm -lc, $(LIBS))
+
+override CPPFLAGS += -DWIN32_STACK_RLIMIT=$(WIN32_STACK_RLIMIT)
+
+ifneq (,$(findstring backend,$(subdir)))
+ifeq (,$(findstring conversion_procs,$(subdir)))
+ifeq (,$(findstring libpqwalreceiver,$(subdir)))
+ifeq (,$(findstring replication/pgoutput,$(subdir)))
+ifeq (,$(findstring snowball,$(subdir)))
+override CPPFLAGS+= -DBUILDING_DLL
+endif
+endif
+endif
+endif
+endif
+
+ifneq (,$(findstring src/common,$(subdir)))
+override CPPFLAGS+= -DBUILDING_DLL
+endif
+
+ifneq (,$(findstring src/port,$(subdir)))
+override CPPFLAGS+= -DBUILDING_DLL
+endif
+
+ifneq (,$(findstring timezone,$(subdir)))
+override CPPFLAGS+= -DBUILDING_DLL
+endif
+
+ifneq (,$(findstring ecpg/ecpglib,$(subdir)))
+override CPPFLAGS+= -DBUILDING_DLL
+endif
+
+# required by Python headers
+ifneq (,$(findstring src/pl/plpython,$(subdir)))
+override CPPFLAGS+= -DUSE_DL_IMPORT
+endif
+
+# Rule for building a shared library from a single .o file
+%.dll: %.o
+ $(CC) $(CFLAGS) -shared -o $@ $< $(LDFLAGS) $(LDFLAGS_SL) $(BE_DLLLIBS)
diff --git a/src/makefiles/Makefile.darwin b/src/makefiles/Makefile.darwin
new file mode 100644
index 0000000..7095f66
--- /dev/null
+++ b/src/makefiles/Makefile.darwin
@@ -0,0 +1,12 @@
+# env var name to use in place of LD_LIBRARY_PATH
+ld_library_path_var = DYLD_LIBRARY_PATH
+
+ifdef PGXS
+ BE_DLLLIBS = -bundle_loader $(bindir)/postgres
+else
+ BE_DLLLIBS = -bundle_loader $(top_builddir)/src/backend/postgres
+endif
+
+# Rule for building a shared library from a single .o file
+%$(DLSUFFIX): %.o
+ $(CC) $(CFLAGS) $< $(LDFLAGS) $(LDFLAGS_SL) -bundle $(BE_DLLLIBS) -o $@
diff --git a/src/makefiles/Makefile.freebsd b/src/makefiles/Makefile.freebsd
new file mode 100644
index 0000000..8a65d78
--- /dev/null
+++ b/src/makefiles/Makefile.freebsd
@@ -0,0 +1,14 @@
+rpath = -Wl,-R'$(rpathdir)'
+
+# extra stuff for $(with_temp_install)
+# we need this to get LD_LIBRARY_PATH searched ahead of the compiled-in
+# rpath, if no DT_RUNPATH is present in the executable. The conditions
+# under which DT_RUNPATH are added seem unpredictable, so be safe.
+
+define with_temp_install_extra
+LD_LIBRARY_PATH_RPATH=1
+endef
+
+# Rule for building a shared library from a single .o file
+%.so: %.o
+ $(CC) $(CFLAGS) $< $(LDFLAGS) $(LDFLAGS_SL) -shared -o $@
diff --git a/src/makefiles/Makefile.linux b/src/makefiles/Makefile.linux
new file mode 100644
index 0000000..16d8249
--- /dev/null
+++ b/src/makefiles/Makefile.linux
@@ -0,0 +1,8 @@
+# Use --enable-new-dtags to generate DT_RUNPATH instead of DT_RPATH.
+# This allows LD_LIBRARY_PATH to still work when needed.
+rpath = -Wl,-rpath,'$(rpathdir)',--enable-new-dtags
+
+
+# Rule for building a shared library from a single .o file
+%.so: %.o
+ $(CC) $(CFLAGS) $< $(LDFLAGS) $(LDFLAGS_SL) -shared -o $@
diff --git a/src/makefiles/Makefile.netbsd b/src/makefiles/Makefile.netbsd
new file mode 100644
index 0000000..eb86e0b
--- /dev/null
+++ b/src/makefiles/Makefile.netbsd
@@ -0,0 +1,6 @@
+rpath = -Wl,-R'$(rpathdir)'
+
+
+# Rule for building a shared library from a single .o file
+%.so: %.o
+ $(CC) $(CFLAGS) $< $(LDFLAGS) $(LDFLAGS_SL) -shared -o $@
diff --git a/src/makefiles/Makefile.openbsd b/src/makefiles/Makefile.openbsd
new file mode 100644
index 0000000..eb86e0b
--- /dev/null
+++ b/src/makefiles/Makefile.openbsd
@@ -0,0 +1,6 @@
+rpath = -Wl,-R'$(rpathdir)'
+
+
+# Rule for building a shared library from a single .o file
+%.so: %.o
+ $(CC) $(CFLAGS) $< $(LDFLAGS) $(LDFLAGS_SL) -shared -o $@
diff --git a/src/makefiles/Makefile.solaris b/src/makefiles/Makefile.solaris
new file mode 100644
index 0000000..e2b386a
--- /dev/null
+++ b/src/makefiles/Makefile.solaris
@@ -0,0 +1,8 @@
+# src/makefiles/Makefile.solaris
+rpath = -Wl,-rpath,'$(rpathdir)'
+
+# Rule for building a shared library from a single .o file
+%.so: %.o
+ $(CC) $(CFLAGS) $< $(LDFLAGS) $(LDFLAGS_SL) -shared -o $@
+
+sqlmansect = 5sql
diff --git a/src/makefiles/Makefile.win32 b/src/makefiles/Makefile.win32
new file mode 100644
index 0000000..dc1aafa
--- /dev/null
+++ b/src/makefiles/Makefile.win32
@@ -0,0 +1,83 @@
+# src/makefiles/Makefile.win32
+
+ifdef PGXS
+BE_DLLLIBS= -L$(libdir) -lpostgres
+override CPPFLAGS+= -I$(includedir_server)/port/win32
+else
+BE_DLLLIBS= -L$(top_builddir)/src/backend -lpostgres
+override CPPFLAGS+="-I$(top_srcdir)/src/include/port/win32"
+endif
+
+override CPPFLAGS += -DWIN32_STACK_RLIMIT=$(WIN32_STACK_RLIMIT)
+
+ifneq (,$(findstring backend,$(subdir)))
+ifeq (,$(findstring conversion_procs,$(subdir)))
+ifeq (,$(findstring libpqwalreceiver,$(subdir)))
+ifeq (,$(findstring replication/pgoutput,$(subdir)))
+ifeq (,$(findstring snowball,$(subdir)))
+override CPPFLAGS+= -DBUILDING_DLL
+endif
+endif
+endif
+endif
+endif
+
+ifneq (,$(findstring src/common,$(subdir)))
+override CPPFLAGS+= -DBUILDING_DLL
+endif
+
+ifneq (,$(findstring src/port,$(subdir)))
+override CPPFLAGS+= -DBUILDING_DLL
+endif
+
+ifneq (,$(findstring timezone,$(subdir)))
+override CPPFLAGS+= -DBUILDING_DLL
+endif
+
+ifneq (,$(findstring ecpg/ecpglib,$(subdir)))
+override CPPFLAGS+= -DBUILDING_DLL
+endif
+
+# required by Python headers
+ifneq (,$(findstring src/pl/plpython,$(subdir)))
+override CPPFLAGS+= -DUSE_DL_IMPORT
+endif
+
+# it is better to install shared-libraries anyway?
+# may be overridden with make MAKE_DLL=false install
+ifndef MAKE_DLL
+MAKE_DLL = true
+endif
+
+
+# Build rules to add versioninfo resources to win32 binaries
+
+WIN32RES += win32ver.o
+PGFTYPE = $(if $(shlib),VFT_DLL,VFT_APP)
+ifneq (,$(PGAPPICON))
+PGICOSTR = $(subst /,\/,IDI_ICON ICON \"$(top_builddir)/src/port/$(PGAPPICON).ico\")
+endif
+
+# We do not install src/port/win32ver.rc, its content being specific to
+# PostgreSQL Global Development Group software. Any module can ship a
+# win32ver.rc or furnish a rule for generating one. Set $(PGFILEDESC) to
+# signal win32ver.rc availability to the dll build rule below.
+ifndef PGXS
+win32ver.rc: $(top_srcdir)/src/port/win32ver.rc
+ sed -e 's;FILEDESC;$(PGFILEDESC);' \
+ -e 's;VFT_APP;$(PGFTYPE);' \
+ -e 's;_ICO_;$(PGICOSTR);' \
+ -e '/_INTERNAL_NAME_/$(if $(shlib),s;_INTERNAL_NAME_;"$(basename $(shlib))";,d)' \
+ -e '/_ORIGINAL_NAME_/$(if $(shlib),s;_ORIGINAL_NAME_;"$(shlib)";,d)' \
+ $< >$@
+
+# Depend on Makefile.global to force rebuild on re-run of configure.
+win32ver.rc: $(top_builddir)/src/Makefile.global
+endif
+
+win32ver.o: win32ver.rc
+ $(WINDRES) -i $< -o $@ --include-dir=$(top_builddir)/src/include --include-dir=$(srcdir)
+
+# Rule for building a shared library from a single .o file
+%.dll: %.o $(if $(PGFILEDESC),$(WIN32RES))
+ $(CC) $(CFLAGS) -shared -static-libgcc -o $@ $^ -Wl,--export-all-symbols $(LDFLAGS) $(LDFLAGS_SL) $(BE_DLLLIBS)
diff --git a/src/makefiles/meson.build b/src/makefiles/meson.build
new file mode 100644
index 0000000..13045cb
--- /dev/null
+++ b/src/makefiles/meson.build
@@ -0,0 +1,262 @@
+# Copyright (c) 2022-2023, PostgreSQL Global Development Group
+
+### Compute pgxs_data, used in src/meson.build to generate Makefile.global
+### etc, that's complete enough for PGXS to work.
+
+
+# Emulation of PGAC_CHECK_STRIP
+strip_bin = find_program(get_option('STRIP'), required: false, native: true)
+strip_cmd = strip_bin.found() ? [strip_bin.path()] : [':']
+
+working_strip = false
+if strip_bin.found()
+ strip_version = run_command(strip_bin, '-V', check: false)
+
+ if strip_version.returncode() == 0 and (
+ strip_version.stdout().contains('GNU strip') or
+ strip_version.stderr().contains('GNU strip'))
+ working_strip = true
+ strip_static_cmd = strip_cmd + ['--strip-unneeded']
+ strip_shared_cmd = strip_cmd + ['--strip-unneeded']
+ elif host_system == 'darwin'
+ working_strip = true
+ strip_static_cmd = strip_cmd + ['-x']
+ strip_shared_cmd = strip_cmd + ['-x']
+ endif
+endif
+
+if not working_strip
+ strip_cmd = [':']
+ strip_static_cmd = [':']
+ strip_shared_cmd = [':']
+endif
+
+
+pgxs_kv = {
+ 'PACKAGE_URL': pg_url,
+ 'PACKAGE_VERSION': pg_version,
+ 'PG_MAJORVERSION': pg_version_major,
+ 'PG_VERSION_NUM': pg_version_num,
+ 'configure_input': 'meson',
+
+ 'vpath_build': 'yes',
+ 'autodepend': cc.get_argument_syntax() == 'gcc' ? 'yes' : 'no',
+
+ 'host_cpu': host_cpu,
+ 'host': '@0@-@1@'.format(host_cpu, host_system),
+ 'host_os': host_system,
+ 'build_os': build_machine.system(),
+ 'PORTNAME': portname,
+ 'PG_SYSROOT': pg_sysroot,
+
+ 'abs_top_builddir': meson.build_root(),
+ 'abs_top_srcdir': meson.source_root(),
+
+ 'enable_thread_safety': 'yes',
+ 'enable_rpath': get_option('rpath') ? 'yes' : 'no',
+ 'enable_nls': libintl.found() ? 'yes' : 'no',
+ 'enable_tap_tests': tap_tests_enabled ? 'yes' : 'no',
+ 'enable_debug': get_option('debug') ? 'yes' : 'no',
+ 'enable_coverage': 'no',
+ 'enable_dtrace': dtrace.found() ? 'yes' : 'no',
+
+ 'DLSUFFIX': dlsuffix,
+ 'EXEEXT': exesuffix,
+
+ 'SUN_STUDIO_CC': 'no', # not supported so far
+
+ # want the chosen option, rather than the library
+ 'with_ssl' : ssl_library,
+ 'with_uuid': uuidopt,
+
+ 'default_port': get_option('pgport'),
+ 'with_system_tzdata': get_option('system_tzdata'),
+
+ 'with_krb_srvnam': get_option('krb_srvnam'),
+ 'krb_srvtab': krb_srvtab,
+
+ 'STRIP': ' '.join(strip_cmd),
+ 'STRIP_STATIC_LIB': ' '.join(strip_static_cmd),
+ 'STRIP_SHARED_LIB': ' '.join(strip_shared_cmd),
+
+ # these seem to be standard these days
+ 'MKDIR_P': 'mkdir -p',
+ 'LN_S': 'ln -s',
+ # Just always use the install_sh fallback that autoconf uses. Unlikely to
+ # matter performance-wise for extensions. If it turns out to do, we can
+ 'install_bin': '$(SHELL) $(top_srcdir)/config/install-sh -c',
+
+ 'CC': var_cc,
+ 'CPP': var_cpp,
+ 'GCC': cc.get_argument_syntax() == 'gcc' ? 'yes' : 'no',
+
+ 'CPPFLAGS': var_cppflags,
+ 'CFLAGS': var_cflags,
+ 'CXXFLAGS': var_cxxflags,
+ 'CFLAGS_SL': var_cflags_sl,
+ 'CFLAGS_SL_MODULE': ' '.join(cflags_mod),
+ 'CXXFLAGS_SL_MODULE': ' '.join(cxxflags_mod),
+ 'PERMIT_DECLARATION_AFTER_STATEMENT':
+ ' '.join(cflags_no_decl_after_statement),
+
+ 'CFLAGS_CRC': ' '.join(cflags_crc),
+ 'CFLAGS_UNROLL_LOOPS': ' '.join(unroll_loops_cflags),
+ 'CFLAGS_VECTORIZE': ' '.join(vectorize_cflags),
+
+ 'LDFLAGS': var_ldflags,
+ 'LDFLAGS_EX': var_ldflags_ex,
+ 'LDFLAGS_EX_BE':
+ ' '.join(cc.get_supported_link_arguments('-Wl,--export-dynamic')),
+ 'LDFLAGS_SL': var_ldflags_sl,
+
+ # TODO: requires bitcode generation to be implemented for meson
+ 'BITCODE_CFLAGS': '',
+ 'BITCODE_CXXFLAGS': '',
+
+ 'BISONFLAGS': ' '.join(bison_flags),
+ 'FLEXFLAGS': ' '.join(flex_flags),
+
+ 'LIBS': var_libs,
+}
+
+if llvm.found()
+ pgxs_kv += {
+ 'CLANG': clang.path(),
+ 'CXX': ' '.join(cpp.cmd_array()),
+ 'LLVM_BINPATH': llvm_binpath,
+ }
+else
+ pgxs_kv += {
+ 'CLANG': '',
+ 'CXX': '',
+ 'LLVM_BINPATH': '',
+ }
+endif
+
+pgxs_bins = {
+ 'AR':
+ find_program(['ar'], native: true, required: false),
+ 'AWK':
+ find_program(['gawk', 'mawk', 'nawk', 'awk'], native: true, required: false),
+ 'BISON': bison,
+ 'FLEX': flex,
+ 'GZIP': gzip,
+ 'LZ4': program_lz4,
+ 'OPENSSL': openssl,
+ 'PERL': perl,
+ 'PROVE': prove,
+ 'PYTHON': python,
+ 'TAR': tar,
+ 'ZSTD': program_zstd,
+ 'DTRACE': dtrace,
+}
+
+pgxs_empty = [
+ 'ICU_CFLAGS', # needs to be added, included by public server headers
+
+ # hard to see why we'd need either?
+ 'ZIC',
+ 'TCLSH',
+
+ # docs don't seem to be supported by pgxs
+ 'XMLLINT',
+ 'XSLTPROC',
+ 'DBTOEPUB',
+ 'FOP',
+
+ # supporting coverage for pgxs-in-meson build doesn't seem worth it
+ 'GENHTML',
+ 'LCOV',
+ 'GCOV',
+ 'MSGFMT_FLAGS',
+
+ # translation doesn't appear to be supported by pgxs
+ 'MSGFMT',
+ 'XGETTEXT',
+ 'MSGMERGE',
+ 'WANTED_LANGUAGES',
+
+ # Not needed because we don't build the server / PLs with the generated makefile
+ 'LIBOBJS', 'PG_CRC32C_OBJS', 'TAS',
+ 'DTRACEFLAGS', # only server has dtrace probes
+
+ 'perl_archlibexp', 'perl_embed_ccflags', 'perl_embed_ldflags', 'perl_includespec', 'perl_privlibexp',
+ 'python_additional_libs', 'python_includespec', 'python_libdir', 'python_libspec', 'python_majorversion', 'python_version',
+
+ # possible that some of these are referenced explicitly in pgxs makefiles?
+ # For now not worth it.
+ 'TCL_INCLUDE_SPEC', 'TCL_LIBS', 'TCL_LIB_SPEC', 'TCL_SHARED_BUILD',
+
+ 'LLVM_CFLAGS', 'LLVM_CPPFLAGS', 'LLVM_CXXFLAGS', 'LLVM_LIBS',
+
+ 'LDAP_LIBS_BE', 'LDAP_LIBS_FE',
+
+ 'UUID_LIBS',
+
+ 'PTHREAD_CFLAGS', 'PTHREAD_LIBS',
+
+ 'ICU_LIBS',
+]
+
+if host_system == 'windows' and cc.get_argument_syntax() != 'msvc'
+ pgxs_bins += {'WINDRES': windres}
+else
+ pgxs_empty += 'WINDRES'
+endif
+
+pgxs_dirs = {
+ 'prefix': get_option('prefix'),
+
+ 'bindir': '${exec_prefix}' / get_option('bindir'),
+ 'datarootdir': '${prefix}' / get_option('datadir'),
+ 'datadir': '${datarootdir}',
+ 'docdir': '${prefix}' / dir_doc,
+ 'exec_prefix': '${prefix}',
+ 'htmldir': '${docdir}',
+ 'includedir': '${prefix}' / get_option('includedir'),
+ 'libdir': '${exec_prefix}' / get_option('libdir'),
+ 'localedir': '${prefix}' / get_option('localedir'),
+ 'mandir': '${prefix}' / get_option('mandir'),
+ 'sysconfdir': '${prefix}' / get_option('sysconfdir'),
+}
+
+pgxs_deps = {
+ 'bonjour': bonjour,
+ 'bsd_auth': bsd_auth,
+ 'gssapi': gssapi,
+ 'icu': icu,
+ 'ldap': ldap,
+ 'libxml': libxml,
+ 'libxslt': libxslt,
+ 'llvm': llvm,
+ 'lz4': lz4,
+ 'nls': libintl,
+ 'pam': pam,
+ 'perl': perl_dep,
+ 'python': python3_dep,
+ 'readline': readline,
+ 'selinux': selinux,
+ 'systemd': systemd,
+ 'tcl': tcl_dep,
+ 'zlib': zlib,
+ 'zstd': zstd,
+}
+
+
+pgxs_cdata = configuration_data(pgxs_kv)
+
+foreach b, p : pgxs_bins
+ pgxs_cdata.set(b, p.found() ? p.path() : '')
+endforeach
+
+foreach pe : pgxs_empty
+ pgxs_cdata.set(pe, '')
+endforeach
+
+foreach d, p : pgxs_dirs
+ pgxs_cdata.set(d, p)
+endforeach
+
+foreach d, v : pgxs_deps
+ pgxs_cdata.set('with_@0@'.format(d), v.found() ? 'yes' : 'no')
+endforeach
diff --git a/src/makefiles/pgxs.mk b/src/makefiles/pgxs.mk
new file mode 100644
index 0000000..7ba8d5b
--- /dev/null
+++ b/src/makefiles/pgxs.mk
@@ -0,0 +1,479 @@
+# PGXS: PostgreSQL extensions makefile
+
+# src/makefiles/pgxs.mk
+
+# This file contains generic rules to build many kinds of simple
+# extension modules. You only need to set a few variables and include
+# this file, the rest will be done here.
+#
+# Use the following layout for your Makefile:
+#
+# [variable assignments, see below]
+#
+# PG_CONFIG = pg_config
+# PGXS := $(shell $(PG_CONFIG) --pgxs)
+# include $(PGXS)
+#
+# [custom rules, rarely necessary]
+#
+# Set one of these three variables to specify what is built:
+#
+# MODULES -- list of shared-library objects to be built from source files
+# with same stem (do not include library suffixes in this list)
+# MODULE_big -- a shared library to build from multiple source files
+# (list object files in OBJS)
+# PROGRAM -- an executable program to build (list object files in OBJS)
+#
+# The following variables can also be set:
+#
+# EXTENSION -- name of extension (there must be a $EXTENSION.control file)
+# MODULEDIR -- subdirectory of $PREFIX/share into which DATA and DOCS files
+# should be installed (if not set, default is "extension" if EXTENSION
+# is set, or "contrib" if not)
+# DATA -- random files to install into $PREFIX/share/$MODULEDIR
+# DATA_built -- random files to install into $PREFIX/share/$MODULEDIR,
+# which need to be built first
+# DATA_TSEARCH -- random files to install into $PREFIX/share/tsearch_data
+# DOCS -- random files to install under $PREFIX/doc/$MODULEDIR
+# SCRIPTS -- script files (not binaries) to install into $PREFIX/bin
+# SCRIPTS_built -- script files (not binaries) to install into $PREFIX/bin,
+# which need to be built first
+# HEADERS -- files to install into $(includedir_server)/$MODULEDIR/$MODULE_big
+# HEADERS_built -- as above but built first (but NOT cleaned)
+# HEADERS_$(MODULE) -- files to install into
+# $(includedir_server)/$MODULEDIR/$MODULE; the value of $MODULE must be
+# listed in MODULES or MODULE_big
+# HEADERS_built_$(MODULE) -- as above but built first (also NOT cleaned)
+# REGRESS -- list of regression test cases (without suffix)
+# REGRESS_OPTS -- additional switches to pass to pg_regress
+# TAP_TESTS -- switch to enable TAP tests
+# ISOLATION -- list of isolation test cases
+# ISOLATION_OPTS -- additional switches to pass to pg_isolation_regress
+# NO_INSTALL -- don't define an install target, useful for test modules
+# that don't need their build products to be installed
+# NO_INSTALLCHECK -- don't define an installcheck target, useful e.g. if
+# tests require special configuration, or don't use pg_regress
+# EXTRA_CLEAN -- extra files to remove in 'make clean'
+# PG_CPPFLAGS -- will be prepended to CPPFLAGS
+# PG_CFLAGS -- will be appended to CFLAGS
+# PG_CXXFLAGS -- will be appended to CXXFLAGS
+# PG_LDFLAGS -- will be prepended to LDFLAGS
+# PG_LIBS -- will be added to PROGRAM link line
+# PG_LIBS_INTERNAL -- same, for references to libraries within build tree
+# SHLIB_LINK -- will be added to MODULE_big link line
+# SHLIB_LINK_INTERNAL -- same, for references to libraries within build tree
+# PG_CONFIG -- path to pg_config program for the PostgreSQL installation
+# to build against (typically just "pg_config" to use the first one in
+# your PATH)
+#
+# Better look at some of the existing uses for examples...
+
+ifndef PGXS
+ifndef NO_PGXS
+$(error pgxs error: makefile variable PGXS or NO_PGXS must be set)
+endif
+endif
+
+
+ifdef PGXS
+
+# External extensions must assume generated headers are available
+NO_GENERATED_HEADERS=yes
+# The temp-install rule won't work, either
+NO_TEMP_INSTALL=yes
+
+# We assume that we are in src/makefiles/, so top is ...
+top_builddir := $(dir $(PGXS))../..
+include $(top_builddir)/src/Makefile.global
+
+# These might be set in Makefile.global, but if they were not found
+# during the build of PostgreSQL, supply default values so that users
+# of pgxs can use the variables.
+ifeq ($(BISON),)
+BISON = bison
+endif
+ifeq ($(FLEX),)
+FLEX = flex
+endif
+
+endif # PGXS
+
+
+override CPPFLAGS := -I. -I$(srcdir) $(CPPFLAGS)
+
+# See equivalent block in Makefile.shlib
+ifdef MODULES
+override LDFLAGS_SL += $(CFLAGS_SL_MODULE)
+override CFLAGS += $(CFLAGS_SL) $(CFLAGS_SL_MODULE)
+override CXXFLAGS += $(CFLAGS_SL) $(CXXFLAGS_SL_MODULE)
+endif
+
+ifdef MODULEDIR
+datamoduledir := $(MODULEDIR)
+docmoduledir := $(MODULEDIR)
+incmoduledir := $(MODULEDIR)
+else
+ifdef EXTENSION
+datamoduledir := extension
+docmoduledir := extension
+incmoduledir := extension
+else
+datamoduledir := contrib
+docmoduledir := contrib
+incmoduledir := contrib
+endif
+endif
+
+ifdef PG_CPPFLAGS
+override CPPFLAGS := $(PG_CPPFLAGS) $(CPPFLAGS)
+endif
+ifdef PG_CFLAGS
+override CFLAGS := $(CFLAGS) $(PG_CFLAGS)
+endif
+ifdef PG_CXXFLAGS
+override CXXFLAGS := $(CXXFLAGS) $(PG_CXXFLAGS)
+endif
+ifdef PG_LDFLAGS
+override LDFLAGS := $(PG_LDFLAGS) $(LDFLAGS)
+endif
+
+# logic for HEADERS_* stuff
+
+# get list of all names used with or without built_ prefix
+# note that use of HEADERS_built_foo will get both "foo" and "built_foo",
+# we cope with that later when filtering this list against MODULES.
+# If someone wants to name a module "built_foo", they can do that and it
+# works, but if they have MODULES = foo built_foo then they will need to
+# force building of all headers and use HEADERS_built_foo and
+# HEADERS_built_built_foo.
+HEADER_alldirs := $(patsubst HEADERS_%,%,$(filter HEADERS_%, $(.VARIABLES)))
+HEADER_alldirs += $(patsubst HEADERS_built_%,%,$(filter HEADERS_built_%, $(.VARIABLES)))
+
+# collect all names of built headers to use as a dependency
+HEADER_allbuilt :=
+
+ifdef MODULE_big
+
+# we can unconditionally add $(MODULE_big) here, because we will strip it
+# back out below if it turns out not to actually define any headers.
+HEADER_dirs := $(MODULE_big)
+HEADER_unbuilt_$(MODULE_big) = $(HEADERS)
+HEADER_built_$(MODULE_big) = $(HEADERS_built)
+HEADER_allbuilt += $(HEADERS_built)
+# treat "built" as an exclusion below as well as "built_foo"
+HEADER_xdirs := built built_$(MODULE_big)
+
+else # not MODULE_big, so check MODULES
+
+# HEADERS is an error in the absence of MODULE_big to provide a dir name
+ifdef HEADERS
+$(error HEADERS requires MODULE_big to be set)
+endif
+# make list of modules that have either HEADERS_foo or HEADERS_built_foo
+HEADER_dirs := $(foreach m,$(MODULES),$(if $(filter $(m) built_$(m),$(HEADER_alldirs)),$(m)))
+# make list of conflicting names to exclude
+HEADER_xdirs := $(addprefix built_,$(HEADER_dirs))
+
+endif # MODULE_big or MODULES
+
+# HEADERS_foo requires that "foo" is in MODULES as a sanity check
+ifneq (,$(filter-out $(HEADER_dirs) $(HEADER_xdirs),$(HEADER_alldirs)))
+$(error $(patsubst %,HEADERS_%,$(filter-out $(HEADER_dirs) $(HEADER_xdirs),$(HEADER_alldirs))) defined with no module)
+endif
+
+# assign HEADER_unbuilt_foo and HEADER_built_foo, but make sure
+# that "built" takes precedence in the case of conflict, by removing
+# conflicting module names when matching the unbuilt name
+$(foreach m,$(filter-out $(HEADER_xdirs),$(HEADER_dirs)),$(eval HEADER_unbuilt_$(m) += $$(HEADERS_$(m))))
+$(foreach m,$(HEADER_dirs),$(eval HEADER_built_$(m) += $$(HEADERS_built_$(m))))
+$(foreach m,$(HEADER_dirs),$(eval HEADER_allbuilt += $$(HEADERS_built_$(m))))
+
+# expand out the list of headers for each dir, attaching source prefixes
+header_file_list = $(HEADER_built_$(1)) $(addprefix $(srcdir)/,$(HEADER_unbuilt_$(1)))
+$(foreach m,$(HEADER_dirs),$(eval HEADER_files_$(m) := $$(call header_file_list,$$(m))))
+
+# note that the caller's HEADERS* vars have all been expanded now, and
+# later changes will have no effect.
+
+# remove entries in HEADER_dirs that produced an empty list of files,
+# to ensure we don't try and install them
+HEADER_dirs := $(foreach m,$(HEADER_dirs),$(if $(strip $(HEADER_files_$(m))),$(m)))
+
+# Functions for generating install/uninstall commands; the blank lines
+# before the "endef" are required, don't lose them
+# $(call install_headers,dir,headers)
+define install_headers
+$(MKDIR_P) '$(DESTDIR)$(includedir_server)/$(incmoduledir)/$(1)/'
+$(INSTALL_DATA) $(2) '$(DESTDIR)$(includedir_server)/$(incmoduledir)/$(1)/'
+
+endef
+# $(call uninstall_headers,dir,headers)
+define uninstall_headers
+rm -f $(addprefix '$(DESTDIR)$(includedir_server)/$(incmoduledir)/$(1)'/, $(notdir $(2)))
+
+endef
+
+# end of HEADERS_* stuff
+
+
+all: $(PROGRAM) $(DATA_built) $(HEADER_allbuilt) $(SCRIPTS_built) $(addsuffix $(DLSUFFIX), $(MODULES)) $(addsuffix .control, $(EXTENSION))
+
+ifeq ($(with_llvm), yes)
+all: $(addsuffix .bc, $(MODULES)) $(patsubst %.o,%.bc, $(OBJS))
+endif
+
+ifdef MODULE_big
+# shared library parameters
+NAME = $(MODULE_big)
+
+include $(top_srcdir)/src/Makefile.shlib
+
+all: all-lib
+endif # MODULE_big
+
+
+ifndef NO_INSTALL
+
+install: all installdirs
+ifneq (,$(EXTENSION))
+ $(INSTALL_DATA) $(addprefix $(srcdir)/, $(addsuffix .control, $(EXTENSION))) '$(DESTDIR)$(datadir)/extension/'
+endif # EXTENSION
+ifneq (,$(DATA)$(DATA_built))
+ $(INSTALL_DATA) $(addprefix $(srcdir)/, $(DATA)) $(DATA_built) '$(DESTDIR)$(datadir)/$(datamoduledir)/'
+endif # DATA
+ifneq (,$(DATA_TSEARCH))
+ $(INSTALL_DATA) $(addprefix $(srcdir)/, $(DATA_TSEARCH)) '$(DESTDIR)$(datadir)/tsearch_data/'
+endif # DATA_TSEARCH
+ifdef MODULES
+ $(INSTALL_SHLIB) $(addsuffix $(DLSUFFIX), $(MODULES)) '$(DESTDIR)$(pkglibdir)/'
+ifeq ($(with_llvm), yes)
+ $(foreach mod, $(MODULES), $(call install_llvm_module,$(mod),$(mod).bc))
+endif # with_llvm
+endif # MODULES
+ifdef DOCS
+ifdef docdir
+ $(INSTALL_DATA) $(addprefix $(srcdir)/, $(DOCS)) '$(DESTDIR)$(docdir)/$(docmoduledir)/'
+endif # docdir
+endif # DOCS
+ifdef PROGRAM
+ $(INSTALL_PROGRAM) $(PROGRAM)$(X) '$(DESTDIR)$(bindir)'
+endif # PROGRAM
+ifdef SCRIPTS
+ $(INSTALL_SCRIPT) $(addprefix $(srcdir)/, $(SCRIPTS)) '$(DESTDIR)$(bindir)/'
+endif # SCRIPTS
+ifdef SCRIPTS_built
+ $(INSTALL_SCRIPT) $(SCRIPTS_built) '$(DESTDIR)$(bindir)/'
+endif # SCRIPTS_built
+ifneq (,$(strip $(HEADER_dirs)))
+ $(foreach dir,$(HEADER_dirs),$(call install_headers,$(dir),$(HEADER_files_$(dir))))
+endif # HEADERS
+ifdef MODULE_big
+ifeq ($(with_llvm), yes)
+ $(call install_llvm_module,$(MODULE_big),$(OBJS))
+endif # with_llvm
+
+install: install-lib
+endif # MODULE_big
+
+
+installdirs:
+ifneq (,$(EXTENSION))
+ $(MKDIR_P) '$(DESTDIR)$(datadir)/extension'
+endif
+ifneq (,$(DATA)$(DATA_built))
+ $(MKDIR_P) '$(DESTDIR)$(datadir)/$(datamoduledir)'
+endif
+ifneq (,$(DATA_TSEARCH))
+ $(MKDIR_P) '$(DESTDIR)$(datadir)/tsearch_data'
+endif
+ifneq (,$(MODULES))
+ $(MKDIR_P) '$(DESTDIR)$(pkglibdir)'
+endif
+ifdef DOCS
+ifdef docdir
+ $(MKDIR_P) '$(DESTDIR)$(docdir)/$(docmoduledir)'
+endif # docdir
+endif # DOCS
+ifneq (,$(PROGRAM)$(SCRIPTS)$(SCRIPTS_built))
+ $(MKDIR_P) '$(DESTDIR)$(bindir)'
+endif
+
+ifdef MODULE_big
+installdirs: installdirs-lib
+endif # MODULE_big
+
+
+uninstall:
+ifneq (,$(EXTENSION))
+ rm -f $(addprefix '$(DESTDIR)$(datadir)/extension'/, $(notdir $(addsuffix .control, $(EXTENSION))))
+endif
+ifneq (,$(DATA)$(DATA_built))
+ rm -f $(addprefix '$(DESTDIR)$(datadir)/$(datamoduledir)'/, $(notdir $(DATA) $(DATA_built)))
+endif
+ifneq (,$(DATA_TSEARCH))
+ rm -f $(addprefix '$(DESTDIR)$(datadir)/tsearch_data'/, $(notdir $(DATA_TSEARCH)))
+endif
+ifdef MODULES
+ rm -f $(addprefix '$(DESTDIR)$(pkglibdir)'/, $(addsuffix $(DLSUFFIX), $(MODULES)))
+ifeq ($(with_llvm), yes)
+ $(foreach mod, $(MODULES), $(call uninstall_llvm_module,$(mod)))
+endif # with_llvm
+endif # MODULES
+ifdef DOCS
+ rm -f $(addprefix '$(DESTDIR)$(docdir)/$(docmoduledir)'/, $(DOCS))
+endif
+ifdef PROGRAM
+ rm -f '$(DESTDIR)$(bindir)/$(PROGRAM)$(X)'
+endif
+ifdef SCRIPTS
+ rm -f $(addprefix '$(DESTDIR)$(bindir)'/, $(SCRIPTS))
+endif
+ifdef SCRIPTS_built
+ rm -f $(addprefix '$(DESTDIR)$(bindir)'/, $(SCRIPTS_built))
+endif
+ifneq (,$(strip $(HEADER_dirs)))
+ $(foreach dir,$(HEADER_dirs),$(call uninstall_headers,$(dir),$(HEADER_files_$(dir))))
+endif # HEADERS
+
+ifdef MODULE_big
+ifeq ($(with_llvm), yes)
+ $(call uninstall_llvm_module,$(MODULE_big))
+endif # with_llvm
+
+uninstall: uninstall-lib
+endif # MODULE_big
+
+else # NO_INSTALL
+
+# Need this so that temp-install builds artifacts not meant for
+# installation (Normally, check should depend on all, but we don't do
+# that because of parallel make risk (dbf2ec1a1c0).)
+install: all
+
+endif # NO_INSTALL
+
+
+clean:
+ifdef MODULES
+ rm -f $(addsuffix $(DLSUFFIX), $(MODULES)) $(addsuffix .o, $(MODULES)) $(if $(PGFILEDESC),$(WIN32RES)) \
+ $(addsuffix .bc, $(MODULES))
+endif
+ifdef DATA_built
+ rm -f $(DATA_built)
+endif
+ifdef SCRIPTS_built
+ rm -f $(SCRIPTS_built)
+endif
+ifdef PROGRAM
+ rm -f $(PROGRAM)$(X)
+endif
+ifdef OBJS
+ rm -f $(OBJS) $(patsubst %.o,%.bc, $(OBJS))
+endif
+ifdef EXTRA_CLEAN
+ rm -rf $(EXTRA_CLEAN)
+endif
+ifdef REGRESS
+# things created by various check targets
+ rm -rf $(pg_regress_clean_files)
+ifeq ($(PORTNAME), win)
+ rm -f regress.def
+endif
+endif # REGRESS
+ifdef TAP_TESTS
+ rm -rf tmp_check/
+endif
+ifdef ISOLATION
+ rm -rf output_iso/ tmp_check_iso/
+endif
+
+ifdef MODULE_big
+clean: clean-lib
+endif
+
+distclean maintainer-clean: clean
+
+
+ifdef REGRESS
+
+REGRESS_OPTS += --dbname=$(CONTRIB_TESTDB)
+
+# When doing a VPATH build, must copy over the data files so that the
+# driver script can find them. We have to use an absolute path for
+# the targets, because otherwise make will try to locate the missing
+# files using VPATH, and will find them in $(srcdir), but the point
+# here is that we want to copy them from $(srcdir) to the build
+# directory.
+
+ifdef VPATH
+abs_builddir := $(shell pwd)
+test_files_src := $(wildcard $(srcdir)/data/*.data)
+test_files_build := $(patsubst $(srcdir)/%, $(abs_builddir)/%, $(test_files_src))
+
+all: $(test_files_build)
+$(test_files_build): $(abs_builddir)/%: $(srcdir)/%
+ $(MKDIR_P) $(dir $@)
+ ln -s $< $@
+endif # VPATH
+endif # REGRESS
+
+.PHONY: submake
+submake:
+ifndef PGXS
+ $(MAKE) -C $(top_builddir)/src/test/regress pg_regress$(X)
+ $(MAKE) -C $(top_builddir)/src/test/isolation all
+endif
+
+ifdef ISOLATION
+ISOLATION_OPTS += --dbname=$(ISOLATION_TESTDB)
+endif
+
+# Standard rules to run regression tests including multiple test suites.
+# Runs against an installed postmaster.
+ifndef NO_INSTALLCHECK
+installcheck: submake $(REGRESS_PREP)
+ifdef REGRESS
+ $(pg_regress_installcheck) $(REGRESS_OPTS) $(REGRESS)
+endif
+ifdef ISOLATION
+ $(pg_isolation_regress_installcheck) $(ISOLATION_OPTS) $(ISOLATION)
+endif
+ifdef TAP_TESTS
+ $(prove_installcheck)
+endif
+endif # NO_INSTALLCHECK
+
+# Runs independently of any installation
+ifdef PGXS
+check:
+ @echo '"$(MAKE) check" is not supported.'
+ @echo 'Do "$(MAKE) install", then "$(MAKE) installcheck" instead.'
+else
+check: submake $(REGRESS_PREP)
+ifdef REGRESS
+ $(pg_regress_check) $(REGRESS_OPTS) $(REGRESS)
+endif
+ifdef ISOLATION
+ $(pg_isolation_regress_check) $(ISOLATION_OPTS) $(ISOLATION)
+endif
+ifdef TAP_TESTS
+ $(prove_check)
+endif
+endif # PGXS
+
+ifndef NO_TEMP_INSTALL
+checkprep: EXTRA_INSTALL+=$(subdir)
+endif
+
+
+# STANDARD RULES
+
+ifneq (,$(MODULES)$(MODULE_big))
+%.sql: %.sql.in
+ sed 's,MODULE_PATHNAME,$$libdir/$*,g' $< >$@
+endif
+
+ifdef PROGRAM
+$(PROGRAM): $(OBJS)
+ $(CC) $(CFLAGS) $(OBJS) $(PG_LIBS_INTERNAL) $(LDFLAGS) $(LDFLAGS_EX) $(PG_LIBS) $(LIBS) -o $@$(X)
+endif