18c2ecf20Sopenharmony_ci# SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci#### 38c2ecf20Sopenharmony_ci# kbuild: Generic definitions 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ci# Convenient variables 68c2ecf20Sopenharmony_cicomma := , 78c2ecf20Sopenharmony_ciquote := " 88c2ecf20Sopenharmony_cisquote := ' 98c2ecf20Sopenharmony_ciempty := 108c2ecf20Sopenharmony_cispace := $(empty) $(empty) 118c2ecf20Sopenharmony_cispace_escape := _-_SPACE_-_ 128c2ecf20Sopenharmony_cipound := \# 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_ci### 158c2ecf20Sopenharmony_ci# Name of target with a '.' as filename prefix. foo/bar.o => foo/.bar.o 168c2ecf20Sopenharmony_cidot-target = $(dir $@).$(notdir $@) 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ci### 198c2ecf20Sopenharmony_ci# The temporary file to save gcc -MMD generated dependencies must not 208c2ecf20Sopenharmony_ci# contain a comma 218c2ecf20Sopenharmony_cidepfile = $(subst $(comma),_,$(dot-target).d) 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ci### 248c2ecf20Sopenharmony_ci# filename of target with directory and extension stripped 258c2ecf20Sopenharmony_cibasetarget = $(basename $(notdir $@)) 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci### 288c2ecf20Sopenharmony_ci# real prerequisites without phony targets 298c2ecf20Sopenharmony_cireal-prereqs = $(filter-out $(PHONY), $^) 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ci### 328c2ecf20Sopenharmony_ci# Escape single quote for use in echo statements 338c2ecf20Sopenharmony_ciescsq = $(subst $(squote),'\$(squote)',$1) 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci### 368c2ecf20Sopenharmony_ci# Quote a string to pass it to C files. foo => '"foo"' 378c2ecf20Sopenharmony_cistringify = $(squote)$(quote)$1$(quote)$(squote) 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci### 408c2ecf20Sopenharmony_ci# Easy method for doing a status message 418c2ecf20Sopenharmony_ci kecho := : 428c2ecf20Sopenharmony_ci quiet_kecho := echo 438c2ecf20Sopenharmony_cisilent_kecho := : 448c2ecf20Sopenharmony_cikecho := $($(quiet)kecho) 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_ci### 478c2ecf20Sopenharmony_ci# filechk is used to check if the content of a generated file is updated. 488c2ecf20Sopenharmony_ci# Sample usage: 498c2ecf20Sopenharmony_ci# 508c2ecf20Sopenharmony_ci# filechk_sample = echo $(KERNELRELEASE) 518c2ecf20Sopenharmony_ci# version.h: FORCE 528c2ecf20Sopenharmony_ci# $(call filechk,sample) 538c2ecf20Sopenharmony_ci# 548c2ecf20Sopenharmony_ci# The rule defined shall write to stdout the content of the new file. 558c2ecf20Sopenharmony_ci# The existing file will be compared with the new one. 568c2ecf20Sopenharmony_ci# - If no file exist it is created 578c2ecf20Sopenharmony_ci# - If the content differ the new file is used 588c2ecf20Sopenharmony_ci# - If they are equal no change, and no timestamp update 598c2ecf20Sopenharmony_cidefine filechk 608c2ecf20Sopenharmony_ci $(Q)set -e; \ 618c2ecf20Sopenharmony_ci mkdir -p $(dir $@); \ 628c2ecf20Sopenharmony_ci trap "rm -f $(dot-target).tmp" EXIT; \ 638c2ecf20Sopenharmony_ci { $(filechk_$(1)); } > $(dot-target).tmp; \ 648c2ecf20Sopenharmony_ci if [ ! -r $@ ] || ! cmp -s $@ $(dot-target).tmp; then \ 658c2ecf20Sopenharmony_ci $(kecho) ' UPD $@'; \ 668c2ecf20Sopenharmony_ci mv -f $(dot-target).tmp $@; \ 678c2ecf20Sopenharmony_ci fi 688c2ecf20Sopenharmony_ciendef 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ci###### 718c2ecf20Sopenharmony_ci# gcc support functions 728c2ecf20Sopenharmony_ci# See documentation in Documentation/kbuild/makefiles.rst 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_ci# cc-cross-prefix 758c2ecf20Sopenharmony_ci# Usage: CROSS_COMPILE := $(call cc-cross-prefix, m68k-linux-gnu- m68k-linux-) 768c2ecf20Sopenharmony_ci# Return first <prefix> where a <prefix>gcc is found in PATH. 778c2ecf20Sopenharmony_ci# If no gcc found in PATH with listed prefixes return nothing 788c2ecf20Sopenharmony_ci# 798c2ecf20Sopenharmony_ci# Note: '2>/dev/null' is here to force Make to invoke a shell. Otherwise, it 808c2ecf20Sopenharmony_ci# would try to directly execute the shell builtin 'command'. This workaround 818c2ecf20Sopenharmony_ci# should be kept for a long time since this issue was fixed only after the 828c2ecf20Sopenharmony_ci# GNU Make 4.2.1 release. 838c2ecf20Sopenharmony_cicc-cross-prefix = $(firstword $(foreach c, $(1), \ 848c2ecf20Sopenharmony_ci $(if $(shell command -v -- $(c)gcc 2>/dev/null), $(c)))) 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_ci# output directory for tests below 878c2ecf20Sopenharmony_ciTMPOUT = $(if $(KBUILD_EXTMOD),$(firstword $(KBUILD_EXTMOD))/).tmp_$$$$ 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_ci# try-run 908c2ecf20Sopenharmony_ci# Usage: option = $(call try-run, $(CC)...-o "$$TMP",option-ok,otherwise) 918c2ecf20Sopenharmony_ci# Exit code chooses option. "$$TMP" serves as a temporary file and is 928c2ecf20Sopenharmony_ci# automatically cleaned up. 938c2ecf20Sopenharmony_citry-run = $(shell set -e; \ 948c2ecf20Sopenharmony_ci TMP=$(TMPOUT)/tmp; \ 958c2ecf20Sopenharmony_ci TMPO=$(TMPOUT)/tmp.o; \ 968c2ecf20Sopenharmony_ci mkdir -p $(TMPOUT); \ 978c2ecf20Sopenharmony_ci trap "rm -rf $(TMPOUT)" EXIT; \ 988c2ecf20Sopenharmony_ci if ($(1)) >/dev/null 2>&1; \ 998c2ecf20Sopenharmony_ci then echo "$(2)"; \ 1008c2ecf20Sopenharmony_ci else echo "$(3)"; \ 1018c2ecf20Sopenharmony_ci fi) 1028c2ecf20Sopenharmony_ci 1038c2ecf20Sopenharmony_ci# as-option 1048c2ecf20Sopenharmony_ci# Usage: cflags-y += $(call as-option,-Wa$(comma)-isa=foo,) 1058c2ecf20Sopenharmony_ci 1068c2ecf20Sopenharmony_cias-option = $(call try-run,\ 1078c2ecf20Sopenharmony_ci $(CC) $(KBUILD_CFLAGS) $(1) -c -x assembler /dev/null -o "$$TMP",$(1),$(2)) 1088c2ecf20Sopenharmony_ci 1098c2ecf20Sopenharmony_ci# as-instr 1108c2ecf20Sopenharmony_ci# Usage: cflags-y += $(call as-instr,instr,option1,option2) 1118c2ecf20Sopenharmony_ci 1128c2ecf20Sopenharmony_cias-instr = $(call try-run,\ 1138c2ecf20Sopenharmony_ci printf "%b\n" "$(1)" | $(CC) $(KBUILD_AFLAGS) -c -x assembler -o "$$TMP" -,$(2),$(3)) 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_ci# __cc-option 1168c2ecf20Sopenharmony_ci# Usage: MY_CFLAGS += $(call __cc-option,$(CC),$(MY_CFLAGS),-march=winchip-c6,-march=i586) 1178c2ecf20Sopenharmony_ci__cc-option = $(call try-run,\ 1188c2ecf20Sopenharmony_ci $(1) -Werror $(2) $(3) -c -x c /dev/null -o "$$TMP",$(3),$(4)) 1198c2ecf20Sopenharmony_ci 1208c2ecf20Sopenharmony_ci# cc-option 1218c2ecf20Sopenharmony_ci# Usage: cflags-y += $(call cc-option,-march=winchip-c6,-march=i586) 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_cicc-option = $(call __cc-option, $(CC),\ 1248c2ecf20Sopenharmony_ci $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS),$(1),$(2)) 1258c2ecf20Sopenharmony_ci 1268c2ecf20Sopenharmony_ci# cc-option-yn 1278c2ecf20Sopenharmony_ci# Usage: flag := $(call cc-option-yn,-march=winchip-c6) 1288c2ecf20Sopenharmony_cicc-option-yn = $(call try-run,\ 1298c2ecf20Sopenharmony_ci $(CC) -Werror $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(1) -c -x c /dev/null -o "$$TMP",y,n) 1308c2ecf20Sopenharmony_ci 1318c2ecf20Sopenharmony_ci# cc-disable-warning 1328c2ecf20Sopenharmony_ci# Usage: cflags-y += $(call cc-disable-warning,unused-but-set-variable) 1338c2ecf20Sopenharmony_cicc-disable-warning = $(call try-run,\ 1348c2ecf20Sopenharmony_ci $(CC) -Werror $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) -W$(strip $(1)) -c -x c /dev/null -o "$$TMP",-Wno-$(strip $(1))) 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_ci# cc-ifversion 1378c2ecf20Sopenharmony_ci# Usage: EXTRA_CFLAGS += $(call cc-ifversion, -lt, 0402, -O1) 1388c2ecf20Sopenharmony_cicc-ifversion = $(shell [ $(CONFIG_GCC_VERSION)0 $(1) $(2)000 ] && echo $(3) || echo $(4)) 1398c2ecf20Sopenharmony_ci 1408c2ecf20Sopenharmony_ci# ld-option 1418c2ecf20Sopenharmony_ci# Usage: KBUILD_LDFLAGS += $(call ld-option, -X, -Y) 1428c2ecf20Sopenharmony_cild-option = $(call try-run, $(LD) $(KBUILD_LDFLAGS) $(1) -v,$(1),$(2),$(3)) 1438c2ecf20Sopenharmony_ci 1448c2ecf20Sopenharmony_ci# ld-version 1458c2ecf20Sopenharmony_ci# Note this is mainly for HJ Lu's 3 number binutil versions 1468c2ecf20Sopenharmony_cild-version = $(shell $(LD) --version | $(srctree)/scripts/ld-version.sh) 1478c2ecf20Sopenharmony_ci 1488c2ecf20Sopenharmony_ci# ld-ifversion 1498c2ecf20Sopenharmony_ci# Usage: $(call ld-ifversion, -ge, 22252, y) 1508c2ecf20Sopenharmony_cild-ifversion = $(shell [ $(ld-version) $(1) $(2) ] && echo $(3) || echo $(4)) 1518c2ecf20Sopenharmony_ci 1528c2ecf20Sopenharmony_ci###### 1538c2ecf20Sopenharmony_ci 1548c2ecf20Sopenharmony_ci### 1558c2ecf20Sopenharmony_ci# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.build obj= 1568c2ecf20Sopenharmony_ci# Usage: 1578c2ecf20Sopenharmony_ci# $(Q)$(MAKE) $(build)=dir 1588c2ecf20Sopenharmony_cibuild := -f $(srctree)/scripts/Makefile.build obj 1598c2ecf20Sopenharmony_ci 1608c2ecf20Sopenharmony_ci### 1618c2ecf20Sopenharmony_ci# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.dtbinst obj= 1628c2ecf20Sopenharmony_ci# Usage: 1638c2ecf20Sopenharmony_ci# $(Q)$(MAKE) $(dtbinst)=dir 1648c2ecf20Sopenharmony_cidtbinst := -f $(srctree)/scripts/Makefile.dtbinst obj 1658c2ecf20Sopenharmony_ci 1668c2ecf20Sopenharmony_ci### 1678c2ecf20Sopenharmony_ci# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.clean obj= 1688c2ecf20Sopenharmony_ci# Usage: 1698c2ecf20Sopenharmony_ci# $(Q)$(MAKE) $(clean)=dir 1708c2ecf20Sopenharmony_ciclean := -f $(srctree)/scripts/Makefile.clean obj 1718c2ecf20Sopenharmony_ci 1728c2ecf20Sopenharmony_ci# echo command. 1738c2ecf20Sopenharmony_ci# Short version is used, if $(quiet) equals `quiet_', otherwise full one. 1748c2ecf20Sopenharmony_ciecho-cmd = $(if $($(quiet)cmd_$(1)),\ 1758c2ecf20Sopenharmony_ci echo ' $(call escsq,$($(quiet)cmd_$(1)))$(echo-why)';) 1768c2ecf20Sopenharmony_ci 1778c2ecf20Sopenharmony_ci# sink stdout for 'make -s' 1788c2ecf20Sopenharmony_ci redirect := 1798c2ecf20Sopenharmony_ci quiet_redirect := 1808c2ecf20Sopenharmony_cisilent_redirect := exec >/dev/null; 1818c2ecf20Sopenharmony_ci 1828c2ecf20Sopenharmony_ci# Delete the target on interruption 1838c2ecf20Sopenharmony_ci# 1848c2ecf20Sopenharmony_ci# GNU Make automatically deletes the target if it has already been changed by 1858c2ecf20Sopenharmony_ci# the interrupted recipe. So, you can safely stop the build by Ctrl-C (Make 1868c2ecf20Sopenharmony_ci# will delete incomplete targets), and resume it later. 1878c2ecf20Sopenharmony_ci# 1888c2ecf20Sopenharmony_ci# However, this does not work when the stderr is piped to another program, like 1898c2ecf20Sopenharmony_ci# $ make >&2 | tee log 1908c2ecf20Sopenharmony_ci# Make dies with SIGPIPE before cleaning the targets. 1918c2ecf20Sopenharmony_ci# 1928c2ecf20Sopenharmony_ci# To address it, we clean the target in signal traps. 1938c2ecf20Sopenharmony_ci# 1948c2ecf20Sopenharmony_ci# Make deletes the target when it catches SIGHUP, SIGINT, SIGQUIT, SIGTERM. 1958c2ecf20Sopenharmony_ci# So, we cover them, and also SIGPIPE just in case. 1968c2ecf20Sopenharmony_ci# 1978c2ecf20Sopenharmony_ci# Of course, this is unneeded for phony targets. 1988c2ecf20Sopenharmony_cidelete-on-interrupt = \ 1998c2ecf20Sopenharmony_ci $(if $(filter-out $(PHONY), $@), \ 2008c2ecf20Sopenharmony_ci $(foreach sig, HUP INT QUIT TERM PIPE, \ 2018c2ecf20Sopenharmony_ci trap 'rm -f $@; trap - $(sig); kill -s $(sig) $$$$' $(sig);)) 2028c2ecf20Sopenharmony_ci 2038c2ecf20Sopenharmony_ci# printing commands 2048c2ecf20Sopenharmony_cicmd = @set -e; $(echo-cmd) $($(quiet)redirect) $(delete-on-interrupt) $(cmd_$(1)) 2058c2ecf20Sopenharmony_ci 2068c2ecf20Sopenharmony_ci### 2078c2ecf20Sopenharmony_ci# if_changed - execute command if any prerequisite is newer than 2088c2ecf20Sopenharmony_ci# target, or command line has changed 2098c2ecf20Sopenharmony_ci# if_changed_dep - as if_changed, but uses fixdep to reveal dependencies 2108c2ecf20Sopenharmony_ci# including used config symbols 2118c2ecf20Sopenharmony_ci# if_changed_rule - as if_changed but execute rule instead 2128c2ecf20Sopenharmony_ci# See Documentation/kbuild/makefiles.rst for more info 2138c2ecf20Sopenharmony_ci 2148c2ecf20Sopenharmony_ciifneq ($(KBUILD_NOCMDDEP),1) 2158c2ecf20Sopenharmony_ci# Check if both commands are the same including their order. Result is empty 2168c2ecf20Sopenharmony_ci# string if equal. User may override this check using make KBUILD_NOCMDDEP=1 2178c2ecf20Sopenharmony_cicmd-check = $(filter-out $(subst $(space),$(space_escape),$(strip $(cmd_$@))), \ 2188c2ecf20Sopenharmony_ci $(subst $(space),$(space_escape),$(strip $(cmd_$1)))) 2198c2ecf20Sopenharmony_cielse 2208c2ecf20Sopenharmony_cicmd-check = $(if $(strip $(cmd_$@)),,1) 2218c2ecf20Sopenharmony_ciendif 2228c2ecf20Sopenharmony_ci 2238c2ecf20Sopenharmony_ci# Replace >$< with >$$< to preserve $ when reloading the .cmd file 2248c2ecf20Sopenharmony_ci# (needed for make) 2258c2ecf20Sopenharmony_ci# Replace >#< with >$(pound)< to avoid starting a comment in the .cmd file 2268c2ecf20Sopenharmony_ci# (needed for make) 2278c2ecf20Sopenharmony_ci# Replace >'< with >'\''< to be able to enclose the whole string in '...' 2288c2ecf20Sopenharmony_ci# (needed for the shell) 2298c2ecf20Sopenharmony_cimake-cmd = $(call escsq,$(subst $(pound),$$(pound),$(subst $$,$$$$,$(cmd_$(1))))) 2308c2ecf20Sopenharmony_ci 2318c2ecf20Sopenharmony_ci# Find any prerequisites that are newer than target or that do not exist. 2328c2ecf20Sopenharmony_ci# (This is not true for now; $? should contain any non-existent prerequisites, 2338c2ecf20Sopenharmony_ci# but it does not work as expected when .SECONDARY is present. This seems a bug 2348c2ecf20Sopenharmony_ci# of GNU Make.) 2358c2ecf20Sopenharmony_ci# PHONY targets skipped in both cases. 2368c2ecf20Sopenharmony_cinewer-prereqs = $(filter-out $(PHONY),$?) 2378c2ecf20Sopenharmony_ci 2388c2ecf20Sopenharmony_ci# Execute command if command has changed or prerequisite(s) are updated. 2398c2ecf20Sopenharmony_ciif_changed = $(if $(newer-prereqs)$(cmd-check), \ 2408c2ecf20Sopenharmony_ci $(cmd); \ 2418c2ecf20Sopenharmony_ci printf '%s\n' 'cmd_$@ := $(make-cmd)' > $(dot-target).cmd, @:) 2428c2ecf20Sopenharmony_ci 2438c2ecf20Sopenharmony_ci# Execute the command and also postprocess generated .d dependencies file. 2448c2ecf20Sopenharmony_ciif_changed_dep = $(if $(newer-prereqs)$(cmd-check),$(cmd_and_fixdep),@:) 2458c2ecf20Sopenharmony_ci 2468c2ecf20Sopenharmony_cicmd_and_fixdep = \ 2478c2ecf20Sopenharmony_ci $(cmd); \ 2488c2ecf20Sopenharmony_ci scripts/basic/fixdep $(depfile) $@ '$(make-cmd)' > $(dot-target).cmd;\ 2498c2ecf20Sopenharmony_ci rm -f $(depfile) 2508c2ecf20Sopenharmony_ci 2518c2ecf20Sopenharmony_ci# Usage: $(call if_changed_rule,foo) 2528c2ecf20Sopenharmony_ci# Will check if $(cmd_foo) or any of the prerequisites changed, 2538c2ecf20Sopenharmony_ci# and if so will execute $(rule_foo). 2548c2ecf20Sopenharmony_ciif_changed_rule = $(if $(newer-prereqs)$(cmd-check),$(rule_$(1)),@:) 2558c2ecf20Sopenharmony_ci 2568c2ecf20Sopenharmony_ci### 2578c2ecf20Sopenharmony_ci# why - tell why a target got built 2588c2ecf20Sopenharmony_ci# enabled by make V=2 2598c2ecf20Sopenharmony_ci# Output (listed in the order they are checked): 2608c2ecf20Sopenharmony_ci# (1) - due to target is PHONY 2618c2ecf20Sopenharmony_ci# (2) - due to target missing 2628c2ecf20Sopenharmony_ci# (3) - due to: file1.h file2.h 2638c2ecf20Sopenharmony_ci# (4) - due to command line change 2648c2ecf20Sopenharmony_ci# (5) - due to missing .cmd file 2658c2ecf20Sopenharmony_ci# (6) - due to target not in $(targets) 2668c2ecf20Sopenharmony_ci# (1) PHONY targets are always build 2678c2ecf20Sopenharmony_ci# (2) No target, so we better build it 2688c2ecf20Sopenharmony_ci# (3) Prerequisite is newer than target 2698c2ecf20Sopenharmony_ci# (4) The command line stored in the file named dir/.target.cmd 2708c2ecf20Sopenharmony_ci# differed from actual command line. This happens when compiler 2718c2ecf20Sopenharmony_ci# options changes 2728c2ecf20Sopenharmony_ci# (5) No dir/.target.cmd file (used to store command line) 2738c2ecf20Sopenharmony_ci# (6) No dir/.target.cmd file and target not listed in $(targets) 2748c2ecf20Sopenharmony_ci# This is a good hint that there is a bug in the kbuild file 2758c2ecf20Sopenharmony_ciifeq ($(KBUILD_VERBOSE),2) 2768c2ecf20Sopenharmony_ciwhy = \ 2778c2ecf20Sopenharmony_ci $(if $(filter $@, $(PHONY)),- due to target is PHONY, \ 2788c2ecf20Sopenharmony_ci $(if $(wildcard $@), \ 2798c2ecf20Sopenharmony_ci $(if $(newer-prereqs),- due to: $(newer-prereqs), \ 2808c2ecf20Sopenharmony_ci $(if $(cmd-check), \ 2818c2ecf20Sopenharmony_ci $(if $(cmd_$@),- due to command line change, \ 2828c2ecf20Sopenharmony_ci $(if $(filter $@, $(targets)), \ 2838c2ecf20Sopenharmony_ci - due to missing .cmd file, \ 2848c2ecf20Sopenharmony_ci - due to $(notdir $@) not in $$(targets) \ 2858c2ecf20Sopenharmony_ci ) \ 2868c2ecf20Sopenharmony_ci ) \ 2878c2ecf20Sopenharmony_ci ) \ 2888c2ecf20Sopenharmony_ci ), \ 2898c2ecf20Sopenharmony_ci - due to target missing \ 2908c2ecf20Sopenharmony_ci ) \ 2918c2ecf20Sopenharmony_ci ) 2928c2ecf20Sopenharmony_ci 2938c2ecf20Sopenharmony_ciecho-why = $(call escsq, $(strip $(why))) 2948c2ecf20Sopenharmony_ciendif 2958c2ecf20Sopenharmony_ci 2968c2ecf20Sopenharmony_ci############################################################################### 2978c2ecf20Sopenharmony_ci# 2988c2ecf20Sopenharmony_ci# When a Kconfig string contains a filename, it is suitable for 2998c2ecf20Sopenharmony_ci# passing to shell commands. It is surrounded by double-quotes, and 3008c2ecf20Sopenharmony_ci# any double-quotes or backslashes within it are escaped by 3018c2ecf20Sopenharmony_ci# backslashes. 3028c2ecf20Sopenharmony_ci# 3038c2ecf20Sopenharmony_ci# This is no use for dependencies or $(wildcard). We need to strip the 3048c2ecf20Sopenharmony_ci# surrounding quotes and the escaping from quotes and backslashes, and 3058c2ecf20Sopenharmony_ci# we *do* need to escape any spaces in the string. So, for example: 3068c2ecf20Sopenharmony_ci# 3078c2ecf20Sopenharmony_ci# Usage: $(eval $(call config_filename,FOO)) 3088c2ecf20Sopenharmony_ci# 3098c2ecf20Sopenharmony_ci# Defines FOO_FILENAME based on the contents of the CONFIG_FOO option, 3108c2ecf20Sopenharmony_ci# transformed as described above to be suitable for use within the 3118c2ecf20Sopenharmony_ci# makefile. 3128c2ecf20Sopenharmony_ci# 3138c2ecf20Sopenharmony_ci# Also, if the filename is a relative filename and exists in the source 3148c2ecf20Sopenharmony_ci# tree but not the build tree, define FOO_SRCPREFIX as $(srctree)/ to 3158c2ecf20Sopenharmony_ci# be prefixed to *both* command invocation and dependencies. 3168c2ecf20Sopenharmony_ci# 3178c2ecf20Sopenharmony_ci# Note: We also print the filenames in the quiet_cmd_foo text, and 3188c2ecf20Sopenharmony_ci# perhaps ought to have a version specially escaped for that purpose. 3198c2ecf20Sopenharmony_ci# But it's only cosmetic, and $(patsubst "%",%,$(CONFIG_FOO)) is good 3208c2ecf20Sopenharmony_ci# enough. It'll strip the quotes in the common case where there's no 3218c2ecf20Sopenharmony_ci# space and it's a simple filename, and it'll retain the quotes when 3228c2ecf20Sopenharmony_ci# there's a space. There are some esoteric cases in which it'll print 3238c2ecf20Sopenharmony_ci# the wrong thing, but we don't really care. The actual dependencies 3248c2ecf20Sopenharmony_ci# and commands *do* get it right, with various combinations of single 3258c2ecf20Sopenharmony_ci# and double quotes, backslashes and spaces in the filenames. 3268c2ecf20Sopenharmony_ci# 3278c2ecf20Sopenharmony_ci############################################################################### 3288c2ecf20Sopenharmony_ci# 3298c2ecf20Sopenharmony_cidefine config_filename 3308c2ecf20Sopenharmony_ciifneq ($$(CONFIG_$(1)),"") 3318c2ecf20Sopenharmony_ci$(1)_FILENAME := $$(subst \\,\,$$(subst \$$(quote),$$(quote),$$(subst $$(space_escape),\$$(space),$$(patsubst "%",%,$$(subst $$(space),$$(space_escape),$$(CONFIG_$(1))))))) 3328c2ecf20Sopenharmony_ciifneq ($$(patsubst /%,%,$$(firstword $$($(1)_FILENAME))),$$(firstword $$($(1)_FILENAME))) 3338c2ecf20Sopenharmony_cielse 3348c2ecf20Sopenharmony_ciifeq ($$(wildcard $$($(1)_FILENAME)),) 3358c2ecf20Sopenharmony_ciifneq ($$(wildcard $$(srctree)/$$($(1)_FILENAME)),) 3368c2ecf20Sopenharmony_ci$(1)_SRCPREFIX := $(srctree)/ 3378c2ecf20Sopenharmony_ciendif 3388c2ecf20Sopenharmony_ciendif 3398c2ecf20Sopenharmony_ciendif 3408c2ecf20Sopenharmony_ciendif 3418c2ecf20Sopenharmony_ciendef 3428c2ecf20Sopenharmony_ci# 3438c2ecf20Sopenharmony_ci############################################################################### 3448c2ecf20Sopenharmony_ci 3458c2ecf20Sopenharmony_ci# delete partially updated (i.e. corrupted) files on error 3468c2ecf20Sopenharmony_ci.DELETE_ON_ERROR: 3478c2ecf20Sopenharmony_ci 3488c2ecf20Sopenharmony_ci# do not delete intermediate files automatically 3498c2ecf20Sopenharmony_ci.SECONDARY: 350