Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a0f97e06 authored by Sam Ravnborg's avatar Sam Ravnborg
Browse files

kbuild: enable 'make CFLAGS=...' to add additional options to CC



The variable CFLAGS is a wellknown variable and the usage by
kbuild may result in unexpected behaviour.
On top of that several people over time has asked for a way to
pass in additional flags to gcc.

This patch replace use of CFLAGS with KBUILD_CFLAGS all over the
tree and enabling one to use:
make CFLAGS=...
to specify additional gcc commandline options.

One usecase is when trying to find gcc bugs but other
use cases has been requested too.

Patch was tested on following architectures:
alpha, arm, i386, x86_64, mips, sparc, sparc64, ia64, m68k

Test was simple to do a defconfig build, apply the patch and check
that nothing got rebuild.

Signed-off-by: default avatarSam Ravnborg <sam@ravnborg.org>
parent 9a39e273
Loading
Loading
Loading
Loading
+9 −6
Original line number Diff line number Diff line
@@ -294,7 +294,7 @@ more details, with real examples.


	This variable is necessary because the top Makefile owns the
	variable $(CFLAGS) and uses it for compilation flags for the
	variable $(KBUILD_CFLAGS) and uses it for compilation flags for the
	entire tree.

	$(EXTRA_AFLAGS) is a similar string for per-directory options
@@ -437,6 +437,7 @@ more details, with real examples.
	-march=pentium-mmx if supported by $(CC), otherwise -march=i586.
	The second argument to cc-option is optional, and if omitted,
	cflags-y will be assigned no value if first option is not supported.
	Note: cc-option uses KBUILD_CFLAGS for $(CC) options

   cc-option-yn
	cc-option-yn is used to check if gcc supports a given option
@@ -452,6 +453,7 @@ more details, with real examples.
	option. When $(biarch) equals 'y', the expanded variables $(aflags-y)
	and $(cflags-y) will be assigned the values -a32 and -m32,
	respectively.
	Note: cc-option-yn uses KBUILD_CFLAGS for $(CC) options

    cc-option-align
	gcc versions >= 3.0 changed the type of options used to specify
@@ -463,10 +465,11 @@ more details, with real examples.
		cc-option-align = -falign

	Example:
		CFLAGS += $(cc-option-align)-functions=4
		KBUILD_CFLAGS += $(cc-option-align)-functions=4

	In the above example, the option -falign-functions=4 is used for
	gcc >= 3.00. For gcc < 3.00, -malign-functions=4 is used.
	Note: cc-option-align uses KBUILD_CFLAGS for $(CC) options

    cc-version
	cc-version returns a numerical version of the $(CC) compiler version.
@@ -825,17 +828,17 @@ When kbuild executes, the following steps are followed (roughly):
		#arch/sparc64/Makefile
		AFLAGS += -m64 -mcpu=ultrasparc

    CFLAGS		$(CC) compiler flags
    KBUILD_CFLAGS		$(CC) compiler flags

	Default value - see top level Makefile
	Append or modify as required per architecture.

	Often, the CFLAGS variable depends on the configuration.
	Often, the KBUILD_CFLAGS variable depends on the configuration.

	Example:
		#arch/i386/Makefile
		cflags-$(CONFIG_M386) += -march=i386
		CFLAGS += $(cflags-y)
		KBUILD_CFLAGS += $(cflags-y)

	Many arch Makefiles dynamically run the target C compiler to
	probe supported options:
@@ -847,7 +850,7 @@ When kbuild executes, the following steps are followed (roughly):
						-march=pentium2,-march=i686)
		...
		# Disable unit-at-a-time mode ...
		CFLAGS += $(call cc-option,-fno-unit-at-a-time)
		KBUILD_CFLAGS += $(call cc-option,-fno-unit-at-a-time)
		...


+10 −10
Original line number Diff line number Diff line
@@ -320,7 +320,7 @@ LINUXINCLUDE := -Iinclude \

CPPFLAGS        := -D__KERNEL__ $(LINUXINCLUDE)

