2 # kbuild: Generic definitions
8 space := $(empty) $(empty)
11 # The temporary file to save gcc -MD generated dependencies must not
13 depfile = $(subst $(comma),_,$(@D)/.$(@F).d)
16 # Escape single quote for use in echo statements
17 escsq = $(subst $(squote),'\$(squote)',$1)
20 # filechk is used to check if the content of a generated file is updated.
22 # define filechk_sample
25 # version.h : Makefile
26 # $(call filechk,sample)
27 # The rule defined shall write to stdout the content of the new file.
28 # The existing file will be compared with the new one.
29 # - If no file exist it is created
30 # - If the content differ the new file is used
31 # - If they are equal no change, and no timestamp update
32 # - stdin is piped in from the first prerequisite ($<) so one has
33 # to specify a valid file as first prerequisite (often the kbuild file)
38 $(filechk_$(1)) < $< > $@.tmp; \
39 if [ -r $@ ] && cmp -s $@ $@.tmp; then \
48 # Shorthand for $(Q)$(MAKE) -f scripts/Makefile.build obj=
50 # $(Q)$(MAKE) $(build)=dir
51 build := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.build obj
53 # If quiet is set, only print short version of command
54 cmd = @$(if $($(quiet)cmd_$(1)),\
55 echo ' $(call escsq,$($(quiet)cmd_$(1)))' &&) $(cmd_$(1))
57 # Add $(obj)/ for paths that is not absolute
58 objectify = $(foreach o,$(1),$(if $(filter /%,$(o)),$(o),$(obj)/$(o)))
61 # if_changed - execute command if any prerequisite is newer than
62 # target, or command line has changed
63 # if_changed_dep - as if_changed, but uses fixdep to reveal dependencies
64 # including used config symbols
65 # if_changed_rule - as if_changed but execute rule instead
66 # See Documentation/kbuild/makefiles.txt for more info
68 ifneq ($(KBUILD_NOCMDDEP),1)
69 # Check if both arguments has same arguments. Result in empty string if equal
70 # User may override this check using make KBUILD_NOCMDDEP=1
71 arg-check = $(strip $(filter-out $(1), $(2)) $(filter-out $(2), $(1)) )
74 # echo command. Short version is $(quiet) equals quiet, otherwise full command
75 echo-cmd = $(if $($(quiet)cmd_$(1)), \
76 echo ' $(call escsq,$($(quiet)cmd_$(1)))';)
78 # function to only execute the passed command if necessary
79 # >'< substitution is for echo to work, >$< substitution to preserve $ when reloading .cmd file
80 # note: when using inline perl scripts [perl -e '...$$t=1;...'] in $(cmd_xxx) double $$ your perl vars
82 if_changed = $(if $(strip $? $(call arg-check, $(cmd_$(1)), $(cmd_$@)) ), \
86 echo 'cmd_$@ := $(subst $$,$$$$,$(call escsq,$(cmd_$(1))))' > $(@D)/.$(@F).cmd)
88 # execute the command and also postprocess generated .d dependencies
90 if_changed_dep = $(if $(strip $? $(filter-out FORCE $(wildcard $^),$^)\
91 $(call arg-check, $(cmd_$(1)), $(cmd_$@)) ), \
95 scripts/basic/fixdep $(depfile) $@ '$(subst $$,$$$$,$(call escsq,$(cmd_$(1))))' > $(@D)/.$(@F).tmp; \
97 mv -f $(@D)/.$(@F).tmp $(@D)/.$(@F).cmd)
99 # Usage: $(call if_changed_rule,foo)
100 # will check if $(cmd_foo) changed, or any of the prequisites changed,
101 # and if so will execute $(rule_foo)
102 if_changed_rule = $(if $(strip $? $(call arg-check, $(cmd_$(1)), $(cmd_$@)) ),\