96ac6d4351004 (Greg Kroah-Hartman 2019-05-30 05:03:44 -0700 1) # SPDX-License-Identifier: GPL-2.0
8ec4b4ff1c89b (Sam Ravnborg 2005-07-25 20:10:36 +0000 2) ####
8ec4b4ff1c89b (Sam Ravnborg 2005-07-25 20:10:36 +0000 3) # kbuild: Generic definitions
8ec4b4ff1c89b (Sam Ravnborg 2005-07-25 20:10:36 +0000 4)
beda9f3a13bbb (Roman Zippel 2007-02-08 22:48:51 +0100 5) # Convenient variables
8ec4b4ff1c89b (Sam Ravnborg 2005-07-25 20:10:36 +0000 6) comma := ,
13338935f1574 (Masahiro Yamada 2014-03-20 11:08:20 +0900 7) quote := "
d51bfb7852d0e (Sam Ravnborg 2006-01-06 22:35:59 +0100 8) squote := '
8ec4b4ff1c89b (Sam Ravnborg 2005-07-25 20:10:36 +0000 9) empty :=
8ec4b4ff1c89b (Sam Ravnborg 2005-07-25 20:10:36 +0000 10) space := $(empty) $(empty)
9c8fa9bc08f60 (Masahiro Yamada 2016-05-07 15:48:26 +0900 11) space_escape := _-_SPACE_-_
9564a8cf422d7 (Rasmus Villemoes 2018-04-08 23:35:28 +0200 12) pound := \#
8ec4b4ff1c89b (Sam Ravnborg 2005-07-25 20:10:36 +0000 13)
48f1f0589dd09 (Sam Ravnborg 2006-07-23 19:37:44 +0200 14) ###
48f1f0589dd09 (Sam Ravnborg 2006-07-23 19:37:44 +0200 15) # Name of target with a '.' as filename prefix. foo/bar.o => foo/.bar.o
48f1f0589dd09 (Sam Ravnborg 2006-07-23 19:37:44 +0200 16) dot-target = $(dir $@).$(notdir $@)
48f1f0589dd09 (Sam Ravnborg 2006-07-23 19:37:44 +0200 17)
8ec4b4ff1c89b (Sam Ravnborg 2005-07-25 20:10:36 +0000 18) ###
30a7729771731 (Masahiro Yamada 2020-04-23 23:23:53 +0900 19) # The temporary file to save gcc -MMD generated dependencies must not
8ec4b4ff1c89b (Sam Ravnborg 2005-07-25 20:10:36 +0000 20) # contain a comma
48f1f0589dd09 (Sam Ravnborg 2006-07-23 19:37:44 +0200 21) depfile = $(subst $(comma),_,$(dot-target).d)
8ec4b4ff1c89b (Sam Ravnborg 2005-07-25 20:10:36 +0000 22)
5e8d780d745c1 (Sam Ravnborg 2006-07-01 09:58:02 +0200 23) ###
5e8d780d745c1 (Sam Ravnborg 2006-07-01 09:58:02 +0200 24) # filename of target with directory and extension stripped
5e8d780d745c1 (Sam Ravnborg 2006-07-01 09:58:02 +0200 25) basetarget = $(basename $(notdir $@))
5e8d780d745c1 (Sam Ravnborg 2006-07-01 09:58:02 +0200 26)
afa974b771281 (Masahiro Yamada 2019-01-17 19:02:43 +0900 27) ###
afa974b771281 (Masahiro Yamada 2019-01-17 19:02:43 +0900 28) # real prerequisites without phony targets
afa974b771281 (Masahiro Yamada 2019-01-17 19:02:43 +0900 29) real-prereqs = $(filter-out $(PHONY), $^)
afa974b771281 (Masahiro Yamada 2019-01-17 19:02:43 +0900 30)
d51bfb7852d0e (Sam Ravnborg 2006-01-06 22:35:59 +0100 31) ###
d51bfb7852d0e (Sam Ravnborg 2006-01-06 22:35:59 +0100 32) # Escape single quote for use in echo statements
d51bfb7852d0e (Sam Ravnborg 2006-01-06 22:35:59 +0100 33) escsq = $(subst $(squote),'\$(squote)',$1)
d51bfb7852d0e (Sam Ravnborg 2006-01-06 22:35:59 +0100 34)
7e826c44f5de3 (Masahiro Yamada 2019-12-19 17:33:27 +0900 35) ###
7e826c44f5de3 (Masahiro Yamada 2019-12-19 17:33:27 +0900 36) # Quote a string to pass it to C files. foo => '"foo"'
7e826c44f5de3 (Masahiro Yamada 2019-12-19 17:33:27 +0900 37) stringify = $(squote)$(quote)$1$(quote)$(squote)
7e826c44f5de3 (Masahiro Yamada 2019-12-19 17:33:27 +0900 38)
5410ecc0def89 (Mike Frysinger 2008-11-06 03:31:34 -0500 39) ###
5410ecc0def89 (Mike Frysinger 2008-11-06 03:31:34 -0500 40) # Easy method for doing a status message
5410ecc0def89 (Mike Frysinger 2008-11-06 03:31:34 -0500 41) kecho := :
5410ecc0def89 (Mike Frysinger 2008-11-06 03:31:34 -0500 42) quiet_kecho := echo
5410ecc0def89 (Mike Frysinger 2008-11-06 03:31:34 -0500 43) silent_kecho := :
5410ecc0def89 (Mike Frysinger 2008-11-06 03:31:34 -0500 44) kecho := $($(quiet)kecho)
5410ecc0def89 (Mike Frysinger 2008-11-06 03:31:34 -0500 45)
8ec4b4ff1c89b (Sam Ravnborg 2005-07-25 20:10:36 +0000 46) ###
8ec4b4ff1c89b (Sam Ravnborg 2005-07-25 20:10:36 +0000 47) # filechk is used to check if the content of a generated file is updated.
8ec4b4ff1c89b (Sam Ravnborg 2005-07-25 20:10:36 +0000 48) # Sample usage:
ba97df45581f0 (Masahiro Yamada 2019-01-03 10:16:54 +0900 49) #
ba97df45581f0 (Masahiro Yamada 2019-01-03 10:16:54 +0900 50) # filechk_sample = echo $(KERNELRELEASE)
ba97df45581f0 (Masahiro Yamada 2019-01-03 10:16:54 +0900 51) # version.h: FORCE
8ec4b4ff1c89b (Sam Ravnborg 2005-07-25 20:10:36 +0000 52) # $(call filechk,sample)
ba97df45581f0 (Masahiro Yamada 2019-01-03 10:16:54 +0900 53) #
8ec4b4ff1c89b (Sam Ravnborg 2005-07-25 20:10:36 +0000 54) # The rule defined shall write to stdout the content of the new file.
8ec4b4ff1c89b (Sam Ravnborg 2005-07-25 20:10:36 +0000 55) # The existing file will be compared with the new one.
8ec4b4ff1c89b (Sam Ravnborg 2005-07-25 20:10:36 +0000 56) # - If no file exist it is created
8ec4b4ff1c89b (Sam Ravnborg 2005-07-25 20:10:36 +0000 57) # - If the content differ the new file is used
8ec4b4ff1c89b (Sam Ravnborg 2005-07-25 20:10:36 +0000 58) # - If they are equal no change, and no timestamp update
8ec4b4ff1c89b (Sam Ravnborg 2005-07-25 20:10:36 +0000 59) define filechk
e1f86d7b4b2a5 (Masahiro Yamada 2021-08-13 15:30:05 +0900 60) $(check-FORCE)
88fe89a47153f (Masahiro Yamada 2020-01-10 14:02:24 +0900 61) $(Q)set -e; \
88fe89a47153f (Masahiro Yamada 2020-01-10 14:02:24 +0900 62) mkdir -p $(dir $@); \
88fe89a47153f (Masahiro Yamada 2020-01-10 14:02:24 +0900 63) trap "rm -f $(dot-target).tmp" EXIT; \
88fe89a47153f (Masahiro Yamada 2020-01-10 14:02:24 +0900 64) { $(filechk_$(1)); } > $(dot-target).tmp; \
88fe89a47153f (Masahiro Yamada 2020-01-10 14:02:24 +0900 65) if [ ! -r $@ ] || ! cmp -s $@ $(dot-target).tmp; then \
88fe89a47153f (Masahiro Yamada 2020-01-10 14:02:24 +0900 66) $(kecho) ' UPD $@'; \
88fe89a47153f (Masahiro Yamada 2020-01-10 14:02:24 +0900 67) mv -f $(dot-target).tmp $@; \
8ec4b4ff1c89b (Sam Ravnborg 2005-07-25 20:10:36 +0000 68) fi
8ec4b4ff1c89b (Sam Ravnborg 2005-07-25 20:10:36 +0000 69) endef
8ec4b4ff1c89b (Sam Ravnborg 2005-07-25 20:10:36 +0000 70)
beda9f3a13bbb (Roman Zippel 2007-02-08 22:48:51 +0100 71) ###
8ec4b4ff1c89b (Sam Ravnborg 2005-07-25 20:10:36 +0000 72) # Shorthand for $(Q)$(MAKE) -f scripts/Makefile.build obj=
8ec4b4ff1c89b (Sam Ravnborg 2005-07-25 20:10:36 +0000 73) # Usage:
8ec4b4ff1c89b (Sam Ravnborg 2005-07-25 20:10:36 +0000 74) # $(Q)$(MAKE) $(build)=dir
5b2389b45d1a9 (Masahiro Yamada 2014-09-09 20:03:58 +0900 75) build := -f $(srctree)/scripts/Makefile.build obj
8ec4b4ff1c89b (Sam Ravnborg 2005-07-25 20:10:36 +0000 76)
9fb5e53722089 (Robert Richter 2014-09-03 15:29:24 +0200 77) ###
9fb5e53722089 (Robert Richter 2014-09-03 15:29:24 +0200 78) # Shorthand for $(Q)$(MAKE) -f scripts/Makefile.dtbinst obj=
9fb5e53722089 (Robert Richter 2014-09-03 15:29:24 +0200 79) # Usage:
9fb5e53722089 (Robert Richter 2014-09-03 15:29:24 +0200 80) # $(Q)$(MAKE) $(dtbinst)=dir
487c7c7702ab1 (Masahiro Yamada 2018-09-12 13:52:54 +0900 81) dtbinst := -f $(srctree)/scripts/Makefile.dtbinst obj
9fb5e53722089 (Robert Richter 2014-09-03 15:29:24 +0200 82)
371fdc77af44f (Masahiro Yamada 2014-11-26 19:31:13 +0900 83) ###
371fdc77af44f (Masahiro Yamada 2014-11-26 19:31:13 +0900 84) # Shorthand for $(Q)$(MAKE) -f scripts/Makefile.clean obj=
371fdc77af44f (Masahiro Yamada 2014-11-26 19:31:13 +0900 85) # Usage:
371fdc77af44f (Masahiro Yamada 2014-11-26 19:31:13 +0900 86) # $(Q)$(MAKE) $(clean)=dir
371fdc77af44f (Masahiro Yamada 2014-11-26 19:31:13 +0900 87) clean := -f $(srctree)/scripts/Makefile.clean obj
371fdc77af44f (Masahiro Yamada 2014-11-26 19:31:13 +0900 88)
5de043f4bd11a (Oleg Verych 2007-02-06 02:18:21 +0100 89) # echo command.
5de043f4bd11a (Oleg Verych 2007-02-06 02:18:21 +0100 90) # Short version is used, if $(quiet) equals `quiet_', otherwise full one.
bff288c19e8b6 (Oleg Verych 2007-02-07 23:04:35 +0100 91) echo-cmd = $(if $($(quiet)cmd_$(1)),\
5de043f4bd11a (Oleg Verych 2007-02-06 02:18:21 +0100 92) echo ' $(call escsq,$($(quiet)cmd_$(1)))$(echo-why)';)
5de043f4bd11a (Oleg Verych 2007-02-06 02:18:21 +0100 93)
174a1dcc96429 (Masahiro Yamada 2021-05-17 16:03:13 +0900 94) # sink stdout for 'make -s'
174a1dcc96429 (Masahiro Yamada 2021-05-17 16:03:13 +0900 95) redirect :=
174a1dcc96429 (Masahiro Yamada 2021-05-17 16:03:13 +0900 96) quiet_redirect :=
174a1dcc96429 (Masahiro Yamada 2021-05-17 16:03:13 +0900 97) silent_redirect := exec >/dev/null;
174a1dcc96429 (Masahiro Yamada 2021-05-17 16:03:13 +0900 98)
5de043f4bd11a (Oleg Verych 2007-02-06 02:18:21 +0100 99) # printing commands
174a1dcc96429 (Masahiro Yamada 2021-05-17 16:03:13 +0900 100) cmd = @set -e; $(echo-cmd) $($(quiet)redirect) $(cmd_$(1))
8ec4b4ff1c89b (Sam Ravnborg 2005-07-25 20:10:36 +0000 101)
8ec4b4ff1c89b (Sam Ravnborg 2005-07-25 20:10:36 +0000 102) ###
5de043f4bd11a (Oleg Verych 2007-02-06 02:18:21 +0100 103) # if_changed - execute command if any prerequisite is newer than
8ec4b4ff1c89b (Sam Ravnborg 2005-07-25 20:10:36 +0000 104) # target, or command line has changed
8ec4b4ff1c89b (Sam Ravnborg 2005-07-25 20:10:36 +0000 105) # if_changed_dep - as if_changed, but uses fixdep to reveal dependencies
8ec4b4ff1c89b (Sam Ravnborg 2005-07-25 20:10:36 +0000 106) # including used config symbols
8ec4b4ff1c89b (Sam Ravnborg 2005-07-25 20:10:36 +0000 107) # if_changed_rule - as if_changed but execute rule instead
cd238effefa28 (Mauro Carvalho Chehab 2019-06-12 14:52:48 -0300 108) # See Documentation/kbuild/makefiles.rst for more info
8ec4b4ff1c89b (Sam Ravnborg 2005-07-25 20:10:36 +0000 109)
8ec4b4ff1c89b (Sam Ravnborg 2005-07-25 20:10:36 +0000 110) ifneq ($(KBUILD_NOCMDDEP),1)
50bcca6ac417b (Masahiro Yamada 2019-06-23 01:07:03 +0900 111) # Check if both commands are the same including their order. Result is empty
9c8fa9bc08f60 (Masahiro Yamada 2016-05-07 15:48:26 +0900 112) # string if equal. User may override this check using make KBUILD_NOCMDDEP=1
50bcca6ac417b (Masahiro Yamada 2019-06-23 01:07:03 +0900 113) cmd-check = $(filter-out $(subst $(space),$(space_escape),$(strip $(cmd_$@))), \
9c8fa9bc08f60 (Masahiro Yamada 2016-05-07 15:48:26 +0900 114) $(subst $(space),$(space_escape),$(strip $(cmd_$1))))
c4d5ee13984f5 (Michal Marek 2011-05-16 16:37:34 +0200 115) else
50bcca6ac417b (Masahiro Yamada 2019-06-23 01:07:03 +0900 116) cmd-check = $(if $(strip $(cmd_$@)),,1)
8ec4b4ff1c89b (Sam Ravnborg 2005-07-25 20:10:36 +0000 117) endif
8ec4b4ff1c89b (Sam Ravnborg 2005-07-25 20:10:36 +0000 118)
164f0d2efaaef (Michal Marek 2014-08-07 21:39:57 +0200 119) # Replace >$< with >$$< to preserve $ when reloading the .cmd file
164f0d2efaaef (Michal Marek 2014-08-07 21:39:57 +0200 120) # (needed for make)
9564a8cf422d7 (Rasmus Villemoes 2018-04-08 23:35:28 +0200 121) # Replace >#< with >$(pound)< to avoid starting a comment in the .cmd file
164f0d2efaaef (Michal Marek 2014-08-07 21:39:57 +0200 122) # (needed for make)
164f0d2efaaef (Michal Marek 2014-08-07 21:39:57 +0200 123) # Replace >'< with >'\''< to be able to enclose the whole string in '...'
164f0d2efaaef (Michal Marek 2014-08-07 21:39:57 +0200 124) # (needed for the shell)
9564a8cf422d7 (Rasmus Villemoes 2018-04-08 23:35:28 +0200 125) make-cmd = $(call escsq,$(subst $(pound),$$(pound),$(subst $$,$$$$,$(cmd_$(1)))))
6176aa9ae4b83 (Jan Beulich 2006-01-30 10:04:27 +0100 126)
2d3b1b8f0da7b (Masahiro Yamada 2019-11-08 00:09:44 +0900 127) # Find any prerequisites that are newer than target or that do not exist.
2d3b1b8f0da7b (Masahiro Yamada 2019-11-08 00:09:44 +0900 128) # (This is not true for now; $? should contain any non-existent prerequisites,
2d3b1b8f0da7b (Masahiro Yamada 2019-11-08 00:09:44 +0900 129) # but it does not work as expected when .SECONDARY is present. This seems a bug
2d3b1b8f0da7b (Masahiro Yamada 2019-11-08 00:09:44 +0900 130) # of GNU Make.)
48f1f0589dd09 (Sam Ravnborg 2006-07-23 19:37:44 +0200 131) # PHONY targets skipped in both cases.
eba19032f99c3 (Masahiro Yamada 2019-11-08 00:09:45 +0900 132) newer-prereqs = $(filter-out $(PHONY),$?)
48f1f0589dd09 (Sam Ravnborg 2006-07-23 19:37:44 +0200 133)
e1f86d7b4b2a5 (Masahiro Yamada 2021-08-13 15:30:05 +0900 134) # It is a typical mistake to forget the FORCE prerequisite. Check it here so
e1f86d7b4b2a5 (Masahiro Yamada 2021-08-13 15:30:05 +0900 135) # no more breakage will slip in.
e1f86d7b4b2a5 (Masahiro Yamada 2021-08-13 15:30:05 +0900 136) check-FORCE = $(if $(filter FORCE, $^),,$(warning FORCE prerequisite is missing))
e1f86d7b4b2a5 (Masahiro Yamada 2021-08-13 15:30:05 +0900 137)
e1f86d7b4b2a5 (Masahiro Yamada 2021-08-13 15:30:05 +0900 138) if-changed-cond = $(newer-prereqs)$(cmd-check)$(check-FORCE)
6796e80409b90 (Masahiro Yamada 2021-08-13 15:30:04 +0900 139)
5de043f4bd11a (Oleg Verych 2007-02-06 02:18:21 +0100 140) # Execute command if command has changed or prerequisite(s) are updated.
6796e80409b90 (Masahiro Yamada 2021-08-13 15:30:04 +0900 141) if_changed = $(if $(if-changed-cond), \
67126965ee085 (Masahiro Yamada 2018-11-30 10:05:29 +0900 142) $(cmd); \
2aedcd098a944 (Masahiro Yamada 2016-03-03 17:36:30 +0900 143) printf '%s\n' 'cmd_$@ := $(make-cmd)' > $(dot-target).cmd, @:)
8ec4b4ff1c89b (Sam Ravnborg 2005-07-25 20:10:36 +0000 144)
5de043f4bd11a (Oleg Verych 2007-02-06 02:18:21 +0100 145) # Execute the command and also postprocess generated .d dependencies file.
6796e80409b90 (Masahiro Yamada 2021-08-13 15:30:04 +0900 146) if_changed_dep = $(if $(if-changed-cond),$(cmd_and_fixdep),@:)
c1a95fda2a40a (Nicolas Pitre 2016-01-22 13:41:57 -0500 147)
e4aca45950050 (Nicolas Pitre 2016-02-17 15:50:06 -0500 148) cmd_and_fixdep = \
3a2429e1faf40 (Masahiro Yamada 2018-11-30 10:05:27 +0900 149) $(cmd); \
392885ee82d35 (Masahiro Yamada 2018-11-30 10:05:22 +0900 150) scripts/basic/fixdep $(depfile) $@ '$(make-cmd)' > $(dot-target).cmd;\
e5d289100d3ae (Masahiro Yamada 2018-11-30 10:05:28 +0900 151) rm -f $(depfile)
c1a95fda2a40a (Nicolas Pitre 2016-01-22 13:41:57 -0500 152)
8ec4b4ff1c89b (Sam Ravnborg 2005-07-25 20:10:36 +0000 153) # Usage: $(call if_changed_rule,foo)
beda9f3a13bbb (Roman Zippel 2007-02-08 22:48:51 +0100 154) # Will check if $(cmd_foo) or any of the prerequisites changed,
beda9f3a13bbb (Roman Zippel 2007-02-08 22:48:51 +0100 155) # and if so will execute $(rule_foo).
6796e80409b90 (Masahiro Yamada 2021-08-13 15:30:04 +0900 156) if_changed_rule = $(if $(if-changed-cond),$(rule_$(1)),@:)
48f1f0589dd09 (Sam Ravnborg 2006-07-23 19:37:44 +0200 157)
45d506bd65e2e (Sam Ravnborg 2006-08-08 21:35:14 +0200 158) ###
312a3d0918bb7 (Cao jin 2017-08-02 10:31:06 +0800 159) # why - tell why a target got built
45d506bd65e2e (Sam Ravnborg 2006-08-08 21:35:14 +0200 160) # enabled by make V=2
45d506bd65e2e (Sam Ravnborg 2006-08-08 21:35:14 +0200 161) # Output (listed in the order they are checked):
45d506bd65e2e (Sam Ravnborg 2006-08-08 21:35:14 +0200 162) # (1) - due to target is PHONY
45d506bd65e2e (Sam Ravnborg 2006-08-08 21:35:14 +0200 163) # (2) - due to target missing
45d506bd65e2e (Sam Ravnborg 2006-08-08 21:35:14 +0200 164) # (3) - due to: file1.h file2.h
45d506bd65e2e (Sam Ravnborg 2006-08-08 21:35:14 +0200 165) # (4) - due to command line change
45d506bd65e2e (Sam Ravnborg 2006-08-08 21:35:14 +0200 166) # (5) - due to missing .cmd file
45d506bd65e2e (Sam Ravnborg 2006-08-08 21:35:14 +0200 167) # (6) - due to target not in $(targets)
45d506bd65e2e (Sam Ravnborg 2006-08-08 21:35:14 +0200 168) # (1) PHONY targets are always build
45d506bd65e2e (Sam Ravnborg 2006-08-08 21:35:14 +0200 169) # (2) No target, so we better build it
45d506bd65e2e (Sam Ravnborg 2006-08-08 21:35:14 +0200 170) # (3) Prerequisite is newer than target
45d506bd65e2e (Sam Ravnborg 2006-08-08 21:35:14 +0200 171) # (4) The command line stored in the file named dir/.target.cmd
45d506bd65e2e (Sam Ravnborg 2006-08-08 21:35:14 +0200 172) # differed from actual command line. This happens when compiler
45d506bd65e2e (Sam Ravnborg 2006-08-08 21:35:14 +0200 173) # options changes
45d506bd65e2e (Sam Ravnborg 2006-08-08 21:35:14 +0200 174) # (5) No dir/.target.cmd file (used to store command line)
45d506bd65e2e (Sam Ravnborg 2006-08-08 21:35:14 +0200 175) # (6) No dir/.target.cmd file and target not listed in $(targets)
45d506bd65e2e (Sam Ravnborg 2006-08-08 21:35:14 +0200 176) # This is a good hint that there is a bug in the kbuild file
45d506bd65e2e (Sam Ravnborg 2006-08-08 21:35:14 +0200 177) ifeq ($(KBUILD_VERBOSE),2)
45d506bd65e2e (Sam Ravnborg 2006-08-08 21:35:14 +0200 178) why = \
45d506bd65e2e (Sam Ravnborg 2006-08-08 21:35:14 +0200 179) $(if $(filter $@, $(PHONY)),- due to target is PHONY, \
45d506bd65e2e (Sam Ravnborg 2006-08-08 21:35:14 +0200 180) $(if $(wildcard $@), \
eba19032f99c3 (Masahiro Yamada 2019-11-08 00:09:45 +0900 181) $(if $(newer-prereqs),- due to: $(newer-prereqs), \
50bcca6ac417b (Masahiro Yamada 2019-06-23 01:07:03 +0900 182) $(if $(cmd-check), \
45d506bd65e2e (Sam Ravnborg 2006-08-08 21:35:14 +0200 183) $(if $(cmd_$@),- due to command line change, \
45d506bd65e2e (Sam Ravnborg 2006-08-08 21:35:14 +0200 184) $(if $(filter $@, $(targets)), \
45d506bd65e2e (Sam Ravnborg 2006-08-08 21:35:14 +0200 185) - due to missing .cmd file, \
45d506bd65e2e (Sam Ravnborg 2006-08-08 21:35:14 +0200 186) - due to $(notdir $@) not in $$(targets) \
45d506bd65e2e (Sam Ravnborg 2006-08-08 21:35:14 +0200 187) ) \
45d506bd65e2e (Sam Ravnborg 2006-08-08 21:35:14 +0200 188) ) \
45d506bd65e2e (Sam Ravnborg 2006-08-08 21:35:14 +0200 189) ) \
45d506bd65e2e (Sam Ravnborg 2006-08-08 21:35:14 +0200 190) ), \
45d506bd65e2e (Sam Ravnborg 2006-08-08 21:35:14 +0200 191) - due to target missing \
45d506bd65e2e (Sam Ravnborg 2006-08-08 21:35:14 +0200 192) ) \
45d506bd65e2e (Sam Ravnborg 2006-08-08 21:35:14 +0200 193) )
45d506bd65e2e (Sam Ravnborg 2006-08-08 21:35:14 +0200 194)
45d506bd65e2e (Sam Ravnborg 2006-08-08 21:35:14 +0200 195) echo-why = $(call escsq, $(strip $(why)))
45d506bd65e2e (Sam Ravnborg 2006-08-08 21:35:14 +0200 196) endif
3ee550f12c152 (David Woodhouse 2015-08-14 16:17:16 +0100 197)
3ee550f12c152 (David Woodhouse 2015-08-14 16:17:16 +0100 198) ###############################################################################
3ee550f12c152 (David Woodhouse 2015-08-14 16:17:16 +0100 199) #
3ee550f12c152 (David Woodhouse 2015-08-14 16:17:16 +0100 200) # When a Kconfig string contains a filename, it is suitable for
3ee550f12c152 (David Woodhouse 2015-08-14 16:17:16 +0100 201) # passing to shell commands. It is surrounded by double-quotes, and
3ee550f12c152 (David Woodhouse 2015-08-14 16:17:16 +0100 202) # any double-quotes or backslashes within it are escaped by
3ee550f12c152 (David Woodhouse 2015-08-14 16:17:16 +0100 203) # backslashes.
3ee550f12c152 (David Woodhouse 2015-08-14 16:17:16 +0100 204) #
3ee550f12c152 (David Woodhouse 2015-08-14 16:17:16 +0100 205) # This is no use for dependencies or $(wildcard). We need to strip the
3ee550f12c152 (David Woodhouse 2015-08-14 16:17:16 +0100 206) # surrounding quotes and the escaping from quotes and backslashes, and
3ee550f12c152 (David Woodhouse 2015-08-14 16:17:16 +0100 207) # we *do* need to escape any spaces in the string. So, for example:
3ee550f12c152 (David Woodhouse 2015-08-14 16:17:16 +0100 208) #
3ee550f12c152 (David Woodhouse 2015-08-14 16:17:16 +0100 209) # Usage: $(eval $(call config_filename,FOO))
3ee550f12c152 (David Woodhouse 2015-08-14 16:17:16 +0100 210) #
3ee550f12c152 (David Woodhouse 2015-08-14 16:17:16 +0100 211) # Defines FOO_FILENAME based on the contents of the CONFIG_FOO option,
3ee550f12c152 (David Woodhouse 2015-08-14 16:17:16 +0100 212) # transformed as described above to be suitable for use within the
3ee550f12c152 (David Woodhouse 2015-08-14 16:17:16 +0100 213) # makefile.
3ee550f12c152 (David Woodhouse 2015-08-14 16:17:16 +0100 214) #
3ee550f12c152 (David Woodhouse 2015-08-14 16:17:16 +0100 215) # Also, if the filename is a relative filename and exists in the source
3ee550f12c152 (David Woodhouse 2015-08-14 16:17:16 +0100 216) # tree but not the build tree, define FOO_SRCPREFIX as $(srctree)/ to
3ee550f12c152 (David Woodhouse 2015-08-14 16:17:16 +0100 217) # be prefixed to *both* command invocation and dependencies.
3ee550f12c152 (David Woodhouse 2015-08-14 16:17:16 +0100 218) #
3ee550f12c152 (David Woodhouse 2015-08-14 16:17:16 +0100 219) # Note: We also print the filenames in the quiet_cmd_foo text, and
3ee550f12c152 (David Woodhouse 2015-08-14 16:17:16 +0100 220) # perhaps ought to have a version specially escaped for that purpose.
3ee550f12c152 (David Woodhouse 2015-08-14 16:17:16 +0100 221) # But it's only cosmetic, and $(patsubst "%",%,$(CONFIG_FOO)) is good
3ee550f12c152 (David Woodhouse 2015-08-14 16:17:16 +0100 222) # enough. It'll strip the quotes in the common case where there's no
3ee550f12c152 (David Woodhouse 2015-08-14 16:17:16 +0100 223) # space and it's a simple filename, and it'll retain the quotes when
3ee550f12c152 (David Woodhouse 2015-08-14 16:17:16 +0100 224) # there's a space. There are some esoteric cases in which it'll print
3ee550f12c152 (David Woodhouse 2015-08-14 16:17:16 +0100 225) # the wrong thing, but we don't really care. The actual dependencies
3ee550f12c152 (David Woodhouse 2015-08-14 16:17:16 +0100 226) # and commands *do* get it right, with various combinations of single
3ee550f12c152 (David Woodhouse 2015-08-14 16:17:16 +0100 227) # and double quotes, backslashes and spaces in the filenames.
3ee550f12c152 (David Woodhouse 2015-08-14 16:17:16 +0100 228) #
3ee550f12c152 (David Woodhouse 2015-08-14 16:17:16 +0100 229) ###############################################################################
3ee550f12c152 (David Woodhouse 2015-08-14 16:17:16 +0100 230) #
3ee550f12c152 (David Woodhouse 2015-08-14 16:17:16 +0100 231) define config_filename
3ee550f12c152 (David Woodhouse 2015-08-14 16:17:16 +0100 232) ifneq ($$(CONFIG_$(1)),"")
3ee550f12c152 (David Woodhouse 2015-08-14 16:17:16 +0100 233) $(1)_FILENAME := $$(subst \\,\,$$(subst \$$(quote),$$(quote),$$(subst $$(space_escape),\$$(space),$$(patsubst "%",%,$$(subst $$(space),$$(space_escape),$$(CONFIG_$(1)))))))
3ee550f12c152 (David Woodhouse 2015-08-14 16:17:16 +0100 234) ifneq ($$(patsubst /%,%,$$(firstword $$($(1)_FILENAME))),$$(firstword $$($(1)_FILENAME)))
3ee550f12c152 (David Woodhouse 2015-08-14 16:17:16 +0100 235) else
3ee550f12c152 (David Woodhouse 2015-08-14 16:17:16 +0100 236) ifeq ($$(wildcard $$($(1)_FILENAME)),)
3ee550f12c152 (David Woodhouse 2015-08-14 16:17:16 +0100 237) ifneq ($$(wildcard $$(srctree)/$$($(1)_FILENAME)),)
3ee550f12c152 (David Woodhouse 2015-08-14 16:17:16 +0100 238) $(1)_SRCPREFIX := $(srctree)/
3ee550f12c152 (David Woodhouse 2015-08-14 16:17:16 +0100 239) endif
3ee550f12c152 (David Woodhouse 2015-08-14 16:17:16 +0100 240) endif
3ee550f12c152 (David Woodhouse 2015-08-14 16:17:16 +0100 241) endif
3ee550f12c152 (David Woodhouse 2015-08-14 16:17:16 +0100 242) endif
3ee550f12c152 (David Woodhouse 2015-08-14 16:17:16 +0100 243) endef
3ee550f12c152 (David Woodhouse 2015-08-14 16:17:16 +0100 244) #
3ee550f12c152 (David Woodhouse 2015-08-14 16:17:16 +0100 245) ###############################################################################
9c2af1c7377a8 (Masahiro Yamada 2018-07-20 16:46:33 +0900 246)
9c2af1c7377a8 (Masahiro Yamada 2018-07-20 16:46:33 +0900 247) # delete partially updated (i.e. corrupted) files on error
9c2af1c7377a8 (Masahiro Yamada 2018-07-20 16:46:33 +0900 248) .DELETE_ON_ERROR:
8e9b61b293d98 (Masahiro Yamada 2018-12-01 09:27:15 +0900 249)
8e9b61b293d98 (Masahiro Yamada 2018-12-01 09:27:15 +0900 250) # do not delete intermediate files automatically
8e9b61b293d98 (Masahiro Yamada 2018-12-01 09:27:15 +0900 251) .SECONDARY: