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_-_ 118ec4b4ffSSam Ravnborg 128ec4b4ffSSam Ravnborg### 1348f1f058SSam Ravnborg# Name of target with a '.' as filename prefix. foo/bar.o => foo/.bar.o 1448f1f058SSam Ravnborgdot-target = $(dir $@).$(notdir $@) 1548f1f058SSam Ravnborg 1648f1f058SSam Ravnborg### 178ec4b4ffSSam Ravnborg# The temporary file to save gcc -MD generated dependencies must not 188ec4b4ffSSam Ravnborg# contain a comma 1948f1f058SSam Ravnborgdepfile = $(subst $(comma),_,$(dot-target).d) 208ec4b4ffSSam Ravnborg 218ec4b4ffSSam Ravnborg### 225e8d780dSSam Ravnborg# filename of target with directory and extension stripped 235e8d780dSSam Ravnborgbasetarget = $(basename $(notdir $@)) 245e8d780dSSam Ravnborg 255e8d780dSSam Ravnborg### 26e0318d85SArnaud Lacombe# filename of first prerequisite with directory and extension stripped 27e0318d85SArnaud Lacombebaseprereq = $(basename $(notdir $<)) 28e0318d85SArnaud Lacombe 29e0318d85SArnaud Lacombe### 30d51bfb78SSam Ravnborg# Escape single quote for use in echo statements 31d51bfb78SSam Ravnborgescsq = $(subst $(squote),'\$(squote)',$1) 32d51bfb78SSam Ravnborg 33d51bfb78SSam Ravnborg### 345410ecc0SMike Frysinger# Easy method for doing a status message 355410ecc0SMike Frysinger kecho := : 365410ecc0SMike Frysinger quiet_kecho := echo 375410ecc0SMike Frysingersilent_kecho := : 385410ecc0SMike Frysingerkecho := $($(quiet)kecho) 395410ecc0SMike Frysinger 405410ecc0SMike Frysinger### 418ec4b4ffSSam Ravnborg# filechk is used to check if the content of a generated file is updated. 428ec4b4ffSSam Ravnborg# Sample usage: 438ec4b4ffSSam Ravnborg# define filechk_sample 448ec4b4ffSSam Ravnborg# echo $KERNELRELEASE 458ec4b4ffSSam Ravnborg# endef 468ec4b4ffSSam Ravnborg# version.h : Makefile 478ec4b4ffSSam Ravnborg# $(call filechk,sample) 488ec4b4ffSSam Ravnborg# The rule defined shall write to stdout the content of the new file. 498ec4b4ffSSam Ravnborg# The existing file will be compared with the new one. 508ec4b4ffSSam Ravnborg# - If no file exist it is created 518ec4b4ffSSam Ravnborg# - If the content differ the new file is used 528ec4b4ffSSam Ravnborg# - If they are equal no change, and no timestamp update 538ec4b4ffSSam Ravnborg# - stdin is piped in from the first prerequisite ($<) so one has 548ec4b4ffSSam Ravnborg# to specify a valid file as first prerequisite (often the kbuild file) 558ec4b4ffSSam Ravnborgdefine filechk 568ec4b4ffSSam Ravnborg $(Q)set -e; \ 57fd54f502SMike Frysinger $(kecho) ' CHK $@'; \ 588ec4b4ffSSam Ravnborg mkdir -p $(dir $@); \ 598ec4b4ffSSam Ravnborg $(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) 88beda9f3aSRoman Zippel# Exit code chooses option. "$$TMP" is can be used as temporary file and 89beda9f3aSRoman Zippel# is automatically cleaned up. 90beda9f3aSRoman Zippeltry-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; \ 97691ef3e7SSam Ravnborg rm -f "$$TMP" "$$TMPO") 98347a00fbSRoman Zippel 9920a468b5SSam Ravnborg# as-option 10020a468b5SSam Ravnborg# Usage: cflags-y += $(call as-option,-Wa$(comma)-isa=foo,) 101beda9f3aSRoman Zippel 102beda9f3aSRoman Zippelas-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 108beda9f3aSRoman Zippelas-instr = $(call try-run,\ 109875de986SBernhard Walle printf "%b\n" "$(1)" | $(CC) $(KBUILD_AFLAGS) -c -x assembler -o "$$TMP" -,$(2),$(3)) 110e2414910SAndi Kleen 111d26e9414SEmese Revfy# Do not attempt to build with gcc plugins during cc-option tests. 112d26e9414SEmese Revfy# (And this uses delayed resolution so the flags will be up to date.) 113d26e9414SEmese RevfyCC_OPTION_CFLAGS = $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS)) 114d26e9414SEmese Revfy 11520a468b5SSam Ravnborg# cc-option 11620a468b5SSam Ravnborg# Usage: cflags-y += $(call cc-option,-march=winchip-c6,-march=i586) 117beda9f3aSRoman Zippel 118beda9f3aSRoman Zippelcc-option = $(call try-run,\ 119d26e9414SEmese Revfy $(CC) $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS) $(1) -c -x c /dev/null -o "$$TMP",$(1),$(2)) 12020a468b5SSam Ravnborg 12120a468b5SSam Ravnborg# cc-option-yn 12220a468b5SSam Ravnborg# Usage: flag := $(call cc-option-yn,-march=winchip-c6) 123beda9f3aSRoman Zippelcc-option-yn = $(call try-run,\ 124d26e9414SEmese Revfy $(CC) $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS) $(1) -c -x c /dev/null -o "$$TMP",y,n) 12520a468b5SSam Ravnborg 12620a468b5SSam Ravnborg# cc-option-align 12720a468b5SSam Ravnborg# Prefix align with either -falign or -malign 12820a468b5SSam Ravnborgcc-option-align = $(subst -functions=0,,\ 12920a468b5SSam Ravnborg $(call cc-option,-falign-functions=0,-malign-functions=0)) 13020a468b5SSam Ravnborg 1318417da6fSMichal Marek# cc-disable-warning 1328417da6fSMichal Marek# Usage: cflags-y += $(call cc-disable-warning,unused-but-set-variable) 1338417da6fSMichal Marekcc-disable-warning = $(call try-run,\ 134d26e9414SEmese Revfy $(CC) $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS) -W$(strip $(1)) -c -x c /dev/null -o "$$TMP",-Wno-$(strip $(1))) 1358417da6fSMichal Marek 1365631d9c4SMichal Marek# cc-name 1375631d9c4SMichal Marek# Expands to either gcc or clang 1385631d9c4SMichal Marekcc-name = $(shell $(CC) -v 2>&1 | grep -q "clang version" && echo clang || echo gcc) 1395631d9c4SMichal Marek 14020a468b5SSam Ravnborg# cc-version 1418eb3afe0SSam Ravnborgcc-version = $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-version.sh $(CC)) 14220a468b5SSam Ravnborg 1430ab2a272SSegher Boessenkool# cc-fullversion 1440ab2a272SSegher Boessenkoolcc-fullversion = $(shell $(CONFIG_SHELL) \ 1450ab2a272SSegher Boessenkool $(srctree)/scripts/gcc-version.sh -p $(CC)) 1460ab2a272SSegher Boessenkool 14720a468b5SSam Ravnborg# cc-ifversion 14820a468b5SSam Ravnborg# Usage: EXTRA_CFLAGS += $(call cc-ifversion, -lt, 0402, -O1) 1496dcb4e5eSMasahiro Yamadacc-ifversion = $(shell [ $(cc-version) $(1) $(2) ] && echo $(3) || echo $(4)) 15020a468b5SSam Ravnborg 151*3f135e57SJosh Poimboeuf# cc-if-fullversion 152*3f135e57SJosh Poimboeuf# Usage: EXTRA_CFLAGS += $(call cc-if-fullversion, -lt, 040502, -O1) 153*3f135e57SJosh Poimboeufcc-if-fullversion = $(shell [ $(cc-fullversion) $(1) $(2) ] && echo $(3) || echo $(4)) 154*3f135e57SJosh Poimboeuf 155f86fd306SSam Ravnborg# cc-ldoption 156f86fd306SSam Ravnborg# Usage: ldflags += $(call cc-ldoption, -Wl$(comma)--hash-style=both) 157f86fd306SSam Ravnborgcc-ldoption = $(call try-run,\ 158beda9f3aSRoman Zippel $(CC) $(1) -nostdlib -x c /dev/null -o "$$TMP",$(1),$(2)) 1590b0bf7a3SRoland McGrath 160691ef3e7SSam Ravnborg# ld-option 161691ef3e7SSam Ravnborg# Usage: LDFLAGS += $(call ld-option, -X) 162691ef3e7SSam Ravnborgld-option = $(call try-run,\ 1635b83df2bSAntony Pavlov $(CC) -x c /dev/null -c -o "$$TMPO" ; $(LD) $(1) "$$TMPO" -o "$$TMP",$(1),$(2)) 164691ef3e7SSam Ravnborg 16540df759eSMichal Marek# ar-option 16640df759eSMichal Marek# Usage: KBUILD_ARFLAGS := $(call ar-option,D) 16740df759eSMichal Marek# Important: no spaces around options 16840df759eSMichal Marekar-option = $(call try-run, $(AR) rc$(1) "$$TMP",$(1),$(2)) 16940df759eSMichal Marek 170ccbef167SAndi Kleen# ld-version 171ccbef167SAndi Kleen# Note this is mainly for HJ Lu's 3 number binutil versions 172ccbef167SAndi Kleenld-version = $(shell $(LD) --version | $(srctree)/scripts/ld-version.sh) 173ccbef167SAndi Kleen 174ccbef167SAndi Kleen# ld-ifversion 175ccbef167SAndi Kleen# Usage: $(call ld-ifversion, -ge, 22252, y) 1766dcb4e5eSMasahiro Yamadald-ifversion = $(shell [ $(ld-version) $(1) $(2) ] && echo $(3) || echo $(4)) 177ccbef167SAndi Kleen 1785de043f4SOleg Verych###### 1795de043f4SOleg Verych 180beda9f3aSRoman Zippel### 1818ec4b4ffSSam Ravnborg# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.build obj= 1828ec4b4ffSSam Ravnborg# Usage: 1838ec4b4ffSSam Ravnborg# $(Q)$(MAKE) $(build)=dir 1845b2389b4SMasahiro Yamadabuild := -f $(srctree)/scripts/Makefile.build obj 1858ec4b4ffSSam Ravnborg 186bc081dd6SMichal Marek### 187bc081dd6SMichal Marek# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.modbuiltin obj= 188bc081dd6SMichal Marek# Usage: 189bc081dd6SMichal Marek# $(Q)$(MAKE) $(modbuiltin)=dir 1905b2389b4SMasahiro Yamadamodbuiltin := -f $(srctree)/scripts/Makefile.modbuiltin obj 191bc081dd6SMichal Marek 1929fb5e537SRobert Richter### 1939fb5e537SRobert Richter# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.dtbinst obj= 1949fb5e537SRobert Richter# Usage: 1959fb5e537SRobert Richter# $(Q)$(MAKE) $(dtbinst)=dir 1969fb5e537SRobert Richterdtbinst := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.dtbinst obj 1979fb5e537SRobert Richter 198d08372caSLinus Torvalds### 199371fdc77SMasahiro Yamada# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.clean obj= 200371fdc77SMasahiro Yamada# Usage: 201371fdc77SMasahiro Yamada# $(Q)$(MAKE) $(clean)=dir 202371fdc77SMasahiro Yamadaclean := -f $(srctree)/scripts/Makefile.clean obj 203371fdc77SMasahiro Yamada 204371fdc77SMasahiro Yamada### 2051846dfbdSMasahiro Yamada# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.headersinst obj= 206371fdc77SMasahiro Yamada# Usage: 207371fdc77SMasahiro Yamada# $(Q)$(MAKE) $(hdr-inst)=dir 2081846dfbdSMasahiro Yamadahdr-inst := -f $(srctree)/scripts/Makefile.headersinst obj 209371fdc77SMasahiro Yamada 210beda9f3aSRoman Zippel# Prefix -I with $(srctree) if it is not an absolute path. 2115b91c33cSSam Ravnborg# skip if -I has no parameter 2125b91c33cSSam Ravnborgaddtree = $(if $(patsubst -I%,%,$(1)), \ 213db547ef1SArnd Bergmann$(if $(filter-out -I/% -I./% -I../%,$(1)),$(patsubst -I%,-I$(srctree)/%,$(1)),$(1))) 214d9df92e2SSam Ravnborg 2155de043f4SOleg Verych# Find all -I options and call addtree 216beda9f3aSRoman Zippelflags = $(foreach o,$($(1)),$(if $(filter -I%,$(o)),$(call addtree,$(o)),$(o))) 2175de043f4SOleg Verych 2185de043f4SOleg Verych# echo command. 2195de043f4SOleg Verych# Short version is used, if $(quiet) equals `quiet_', otherwise full one. 2205de043f4SOleg Verychecho-cmd = $(if $($(quiet)cmd_$(1)),\ 2215de043f4SOleg Verych echo ' $(call escsq,$($(quiet)cmd_$(1)))$(echo-why)';) 2225de043f4SOleg Verych 2235de043f4SOleg Verych# printing commands 2246176aa9aSJan Beulichcmd = @$(echo-cmd) $(cmd_$(1)) 2258ec4b4ffSSam Ravnborg 2265de043f4SOleg Verych# Add $(obj)/ for paths that are not absolute 2270a504f25SSam Ravnborgobjectify = $(foreach o,$(1),$(if $(filter /%,$(o)),$(o),$(obj)/$(o))) 2280a504f25SSam Ravnborg 2298ec4b4ffSSam Ravnborg### 2308ec4b4ffSSam Ravnborg# if_changed - execute command if any prerequisite is newer than 2318ec4b4ffSSam Ravnborg# target, or command line has changed 2328ec4b4ffSSam Ravnborg# if_changed_dep - as if_changed, but uses fixdep to reveal dependencies 2338ec4b4ffSSam Ravnborg# including used config symbols 2348ec4b4ffSSam Ravnborg# if_changed_rule - as if_changed but execute rule instead 2358ec4b4ffSSam Ravnborg# See Documentation/kbuild/makefiles.txt for more info 2368ec4b4ffSSam Ravnborg 2378ec4b4ffSSam Ravnborgifneq ($(KBUILD_NOCMDDEP),1) 2389c8fa9bcSMasahiro Yamada# Check if both arguments are the same including their order. Result is empty 2399c8fa9bcSMasahiro Yamada# string if equal. User may override this check using make KBUILD_NOCMDDEP=1 2409c8fa9bcSMasahiro Yamadaarg-check = $(filter-out $(subst $(space),$(space_escape),$(strip $(cmd_$@))), \ 2419c8fa9bcSMasahiro Yamada $(subst $(space),$(space_escape),$(strip $(cmd_$1)))) 242c4d5ee13SMichal Marekelse 243c4d5ee13SMichal Marekarg-check = $(if $(strip $(cmd_$@)),,1) 2448ec4b4ffSSam Ravnborgendif 2458ec4b4ffSSam Ravnborg 246164f0d2eSMichal Marek# Replace >$< with >$$< to preserve $ when reloading the .cmd file 247164f0d2eSMichal Marek# (needed for make) 248164f0d2eSMichal Marek# Replace >#< with >\#< to avoid starting a comment in the .cmd file 249164f0d2eSMichal Marek# (needed for make) 250164f0d2eSMichal Marek# Replace >'< with >'\''< to be able to enclose the whole string in '...' 251164f0d2eSMichal Marek# (needed for the shell) 252164f0d2eSMichal Marekmake-cmd = $(call escsq,$(subst \#,\\\#,$(subst $$,$$$$,$(cmd_$(1))))) 2536176aa9aSJan Beulich 25448f1f058SSam Ravnborg# Find any prerequisites that is newer than target or that does not exist. 25548f1f058SSam Ravnborg# PHONY targets skipped in both cases. 25648f1f058SSam Ravnborgany-prereq = $(filter-out $(PHONY),$?) $(filter-out $(PHONY) $(wildcard $^),$^) 25748f1f058SSam Ravnborg 2585de043f4SOleg Verych# Execute command if command has changed or prerequisite(s) are updated. 2598ec4b4ffSSam Ravnborg# 26048f1f058SSam Ravnborgif_changed = $(if $(strip $(any-prereq) $(arg-check)), \ 2618ec4b4ffSSam Ravnborg @set -e; \ 2626176aa9aSJan Beulich $(echo-cmd) $(cmd_$(1)); \ 2632aedcd09SMasahiro Yamada printf '%s\n' 'cmd_$@ := $(make-cmd)' > $(dot-target).cmd, @:) 2648ec4b4ffSSam Ravnborg 2655de043f4SOleg Verych# Execute the command and also postprocess generated .d dependencies file. 26648f1f058SSam Ravnborgif_changed_dep = $(if $(strip $(any-prereq) $(arg-check) ), \ 2678ec4b4ffSSam Ravnborg @set -e; \ 268e4aca459SNicolas Pitre $(cmd_and_fixdep), @:) 269e4aca459SNicolas Pitre 270c1a95fdaSNicolas Pitreifndef CONFIG_TRIM_UNUSED_KSYMS 271c1a95fdaSNicolas Pitre 272e4aca459SNicolas Pitrecmd_and_fixdep = \ 2736176aa9aSJan Beulich $(echo-cmd) $(cmd_$(1)); \ 27448f1f058SSam Ravnborg scripts/basic/fixdep $(depfile) $@ '$(make-cmd)' > $(dot-target).tmp;\ 2758ec4b4ffSSam Ravnborg rm -f $(depfile); \ 276e4aca459SNicolas Pitre mv -f $(dot-target).tmp $(dot-target).cmd; 2778ec4b4ffSSam Ravnborg 278c1a95fdaSNicolas Pitreelse 279c1a95fdaSNicolas Pitre 280c1a95fdaSNicolas Pitre# Filter out exported kernel symbol names from the preprocessor output. 281c1a95fdaSNicolas Pitre# See also __KSYM_DEPS__ in include/linux/export.h. 282c1a95fdaSNicolas Pitre# We disable the depfile generation here, so as not to overwrite the existing 283c1a95fdaSNicolas Pitre# depfile while fixdep is parsing it. 284c1a95fdaSNicolas Pitreflags_nodeps = $(filter-out -Wp$(comma)-M%, $($(1))) 285c1a95fdaSNicolas Pitreksym_dep_filter = \ 286c1a95fdaSNicolas Pitre case "$(1)" in \ 287366f4856SNicolas Pitre cc_*_c|cpp_i_c) \ 288366f4856SNicolas Pitre $(CPP) $(call flags_nodeps,c_flags) -D__KSYM_DEPS__ $< ;; \ 289366f4856SNicolas Pitre as_*_S|cpp_s_S) \ 290366f4856SNicolas Pitre $(CPP) $(call flags_nodeps,a_flags) -D__KSYM_DEPS__ $< ;; \ 2910d070d2bSMarcin Nowakowski boot*|build*|cpp_its_S|*cpp_lds_S|dtc|host*|vdso*) : ;; \ 292c1a95fdaSNicolas Pitre *) echo "Don't know how to preprocess $(1)" >&2; false ;; \ 293f110e0feSNicolas Pitre esac | tr ";" "\n" | sed -rn 's/^.*=== __KSYM_(.*) ===.*$$/KSYM_\1/p' 294c1a95fdaSNicolas Pitre 295c1a95fdaSNicolas Pitrecmd_and_fixdep = \ 296c1a95fdaSNicolas Pitre $(echo-cmd) $(cmd_$(1)); \ 297c1a95fdaSNicolas Pitre $(ksym_dep_filter) | \ 298c1a95fdaSNicolas Pitre scripts/basic/fixdep -e $(depfile) $@ '$(make-cmd)' \ 299c1a95fdaSNicolas Pitre > $(dot-target).tmp; \ 300c1a95fdaSNicolas Pitre rm -f $(depfile); \ 301c1a95fdaSNicolas Pitre mv -f $(dot-target).tmp $(dot-target).cmd; 302c1a95fdaSNicolas Pitre 303c1a95fdaSNicolas Pitreendif 304c1a95fdaSNicolas Pitre 3058ec4b4ffSSam Ravnborg# Usage: $(call if_changed_rule,foo) 306beda9f3aSRoman Zippel# Will check if $(cmd_foo) or any of the prerequisites changed, 307beda9f3aSRoman Zippel# and if so will execute $(rule_foo). 30848f1f058SSam Ravnborgif_changed_rule = $(if $(strip $(any-prereq) $(arg-check) ), \ 3098ec4b4ffSSam Ravnborg @set -e; \ 3102aedcd09SMasahiro Yamada $(rule_$(1)), @:) 31148f1f058SSam Ravnborg 31245d506bdSSam Ravnborg### 31345d506bdSSam Ravnborg# why - tell why a a target got build 31445d506bdSSam Ravnborg# enabled by make V=2 31545d506bdSSam Ravnborg# Output (listed in the order they are checked): 31645d506bdSSam Ravnborg# (1) - due to target is PHONY 31745d506bdSSam Ravnborg# (2) - due to target missing 31845d506bdSSam Ravnborg# (3) - due to: file1.h file2.h 31945d506bdSSam Ravnborg# (4) - due to command line change 32045d506bdSSam Ravnborg# (5) - due to missing .cmd file 32145d506bdSSam Ravnborg# (6) - due to target not in $(targets) 32245d506bdSSam Ravnborg# (1) PHONY targets are always build 32345d506bdSSam Ravnborg# (2) No target, so we better build it 32445d506bdSSam Ravnborg# (3) Prerequisite is newer than target 32545d506bdSSam Ravnborg# (4) The command line stored in the file named dir/.target.cmd 32645d506bdSSam Ravnborg# differed from actual command line. This happens when compiler 32745d506bdSSam Ravnborg# options changes 32845d506bdSSam Ravnborg# (5) No dir/.target.cmd file (used to store command line) 32945d506bdSSam Ravnborg# (6) No dir/.target.cmd file and target not listed in $(targets) 33045d506bdSSam Ravnborg# This is a good hint that there is a bug in the kbuild file 33145d506bdSSam Ravnborgifeq ($(KBUILD_VERBOSE),2) 33245d506bdSSam Ravnborgwhy = \ 33345d506bdSSam Ravnborg $(if $(filter $@, $(PHONY)),- due to target is PHONY, \ 33445d506bdSSam Ravnborg $(if $(wildcard $@), \ 33545d506bdSSam Ravnborg $(if $(strip $(any-prereq)),- due to: $(any-prereq), \ 33645d506bdSSam Ravnborg $(if $(arg-check), \ 33745d506bdSSam Ravnborg $(if $(cmd_$@),- due to command line change, \ 33845d506bdSSam Ravnborg $(if $(filter $@, $(targets)), \ 33945d506bdSSam Ravnborg - due to missing .cmd file, \ 34045d506bdSSam Ravnborg - due to $(notdir $@) not in $$(targets) \ 34145d506bdSSam Ravnborg ) \ 34245d506bdSSam Ravnborg ) \ 34345d506bdSSam Ravnborg ) \ 34445d506bdSSam Ravnborg ), \ 34545d506bdSSam Ravnborg - due to target missing \ 34645d506bdSSam Ravnborg ) \ 34745d506bdSSam Ravnborg ) 34845d506bdSSam Ravnborg 34945d506bdSSam Ravnborgecho-why = $(call escsq, $(strip $(why))) 35045d506bdSSam Ravnborgendif 3513ee550f1SDavid Woodhouse 3523ee550f1SDavid Woodhouse############################################################################### 3533ee550f1SDavid Woodhouse# 3543ee550f1SDavid Woodhouse# When a Kconfig string contains a filename, it is suitable for 3553ee550f1SDavid Woodhouse# passing to shell commands. It is surrounded by double-quotes, and 3563ee550f1SDavid Woodhouse# any double-quotes or backslashes within it are escaped by 3573ee550f1SDavid Woodhouse# backslashes. 3583ee550f1SDavid Woodhouse# 3593ee550f1SDavid Woodhouse# This is no use for dependencies or $(wildcard). We need to strip the 3603ee550f1SDavid Woodhouse# surrounding quotes and the escaping from quotes and backslashes, and 3613ee550f1SDavid Woodhouse# we *do* need to escape any spaces in the string. So, for example: 3623ee550f1SDavid Woodhouse# 3633ee550f1SDavid Woodhouse# Usage: $(eval $(call config_filename,FOO)) 3643ee550f1SDavid Woodhouse# 3653ee550f1SDavid Woodhouse# Defines FOO_FILENAME based on the contents of the CONFIG_FOO option, 3663ee550f1SDavid Woodhouse# transformed as described above to be suitable for use within the 3673ee550f1SDavid Woodhouse# makefile. 3683ee550f1SDavid Woodhouse# 3693ee550f1SDavid Woodhouse# Also, if the filename is a relative filename and exists in the source 3703ee550f1SDavid Woodhouse# tree but not the build tree, define FOO_SRCPREFIX as $(srctree)/ to 3713ee550f1SDavid Woodhouse# be prefixed to *both* command invocation and dependencies. 3723ee550f1SDavid Woodhouse# 3733ee550f1SDavid Woodhouse# Note: We also print the filenames in the quiet_cmd_foo text, and 3743ee550f1SDavid Woodhouse# perhaps ought to have a version specially escaped for that purpose. 3753ee550f1SDavid Woodhouse# But it's only cosmetic, and $(patsubst "%",%,$(CONFIG_FOO)) is good 3763ee550f1SDavid Woodhouse# enough. It'll strip the quotes in the common case where there's no 3773ee550f1SDavid Woodhouse# space and it's a simple filename, and it'll retain the quotes when 3783ee550f1SDavid Woodhouse# there's a space. There are some esoteric cases in which it'll print 3793ee550f1SDavid Woodhouse# the wrong thing, but we don't really care. The actual dependencies 3803ee550f1SDavid Woodhouse# and commands *do* get it right, with various combinations of single 3813ee550f1SDavid Woodhouse# and double quotes, backslashes and spaces in the filenames. 3823ee550f1SDavid Woodhouse# 3833ee550f1SDavid Woodhouse############################################################################### 3843ee550f1SDavid Woodhouse# 3853ee550f1SDavid Woodhousedefine config_filename 3863ee550f1SDavid Woodhouseifneq ($$(CONFIG_$(1)),"") 3873ee550f1SDavid Woodhouse$(1)_FILENAME := $$(subst \\,\,$$(subst \$$(quote),$$(quote),$$(subst $$(space_escape),\$$(space),$$(patsubst "%",%,$$(subst $$(space),$$(space_escape),$$(CONFIG_$(1))))))) 3883ee550f1SDavid Woodhouseifneq ($$(patsubst /%,%,$$(firstword $$($(1)_FILENAME))),$$(firstword $$($(1)_FILENAME))) 3893ee550f1SDavid Woodhouseelse 3903ee550f1SDavid Woodhouseifeq ($$(wildcard $$($(1)_FILENAME)),) 3913ee550f1SDavid Woodhouseifneq ($$(wildcard $$(srctree)/$$($(1)_FILENAME)),) 3923ee550f1SDavid Woodhouse$(1)_SRCPREFIX := $(srctree)/ 3933ee550f1SDavid Woodhouseendif 3943ee550f1SDavid Woodhouseendif 3953ee550f1SDavid Woodhouseendif 3963ee550f1SDavid Woodhouseendif 3973ee550f1SDavid Woodhouseendef 3983ee550f1SDavid Woodhouse# 3993ee550f1SDavid Woodhouse############################################################################### 400