From: YOKOTA Hiroshi <qykth-git@users.noreply.github.com>
Date: Sat, 23 Nov 2019 17:48:46 +0900
Subject: Hardening Qt code

Forwarded: not-needed

Allow hardening flags from debhelper.
---
 setup/build.py | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/setup/build.py b/setup/build.py
index b67803b..74f6ebc 100644
--- a/setup/build.py
+++ b/setup/build.py
@@ -259,6 +259,7 @@ def init_env(debug=False, sanitize=False, compiling_for='native'):
         ldflags = os.environ.get('OVERRIDE_LDFLAGS', '-Wall')
         ldflags = shlex.split(ldflags)
         cflags += shlex.split(os.environ.get('CFLAGS', ''))
+        cflags += shlex.split(os.environ.get('CPPFLAGS', ''))
         ldflags += shlex.split(os.environ.get('LDFLAGS', ''))
         cflags += ['-fvisibility=hidden']
         if sanitize:
@@ -712,6 +713,15 @@ sip-file = "{os.path.basename(sipf)}"
         cwd = os.getcwd()
         try:
             os.chdir(os.path.join(src_dir, 'build'))
+            for q in walk('.'):
+                if os.path.basename(q) in ('Makefile',):
+                    with open(q, 'r+') as f:
+                        raw = f.read()
+                        raw = raw.replace('CFLAGS        =', 'CFLAGS        = ' + os.environ.get('CFLAGS',   '') + ' ' + os.environ.get('CPPFLAGS', ''))
+                        raw = raw.replace('CXXFLAGS      =', 'CXXFLAGS      = ' + os.environ.get('CXXFLAGS', '') + ' ' + os.environ.get('CPPFLAGS', ''))
+                        raw = raw.replace('LFLAGS        =', 'LFLAGS        = ' + os.environ.get('LDFLAGS',  ''))
+                        f.seek(0), f.truncate()
+                        f.write(raw)
             self.check_call([self.env.make] + ([] if iswindows else ['-j%d'%(os.cpu_count() or 1)]))
             e = 'pyd' if iswindows else 'so'
             m = glob.glob(f'{ext.name}/{ext.name}.*{e}')
