Skip to content

Commit 06c5040

Browse files
author
Sam Ravnborg
committed
kbuild: enable 'make CPPFLAGS=...' to add additional options to CPP
The variable CPPFLAGS is a wellknown variable and the usage by kbuild may result in unexpected behaviour. This patch replace use of CPPFLAGS with KBUILD_CPPFLAGS all over the tree and enabling one to use: make CPPFLAGS=... to specify additional CPP commandline options. Patch was tested on following architectures: alpha, arm, i386, x86_64, mips, sparc, sparc64, ia64, m68k, s390 Signed-off-by: Sam Ravnborg <[email protected]>
1 parent 52bcc33 commit 06c5040

File tree

9 files changed

+18
-17
lines changed

9 files changed

+18
-17
lines changed

Documentation/kbuild/makefiles.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1099,7 +1099,7 @@ When kbuild executes, the following steps are followed (roughly):
10991099
specified options when building the target vmlinux.lds.
11001100

11011101
When building the *.lds target, kbuild uses the variables:
1102-
CPPFLAGS : Set in top-level Makefile
1102+
KBUILD_CPPFLAGS : Set in top-level Makefile
11031103
EXTRA_CPPFLAGS : May be set in the kbuild makefile
11041104
CPPFLAGS_$(@F) : Target specific flags.
11051105
Note that the full filename is used in this

Makefile

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ LINUXINCLUDE := -Iinclude \
318318
$(if $(KBUILD_SRC),-Iinclude2 -I$(srctree)/include) \
319319
-include include/linux/autoconf.h
320320

321-
CPPFLAGS := -D__KERNEL__ $(LINUXINCLUDE)
321+
KBUILD_CPPFLAGS := -D__KERNEL__ $(LINUXINCLUDE)
322322

323323
KBUILD_CFLAGS := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
324324
-fno-strict-aliasing -fno-common \
@@ -334,7 +334,7 @@ export ARCH SRCARCH CONFIG_SHELL HOSTCC HOSTCFLAGS CROSS_COMPILE AS LD CC
334334
export CPP AR NM STRIP OBJCOPY OBJDUMP MAKE AWK GENKSYMS PERL UTS_MACHINE
335335
export HOSTCXX HOSTCXXFLAGS LDFLAGS_MODULE CHECK CHECKFLAGS
336336

337-
export CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS LDFLAGS
337+
export KBUILD_CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS LDFLAGS
338338
export KBUILD_CFLAGS CFLAGS_KERNEL CFLAGS_MODULE
339339
export KBUILD_AFLAGS AFLAGS_KERNEL AFLAGS_MODULE
340340

@@ -523,9 +523,10 @@ KBUILD_CFLAGS += $(call cc-option,-Wdeclaration-after-statement,)
523523
# disable pointer signed / unsigned warnings in gcc 4.0
524524
KBUILD_CFLAGS += $(call cc-option,-Wno-pointer-sign,)
525525

526-
# Add user supplied AFLAGS and CFLAGS as the last assignments
527-
KBUILD_AFLAGS += $(AFLAGS)
528-
KBUILD_CFLAGS += $(CFLAGS)
526+
# Add user supplied CPPFLAGS, AFLAGS and CFLAGS as the last assignments
527+
KBUILD_CPPFLAGS += $(CPPFLAGS)
528+
KBUILD_AFLAGS += $(AFLAGS)
529+
KBUILD_CFLAGS += $(CFLAGS)
529530