CFLAGS          := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
KBUILD_CFLAGS   := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
		   -fno-strict-aliasing -fno-common \
		   -Werror-implicit-function-declaration
AFLAGS          := -D__ASSEMBLY__
@@ -335,7 +335,7 @@ export CPP AR NM STRIP OBJCOPY OBJDUMP MAKE AWK GENKSYMS PERL UTS_MACHINE
export HOSTCXX HOSTCXXFLAGS LDFLAGS_MODULE CHECK CHECKFLAGS

export CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS LDFLAGS
export CFLAGS CFLAGS_KERNEL CFLAGS_MODULE
export KBUILD_CFLAGS CFLAGS_KERNEL CFLAGS_MODULE
export AFLAGS AFLAGS_KERNEL AFLAGS_MODULE

# When compiling out-of-tree modules, put MODVERDIR in the module
@@ -492,36 +492,36 @@ endif # $(dot-config)
all: vmlinux

ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE
CFLAGS		+= -Os
KBUILD_CFLAGS	+= -Os
else
CFLAGS		+= -O2
KBUILD_CFLAGS	+= -O2
endif

include $(srctree)/arch/$(ARCH)/Makefile

ifdef CONFIG_FRAME_POINTER
CFLAGS		+= -fno-omit-frame-pointer -fno-optimize-sibling-calls
KBUILD_CFLAGS	+= -fno-omit-frame-pointer -fno-optimize-sibling-calls
else
CFLAGS		+= -fomit-frame-pointer
KBUILD_CFLAGS	+= -fomit-frame-pointer
endif

ifdef CONFIG_DEBUG_INFO
CFLAGS		+= -g
KBUILD_CFLAGS	+= -g
AFLAGS		+= -gdwarf-2
endif

# Force gcc to behave correct even for buggy distributions
CFLAGS          += $(call cc-option, -fno-stack-protector)
KBUILD_CFLAGS         += $(call cc-option, -fno-stack-protector)

# arch Makefile may override CC so keep this after arch Makefile is included
NOSTDINC_FLAGS += -nostdinc -isystem $(shell $(CC) -print-file-name=include)
CHECKFLAGS     += $(NOSTDINC_FLAGS)

# warn about C99 declaration after statement
CFLAGS += $(call cc-option,-Wdeclaration-after-statement,)
KBUILD_CFLAGS += $(call cc-option,-Wdeclaration-after-statement,)

# disable pointer signed / unsigned warnings in gcc 4.0
CFLAGS += $(call cc-option,-Wno-pointer-sign,)
KBUILD_CFLAGS += $(call cc-option,-Wno-pointer-sign,)

# Use --build-id when available.
LDFLAGS_BUILD_ID = $(patsubst -Wl$(comma)%,%,\
+1 −1
Original line number Diff line number Diff line
@@ -84,7 +84,7 @@ endif
# For TSUNAMI, we must have the assembler not emulate our instructions.
# The same is true for IRONGATE, POLARIS, PYXIS.
# BWX is most important, but we don't really want any emulation ever.
CFLAGS += $(cflags-y) -Wa,-mev6
KBUILD_CFLAGS += $(cflags-y) -Wa,-mev6

head-y := arch/alpha/kernel/head.o

+1 −1
Original line number Diff line number Diff line
@@ -3,7 +3,7 @@
#

extra-y		:= head.o vmlinux.lds
EXTRA_AFLAGS	:= $(CFLAGS)
EXTRA_AFLAGS	:= $(KBUILD_CFLAGS)
EXTRA_CFLAGS	:= -Werror -Wno-sign-compare

obj-y    := entry.o traps.o process.o init_task.o osf_sys.o irq.o \
+1 −1
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@
# Makefile for alpha-specific library files..
#

EXTRA_AFLAGS := $(CFLAGS)
EXTRA_AFLAGS := $(KBUILD_CFLAGS)
EXTRA_CFLAGS := -Werror

# Many of these routines have implementations tuned for ev6.
Loading