Description: Honor the environment variables CFLAGS, CPPFLAGS, and CXXFLAGS
 This is required in Debian, such that hardening flags like
 -D_FORTIFY_SOURCE=2, -fstack-protector-strong, -Wformat, and
 -Werror=format-security are used in the compilation of C++ files.
Author: Rafael Laboissière <rafael@debian.org>
Forwarded: https://savannah.gnu.org/bugs/index.php?61516
Last-Update: 2021-11-20

--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -45,7 +45,7 @@
 # not for calling mkoctfile
 CC = @CC@
 # not for calling mkoctfile
-CFLAGS = -g -O2
+CFLAGS += -g -O2
 
 HAVE_GNUTLS := @HAVE_GNUTLS@
 HAVE_GNUTLS_EXTRA := @HAVE_GNUTLS_EXTRA@
@@ -165,7 +165,7 @@
 # the various gnulib header files under gl/ might have been updated,
 # to avoid having to mention them all here
 gnulib-wrappers.o: gnulib-wrappers.c gl/libgnu.a
-	$(CC) -c gnulib-wrappers.c -Igl $(CFLAGS) -fPIC
+	$(CC) $(CPPFLAGS) -c gnulib-wrappers.c -Igl $(CFLAGS) -fPIC
 
 error-helpers.o: error-helpers.cc error-helpers.h
 	CXXFLAGS="$(CXXFLAGS) $(RELEASE_CXXFLAGS)" $(MKOCTFILE) -c error-helpers.cc
@@ -220,7 +220,7 @@
 	$(MKOCTFILE) $< error-helpers.o minimal-load-save.o gl/libgnu.a gnulib-wrappers.o $(gnulib_libs)
 
 $(standalone): octave-pserver.cc octave-pserver.h
-	$(CXX) -pthread -Wall -o octave-pserver octave-pserver.cc
+	$(CXX) $(CPPFLAGS) $(CXXFLAGS) -pthread -Wall $(LDFLAGS) -o octave-pserver octave-pserver.cc
 	install -D octave-pserver ../bin/octave-pserver
 
 doc: $(INFOFILE)
