diff mbox

[5/6] build: pass standard make variables to compiler and linker

Message ID 20171004132605.24734-6-uwe@kleine-koenig.org (mailing list archive)
State Rejected, archived
Headers show

Commit Message

Uwe Kleine-König Oct. 4, 2017, 1:26 p.m. UTC
Add all variables that make's builtin rules pass to compiler and linker.

I don't know a user of TARGET_ARCH but Debian packages use CPPFLAGS to
pass -D_FORTIFY_SOURCE=2 for hardening.

Signed-off-by: Uwe Kleine-König <uwe@kleine-koenig.org>
---
 Makefile | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Comments

Luc Van Oostenryck Nov. 4, 2017, 6:43 a.m. UTC | #1
On Wed, Oct 04, 2017 at 03:26:04PM +0200, Uwe Kleine-König wrote:
> Add all variables that make's builtin rules pass to compiler and linker.
> 
> I don't know a user of TARGET_ARCH but Debian packages use CPPFLAGS to
> pass -D_FORTIFY_SOURCE=2 for hardening.

I've looked a bit at this. What I think is:
- LOADLIBES & LDLIBS are standard (g)make variables but I don't think
  there is any reasons to allow them to be overriden from the command
  line or the environment.
- TARGET_ARCH is a strange beast, it seems the intention was for
  something like '-march=armv7' which should be OK here but the only
  use I saw was to hold the output of 'uname -m'.
  I think it's better to not have it here
- of course the change for CPPFLAGS is completly legitimate.

-- Luc
--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/Makefile b/Makefile
index 39b34f90107d..f6c577c02143 100644
--- a/Makefile
+++ b/Makefile
@@ -190,13 +190,13 @@  compile_EXTRA_DEPS = compile-i386.o
 
 $(foreach p,$(PROGRAMS),$(eval $(p): $($(p)_EXTRA_DEPS) $(LIBS)))
 $(PROGRAMS): % : %.o 
-	$(QUIET_LINK)$(LD) $(LDFLAGS) -o $@ $^ $($@_EXTRA_OBJS)
+	$(QUIET_LINK)$(LD) $(LDFLAGS) $(TARGET_ARCH) $^ $(LOADLIBES) $(LDLIBS) -o $@ $($@_EXTRA_OBJS)
 
 $(LIB_FILE): $(LIB_OBJS)
 	$(QUIET_AR)$(AR) rcs $@ $(LIB_OBJS)
 
 $(SLIB_FILE): $(LIB_OBJS)
-	$(QUIET_LINK)$(CC) $(LDFLAGS) -Wl,-soname,$@ -shared -o $@ $(LIB_OBJS)
+	$(QUIET_LINK)$(CC) $(LDFLAGS) $(TARGET_ARCH) -Wl,-soname,$@ -shared $^ $(LOADLIBES) $(LDLIBS) -o $@
 
 DEP_FILES := $(wildcard .*.o.d)
 
@@ -209,10 +209,10 @@  c2xml.o c2xml.sc: CFLAGS += $(LIBXML_CFLAGS)
 pre-process.sc: CHECKER_FLAGS += -Wno-vla
 
 %.o: %.c $(LIB_H)
-	$(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) $<
+	$(QUIET_CC)$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c -o $@ $<
 
 %.sc: %.c sparse
-	$(QUIET_CHECK) $(CHECKER) $(CHECKER_FLAGS) -c $(CFLAGS) $<
+	$(QUIET_CHECK) $(CHECKER) $(CHECKER_FLAGS) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c $<
 
 ALL_OBJS :=  $(LIB_OBJS) $(foreach p,$(PROGRAMS),$(p).o $($(p)_EXTRA_DEPS))
 selfcheck: $(ALL_OBJS:.o=.sc)