diff --git a/doc/src/sgml/extend.sgml b/doc/src/sgml/extend.sgml
index 695e07fb384..421e059e7bd 100644
--- a/doc/src/sgml/extend.sgml
+++ b/doc/src/sgml/extend.sgml
@@ -1325,7 +1325,34 @@ include $(PGXS)
PG_CPPFLAGS
- will be added to 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
diff --git a/src/makefiles/pgxs.mk b/src/makefiles/pgxs.mk
index 74942b6e194..123bdffaa6a 100644
--- a/src/makefiles/pgxs.mk
+++ b/src/makefiles/pgxs.mk
@@ -49,7 +49,10 @@
# 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 added to CPPFLAGS
+# 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
@@ -116,6 +119,15 @@ 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