From: Gwen Weinholt <weinholt@debian.org>
Date: Sun, 18 Dec 2022 12:46:44 +0100
Subject: Pass through compiler flags to gcc

Forwarded: no
---
 Makefile  | 4 ++--
 build.scm | 4 ++++
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/Makefile b/Makefile
index 9489174..f4a5610 100644
--- a/Makefile
+++ b/Makefile
@@ -305,7 +305,7 @@ require.scm:
 
 # SCMLIT -- Make this first!
 $(SCMLIT):	$(ofiles) scmmain.o require.scm Makefile
-	$(LD) -o scmlit $(ofiles) scmmain.o $(LIBS)
+	$(LD) -o scmlit $(ofiles) scmmain.o $(LDFLAGS) $(LIBS)
 	$(MAKE) checklit
 scmflags.h:	scmflags
 scmflags:
@@ -317,7 +317,7 @@ scmflags:
 	-if (cmp -s newflags.h scmflags.h) then rm newflags.h; \
 		 else mv newflags.h scmflags.h; fi
 .c.o:
-	$(CC) -c $(CFLAGS) $< -o $@
+	$(CC) -c $(CPPFLAGS) $(CFLAGS) $< -o $@
 scm.o:	scm.c scm.h scmfig.h scmflags.h patchlvl.h
 scmmain.o:	scmmain.c scm.h scmfig.h scmflags.h patchlvl.h
 scl.o:	scl.c scm.h scmfig.h scmflags.h
diff --git a/build.scm b/build.scm
index 365a7ef..e3031d7 100644
--- a/build.scm
+++ b/build.scm
@@ -1041,6 +1041,8 @@
 				    (include-spec "-I" parms)
 				    (c-includes parms)
 				    (c-flags parms)
+				    (getenv "CPPFLAGS")
+				    (getenv "CFLAGS")
 				    files)
 	 (truncate-up-to (map c->o files) #\/))))
 (defcommand compile-dll-c-files linux
@@ -1076,6 +1078,7 @@
 	    (string-append
 	     (car (parameter-list-ref parms 'implvic))
 	     oname ".so")
+	    (getenv "CFLAGS")
 	    objects
 	    (map (lambda (l) (build:lib-ld-flag l platform))
 		 (parameter-list-ref parms 'c-lib)))
@@ -1087,6 +1090,7 @@
   (lambda (oname objects libs parms)
     (and (batch:try-command
 	  parms "gcc" "-rdynamic" "-o" oname
+          (getenv "LDFLAGS")
 	  (must-be-first
 	   '("pre-crt0.o" "ecrt0.o" "/usr/lib/crt0.o")
 	   (append objects libs)))
