Skip to contentSkip to conversation

Allow override of CFLAGS/LDFLAGS

PATCH In review Chris Larson 2 participants 3 messages Nov 24, 2003 – Dec 2, 2003 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Allow override of CFLAGS/LDFLAGS

Greetings,

As it is generally a good idea to allow the user to override CFLAGS and LDFLAGS (automake based systems manage this with AM_CFLAGS vs CFLAGS), here's a patch that does so. The key is to keep options that are required to build, along with include and link paths relative to the source dir seperate from those that should be overridable (warning flags, debug flags, optimizations, include/lib paths outside the source tree). Rather than adding another couple variables, I made use of the GNU make 'override' directive.

--
Chris Larson - kergoth at handhelds dot org Embedded Linux Developer - clarson at ti dot com OpenZaurus Project Maintainer - http://openzaurus.org/

#
# Patch managed by http://www.mn-logistik.de/unsupported/pxa250/patcher
#

Makefile renamed from Makefile~flags +7 -6
@@ -94,12 +94,13 @@
 endif
 
 # if DEBUG is enabled, then we do not strip or optimize
+override CFLAGS += -D_GNU_SOURCE
 ifeq ($(strip $(DEBUG)),true)
-	CFLAGS  += $(WARNINGS) -O1 -g -DDEBUG -D_GNU_SOURCE
+	CFLAGS  += $(WARNINGS) -O1 -g -DDEBUG
 	LDFLAGS += -Wl,-warn-common
 	STRIPCMD = /bin/true -Since_we_are_debugging
 else
-	CFLAGS  += $(WARNINGS) $(OPTIMIZATION) -fomit-frame-pointer -D_GNU_SOURCE
+	CFLAGS  += $(WARNINGS) $(OPTIMIZATION) -fomit-frame-pointer
 	LDFLAGS += -s -Wl,-warn-common
 	STRIPCMD = $(STRIP) -s --remove-section=.note --remove-section=.comment
 endif
@@ -118,15 +119,15 @@
 
 	CRT0 = $(KLIBC_DIR)/crt0.o
 	LIBC =	$(ARCH_LIB_OBJS) $(LIB_OBJS)
-	CFLAGS += -nostdinc -I$(INCLUDE_DIR) -I$(INCLUDE_DIR)/bits32 -I$(GCCINCDIR) -Iklibc/linux/include -D__KLIBC__
+	override CFLAGS += -nostdinc -I$(INCLUDE_DIR) -I$(INCLUDE_DIR)/bits32 -I$(GCCINCDIR) -Iklibc/linux/include -D__KLIBC__
 	LIB_OBJS =
-	LDFLAGS = --static --nostdlib -nostartfiles
+	override LDFLAGS += --static --nostdlib -nostartfiles
 else
 	CRT0 =
 	LIBC = 
-	CFLAGS += -I$(GCCINCDIR)
+	override CFLAGS += -I$(GCCINCDIR)
 	LIB_OBJS = -lc
-	LDFLAGS = --static 
+	override LDFLAGS += --static 
 endif
 
 all: $(LIBC) $(ROOT)
#1 lore raw
Quoted 10 lines · Chris Larson

Greetings,

As it is generally a good idea to allow the user to override CFLAGS and LDFLAGS (automake based systems manage this with AM_CFLAGS vs CFLAGS), here's a patch that does so. The key is to keep options that are required to build, along with include and link paths relative to the source dir seperate from those that should be overridable (warning flags, debug flags, optimizations, include/lib paths outside the source tree). Rather than adding another couple variables, I made use of the GNU make 'override' directive.

Hm, this patch breaks the binary when building with klibc. Can you try to fix it up?

thanks,

greg k-h

-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program. Does SourceForge.net help you be more productive? Does it help you create better code? SHARE THE LOVE, and help us help YOU! Click Here: http://sourceforge.net/donate/
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#2 lore raw
In reply to Chris Larson
Quoted 12 lines · * Greg KH ([email protected]) wrote:
Quoted 10 lines · Chris Larson

Greetings,

As it is generally a good idea to allow the user to override CFLAGS and LDFLAGS (automake based systems manage this with AM_CFLAGS vs CFLAGS), here's a patch that does so. The key is to keep options that are required to build, along with include and link paths relative to the source dir seperate from those that should be overridable (warning flags, debug flags, optimizations, include/lib paths outside the source tree). Rather than adding another couple variables, I made use of the GNU make 'override' directive.

Quoted 2 lines

Hm, this patch breaks the binary when building with klibc. Can you try to fix it up?

Will do, thanks.
--
Chris Larson - kergoth at handhelds dot org Embedded Linux Developer - clarson at ti dot com OpenZaurus Project Maintainer - http://openzaurus.org/

-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program. Does SourceForge.net help you be more productive? Does it help you create better code? SHARE THE LOVE, and help us help YOU! Click Here: http://sourceforge.net/donate/
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel