18ec4b4ffSSam Ravnborg#### 28ec4b4ffSSam Ravnborg# kbuild: Generic definitions 38ec4b4ffSSam Ravnborg 4beda9f3aSRoman Zippel# Convenient variables 58ec4b4ffSSam Ravnborgcomma := , 613338935SMasahiro Yamadaquote := " 7d51bfb78SSam Ravnborgsquote := ' 88ec4b4ffSSam Ravnborgempty := 98ec4b4ffSSam Ravnborgspace := $(empty) $(empty) 109c8fa9bcSMasahiro Yamadaspace_escape := _-_SPACE_-_ 119564a8cfSRasmus Villemoespound := \# 128ec4b4ffSSam Ravnborg 138ec4b4ffSSam Ravnborg### 1448f1f058SSam Ravnborg# Name of target with a '.' as filename prefix. foo/bar.o => foo/.bar.o 1548f1f058SSam Ravnborgdot-target = $(dir $@).$(notdir $@) 1648f1f058SSam Ravnborg 1748f1f058SSam Ravnborg### 188ec4b4ffSSam Ravnborg# The temporary file to save gcc -MD generated dependencies must not 198ec4b4ffSSam Ravnborg# contain a comma 2048f1f058SSam Ravnborgdepfile = $(subst $(comma),_,$(dot-target).d) 218ec4b4ffSSam Ravnborg 228ec4b4ffSSam Ravnborg### 235e8d780dSSam Ravnborg# filename of target with directory and extension stripped 245e8d780dSSam Ravnborgbasetarget = $(basename $(notdir $@)) 255e8d780dSSam Ravnborg 265e8d780dSSam Ravnborg### 27e0318d85SArnaud Lacombe# filename of first prerequisite with directory and extension stripped 28e0318d85SArnaud Lacombebaseprereq = $(basename $(notdir $<)) 29e0318d85SArnaud Lacombe 30e0318d85SArnaud Lacombe### 31d51bfb78SSam Ravnborg# Escape single quote for use in echo statements 32d51bfb78SSam Ravnborgescsq = $(subst $(squote),'\$(squote)',$1) 33d51bfb78SSam Ravnborg 34d51bfb78SSam Ravnborg### 355410ecc0SMike Frysinger# Easy method for doing a status message 365410ecc0SMike Frysinger kecho := : 375410ecc0SMike Frysinger quiet_kecho := echo 385410ecc0SMike Frysingersilent_kecho := : 395410ecc0SMike Frysingerkecho := $($(quiet)kecho) 405410ecc0SMike Frysinger 415410ecc0SMike Frysinger### 428ec4b4ffSSam Ravnborg# filechk is used to check if the content of a generated file is updated. 438ec4b4ffSSam Ravnborg# Sample usage: 44*ba97df45SMasahiro Yamada# 45*ba97df45SMasahiro Yamada# filechk_sample = echo $(KERNELRELEASE) 46*ba97df45SMasahiro Yamada# version.h: FORCE 478ec4b4ffSSam Ravnborg# $(call filechk,sample) 48*ba97df45SMasahiro Yamada# 498ec4b4ffSSam Ravnborg# The rule defined shall write to stdout the content of the new file. 508ec4b4ffSSam Ravnborg# The existing file will be compared with the new one. 518ec4b4ffSSam Ravnborg# - If no file exist it is created 528ec4b4ffSSam Ravnborg# - If the content differ the new file is used 538ec4b4ffSSam Ravnborg# - If they are equal no change, and no timestamp update 548ec4b4ffSSam Ravnborg# - stdin is piped in from the first prerequisite ($<) so one has 558ec4b4ffSSam Ravnborg# to specify a valid file as first prerequisite (often the kbuild file) 568ec4b4ffSSam Ravnborgdefine filechk 578ec4b4ffSSam Ravnborg $(Q)set -e; \ 588ec4b4ffSSam Ravnborg mkdir -p $(dir $@); \ 59ad774086SMasahiro Yamada { $(filechk_$(1)); } > $@.tmp; \ 608ec4b4ffSSam Ravnborg if [ -r $@ ] && cmp -s $@ $@.tmp; then \ 618ec4b4ffSSam Ravnborg rm -f $@.tmp; \ 628ec4b4ffSSam Ravnborg else \ 63fd54f502SMike Frysinger $(kecho) ' UPD $@'; \ 648ec4b4ffSSam Ravnborg mv -f $@.tmp $@; \ 658ec4b4ffSSam Ravnborg fi 668ec4b4ffSSam Ravnborgendef 678ec4b4ffSSam Ravnborg 6820a468b5SSam Ravnborg###### 699d6e7a70SSam Ravnborg# gcc support functions 7020a468b5SSam Ravnborg# See documentation in Documentation/kbuild/makefiles.txt 7120a468b5SSam Ravnborg 72910b4046SSam Ravnborg# cc-cross-prefix 73910b4046SSam Ravnborg# Usage: CROSS_COMPILE := $(call cc-cross-prefix, m68k-linux-gnu- m68k-linux-) 74910b4046SSam Ravnborg# Return first prefix where a prefix$(CC) is found in PATH. 75910b4046SSam Ravnborg# If no $(CC) found in PATH with listed prefixes return nothing 76910b4046SSam Ravnborgcc-cross-prefix = \ 77910b4046SSam Ravnborg $(word 1, $(foreach c,$(1), \ 78910b4046SSam Ravnborg $(shell set -e; \ 79910b4046SSam Ravnborg if (which $(strip $(c))$(CC)) > /dev/null 2>&1 ; then \ 80910b4046SSam Ravnborg echo $(c); \ 81910b4046SSam Ravnborg fi))) 82910b4046SSam Ravnborg 83beda9f3aSRoman Zippel# output directory for tests below 84beda9f3aSRoman ZippelTMPOUT := $(if $(KBUILD_EXTMOD),$(firstword $(KBUILD_EXTMOD))/) 85beda9f3aSRoman Zippel 86beda9f3aSRoman Zippel# try-run 87beda9f3aSRoman Zippel# Usage: option = $(call try-run, $(CC)...-o "$$TMP",option-ok,otherwise) 88312a3d09SCao jin# Exit code chooses option. "$$TMP" serves as a temporary file and is 89312a3d09SCao jin# automatically cleaned up. 90e08d6de4SMasahiro Yamadatry-run = $(shell set -e; \ 91beda9f3aSRoman Zippel TMP="$(TMPOUT).$$$$.tmp"; \ 92691ef3e7SSam Ravnborg TMPO="$(TMPOUT).$$$$.o"; \ 93beda9f3aSRoman Zippel if ($(1)) >/dev/null 2>&1; \ 945de043f4SOleg Verych then echo "$(2)"; \ 955de043f4SOleg Verych else echo "$(3)"; \ 965de043f4SOleg Verych fi; \ 97e08d6de4SMasahiro Yamada rm -f "$$TMP" "$$TMPO") 98347a00fbSRoman Zippel 9920a468b5SSam Ravnborg# as-option 10020a468b5SSam Ravnborg# Usage: cflags-y += $(call as-option,-Wa$(comma)-isa=foo,) 101beda9f3aSRoman Zippel 102e08d6de4SMasahiro Yamadaas-option = $(call try-run,\ 103a0f97e06SSam Ravnborg $(CC) $(KBUILD_CFLAGS) $(1) -c -x assembler /dev/null -o "$$TMP",$(1),$(2)) 10420a468b5SSam Ravnborg 105e2414910SAndi Kleen# as-instr 106e2414910SAndi Kleen# Usage: cflags-y += $(call as-instr,instr,option1,option2) 107beda9f3aSRoman Zippel 108e08d6de4SMasahiro Yamadaas-instr = $(call try-run,\ 109875de986SBernhard Walle printf "%b\n" "$(1)" | $(CC) $(KBUILD_AFLAGS) -c -x assembler -o "$$TMP" -,$(2),$(3)) 110e2414910SAndi Kleen 1119f3f1fd2SMatthias Kaehlcke# __cc-option 1129f3f1fd2SMatthias Kaehlcke# Usage: MY_CFLAGS += $(call __cc-option,$(CC),$(MY_CFLAGS),-march=winchip-c6,-march=i586) 113e08d6de4SMasahiro Yamada__cc-option = $(call try-run,\ 1149f3f1fd2SMatthias Kaehlcke $(1) -Werror $(2) $(3) -c -x c /dev/null -o "$$TMP",$(3),$(4)) 1159f3f1fd2SMatthias Kaehlcke 116d26e9414SEmese Revfy# Do not attempt to build with gcc plugins during cc-option tests. 117d26e9414SEmese Revfy# (And this uses delayed resolution so the flags will be up to date.) 1186ac38934SIngo MolnarCC_OPTION_CFLAGS = $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS)) 119d26e9414SEmese Revfy 12020a468b5SSam Ravnborg# cc-option 12120a468b5SSam Ravnborg# Usage: cflags-y += $(call cc-option,-march=winchip-c6,-march=i586) 122beda9f3aSRoman Zippel 1239f3f1fd2SMatthias Kaehlckecc-option = $(call __cc-option, $(CC),\ 1249f3f1fd2SMatthias Kaehlcke $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS),$(1),$(2)) 1259f3f1fd2SMatthias Kaehlcke 1269f3f1fd2SMatthias Kaehlcke# hostcc-option 1279f3f1fd2SMatthias Kaehlcke# Usage: cflags-y += $(call hostcc-option,-march=winchip-c6,-march=i586) 1289f3f1fd2SMatthias Kaehlckehostcc-option = $(call __cc-option, $(HOSTCC),\ 12996f14fe7SLaura Abbott $(KBUILD_HOSTCFLAGS) $(HOST_EXTRACFLAGS),$(1),$(2)) 13020a468b5SSam Ravnborg 13120a468b5SSam Ravnborg# cc-option-yn 13220a468b5SSam Ravnborg# Usage: flag := $(call cc-option-yn,-march=winchip-c6) 133e08d6de4SMasahiro Yamadacc-option-yn = $(call try-run,\ 134c3f0d0bcSMark Charlebois $(CC) -Werror $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS) $(1) -c -x c /dev/null -o "$$TMP",y,n) 13520a468b5SSam Ravnborg 1368417da6fSMichal Marek# cc-disable-warning 1378417da6fSMichal Marek# Usage: cflags-y += $(call cc-disable-warning,unused-but-set-variable) 138e08d6de4SMasahiro Yamadacc-disable-warning = $(call try-run,\ 139c3f0d0bcSMark Charlebois $(CC) -Werror $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS) -W$(strip $(1)) -c -x c /dev/null -o "$$TMP",-Wno-$(strip $(1))) 1408417da6fSMichal Marek 14120a468b5SSam Ravnborg# cc-version 142e08d6de4SMasahiro Yamadacc-version = $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-version.sh $(CC)) 14320a468b5SSam Ravnborg 14420a468b5SSam Ravnborg# cc-ifversion 14520a468b5SSam Ravnborg# Usage: EXTRA_CFLAGS += $(call cc-ifversion, -lt, 0402, -O1) 1466dcb4e5eSMasahiro Yamadacc-ifversion = $(shell [ $(cc-version) $(1) $(2) ] && echo $(3) || echo $(4)) 14720a468b5SSam Ravnborg 148f86fd306SSam Ravnborg# cc-ldoption 149f86fd306SSam Ravnborg# Usage: ldflags += $(call cc-ldoption, -Wl$(comma)--hash-style=both) 150e08d6de4SMasahiro Yamadacc-ldoption = $(call try-run,\ 15186a9df59SNick Desaulniers $(CC) $(1) $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS) -nostdlib -x c /dev/null -o "$$TMP",$(1),$(2)) 1520b0bf7a3SRoland McGrath 153691ef3e7SSam Ravnborg# ld-option 154d503ac53SMasahiro Yamada# Usage: KBUILD_LDFLAGS += $(call ld-option, -X, -Y) 155d503ac53SMasahiro Yamadald-option = $(call try-run, $(LD) $(KBUILD_LDFLAGS) $(1) -v,$(1),$(2),$(3)) 156691ef3e7SSam Ravnborg 15740df759eSMichal Marek# ar-option 15840df759eSMichal Marek# Usage: KBUILD_ARFLAGS := $(call ar-option,D) 15940df759eSMichal Marek# Important: no spaces around options 160e08d6de4SMasahiro Yamadaar-option = $(call try-run, $(AR) rc$(1) "$$TMP",$(1),$(2)) 16140df759eSMichal Marek 162ccbef167SAndi Kleen# ld-version 163ccbef167SAndi Kleen# Note this is mainly for HJ Lu's 3 number binutil versions 164e08d6de4SMasahiro Yamadald-version = $(shell $(LD) --version | $(srctree)/scripts/ld-version.sh) 165ccbef167SAndi Kleen 166ccbef167SAndi Kleen# ld-ifversion 167ccbef167SAndi Kleen# Usage: $(call ld-ifversion, -ge, 22252, y) 1686dcb4e5eSMasahiro Yamadald-ifversion = $(shell [ $(ld-version) $(1) $(2) ] && echo $(3) || echo $(4)) 169ccbef167SAndi Kleen 1705de043f4SOleg Verych###### 1715de043f4SOleg Verych 172beda9f3aSRoman Zippel### 1738ec4b4ffSSam Ravnborg# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.build obj= 1748ec4b4ffSSam Ravnborg# Usage: 1758ec4b4ffSSam Ravnborg# $(Q)$(MAKE) $(build)=dir 1765b2389b4SMasahiro Yamadabuild := -f $(srctree)/scripts/Makefile.build obj 1778ec4b4ffSSam Ravnborg 178bc081dd6SMichal Marek### 179bc081dd6SMichal Marek# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.modbuiltin obj= 180bc081dd6SMichal Marek# Usage: 181bc081dd6SMichal Marek# $(Q)$(MAKE) $(modbuiltin)=dir 1825b2389b4SMasahiro Yamadamodbuiltin := -f $(srctree)/scripts/Makefile.modbuiltin obj 183bc081dd6SMichal Marek 1849fb5e537SRobert Richter### 1859fb5e537SRobert Richter# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.dtbinst obj= 1869fb5e537SRobert Richter# Usage: 1879fb5e537SRobert Richter# $(Q)$(MAKE) $(dtbinst)=dir 188487c7c77SMasahiro Yamadadtbinst := -f $(srctree)/scripts/Makefile.dtbinst obj 1899fb5e537SRobert Richter 190d08372caSLinus Torvalds### 191371fdc77SMasahiro Yamada# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.clean obj= 192371fdc77SMasahiro Yamada# Usage: 193371fdc77SMasahiro Yamada# $(Q)$(MAKE) $(clean)=dir 194371fdc77SMasahiro Yamadaclean := -f $(srctree)/scripts/Makefile.clean obj 195371fdc77SMasahiro Yamada 196371fdc77SMasahiro Yamada### 1971846dfbdSMasahiro Yamada# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.headersinst obj= 198371fdc77SMasahiro Yamada# Usage: 199371fdc77SMasahiro Yamada# $(Q)$(MAKE) $(hdr-inst)=dir 2001846dfbdSMasahiro Yamadahdr-inst := -f $(srctree)/scripts/Makefile.headersinst obj 201371fdc77SMasahiro Yamada 202beda9f3aSRoman Zippel# Prefix -I with $(srctree) if it is not an absolute path. 2035b91c33cSSam Ravnborg# skip if -I has no parameter 2045b91c33cSSam Ravnborgaddtree = $(if $(patsubst -I%,%,$(1)), \ 20548f6e3cfSMasahiro Yamada$(if $(filter-out -I/% -I./% -I../%,$(1)),$(patsubst -I%,-I$(srctree)/%,$(1)),$(1)),$(1)) 206d9df92e2SSam Ravnborg 2075de043f4SOleg Verych# Find all -I options and call addtree 208beda9f3aSRoman Zippelflags = $(foreach o,$($(1)),$(if $(filter -I%,$(o)),$(call addtree,$(o)),$(o))) 2095de043f4SOleg Verych 2105de043f4SOleg Verych# echo command. 2115de043f4SOleg Verych# Short version is used, if $(quiet) equals `quiet_', otherwise full one. 2125de043f4SOleg Verychecho-cmd = $(if $($(quiet)cmd_$(1)),\ 2135de043f4SOleg Verych echo ' $(call escsq,$($(quiet)cmd_$(1)))$(echo-why)';) 2145de043f4SOleg Verych 2155de043f4SOleg Verych# printing commands 2163a2429e1SMasahiro Yamadacmd = @set -e; $(echo-cmd) $(cmd_$(1)) 2178ec4b4ffSSam Ravnborg 2185de043f4SOleg Verych# Add $(obj)/ for paths that are not absolute 2190a504f25SSam Ravnborgobjectify = $(foreach o,$(1),$(if $(filter /%,$(o)),$(o),$(obj)/$(o))) 2200a504f25SSam Ravnborg 2218ec4b4ffSSam Ravnborg### 2228ec4b4ffSSam Ravnborg# if_changed - execute command if any prerequisite is newer than 2238ec4b4ffSSam Ravnborg# target, or command line has changed 2248ec4b4ffSSam Ravnborg# if_changed_dep - as if_changed, but uses fixdep to reveal dependencies 2258ec4b4ffSSam Ravnborg# including used config symbols 2268ec4b4ffSSam Ravnborg# if_changed_rule - as if_changed but execute rule instead 2278ec4b4ffSSam Ravnborg# See Documentation/kbuild/makefiles.txt for more info 2288ec4b4ffSSam Ravnborg 2298ec4b4ffSSam Ravnborgifneq ($(KBUILD_NOCMDDEP),1) 2309c8fa9bcSMasahiro Yamada# Check if both arguments are the same including their order. Result is empty 2319c8fa9bcSMasahiro Yamada# string if equal. User may override this check using make KBUILD_NOCMDDEP=1 2329c8fa9bcSMasahiro Yamadaarg-check = $(filter-out $(subst $(space),$(space_escape),$(strip $(cmd_$@))), \ 2339c8fa9bcSMasahiro Yamada $(subst $(space),$(space_escape),$(strip $(cmd_$1)))) 234c4d5ee13SMichal Marekelse 235c4d5ee13SMichal Marekarg-check = $(if $(strip $(cmd_$@)),,1) 2368ec4b4ffSSam Ravnborgendif 2378ec4b4ffSSam Ravnborg 238164f0d2eSMichal Marek# Replace >$< with >$$< to preserve $ when reloading the .cmd file 239164f0d2eSMichal Marek# (needed for make) 2409564a8cfSRasmus Villemoes# Replace >#< with >$(pound)< to avoid starting a comment in the .cmd file 241164f0d2eSMichal Marek# (needed for make) 242164f0d2eSMichal Marek# Replace >'< with >'\''< to be able to enclose the whole string in '...' 243164f0d2eSMichal Marek# (needed for the shell) 2449564a8cfSRasmus Villemoesmake-cmd = $(call escsq,$(subst $(pound),$$(pound),$(subst $$,$$$$,$(cmd_$(1))))) 2456176aa9aSJan Beulich 24648f1f058SSam Ravnborg# Find any prerequisites that is newer than target or that does not exist. 24748f1f058SSam Ravnborg# PHONY targets skipped in both cases. 24848f1f058SSam Ravnborgany-prereq = $(filter-out $(PHONY),$?) $(filter-out $(PHONY) $(wildcard $^),$^) 24948f1f058SSam Ravnborg 2505de043f4SOleg Verych# Execute command if command has changed or prerequisite(s) are updated. 25148f1f058SSam Ravnborgif_changed = $(if $(strip $(any-prereq) $(arg-check)), \ 25267126965SMasahiro Yamada $(cmd); \ 2532aedcd09SMasahiro Yamada printf '%s\n' 'cmd_$@ := $(make-cmd)' > $(dot-target).cmd, @:) 2548ec4b4ffSSam Ravnborg 2555de043f4SOleg Verych# Execute the command and also postprocess generated .d dependencies file. 2563a2429e1SMasahiro Yamadaif_changed_dep = $(if $(strip $(any-prereq) $(arg-check)),$(cmd_and_fixdep),@:) 257c1a95fdaSNicolas Pitre 258e4aca459SNicolas Pitrecmd_and_fixdep = \ 2593a2429e1SMasahiro Yamada $(cmd); \ 260392885eeSMasahiro Yamada scripts/basic/fixdep $(depfile) $@ '$(make-cmd)' > $(dot-target).cmd;\ 261e5d28910SMasahiro Yamada rm -f $(depfile) 262c1a95fdaSNicolas Pitre 2638ec4b4ffSSam Ravnborg# Usage: $(call if_changed_rule,foo) 264beda9f3aSRoman Zippel# Will check if $(cmd_foo) or any of the prerequisites changed, 265beda9f3aSRoman Zippel# and if so will execute $(rule_foo). 2663a2429e1SMasahiro Yamadaif_changed_rule = $(if $(strip $(any-prereq) $(arg-check)),$(rule_$(1)),@:) 26748f1f058SSam Ravnborg 26845d506bdSSam Ravnborg### 269312a3d09SCao jin# why - tell why a target got built 27045d506bdSSam Ravnborg# enabled by make V=2 27145d506bdSSam Ravnborg# Output (listed in the order they are checked): 27245d506bdSSam Ravnborg# (1) - due to target is PHONY 27345d506bdSSam Ravnborg# (2) - due to target missing 27445d506bdSSam Ravnborg# (3) - due to: file1.h file2.h 27545d506bdSSam Ravnborg# (4) - due to command line change 27645d506bdSSam Ravnborg# (5) - due to missing .cmd file 27745d506bdSSam Ravnborg# (6) - due to target not in $(targets) 27845d506bdSSam Ravnborg# (1) PHONY targets are always build 27945d506bdSSam Ravnborg# (2) No target, so we better build it 28045d506bdSSam Ravnborg# (3) Prerequisite is newer than target 28145d506bdSSam Ravnborg# (4) The command line stored in the file named dir/.target.cmd 28245d506bdSSam Ravnborg# differed from actual command line. This happens when compiler 28345d506bdSSam Ravnborg# options changes 28445d506bdSSam Ravnborg# (5) No dir/.target.cmd file (used to store command line) 28545d506bdSSam Ravnborg# (6) No dir/.target.cmd file and target not listed in $(targets) 28645d506bdSSam Ravnborg# This is a good hint that there is a bug in the kbuild file 28745d506bdSSam Ravnborgifeq ($(KBUILD_VERBOSE),2) 28845d506bdSSam Ravnborgwhy = \ 28945d506bdSSam Ravnborg $(if $(filter $@, $(PHONY)),- due to target is PHONY, \ 29045d506bdSSam Ravnborg $(if $(wildcard $@), \ 29145d506bdSSam Ravnborg $(if $(strip $(any-prereq)),- due to: $(any-prereq), \ 29245d506bdSSam Ravnborg $(if $(arg-check), \ 29345d506bdSSam Ravnborg $(if $(cmd_$@),- due to command line change, \ 29445d506bdSSam Ravnborg $(if $(filter $@, $(targets)), \ 29545d506bdSSam Ravnborg - due to missing .cmd file, \ 29645d506bdSSam Ravnborg - due to $(notdir $@) not in $$(targets) \ 29745d506bdSSam Ravnborg ) \ 29845d506bdSSam Ravnborg ) \ 29945d506bdSSam Ravnborg ) \ 30045d506bdSSam Ravnborg ), \ 30145d506bdSSam Ravnborg - due to target missing \ 30245d506bdSSam Ravnborg ) \ 30345d506bdSSam Ravnborg ) 30445d506bdSSam Ravnborg 30545d506bdSSam Ravnborgecho-why = $(call escsq, $(strip $(why))) 30645d506bdSSam Ravnborgendif 3073ee550f1SDavid Woodhouse 3083ee550f1SDavid Woodhouse############################################################################### 3093ee550f1SDavid Woodhouse# 3103ee550f1SDavid Woodhouse# When a Kconfig string contains a filename, it is suitable for 3113ee550f1SDavid Woodhouse# passing to shell commands. It is surrounded by double-quotes, and 3123ee550f1SDavid Woodhouse# any double-quotes or backslashes within it are escaped by 3133ee550f1SDavid Woodhouse# backslashes. 3143ee550f1SDavid Woodhouse# 3153ee550f1SDavid Woodhouse# This is no use for dependencies or $(wildcard). We need to strip the 3163ee550f1SDavid Woodhouse# surrounding quotes and the escaping from quotes and backslashes, and 3173ee550f1SDavid Woodhouse# we *do* need to escape any spaces in the string. So, for example: 3183ee550f1SDavid Woodhouse# 3193ee550f1SDavid Woodhouse# Usage: $(eval $(call config_filename,FOO)) 3203ee550f1SDavid Woodhouse# 3213ee550f1SDavid Woodhouse# Defines FOO_FILENAME based on the contents of the CONFIG_FOO option, 3223ee550f1SDavid Woodhouse# transformed as described above to be suitable for use within the 3233ee550f1SDavid Woodhouse# makefile. 3243ee550f1SDavid Woodhouse# 3253ee550f1SDavid Woodhouse# Also, if the filename is a relative filename and exists in the source 3263ee550f1SDavid Woodhouse# tree but not the build tree, define FOO_SRCPREFIX as $(srctree)/ to 3273ee550f1SDavid Woodhouse# be prefixed to *both* command invocation and dependencies. 3283ee550f1SDavid Woodhouse# 3293ee550f1SDavid Woodhouse# Note: We also print the filenames in the quiet_cmd_foo text, and 3303ee550f1SDavid Woodhouse# perhaps ought to have a version specially escaped for that purpose. 3313ee550f1SDavid Woodhouse# But it's only cosmetic, and $(patsubst "%",%,$(CONFIG_FOO)) is good 3323ee550f1SDavid Woodhouse# enough. It'll strip the quotes in the common case where there's no 3333ee550f1SDavid Woodhouse# space and it's a simple filename, and it'll retain the quotes when 3343ee550f1SDavid Woodhouse# there's a space. There are some esoteric cases in which it'll print 3353ee550f1SDavid Woodhouse# the wrong thing, but we don't really care. The actual dependencies 3363ee550f1SDavid Woodhouse# and commands *do* get it right, with various combinations of single 3373ee550f1SDavid Woodhouse# and double quotes, backslashes and spaces in the filenames. 3383ee550f1SDavid Woodhouse# 3393ee550f1SDavid Woodhouse############################################################################### 3403ee550f1SDavid Woodhouse# 3413ee550f1SDavid Woodhousedefine config_filename 3423ee550f1SDavid Woodhouseifneq ($$(CONFIG_$(1)),"") 3433ee550f1SDavid Woodhouse$(1)_FILENAME := $$(subst \\,\,$$(subst \$$(quote),$$(quote),$$(subst $$(space_escape),\$$(space),$$(patsubst "%",%,$$(subst $$(space),$$(space_escape),$$(CONFIG_$(1))))))) 3443ee550f1SDavid Woodhouseifneq ($$(patsubst /%,%,$$(firstword $$($(1)_FILENAME))),$$(firstword $$($(1)_FILENAME))) 3453ee550f1SDavid Woodhouseelse 3463ee550f1SDavid Woodhouseifeq ($$(wildcard $$($(1)_FILENAME)),) 3473ee550f1SDavid Woodhouseifneq ($$(wildcard $$(srctree)/$$($(1)_FILENAME)),) 3483ee550f1SDavid Woodhouse$(1)_SRCPREFIX := $(srctree)/ 3493ee550f1SDavid Woodhouseendif 3503ee550f1SDavid Woodhouseendif 3513ee550f1SDavid Woodhouseendif 3523ee550f1SDavid Woodhouseendif 3533ee550f1SDavid Woodhouseendef 3543ee550f1SDavid Woodhouse# 3553ee550f1SDavid Woodhouse############################################################################### 3569c2af1c7SMasahiro Yamada 3579c2af1c7SMasahiro Yamada# delete partially updated (i.e. corrupted) files on error 3589c2af1c7SMasahiro Yamada.DELETE_ON_ERROR: 3598e9b61b2SMasahiro Yamada 3608e9b61b2SMasahiro Yamada# do not delete intermediate files automatically 3618e9b61b2SMasahiro Yamada.SECONDARY: 362