530531
# Use --build-id when available.
531532
LDFLAGS_BUILD_ID = $(patsubst -Wl$(comma)%,%,\
@@ -1507,7 +1508,7 @@ quiet_cmd_rmfiles = $(if $(wildcard $(rm-files)),CLEAN $(wildcard $(rm-files))
15071508

15081509

15091510
a_flags = -Wp,-MD,$(depfile) $(KBUILD_AFLAGS) $(AFLAGS_KERNEL) \
1510-
$(NOSTDINC_FLAGS) $(CPPFLAGS) \
1511+
$(NOSTDINC_FLAGS) $(KBUILD_CPPFLAGS) \
15111512
$(modkern_aflags) $(EXTRA_AFLAGS) $(AFLAGS_$(basetarget).o)
15121513

15131514
quiet_cmd_as_o_S = AS $@

arch/arm/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ KBUILD_CFLAGS +=-fno-omit-frame-pointer -mapcs -mno-sched-prolog
3232
endif
3333

3434
ifeq ($(CONFIG_CPU_BIG_ENDIAN),y)
35-
CPPFLAGS += -mbig-endian
35+
KBUILD_CPPFLAGS += -mbig-endian
3636
AS += -EB
3737
LD += -EB
3838
else
39-
CPPFLAGS += -mlittle-endian
39+
KBUILD_CPPFLAGS += -mlittle-endian
4040
AS += -EL
4141
LD += -EL
4242
endif

arch/ia64/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ cflags-y := -pipe $(EXTRA) -ffixed-r13 -mfixed-range=f12-f15,f32-f127 \
2929
CFLAGS_KERNEL := -mconstant-gp
3030

3131
GAS_STATUS = $(shell $(srctree)/arch/ia64/scripts/check-gas "$(CC)" "$(OBJDUMP)")
32-
CPPFLAGS += $(shell $(srctree)/arch/ia64/scripts/toolchain-flags "$(CC)" "$(OBJDUMP)" "$(READELF)")
32+
KBUILD_CPPFLAGS += $(shell $(srctree)/arch/ia64/scripts/toolchain-flags "$(CC)" "$(OBJDUMP)" "$(READELF)")
3333

3434
ifeq ($(GAS_STATUS),buggy)
3535
$(error Sorry, you need a newer version of the assember, one that is built from \

arch/powerpc/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ CPPFLAGS-$(CONFIG_PPC32) := -Iarch/$(ARCH)
7575
AFLAGS-$(CONFIG_PPC32) := -Iarch/$(ARCH)
7676
CFLAGS-$(CONFIG_PPC64) := -mminimal-toc -mtraceback=none -mcall-aixdesc
7777
CFLAGS-$(CONFIG_PPC32) := -Iarch/$(ARCH) -ffixed-r2 -mmultiple
78-
CPPFLAGS += $(CPPFLAGS-y)
78+
KBUILD_CPPFLAGS += $(CPPFLAGS-y)
7979
KBUILD_AFLAGS += $(AFLAGS-y)
8080
KBUILD_CFLAGS += -msoft-float -pipe $(CFLAGS-y)
8181
CPP = $(CC) -E $(KBUILD_CFLAGS)

arch/ppc/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ endif
2222

2323
LDFLAGS_vmlinux := -Ttext $(KERNELLOAD) -Bstatic
2424
# The -Iarch/$(ARCH)/include is temporary while we are merging
25-
CPPFLAGS += -Iarch/$(ARCH) -Iarch/$(ARCH)/include
25+
KBUILD_CPPFLAGS += -Iarch/$(ARCH) -Iarch/$(ARCH)/include
2626
KBUILD_AFLAGS += -Iarch/$(ARCH)
2727
KBUILD_CFLAGS += -Iarch/$(ARCH) -msoft-float -pipe \
2828
-ffixed-r2 -mmultiple

arch/um/Makefile-x86_64

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ KBUILD_CFLAGS += $(_extra_flags_)
1414
CHECKFLAGS += -m64
1515
KBUILD_AFLAGS += -m64
1616
LDFLAGS += -m elf_x86_64
17-
CPPFLAGS += -m64
17+
KBUILD_CPPFLAGS += -m64
1818

1919
ELF_ARCH := i386:x86-64
2020
ELF_FORMAT := elf64-x86-64

drivers/atm/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ ifeq ($(CONFIG_ATM_FORE200E_PCA),y)
4141
# guess the target endianess to choose the right PCA-200E firmware image
4242
ifeq ($(CONFIG_ATM_FORE200E_PCA_DEFAULT_FW),y)
4343
byteorder.h := include$(if $(patsubst $(srctree),,$(objtree)),2)/asm/byteorder.h
44-
CONFIG_ATM_FORE200E_PCA_FW := $(obj)/pca200e$(if $(shell $(CC) $(CPPFLAGS) -E -dM $(byteorder.h) | grep ' __LITTLE_ENDIAN '),.bin,_ecd.bin2)
44+
CONFIG_ATM_FORE200E_PCA_FW := $(obj)/pca200e$(if $(shell $(CC) $(KBUILD_CPPFLAGS) -E -dM $(byteorder.h) | grep ' __LITTLE_ENDIAN '),.bin,_ecd.bin2)
4545
endif
4646
endif
4747

scripts/Makefile.lib

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ modname_flags = $(if $(filter 1,$(words $(modname))),\
8686

8787
_c_flags = $(KBUILD_CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$(basetarget).o)
8888
_a_flags = $(KBUILD_AFLAGS) $(EXTRA_AFLAGS) $(AFLAGS_$(basetarget).o)
89-
_cpp_flags = $(CPPFLAGS) $(EXTRA_CPPFLAGS) $(CPPFLAGS_$(@F))
89+
_cpp_flags = $(KBUILD_CPPFLAGS) $(EXTRA_CPPFLAGS) $(CPPFLAGS_$(@F))
9090

9191
# If building the kernel in a separate objtree expand all occurrences
9292
# of -Idir to -I$(srctree)/dir except for absolute paths (starting with '/').
@@ -106,11 +106,11 @@ __a_flags = $(call flags,_a_flags)
106106
__cpp_flags = $(call flags,_cpp_flags)
107107
endif
108108

109-
c_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(CPPFLAGS) \
109+
c_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(KBUILD_CPPFLAGS) \
110110
$(__c_flags) $(modkern_cflags) \
111111
-D"KBUILD_STR(s)=\#s" $(basename_flags) $(modname_flags)
112112

113-
a_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(CPPFLAGS) \
113+
a_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(KBUILD_CPPFLAGS) \
114114
$(__a_flags) $(modkern_aflags)
115115

116116
cpp_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(__cpp_flags)

0 commit comments

Comments
 (0)