From: Ole Streicher <olebole@debian.org>
Date: Fri, 22 Jul 2016 14:45:12 +0200
Subject: Propagate CFLAGS etc. for hardening

---
 QFitsView/QFitsView.pro     | 14 +++++++-------
 QFitsView/QFitsView_dll.pro |  1 -
 dpuser/Makefile             | 28 ++++++++++++++--------------
 utils/Makefile              | 12 ++++++------
 4 files changed, 27 insertions(+), 28 deletions(-)

diff --git a/QFitsView/QFitsView.pro b/QFitsView/QFitsView.pro
index bc2f657..77c9299 100644
--- a/QFitsView/QFitsView.pro
+++ b/QFitsView/QFitsView.pro
@@ -1,3 +1,9 @@
+QMAKE_CPPFLAGS *= $(shell dpkg-buildflags --get CPPFLAGS)
+QMAKE_CFLAGS   *= $(shell dpkg-buildflags --get CFLAGS)
+QMAKE_CFLAGS   += $$QMAKE_CPPFLAGS
+QMAKE_CXXFLAGS *= $(shell dpkg-buildflags --get CXXFLAGS)
+QMAKE_CXXFLAGS += $$QMAKE_CPPFLAGS
+QMAKE_LFLAGS   *= $(shell dpkg-buildflags --get LDFLAGS)
 
 # To disable VTK, search for
 # "contains(QT, opengl):DEFINES += HAS_VTK"
@@ -60,12 +66,7 @@ win32 {
     }
 } else:unix {
     ARCH = LINUX
-    contains(QMAKE_HOST.arch, x86_64):{
-        ARCHBIT = 64
-    } else {
-        ARCHBIT = 32
-    }
-    QMAKE_LFLAGS += " -static-libstdc++ -static-libgcc "
+#    QMAKE_LFLAGS += " -static-libstdc++ -static-libgcc "
 } else:message(">>> ERROR: Unsupported platform!")
 
 ##### set OpenGL #####
@@ -74,7 +75,6 @@ win32 {
 
 # ### set CONFIG ################
 CONFIG += qt c++11 \
-          warn_off \
           thread
 win32:qf_static {
     # MinGW, Win32, static QFitsView
diff --git a/QFitsView/QFitsView_dll.pro b/QFitsView/QFitsView_dll.pro
index baa73d4..07717fe 100644
--- a/QFitsView/QFitsView_dll.pro
+++ b/QFitsView/QFitsView_dll.pro
@@ -31,7 +31,6 @@ QT += script \
 
 #### set CONFIG ################
 CONFIG += qt \
-          warn_off \
           dll
 
 #### set VTK_PATH ################
diff --git a/dpuser/Makefile b/dpuser/Makefile
index b2b61ab..22e9ab7 100644
--- a/dpuser/Makefile
+++ b/dpuser/Makefile
@@ -28,10 +28,10 @@
 #
 ################################################################################
 RM          = rm -f
-SED         = sed
-CC          = gcc
-CXX         = g++
-LINK        = g++
+SED         ?= sed
+CC          ?= gcc
+CXX         ?= g++
+LINK        ?= $(CXX)
 QF          =
 GDL         =
 PY          =
@@ -64,8 +64,8 @@ ifeq ($(QF), -qt)
    DEFINES  += -DDPQT -DNO_READLINE
 endif
 
-CFLAGS      = -pipe -O2 -D_REENTRANT -w $(DEFINES)
-CXXFLAGS    = -pipe -O2 -std=c++11 -D_REENTRANT -w $(DEFINES)
+CFLAGS      += -D_REENTRANT -g -w $(DEFINES) $(CPPFLAGS)
+CXXFLAGS    += -std=c++11 -D_REENTRANT -w $(DEFINES) $(CPPFLAGS)
 INCPATH     = -I. -I../utils -I../libfits -I../include -Iparser -I.
 
 ifeq ($(GDL), -DHAS_GDL)
@@ -289,16 +289,16 @@ static: revision parsers
 else # end WIN, start LINUX & MACOSX
 static: doc/helpmap.cpp revision parsers
 	$(MAKE) $(MULTIPROZGEIL) $(TARGET_LINUX)
-endif # end LINUX & MACOSX
-
-$(TARGET_DLL): $(DLL_OBJECTS)
-	g++ -shared -o $(TARGET_DLL) $(DLL_OBJECTS) $(DLL_LIBS)
-
-$(TARGET_WIN): $(OBJECTS)
-	$(LINK) $(LDFLAG) -o $(TARGET_WIN) $(OBJECTS) $(LIBS)
+endif # end LINUX & MACOSX
+
+$(TARGET_DLL): $(DLL_OBJECTS)
+	$(LINK) -shared -o $(TARGET_DLL) $(DLL_OBJECTS) $(DLL_LIBS)
+
+$(TARGET_WIN): $(OBJECTS)
+	$(LINK) $(LDFLAG) -o $(TARGET_WIN) $(OBJECTS) $(LIBS)
 
 $(TARGET_LINUX): $(OBJECTS)
-	$(LINK) $(LDFLAG) -o $(TARGET_LINUX) $(OBJECTS) $(LIBS)
+	$(LINK) $(LDFLAG) -o $(TARGET_LINUX) $(OBJECTS) $(LDFLAGS) $(LIBS)
 
 # Builds parser-, dpuser2c & idl2c-source-files
 parsers: parsers_qf
diff --git a/utils/Makefile b/utils/Makefile
index 62418b0..9200303 100644
--- a/utils/Makefile
+++ b/utils/Makefile
@@ -8,12 +8,12 @@
 
 ####### Compiler, tools and options
 
-CC             = gcc
-CXX            = g++
-LEX            = flex
-YACC           = yacc
-CFLAGS         = -pipe -Wall -W -O2  -DQT_NO_DEBUG
-CXXFLAGS       = -pipe -Wall -W -O2  -DQT_NO_DEBUG
+CC             ?= gcc
+CXX            ?= g++
+LEX            ?= flex
+YACC           ?= yacc
+CFLAGS         += -DQT_NO_DEBUG
+CXXFLAGS       += -DQT_NO_DEBUG
 LEXFLAGS       = 
 YACCFLAGS      = -d
 INCPATH        = -I/afs/mpe/home/ott/qt-x11-free-3.3.1/mkspecs/default -I. -I$(QTDIR)/include
