1*4882a593Smuzhiyun#### 2*4882a593Smuzhiyun# kbuild: Generic definitions 3*4882a593Smuzhiyun 4*4882a593Smuzhiyun# Convenient variables 5*4882a593Smuzhiyuncomma := , 6*4882a593Smuzhiyunquote := " 7*4882a593Smuzhiyunsquote := ' 8*4882a593Smuzhiyunempty := 9*4882a593Smuzhiyunspace := $(empty) $(empty) 10*4882a593Smuzhiyunspace_escape := _-_SPACE_-_ 11*4882a593Smuzhiyunpound := \# 12*4882a593Smuzhiyun 13*4882a593Smuzhiyun### 14*4882a593Smuzhiyun# Name of target with a '.' as filename prefix. foo/bar.o => foo/.bar.o 15*4882a593Smuzhiyundot-target = $(dir $@).$(notdir $@) 16*4882a593Smuzhiyun 17*4882a593Smuzhiyun### 18*4882a593Smuzhiyun# The temporary file to save gcc -MD generated dependencies must not 19*4882a593Smuzhiyun# contain a comma 20*4882a593Smuzhiyundepfile = $(subst $(comma),_,$(dot-target).d) 21*4882a593Smuzhiyun 22*4882a593Smuzhiyun### 23*4882a593Smuzhiyun# filename of target with directory and extension stripped 24*4882a593Smuzhiyunbasetarget = $(basename $(notdir $@)) 25*4882a593Smuzhiyun 26*4882a593Smuzhiyun### 27*4882a593Smuzhiyun# filename of first prerequisite with directory and extension stripped 28*4882a593Smuzhiyunbaseprereq = $(basename $(notdir $<)) 29*4882a593Smuzhiyun 30*4882a593Smuzhiyun### 31*4882a593Smuzhiyun# Escape single quote for use in echo statements 32*4882a593Smuzhiyunescsq = $(subst $(squote),'\$(squote)',$1) 33*4882a593Smuzhiyun 34*4882a593Smuzhiyun### 35*4882a593Smuzhiyun# Easy method for doing a status message 36*4882a593Smuzhiyun kecho := : 37*4882a593Smuzhiyun quiet_kecho := echo 38*4882a593Smuzhiyunsilent_kecho := : 39*4882a593Smuzhiyunkecho := $($(quiet)kecho) 40*4882a593Smuzhiyun 41*4882a593Smuzhiyun### 42*4882a593Smuzhiyun# filechk is used to check if the content of a generated file is updated. 43*4882a593Smuzhiyun# Sample usage: 44*4882a593Smuzhiyun# define filechk_sample 45*4882a593Smuzhiyun# echo $KERNELRELEASE 46*4882a593Smuzhiyun# endef 47*4882a593Smuzhiyun# version.h : Makefile 48*4882a593Smuzhiyun# $(call filechk,sample) 49*4882a593Smuzhiyun# The rule defined shall write to stdout the content of the new file. 50*4882a593Smuzhiyun# The existing file will be compared with the new one. 51*4882a593Smuzhiyun# - If no file exist it is created 52*4882a593Smuzhiyun# - If the content differ the new file is used 53*4882a593Smuzhiyun# - If they are equal no change, and no timestamp update 54*4882a593Smuzhiyun# - stdin is piped in from the first prerequisite ($<) so one has 55*4882a593Smuzhiyun# to specify a valid file as first prerequisite (often the kbuild file) 56*4882a593Smuzhiyundefine filechk 57*4882a593Smuzhiyun $(Q)set -e; \ 58*4882a593Smuzhiyun mkdir -p $(dir $@); \ 59*4882a593Smuzhiyun $(filechk_$(1)) > $@.tmp; \ 60*4882a593Smuzhiyun if [ -r $@ ] && cmp -s $@ $@.tmp; then \ 61*4882a593Smuzhiyun rm -f $@.tmp; \ 62*4882a593Smuzhiyun else \ 63*4882a593Smuzhiyun $(kecho) ' UPD $@'; \ 64*4882a593Smuzhiyun mv -f $@.tmp $@; \ 65*4882a593Smuzhiyun fi 66*4882a593Smuzhiyunendef 67*4882a593Smuzhiyun 68*4882a593Smuzhiyun###### 69*4882a593Smuzhiyun# gcc support functions 70*4882a593Smuzhiyun# See documentation in Documentation/kbuild/makefiles.txt 71*4882a593Smuzhiyun 72*4882a593Smuzhiyun# cc-cross-prefix 73*4882a593Smuzhiyun# Usage: CROSS_COMPILE := $(call cc-cross-prefix, m68k-linux-gnu- m68k-linux-) 74*4882a593Smuzhiyun# Return first prefix where a prefix$(CC) is found in PATH. 75*4882a593Smuzhiyun# If no $(CC) found in PATH with listed prefixes return nothing 76*4882a593Smuzhiyuncc-cross-prefix = \ 77*4882a593Smuzhiyun $(word 1, $(foreach c,$(1), \ 78*4882a593Smuzhiyun $(shell set -e; \ 79*4882a593Smuzhiyun if (which $(strip $(c))$(CC)) > /dev/null 2>&1 ; then \ 80*4882a593Smuzhiyun echo $(c); \ 81*4882a593Smuzhiyun fi))) 82*4882a593Smuzhiyun 83*4882a593Smuzhiyun# output directory for tests below 84*4882a593SmuzhiyunTMPOUT = $(if $(KBUILD_EXTMOD),$(firstword $(KBUILD_EXTMOD))/).tmp_$$$$ 85*4882a593Smuzhiyun 86*4882a593Smuzhiyun# try-run 87*4882a593Smuzhiyun# Usage: option = $(call try-run, $(CC)...-o "$$TMP",option-ok,otherwise) 88*4882a593Smuzhiyun# Exit code chooses option. "$$TMP" serves as a temporary file and is 89*4882a593Smuzhiyun# automatically cleaned up. 90*4882a593Smuzhiyuntry-run = $(shell set -e; \ 91*4882a593Smuzhiyun TMP=$(TMPOUT)/tmp; \ 92*4882a593Smuzhiyun TMPO=$(TMPOUT)/tmp.o; \ 93*4882a593Smuzhiyun mkdir -p $(TMPOUT); \ 94*4882a593Smuzhiyun trap "rm -rf $(TMPOUT)" EXIT; \ 95*4882a593Smuzhiyun if ($(1)) >/dev/null 2>&1; \ 96*4882a593Smuzhiyun then echo "$(2)"; \ 97*4882a593Smuzhiyun else echo "$(3)"; \ 98*4882a593Smuzhiyun fi) 99*4882a593Smuzhiyun 100*4882a593Smuzhiyun# as-option 101*4882a593Smuzhiyun# Usage: cflags-y += $(call as-option,-Wa$(comma)-isa=foo,) 102*4882a593Smuzhiyun 103*4882a593Smuzhiyunas-option = $(call try-run,\ 104*4882a593Smuzhiyun $(CC) $(KBUILD_CFLAGS) $(1) -c -x assembler /dev/null -o "$$TMP",$(1),$(2)) 105*4882a593Smuzhiyun 106*4882a593Smuzhiyun# as-instr 107*4882a593Smuzhiyun# Usage: cflags-y += $(call as-instr,instr,option1,option2) 108*4882a593Smuzhiyun 109*4882a593Smuzhiyunas-instr = $(call try-run,\ 110*4882a593Smuzhiyun printf "%b\n" "$(1)" | $(CC) $(KBUILD_AFLAGS) -c -x assembler -o "$$TMP" -,$(2),$(3)) 111*4882a593Smuzhiyun 112*4882a593Smuzhiyun# __cc-option 113*4882a593Smuzhiyun# Usage: MY_CFLAGS += $(call __cc-option,$(CC),$(MY_CFLAGS),-march=winchip-c6,-march=i586) 114*4882a593Smuzhiyun__cc-option = $(call try-run,\ 115*4882a593Smuzhiyun $(1) -Werror $(2) $(3) -c -x c /dev/null -o "$$TMP",$(3),$(4)) 116*4882a593Smuzhiyun 117*4882a593Smuzhiyun# Do not attempt to build with gcc plugins during cc-option tests. 118*4882a593Smuzhiyun# (And this uses delayed resolution so the flags will be up to date.) 119*4882a593SmuzhiyunCC_OPTION_CFLAGS = $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS)) 120*4882a593Smuzhiyun 121*4882a593Smuzhiyun# cc-option 122*4882a593Smuzhiyun# Usage: cflags-y += $(call cc-option,-march=winchip-c6,-march=i586) 123*4882a593Smuzhiyun 124*4882a593Smuzhiyuncc-option = $(call __cc-option, $(CC),\ 125*4882a593Smuzhiyun $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS),$(1),$(2)) 126*4882a593Smuzhiyun 127*4882a593Smuzhiyun# hostcc-option 128*4882a593Smuzhiyun# Usage: cflags-y += $(call hostcc-option,-march=winchip-c6,-march=i586) 129*4882a593Smuzhiyunhostcc-option = $(call __cc-option, $(HOSTCC),\ 130*4882a593Smuzhiyun $(KBUILD_HOSTCFLAGS) $(HOST_EXTRACFLAGS),$(1),$(2)) 131*4882a593Smuzhiyun 132*4882a593Smuzhiyun# cc-option-yn 133*4882a593Smuzhiyun# Usage: flag := $(call cc-option-yn,-march=winchip-c6) 134*4882a593Smuzhiyuncc-option-yn = $(call try-run,\ 135*4882a593Smuzhiyun $(CC) -Werror $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS) $(1) -c -x c /dev/null -o "$$TMP",y,n) 136*4882a593Smuzhiyun 137*4882a593Smuzhiyun# cc-disable-warning 138*4882a593Smuzhiyun# Usage: cflags-y += $(call cc-disable-warning,unused-but-set-variable) 139*4882a593Smuzhiyuncc-disable-warning = $(call try-run,\ 140*4882a593Smuzhiyun $(CC) -Werror $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS) -W$(strip $(1)) -c -x c /dev/null -o "$$TMP",-Wno-$(strip $(1))) 141*4882a593Smuzhiyun 142*4882a593Smuzhiyun# cc-name 143*4882a593Smuzhiyun# Expands to either gcc or clang 144*4882a593Smuzhiyuncc-name = $(shell $(CC) -v 2>&1 | grep -q "clang version" && echo clang || echo gcc) 145*4882a593Smuzhiyun 146*4882a593Smuzhiyun# cc-version 147*4882a593Smuzhiyuncc-version = $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-version.sh $(CC)) 148*4882a593Smuzhiyun 149*4882a593Smuzhiyun# cc-fullversion 150*4882a593Smuzhiyuncc-fullversion = $(shell $(CONFIG_SHELL) \ 151*4882a593Smuzhiyun $(srctree)/scripts/gcc-version.sh -p $(CC)) 152*4882a593Smuzhiyun 153*4882a593Smuzhiyun# cc-ifversion 154*4882a593Smuzhiyun# Usage: EXTRA_CFLAGS += $(call cc-ifversion, -lt, 0402, -O1) 155*4882a593Smuzhiyuncc-ifversion = $(shell [ $(cc-version) $(1) $(2) ] && echo $(3) || echo $(4)) 156*4882a593Smuzhiyun 157*4882a593Smuzhiyun# cc-ldoption 158*4882a593Smuzhiyun# Usage: ldflags += $(call cc-ldoption, -Wl$(comma)--hash-style=both) 159*4882a593Smuzhiyuncc-ldoption = $(call try-run,\ 160*4882a593Smuzhiyun $(CC) $(1) $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS) -nostdlib -x c /dev/null -o "$$TMP",$(1),$(2)) 161*4882a593Smuzhiyun 162*4882a593Smuzhiyun# ld-option 163*4882a593Smuzhiyun# Usage: KBUILD_LDFLAGS += $(call ld-option, -X, -Y) 164*4882a593Smuzhiyunld-option = $(call try-run, $(LD) $(KBUILD_LDFLAGS) $(1) -v,$(1),$(2),$(3)) 165*4882a593Smuzhiyun 166*4882a593Smuzhiyun# ar-option 167*4882a593Smuzhiyun# Usage: KBUILD_ARFLAGS := $(call ar-option,D) 168*4882a593Smuzhiyun# Important: no spaces around options 169*4882a593Smuzhiyunar-option = $(call try-run, $(AR) rc$(1) "$$TMP",$(1),$(2)) 170*4882a593Smuzhiyun 171*4882a593Smuzhiyun# ld-version 172*4882a593Smuzhiyun# Note this is mainly for HJ Lu's 3 number binutil versions 173*4882a593Smuzhiyunld-version = $(shell $(LD) --version | $(srctree)/scripts/ld-version.sh) 174*4882a593Smuzhiyun 175*4882a593Smuzhiyun# ld-ifversion 176*4882a593Smuzhiyun# Usage: $(call ld-ifversion, -ge, 22252, y) 177*4882a593Smuzhiyunld-ifversion = $(shell [ $(ld-version) $(1) $(2) ] && echo $(3) || echo $(4)) 178*4882a593Smuzhiyun 179*4882a593Smuzhiyun###### 180*4882a593Smuzhiyun 181*4882a593Smuzhiyun### 182*4882a593Smuzhiyun# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.build obj= 183*4882a593Smuzhiyun# Usage: 184*4882a593Smuzhiyun# $(Q)$(MAKE) $(build)=dir 185*4882a593Smuzhiyunbuild := -f $(srctree)/scripts/Makefile.build obj 186*4882a593Smuzhiyun 187*4882a593Smuzhiyun### 188*4882a593Smuzhiyun# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.modbuiltin obj= 189*4882a593Smuzhiyun# Usage: 190*4882a593Smuzhiyun# $(Q)$(MAKE) $(modbuiltin)=dir 191*4882a593Smuzhiyunmodbuiltin := -f $(srctree)/scripts/Makefile.modbuiltin obj 192*4882a593Smuzhiyun 193*4882a593Smuzhiyun### 194*4882a593Smuzhiyun# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.dtbinst obj= 195*4882a593Smuzhiyun# Usage: 196*4882a593Smuzhiyun# $(Q)$(MAKE) $(dtbinst)=dir 197*4882a593Smuzhiyundtbinst := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.dtbinst obj 198*4882a593Smuzhiyun 199*4882a593Smuzhiyun### 200*4882a593Smuzhiyun# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.clean obj= 201*4882a593Smuzhiyun# Usage: 202*4882a593Smuzhiyun# $(Q)$(MAKE) $(clean)=dir 203*4882a593Smuzhiyunclean := -f $(srctree)/scripts/Makefile.clean obj 204*4882a593Smuzhiyun 205*4882a593Smuzhiyun### 206*4882a593Smuzhiyun# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.headersinst obj= 207*4882a593Smuzhiyun# Usage: 208*4882a593Smuzhiyun# $(Q)$(MAKE) $(hdr-inst)=dir 209*4882a593Smuzhiyunhdr-inst := -f $(srctree)/scripts/Makefile.headersinst obj 210*4882a593Smuzhiyun 211*4882a593Smuzhiyun# Prefix -I with $(srctree) if it is not an absolute path. 212*4882a593Smuzhiyun# skip if -I has no parameter 213*4882a593Smuzhiyunaddtree = $(if $(patsubst -I%,%,$(1)), \ 214*4882a593Smuzhiyun$(if $(filter-out -I/% -I./% -I../%,$(1)),$(patsubst -I%,-I$(srctree)/%,$(1)),$(1)),$(1)) 215*4882a593Smuzhiyun 216*4882a593Smuzhiyun# Find all -I options and call addtree 217*4882a593Smuzhiyunflags = $(foreach o,$($(1)),$(if $(filter -I%,$(o)),$(call addtree,$(o)),$(o))) 218*4882a593Smuzhiyun 219*4882a593Smuzhiyun# echo command. 220*4882a593Smuzhiyun# Short version is used, if $(quiet) equals `quiet_', otherwise full one. 221*4882a593Smuzhiyunecho-cmd = $(if $($(quiet)cmd_$(1)),\ 222*4882a593Smuzhiyun echo ' $(call escsq,$($(quiet)cmd_$(1)))$(echo-why)';) 223*4882a593Smuzhiyun 224*4882a593Smuzhiyun# printing commands 225*4882a593Smuzhiyuncmd = @$(echo-cmd) $(cmd_$(1)) 226*4882a593Smuzhiyun 227*4882a593Smuzhiyun# Add $(obj)/ for paths that are not absolute 228*4882a593Smuzhiyunobjectify = $(foreach o,$(1),$(if $(filter /%,$(o)),$(o),$(obj)/$(o))) 229*4882a593Smuzhiyun 230*4882a593Smuzhiyun### 231*4882a593Smuzhiyun# if_changed - execute command if any prerequisite is newer than 232*4882a593Smuzhiyun# target, or command line has changed 233*4882a593Smuzhiyun# if_changed_dep - as if_changed, but uses fixdep to reveal dependencies 234*4882a593Smuzhiyun# including used config symbols 235*4882a593Smuzhiyun# if_changed_rule - as if_changed but execute rule instead 236*4882a593Smuzhiyun# See Documentation/kbuild/makefiles.txt for more info 237*4882a593Smuzhiyun 238*4882a593Smuzhiyunifneq ($(KBUILD_NOCMDDEP),1) 239*4882a593Smuzhiyun# Check if both arguments are the same including their order. Result is empty 240*4882a593Smuzhiyun# string if equal. User may override this check using make KBUILD_NOCMDDEP=1 241*4882a593Smuzhiyunarg-check = $(filter-out $(subst $(space),$(space_escape),$(strip $(cmd_$@))), \ 242*4882a593Smuzhiyun $(subst $(space),$(space_escape),$(strip $(cmd_$1)))) 243*4882a593Smuzhiyunelse 244*4882a593Smuzhiyunarg-check = $(if $(strip $(cmd_$@)),,1) 245*4882a593Smuzhiyunendif 246*4882a593Smuzhiyun 247*4882a593Smuzhiyun# Replace >$< with >$$< to preserve $ when reloading the .cmd file 248*4882a593Smuzhiyun# (needed for make) 249*4882a593Smuzhiyun# Replace >#< with >$(pound)< to avoid starting a comment in the .cmd file 250*4882a593Smuzhiyun# (needed for make) 251*4882a593Smuzhiyun# Replace >'< with >'\''< to be able to enclose the whole string in '...' 252*4882a593Smuzhiyun# (needed for the shell) 253*4882a593Smuzhiyunmake-cmd = $(call escsq,$(subst $(pound),$$(pound),$(subst $$,$$$$,$(cmd_$(1))))) 254*4882a593Smuzhiyun 255*4882a593Smuzhiyun# Find any prerequisites that is newer than target or that does not exist. 256*4882a593Smuzhiyun# PHONY targets skipped in both cases. 257*4882a593Smuzhiyunany-prereq = $(filter-out $(PHONY),$?) $(filter-out $(PHONY) $(wildcard $^),$^) 258*4882a593Smuzhiyun 259*4882a593Smuzhiyun# Execute command if command has changed or prerequisite(s) are updated. 260*4882a593Smuzhiyunif_changed = $(if $(strip $(any-prereq) $(arg-check)), \ 261*4882a593Smuzhiyun @set -e; \ 262*4882a593Smuzhiyun $(echo-cmd) $(cmd_$(1)); \ 263*4882a593Smuzhiyun printf '%s\n' 'cmd_$@ := $(make-cmd)' > $(dot-target).cmd, @:) 264*4882a593Smuzhiyun 265*4882a593Smuzhiyun# Execute the command and also postprocess generated .d dependencies file. 266*4882a593Smuzhiyunif_changed_dep = $(if $(strip $(any-prereq) $(arg-check) ), \ 267*4882a593Smuzhiyun @set -e; \ 268*4882a593Smuzhiyun $(cmd_and_fixdep), @:) 269*4882a593Smuzhiyun 270*4882a593Smuzhiyunifndef CONFIG_TRIM_UNUSED_KSYMS 271*4882a593Smuzhiyun 272*4882a593Smuzhiyuncmd_and_fixdep = \ 273*4882a593Smuzhiyun $(echo-cmd) $(cmd_$(1)); \ 274*4882a593Smuzhiyun scripts/basic/fixdep $(depfile) $@ '$(make-cmd)' > $(dot-target).tmp;\ 275*4882a593Smuzhiyun rm -f $(depfile); \ 276*4882a593Smuzhiyun mv -f $(dot-target).tmp $(dot-target).cmd; 277*4882a593Smuzhiyun 278*4882a593Smuzhiyunelse 279*4882a593Smuzhiyun 280*4882a593Smuzhiyun# Filter out exported kernel symbol names from the preprocessor output. 281*4882a593Smuzhiyun# See also __KSYM_DEPS__ in include/linux/export.h. 282*4882a593Smuzhiyun# We disable the depfile generation here, so as not to overwrite the existing 283*4882a593Smuzhiyun# depfile while fixdep is parsing it. 284*4882a593Smuzhiyunflags_nodeps = $(filter-out -Wp$(comma)-M%, $($(1))) 285*4882a593Smuzhiyunksym_dep_filter = \ 286*4882a593Smuzhiyun case "$(1)" in \ 287*4882a593Smuzhiyun cc_*_c|cpp_i_c) \ 288*4882a593Smuzhiyun $(CPP) $(call flags_nodeps,c_flags) -D__KSYM_DEPS__ $< ;; \ 289*4882a593Smuzhiyun as_*_S|cpp_s_S) \ 290*4882a593Smuzhiyun $(CPP) $(call flags_nodeps,a_flags) -D__KSYM_DEPS__ $< ;; \ 291*4882a593Smuzhiyun boot*|build*|cpp_its_S|*cpp_lds_S|dtc|host*|vdso*) : ;; \ 292*4882a593Smuzhiyun *) echo "Don't know how to preprocess $(1)" >&2; false ;; \ 293*4882a593Smuzhiyun esac | grep -F '=== __KSYM_' | tr ";" "\n" | sed -n 's/^.*=== __KSYM_\(.*\) ===.*$$/_\1/p' 294*4882a593Smuzhiyun 295*4882a593Smuzhiyuncmd_and_fixdep = \ 296*4882a593Smuzhiyun $(echo-cmd) $(cmd_$(1)); \ 297*4882a593Smuzhiyun $(ksym_dep_filter) | \ 298*4882a593Smuzhiyun scripts/basic/fixdep -e $(depfile) $@ '$(make-cmd)' \ 299*4882a593Smuzhiyun > $(dot-target).tmp; \ 300*4882a593Smuzhiyun rm -f $(depfile); \ 301*4882a593Smuzhiyun mv -f $(dot-target).tmp $(dot-target).cmd; 302*4882a593Smuzhiyun 303*4882a593Smuzhiyunendif 304*4882a593Smuzhiyun 305*4882a593Smuzhiyun# Usage: $(call if_changed_rule,foo) 306*4882a593Smuzhiyun# Will check if $(cmd_foo) or any of the prerequisites changed, 307*4882a593Smuzhiyun# and if so will execute $(rule_foo). 308*4882a593Smuzhiyunif_changed_rule = $(if $(strip $(any-prereq) $(arg-check) ), \ 309*4882a593Smuzhiyun @set -e; \ 310*4882a593Smuzhiyun $(rule_$(1)), @:) 311*4882a593Smuzhiyun 312*4882a593Smuzhiyun### 313*4882a593Smuzhiyun# why - tell why a target got built 314*4882a593Smuzhiyun# enabled by make V=2 315*4882a593Smuzhiyun# Output (listed in the order they are checked): 316*4882a593Smuzhiyun# (1) - due to target is PHONY 317*4882a593Smuzhiyun# (2) - due to target missing 318*4882a593Smuzhiyun# (3) - due to: file1.h file2.h 319*4882a593Smuzhiyun# (4) - due to command line change 320*4882a593Smuzhiyun# (5) - due to missing .cmd file 321*4882a593Smuzhiyun# (6) - due to target not in $(targets) 322*4882a593Smuzhiyun# (1) PHONY targets are always build 323*4882a593Smuzhiyun# (2) No target, so we better build it 324*4882a593Smuzhiyun# (3) Prerequisite is newer than target 325*4882a593Smuzhiyun# (4) The command line stored in the file named dir/.target.cmd 326*4882a593Smuzhiyun# differed from actual command line. This happens when compiler 327*4882a593Smuzhiyun# options changes 328*4882a593Smuzhiyun# (5) No dir/.target.cmd file (used to store command line) 329*4882a593Smuzhiyun# (6) No dir/.target.cmd file and target not listed in $(targets) 330*4882a593Smuzhiyun# This is a good hint that there is a bug in the kbuild file 331*4882a593Smuzhiyunifeq ($(KBUILD_VERBOSE),2) 332*4882a593Smuzhiyunwhy = \ 333*4882a593Smuzhiyun $(if $(filter $@, $(PHONY)),- due to target is PHONY, \ 334*4882a593Smuzhiyun $(if $(wildcard $@), \ 335*4882a593Smuzhiyun $(if $(strip $(any-prereq)),- due to: $(any-prereq), \ 336*4882a593Smuzhiyun $(if $(arg-check), \ 337*4882a593Smuzhiyun $(if $(cmd_$@),- due to command line change, \ 338*4882a593Smuzhiyun $(if $(filter $@, $(targets)), \ 339*4882a593Smuzhiyun - due to missing .cmd file, \ 340*4882a593Smuzhiyun - due to $(notdir $@) not in $$(targets) \ 341*4882a593Smuzhiyun ) \ 342*4882a593Smuzhiyun ) \ 343*4882a593Smuzhiyun ) \ 344*4882a593Smuzhiyun ), \ 345*4882a593Smuzhiyun - due to target missing \ 346*4882a593Smuzhiyun ) \ 347*4882a593Smuzhiyun ) 348*4882a593Smuzhiyun 349*4882a593Smuzhiyunecho-why = $(call escsq, $(strip $(why))) 350*4882a593Smuzhiyunendif 351*4882a593Smuzhiyun 352*4882a593Smuzhiyun############################################################################### 353*4882a593Smuzhiyun# 354*4882a593Smuzhiyun# When a Kconfig string contains a filename, it is suitable for 355*4882a593Smuzhiyun# passing to shell commands. It is surrounded by double-quotes, and 356*4882a593Smuzhiyun# any double-quotes or backslashes within it are escaped by 357*4882a593Smuzhiyun# backslashes. 358*4882a593Smuzhiyun# 359*4882a593Smuzhiyun# This is no use for dependencies or $(wildcard). We need to strip the 360*4882a593Smuzhiyun# surrounding quotes and the escaping from quotes and backslashes, and 361*4882a593Smuzhiyun# we *do* need to escape any spaces in the string. So, for example: 362*4882a593Smuzhiyun# 363*4882a593Smuzhiyun# Usage: $(eval $(call config_filename,FOO)) 364*4882a593Smuzhiyun# 365*4882a593Smuzhiyun# Defines FOO_FILENAME based on the contents of the CONFIG_FOO option, 366*4882a593Smuzhiyun# transformed as described above to be suitable for use within the 367*4882a593Smuzhiyun# makefile. 368*4882a593Smuzhiyun# 369*4882a593Smuzhiyun# Also, if the filename is a relative filename and exists in the source 370*4882a593Smuzhiyun# tree but not the build tree, define FOO_SRCPREFIX as $(srctree)/ to 371*4882a593Smuzhiyun# be prefixed to *both* command invocation and dependencies. 372*4882a593Smuzhiyun# 373*4882a593Smuzhiyun# Note: We also print the filenames in the quiet_cmd_foo text, and 374*4882a593Smuzhiyun# perhaps ought to have a version specially escaped for that purpose. 375*4882a593Smuzhiyun# But it's only cosmetic, and $(patsubst "%",%,$(CONFIG_FOO)) is good 376*4882a593Smuzhiyun# enough. It'll strip the quotes in the common case where there's no 377*4882a593Smuzhiyun# space and it's a simple filename, and it'll retain the quotes when 378*4882a593Smuzhiyun# there's a space. There are some esoteric cases in which it'll print 379*4882a593Smuzhiyun# the wrong thing, but we don't really care. The actual dependencies 380*4882a593Smuzhiyun# and commands *do* get it right, with various combinations of single 381*4882a593Smuzhiyun# and double quotes, backslashes and spaces in the filenames. 382*4882a593Smuzhiyun# 383*4882a593Smuzhiyun############################################################################### 384*4882a593Smuzhiyun# 385*4882a593Smuzhiyundefine config_filename 386*4882a593Smuzhiyunifneq ($$(CONFIG_$(1)),"") 387*4882a593Smuzhiyun$(1)_FILENAME := $$(subst \\,\,$$(subst \$$(quote),$$(quote),$$(subst $$(space_escape),\$$(space),$$(patsubst "%",%,$$(subst $$(space),$$(space_escape),$$(CONFIG_$(1))))))) 388*4882a593Smuzhiyunifneq ($$(patsubst /%,%,$$(firstword $$($(1)_FILENAME))),$$(firstword $$($(1)_FILENAME))) 389*4882a593Smuzhiyunelse 390*4882a593Smuzhiyunifeq ($$(wildcard $$($(1)_FILENAME)),) 391*4882a593Smuzhiyunifneq ($$(wildcard $$(srctree)/$$($(1)_FILENAME)),) 392*4882a593Smuzhiyun$(1)_SRCPREFIX := $(srctree)/ 393*4882a593Smuzhiyunendif 394*4882a593Smuzhiyunendif 395*4882a593Smuzhiyunendif 396*4882a593Smuzhiyunendif 397*4882a593Smuzhiyunendef 398*4882a593Smuzhiyun# 399*4882a593Smuzhiyun############################################################################### 400*4882a593Smuzhiyun 401*4882a593Smuzhiyun# delete partially updated (i.e. corrupted) files on error 402*4882a593Smuzhiyun.DELETE_ON_ERROR: 403