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