Commit cdd750bf authored by Masahiro Yamada's avatar Masahiro Yamada

kbuild: remove 'addtree' and 'flags' magic for header search paths

The 'addtree' and 'flags' in scripts/Kbuild.include are so compilecated
and ugly.

As I mentioned in [1], Kbuild should stop automatic prefixing of header
search path options.

I fixed up (almost) all Makefiles in the kernel. Now 'addtree' and
'flags' have been removed.

Kbuild still caters to add $(srctree)/$(src) and $(objtree)/$(obj)
to the header search path for O= building, but never touches extra
compiler options from ccflags-y etc.

[1]: https://patchwork.kernel.org/patch/9632347/Signed-off-by: default avatarMasahiro Yamada <yamada.masahiro@socionext.com>
parent 9cc342f6
...@@ -192,14 +192,6 @@ clean := -f $(srctree)/scripts/Makefile.clean obj ...@@ -192,14 +192,6 @@ clean := -f $(srctree)/scripts/Makefile.clean obj
# $(Q)$(MAKE) $(hdr-inst)=dir # $(Q)$(MAKE) $(hdr-inst)=dir
hdr-inst := -f $(srctree)/scripts/Makefile.headersinst obj hdr-inst := -f $(srctree)/scripts/Makefile.headersinst obj
# Prefix -I with $(srctree) if it is not an absolute path.
# skip if -I has no parameter
addtree = $(if $(patsubst -I%,%,$(1)), \
$(if $(filter-out -I/% -I./% -I../%,$(1)),$(patsubst -I%,-I$(srctree)/%,$(1)),$(1)),$(1))
# Find all -I options and call addtree
flags = $(foreach o,$($(1)),$(if $(filter -I%,$(o)),$(call addtree,$(o)),$(o)))
# echo command. # echo command.
# Short version is used, if $(quiet) equals `quiet_', otherwise full one. # Short version is used, if $(quiet) equals `quiet_', otherwise full one.
echo-cmd = $(if $($(quiet)cmd_$(1)),\ echo-cmd = $(if $($(quiet)cmd_$(1)),\
......
...@@ -67,18 +67,16 @@ _hostc_flags = $(KBUILD_HOSTCFLAGS) $(HOST_EXTRACFLAGS) \ ...@@ -67,18 +67,16 @@ _hostc_flags = $(KBUILD_HOSTCFLAGS) $(HOST_EXTRACFLAGS) \
_hostcxx_flags = $(KBUILD_HOSTCXXFLAGS) $(HOST_EXTRACXXFLAGS) \ _hostcxx_flags = $(KBUILD_HOSTCXXFLAGS) $(HOST_EXTRACXXFLAGS) \
$(HOSTCXXFLAGS_$(basetarget).o) $(HOSTCXXFLAGS_$(basetarget).o)
__hostc_flags = $(_hostc_flags) # $(objtree)/$(obj) for including generated headers from checkin source files
__hostcxx_flags = $(_hostcxx_flags)
ifeq ($(KBUILD_EXTMOD),) ifeq ($(KBUILD_EXTMOD),)
ifneq ($(srctree),.) ifneq ($(srctree),.)
__hostc_flags = -I$(obj) $(call flags,_hostc_flags) _hostc_flags += -I $(objtree)/$(obj)
__hostcxx_flags = -I$(obj) $(call flags,_hostcxx_flags) _hostcxx_flags += -I $(objtree)/$(obj)
endif endif
endif endif
hostc_flags = -Wp,-MD,$(depfile) $(__hostc_flags) hostc_flags = -Wp,-MD,$(depfile) $(_hostc_flags)
hostcxx_flags = -Wp,-MD,$(depfile) $(__hostcxx_flags) hostcxx_flags = -Wp,-MD,$(depfile) $(_hostcxx_flags)
##### #####
# Compile programs on the host # Compile programs on the host
......
...@@ -137,36 +137,26 @@ _c_flags += $(if $(patsubst n%,, \ ...@@ -137,36 +137,26 @@ _c_flags += $(if $(patsubst n%,, \
$(CFLAGS_KCOV)) $(CFLAGS_KCOV))
endif endif
__c_flags = $(_c_flags) # $(srctree)/$(src) for including checkin headers from generated source files
__a_flags = $(_a_flags) # $(objtree)/$(obj) for including generated headers from checkin source files
__cpp_flags = $(_cpp_flags)
# If building the kernel in a separate objtree expand all occurrences
# of -Idir to -I$(srctree)/dir except for absolute paths (starting with '/').
ifeq ($(KBUILD_EXTMOD),) ifeq ($(KBUILD_EXTMOD),)
ifneq ($(srctree),.) ifneq ($(srctree),.)
_c_flags += -I $(srctree)/$(src) -I $(objtree)/$(obj)
# -I$(obj) locates generated .h files _a_flags += -I $(srctree)/$(src) -I $(objtree)/$(obj)
# $(call addtree,-I$(obj)) locates .h files in srctree, from generated .c files _cpp_flags += -I $(srctree)/$(src) -I $(objtree)/$(obj)
# and locates generated .h files
# FIXME: Replace both with specific CFLAGS* statements in the makefiles
__c_flags = $(if $(obj),$(call addtree,-I$(src)) -I$(obj)) \
$(call flags,_c_flags)
__a_flags = $(call flags,_a_flags)
__cpp_flags = $(call flags,_cpp_flags)
endif endif
endif endif
c_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \ c_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \
-include $(srctree)/include/linux/compiler_types.h \ -include $(srctree)/include/linux/compiler_types.h \
$(__c_flags) $(modkern_cflags) \ $(_c_flags) $(modkern_cflags) \
$(basename_flags) $(modname_flags) $(basename_flags) $(modname_flags)
a_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \ a_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \
$(__a_flags) $(modkern_aflags) $(_a_flags) $(modkern_aflags)
cpp_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \ cpp_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \
$(__cpp_flags) $(_cpp_flags)
ld_flags = $(KBUILD_LDFLAGS) $(ldflags-y) $(LDFLAGS_$(@F)) ld_flags = $(KBUILD_LDFLAGS) $(ldflags-y) $(LDFLAGS_$(@F))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment