Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

kbuild: sort hostprogs before passing it to ifneq

The conditional:

ifneq ($(hostprogs),)

... is evaluated to true if $(hostprogs) does not contain any word but
whitespace characters.

ifneq ($(strip $(hostprogs)),)

... is a safe way to avoid interpreting whitespace as a non-empty value,
but I'd rather want to use the side-effect of $(sort ...) to do the
equivalent.

$(sort ...) is used in scripts/Makefile.host in order to drop duplication
in $(hostprogs). It is also useful to strip excessive spaces.

Move $(sort ...) before evaluating the ifneq.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>

+8 -7
+4 -1
scripts/Makefile.build
··· 45 45 46 46 include scripts/Makefile.lib 47 47 48 - # Do not include hostprogs rules unless needed 48 + # Do not include hostprogs rules unless needed. 49 + # $(sort ...) is used here to remove duplicated words and excessive spaces. 50 + hostprogs := $(sort $(hostprogs)) 49 51 ifneq ($(hostprogs),) 50 52 include scripts/Makefile.host 51 53 endif 52 54 53 55 # Do not include userprogs rules unless needed. 56 + # $(sort ...) is used here to remove duplicated words and excessive spaces. 54 57 userprogs := $(sort $(userprogs)) 55 58 ifneq ($(userprogs),) 56 59 include scripts/Makefile.userprogs
+4 -6
scripts/Makefile.host
··· 38 38 # Will compile qconf as a C++ program, and menu as a C program. 39 39 # They are linked as C++ code to the executable qconf 40 40 41 - __hostprogs := $(sort $(hostprogs)) 42 - 43 41 # C code 44 42 # Executables compiled from a single .c file 45 - host-csingle := $(foreach m,$(__hostprogs), \ 43 + host-csingle := $(foreach m,$(hostprogs), \ 46 44 $(if $($(m)-objs)$($(m)-cxxobjs),,$(m))) 47 45 48 46 # C executables linked based on several .o files 49 - host-cmulti := $(foreach m,$(__hostprogs),\ 47 + host-cmulti := $(foreach m,$(hostprogs),\ 50 48 $(if $($(m)-cxxobjs),,$(if $($(m)-objs),$(m)))) 51 49 52 50 # Object (.o) files compiled from .c files 53 - host-cobjs := $(sort $(foreach m,$(__hostprogs),$($(m)-objs))) 51 + host-cobjs := $(sort $(foreach m,$(hostprogs),$($(m)-objs))) 54 52 55 53 # C++ code 56 54 # C++ executables compiled from at least one .cc file 57 55 # and zero or more .c files 58 - host-cxxmulti := $(foreach m,$(__hostprogs),$(if $($(m)-cxxobjs),$(m))) 56 + host-cxxmulti := $(foreach m,$(hostprogs),$(if $($(m)-cxxobjs),$(m))) 59 57 60 58 # C++ Object (.o) files compiled from .cc files 61 59 host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))