|
1 | | -# =========================================================================== |
2 | | -# kbuild: Generic definitions |
3 | | -# =========================================================================== |
4 | | - |
5 | | -# Standard vars |
6 | | - |
7 | | -comma := , |
8 | | -empty := |
9 | | -space := $(empty) $(empty) |
10 | | - |
11 | 1 | # Backward compatibility - to be removed... |
12 | 2 | extra-y += $(EXTRA_TARGETS) |
13 | 3 | # Figure out what we need to build from the various variables |
@@ -84,10 +74,6 @@ multi-objs-m := $(addprefix $(obj)/,$(multi-objs-m)) |
84 | 74 | subdir-ym := $(addprefix $(obj)/,$(subdir-ym)) |
85 | 75 | obj-dirs := $(addprefix $(obj)/,$(obj-dirs)) |
86 | 76 |
|
87 | | -# The temporary file to save gcc -MD generated dependencies must not |
88 | | -# contain a comma |
89 | | -depfile = $(subst $(comma),_,$(@D)/.$(@F).d) |
90 | | - |
91 | 77 | # These flags are needed for modversions and compiling, so we define them here |
92 | 78 | # already |
93 | 79 | # $(modname_flags) #defines KBUILD_MODNAME as the name of the module it will |
@@ -179,84 +165,4 @@ cmd_objcopy = $(OBJCOPY) $(OBJCOPYFLAGS) $(OBJCOPYFLAGS_$(@F)) $< $@ |
179 | 165 | quiet_cmd_gzip = GZIP $@ |
180 | 166 | cmd_gzip = gzip -f -9 < $< > $@ |
181 | 167 |
|
182 | | -# =========================================================================== |
183 | | -# Generic stuff |
184 | | -# =========================================================================== |
185 | | - |
186 | | -ifneq ($(KBUILD_NOCMDDEP),1) |
187 | | -# Check if both arguments has same arguments. Result in empty string if equal |
188 | | -# User may override this check using make KBUILD_NOCMDDEP=1 |
189 | | -arg-check = $(strip $(filter-out $(1), $(2)) $(filter-out $(2), $(1)) ) |
190 | | - |
191 | | -endif |
192 | | - |
193 | | -# echo command. Short version is $(quiet) equals quiet, otherwise full command |
194 | | -echo-cmd = $(if $($(quiet)cmd_$(1)), \ |
195 | | - echo ' $(subst ','\'',$($(quiet)cmd_$(1)))';) |
196 | | - |
197 | | -# function to only execute the passed command if necessary |
198 | | -# >'< substitution is for echo to work, >$< substitution to preserve $ when reloading .cmd file |
199 | | -# note: when using inline perl scripts [perl -e '...$$t=1;...'] in $(cmd_xxx) double $$ your perl vars |
200 | | -# |
201 | | -if_changed = $(if $(strip $? $(call arg-check, $(cmd_$(1)), $(cmd_$@)) ), \ |
202 | | - @set -e; \ |
203 | | - $(echo-cmd) \ |
204 | | - $(cmd_$(1)); \ |
205 | | - echo 'cmd_$@ := $(subst $$,$$$$,$(subst ','\'',$(cmd_$(1))))' > $(@D)/.$(@F).cmd) |
206 | | - |
207 | | - |
208 | | -# execute the command and also postprocess generated .d dependencies |
209 | | -# file |
210 | | - |
211 | | -if_changed_dep = $(if $(strip $? $(filter-out FORCE $(wildcard $^),$^)\ |
212 | | - $(call arg-check, $(cmd_$(1)), $(cmd_$@)) ), \ |
213 | | - @set -e; \ |
214 | | - $(echo-cmd) \ |
215 | | - $(cmd_$(1)); \ |
216 | | - scripts/basic/fixdep $(depfile) $@ '$(subst $$,$$$$,$(subst ','\'',$(cmd_$(1))))' > $(@D)/.$(@F).tmp; \ |
217 | | - rm -f $(depfile); \ |
218 | | - mv -f $(@D)/.$(@F).tmp $(@D)/.$(@F).cmd) |
219 | | - |
220 | | -# Usage: $(call if_changed_rule,foo) |
221 | | -# will check if $(cmd_foo) changed, or any of the prequisites changed, |
222 | | -# and if so will execute $(rule_foo) |
223 | | - |
224 | | -if_changed_rule = $(if $(strip $? $(call arg-check, $(cmd_$(1)), $(cmd_$@)) ),\ |
225 | | - @set -e; \ |
226 | | - $(rule_$(1))) |
227 | | - |
228 | | -# If quiet is set, only print short version of command |
229 | | - |
230 | | -cmd = @$(if $($(quiet)cmd_$(1)),echo ' $(subst ','\'',$($(quiet)cmd_$(1)))' &&) $(cmd_$(1)) |
231 | | - |
232 | | -# Shorthand for $(Q)$(MAKE) -f scripts/Makefile.build obj= |
233 | | -# Usage: |
234 | | -# $(Q)$(MAKE) $(build)=dir |
235 | | -build := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.build obj |
236 | | - |
237 | | -# filechk is used to check if the content of a generated file is updated. |
238 | | -# Sample usage: |
239 | | -# define filechk_sample |
240 | | -# echo $KERNELRELEASE |
241 | | -# endef |
242 | | -# version.h : Makefile |
243 | | -# $(call filechk,sample) |
244 | | -# The rule defined shall write to stdout the content of the new file. |
245 | | -# The existing file will be compared with the new one. |
246 | | -# - If no file exist it is created |
247 | | -# - If the content differ the new file is used |
248 | | -# - If they are equal no change, and no timestamp update |
249 | | - |
250 | | -define filechk |
251 | | - $(Q)set -e; \ |
252 | | - echo ' CHK $@'; \ |
253 | | - mkdir -p $(dir $@); \ |
254 | | - $(filechk_$(1)) $(2) > $@.tmp; \ |
255 | | - if [ -r $@ ] && cmp -s $@ $@.tmp; then \ |
256 | | - rm -f $@.tmp; \ |
257 | | - else \ |
258 | | - echo ' UPD $@'; \ |
259 | | - mv -f $@.tmp $@; \ |
260 | | - fi |
261 | | -endef |
262 | 168 |
|
0 commit comments