From 51226dc97039b42e7fc8670a895ec51b8d715b12 Mon Sep 17 00:00:00 2001
From: Christoph Berg <christoph.berg@credativ.de>
Date: Tue, 13 Nov 2018 11:35:26 +0100
Subject: [PATCH] Add more flexibility for passing custom compiler flags

The existing machinery for extending CFLAGS and LDFLAGS via COPT and
PROFILE neglected to extend CXXFLAGS as well, causing third party
extensions written in C++ not to get the extra flags.

Also add PG_CFLAGS, PG_CXXFLAGS, and PG_LDFLAGS variables to pgxs.mk
which will append to the corresponding make variables.
---
 src/Makefile.global.in |  6 ++++++
 src/makefiles/pgxs.mk  | 12 ++++++++++++
 2 files changed, 18 insertions(+)

diff --git a/src/Makefile.global.in b/src/Makefile.global.in
index 41c131412e..8ac511756c 100644
--- a/src/Makefile.global.in
+++ b/src/Makefile.global.in
@@ -679,8 +679,14 @@ ifdef COPT
    LDFLAGS += $(COPT)
 endif
 
+ifdef CXXOPT
+   CXXFLAGS += $(CXXOPT)
+   LDFLAGS += $(CXXOPT)
+endif
+
 ifdef PROFILE
    CFLAGS += $(PROFILE)
+   CXXFLAGS += $(PROFILE)
    LDFLAGS += $(PROFILE)
 endif
 
diff --git a/src/makefiles/pgxs.mk b/src/makefiles/pgxs.mk
index d214cb9cf2..56a8b26183 100644
--- a/src/makefiles/pgxs.mk
+++ b/src/makefiles/pgxs.mk
@@ -53,6 +53,9 @@
 #     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_CFLAGS -- will be added to CFLAGS
+#   PG_CXXFLAGS -- will be added to CXXFLAGS
+#   PG_LDFLAGS -- will be added 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
@@ -119,6 +122,15 @@ endif
 ifdef PG_CPPFLAGS
 override CPPFLAGS := $(PG_CPPFLAGS) $(CPPFLAGS)
 endif
+ifdef PG_CFLAGS
+override CFLAGS := $(PG_CFLAGS) $(CFLAGS)
+endif
+ifdef PG_CXXFLAGS
+override CXXFLAGS := $(PG_CXXFLAGS) $(CXXFLAGS)
+endif
+ifdef PG_LDFLAGS
+override LDFLAGS := $(PG_LDFLAGS) $(LDFLAGS)
+endif
 
 # logic for HEADERS_* stuff
 
-- 
2.19.2

