Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

kbuild: introduce Kbuild.include

Kbuild.include is a placeholder for definitions originally present in
both the top-level Makefile and scripts/Makefile.build.
There were a slight difference in the filechk definition, so the most videly
used version was kept and usr/Makefile was adopted for this syntax.

Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
---

+103 -167
+3 -71
Makefile
··· 309 309 # Look for make include files relative to root of kernel src 310 310 MAKEFLAGS += --include-dir=$(srctree) 311 311 312 + # We need some generic definitions 313 + include scripts/Kbuild.include 314 + 312 315 # For maximum performance (+ possibly random breakage, uncomment 313 316 # the following) 314 317 ··· 369 366 # tree rather than in the kernel tree. The kernel tree might 370 367 # even be read-only. 371 368 export MODVERDIR := $(if $(KBUILD_EXTMOD),$(firstword $(KBUILD_EXTMOD))/).tmp_versions 372 - 373 - # The temporary file to save gcc -MD generated dependencies must not 374 - # contain a comma 375 - comma := , 376 - depfile = $(subst $(comma),_,$(@D)/.$(@F).d) 377 369 378 370 # Files to ignore in find ... statements 379 371 ··· 1282 1284 $(cmd_files): ; # Do not try to update included dependency files 1283 1285 include $(cmd_files) 1284 1286 endif 1285 - 1286 - # Execute command and generate cmd file 1287 - if_changed = $(if $(strip $? \ 1288 - $(filter-out $(cmd_$(1)),$(cmd_$@))\ 1289 - $(filter-out $(cmd_$@),$(cmd_$(1)))),\ 1290 - @set -e; \ 1291 - $(if $($(quiet)cmd_$(1)),echo ' $(subst ','\'',$($(quiet)cmd_$(1)))';) \ 1292 - $(cmd_$(1)); \ 1293 - echo 'cmd_$@ := $(subst $$,$$$$,$(subst ','\'',$(cmd_$(1))))' > $(@D)/.$(@F).cmd) 1294 - 1295 - 1296 - # execute the command and also postprocess generated .d dependencies 1297 - # file 1298 - if_changed_dep = $(if $(strip $? $(filter-out FORCE $(wildcard $^),$^)\ 1299 - $(filter-out $(cmd_$(1)),$(cmd_$@))\ 1300 - $(filter-out $(cmd_$@),$(cmd_$(1)))),\ 1301 - $(Q)set -e; \ 1302 - $(if $($(quiet)cmd_$(1)),echo ' $(subst ','\'',$($(quiet)cmd_$(1)))';) \ 1303 - $(cmd_$(1)); \ 1304 - scripts/basic/fixdep $(depfile) $@ '$(subst $$,$$$$,$(subst ','\'',$(cmd_$(1))))' > $(@D)/.$(@F).tmp; \ 1305 - rm -f $(depfile); \ 1306 - mv -f $(@D)/.$(@F).tmp $(@D)/.$(@F).cmd) 1307 - 1308 - # Usage: $(call if_changed_rule,foo) 1309 - # will check if $(cmd_foo) changed, or any of the prequisites changed, 1310 - # and if so will execute $(rule_foo) 1311 - 1312 - if_changed_rule = $(if $(strip $? \ 1313 - $(filter-out $(cmd_$(1)),$(cmd_$(@F)))\ 1314 - $(filter-out $(cmd_$(@F)),$(cmd_$(1)))),\ 1315 - $(Q)$(rule_$(1))) 1316 - 1317 - # If quiet is set, only print short version of command 1318 - 1319 - cmd = @$(if $($(quiet)cmd_$(1)),echo ' $($(quiet)cmd_$(1))' &&) $(cmd_$(1)) 1320 - 1321 - # filechk is used to check if the content of a generated file is updated. 1322 - # Sample usage: 1323 - # define filechk_sample 1324 - # echo $KERNELRELEASE 1325 - # endef 1326 - # version.h : Makefile 1327 - # $(call filechk,sample) 1328 - # The rule defined shall write to stdout the content of the new file. 1329 - # The existing file will be compared with the new one. 1330 - # - If no file exist it is created 1331 - # - If the content differ the new file is used 1332 - # - If they are equal no change, and no timestamp update 1333 - 1334 - define filechk 1335 - @set -e; \ 1336 - echo ' CHK $@'; \ 1337 - mkdir -p $(dir $@); \ 1338 - $(filechk_$(1)) < $< > $@.tmp; \ 1339 - if [ -r $@ ] && cmp -s $@ $@.tmp; then \ 1340 - rm -f $@.tmp; \ 1341 - else \ 1342 - echo ' UPD $@'; \ 1343 - mv -f $@.tmp $@; \ 1344 - fi 1345 - endef 1346 - 1347 - # Shorthand for $(Q)$(MAKE) -f scripts/Makefile.build obj=dir 1348 - # Usage: 1349 - # $(Q)$(MAKE) $(build)=dir 1350 - build := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.build obj 1351 1287 1352 1288 # Shorthand for $(Q)$(MAKE) -f scripts/Makefile.clean obj=dir 1353 1289 # Usage:
+96
scripts/Kbuild.include
··· 1 + #### 2 + # kbuild: Generic definitions 3 + 4 + # Convinient variables 5 + comma := , 6 + empty := 7 + space := $(empty) $(empty) 8 + 9 + ### 10 + # The temporary file to save gcc -MD generated dependencies must not 11 + # contain a comma 12 + depfile = $(subst $(comma),_,$(@D)/.$(@F).d) 13 + 14 + ### 15 + # filechk is used to check if the content of a generated file is updated. 16 + # Sample usage: 17 + # define filechk_sample 18 + # echo $KERNELRELEASE 19 + # endef 20 + # version.h : Makefile 21 + # $(call filechk,sample) 22 + # The rule defined shall write to stdout the content of the new file. 23 + # The existing file will be compared with the new one. 24 + # - If no file exist it is created 25 + # - If the content differ the new file is used 26 + # - If they are equal no change, and no timestamp update 27 + # - stdin is piped in from the first prerequisite ($<) so one has 28 + # to specify a valid file as first prerequisite (often the kbuild file) 29 + define filechk 30 + $(Q)set -e; \ 31 + echo ' CHK $@'; \ 32 + mkdir -p $(dir $@); \ 33 + $(filechk_$(1)) < $< > $@.tmp; \ 34 + if [ -r $@ ] && cmp -s $@ $@.tmp; then \ 35 + rm -f $@.tmp; \ 36 + else \ 37 + echo ' UPD $@'; \ 38 + mv -f $@.tmp $@; \ 39 + fi 40 + endef 41 + 42 + ### 43 + # Shorthand for $(Q)$(MAKE) -f scripts/Makefile.build obj= 44 + # Usage: 45 + # $(Q)$(MAKE) $(build)=dir 46 + build := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.build obj 47 + 48 + # If quiet is set, only print short version of command 49 + cmd = @$(if $($(quiet)cmd_$(1)),\ 50 + echo ' $(subst ','\'',$($(quiet)cmd_$(1)))' &&) $(cmd_$(1)) 51 + 52 + ### 53 + # if_changed - execute command if any prerequisite is newer than 54 + # target, or command line has changed 55 + # if_changed_dep - as if_changed, but uses fixdep to reveal dependencies 56 + # including used config symbols 57 + # if_changed_rule - as if_changed but execute rule instead 58 + # See Documentation/kbuild/makefiles.txt for more info 59 + 60 + ifneq ($(KBUILD_NOCMDDEP),1) 61 + # Check if both arguments has same arguments. Result in empty string if equal 62 + # User may override this check using make KBUILD_NOCMDDEP=1 63 + arg-check = $(strip $(filter-out $(1), $(2)) $(filter-out $(2), $(1)) ) 64 + endif 65 + 66 + # echo command. Short version is $(quiet) equals quiet, otherwise full command 67 + echo-cmd = $(if $($(quiet)cmd_$(1)), \ 68 + echo ' $(subst ','\'',$($(quiet)cmd_$(1)))';) 69 + 70 + # function to only execute the passed command if necessary 71 + # >'< substitution is for echo to work, >$< substitution to preserve $ when reloading .cmd file 72 + # note: when using inline perl scripts [perl -e '...$$t=1;...'] in $(cmd_xxx) double $$ your perl vars 73 + # 74 + if_changed = $(if $(strip $? $(call arg-check, $(cmd_$(1)), $(cmd_$@)) ), \ 75 + @set -e; \ 76 + $(echo-cmd) \ 77 + $(cmd_$(1)); \ 78 + echo 'cmd_$@ := $(subst $$,$$$$,$(subst ','\'',$(cmd_$(1))))' > $(@D)/.$(@F).cmd) 79 + 80 + # execute the command and also postprocess generated .d dependencies 81 + # file 82 + if_changed_dep = $(if $(strip $? $(filter-out FORCE $(wildcard $^),$^)\ 83 + $(call arg-check, $(cmd_$(1)), $(cmd_$@)) ), \ 84 + @set -e; \ 85 + $(echo-cmd) \ 86 + $(cmd_$(1)); \ 87 + scripts/basic/fixdep $(depfile) $@ '$(subst $$,$$$$,$(subst ','\'',$(cmd_$(1))))' > $(@D)/.$(@F).tmp; \ 88 + rm -f $(depfile); \ 89 + mv -f $(@D)/.$(@F).tmp $(@D)/.$(@F).cmd) 90 + 91 + # Usage: $(call if_changed_rule,foo) 92 + # will check if $(cmd_foo) changed, or any of the prequisites changed, 93 + # and if so will execute $(rule_foo) 94 + if_changed_rule = $(if $(strip $? $(call arg-check, $(cmd_$(1)), $(cmd_$@)) ),\ 95 + @set -e; \ 96 + $(rule_$(1)))
+1
scripts/Makefile.build
··· 12 12 13 13 include $(if $(wildcard $(obj)/Kbuild), $(obj)/Kbuild, $(obj)/Makefile) 14 14 15 + include scripts/Kbuild.include 15 16 include scripts/Makefile.lib 16 17 17 18 ifdef host-progs
-94
scripts/Makefile.lib
··· 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 ··· 73 83 multi-objs-m := $(addprefix $(obj)/,$(multi-objs-m)) 74 84 subdir-ym := $(addprefix $(obj)/,$(subdir-ym)) 75 85 obj-dirs := $(addprefix $(obj)/,$(obj-dirs)) 76 - 77 - # The temporary file to save gcc -MD generated dependencies must not 78 - # contain a comma 79 - depfile = $(subst $(comma),_,$(@D)/.$(@F).d) 80 86 81 87 # These flags are needed for modversions and compiling, so we define them here 82 88 # already ··· 165 179 quiet_cmd_gzip = GZIP $@ 166 180 cmd_gzip = gzip -f -9 < $< > $@ 167 181 168 - # =========================================================================== 169 - # Generic stuff 170 - # =========================================================================== 171 - 172 - ifneq ($(KBUILD_NOCMDDEP),1) 173 - # Check if both arguments has same arguments. Result in empty string if equal 174 - # User may override this check using make KBUILD_NOCMDDEP=1 175 - arg-check = $(strip $(filter-out $(1), $(2)) $(filter-out $(2), $(1)) ) 176 - 177 - endif 178 - 179 - # echo command. Short version is $(quiet) equals quiet, otherwise full command 180 - echo-cmd = $(if $($(quiet)cmd_$(1)), \ 181 - echo ' $(subst ','\'',$($(quiet)cmd_$(1)))';) 182 - 183 - # function to only execute the passed command if necessary 184 - # >'< substitution is for echo to work, >$< substitution to preserve $ when reloading .cmd file 185 - # note: when using inline perl scripts [perl -e '...$$t=1;...'] in $(cmd_xxx) double $$ your perl vars 186 - # 187 - if_changed = $(if $(strip $? $(call arg-check, $(cmd_$(1)), $(cmd_$@)) ), \ 188 - @set -e; \ 189 - $(echo-cmd) \ 190 - $(cmd_$(1)); \ 191 - echo 'cmd_$@ := $(subst $$,$$$$,$(subst ','\'',$(cmd_$(1))))' > $(@D)/.$(@F).cmd) 192 - 193 - 194 - # execute the command and also postprocess generated .d dependencies 195 - # file 196 - 197 - if_changed_dep = $(if $(strip $? $(filter-out FORCE $(wildcard $^),$^)\ 198 - $(call arg-check, $(cmd_$(1)), $(cmd_$@)) ), \ 199 - @set -e; \ 200 - $(echo-cmd) \ 201 - $(cmd_$(1)); \ 202 - scripts/basic/fixdep $(depfile) $@ '$(subst $$,$$$$,$(subst ','\'',$(cmd_$(1))))' > $(@D)/.$(@F).tmp; \ 203 - rm -f $(depfile); \ 204 - mv -f $(@D)/.$(@F).tmp $(@D)/.$(@F).cmd) 205 - 206 - # Usage: $(call if_changed_rule,foo) 207 - # will check if $(cmd_foo) changed, or any of the prequisites changed, 208 - # and if so will execute $(rule_foo) 209 - 210 - if_changed_rule = $(if $(strip $? $(call arg-check, $(cmd_$(1)), $(cmd_$@)) ),\ 211 - @set -e; \ 212 - $(rule_$(1))) 213 - 214 - # If quiet is set, only print short version of command 215 - 216 - cmd = @$(if $($(quiet)cmd_$(1)),echo ' $(subst ','\'',$($(quiet)cmd_$(1)))' &&) $(cmd_$(1)) 217 - 218 - # Shorthand for $(Q)$(MAKE) -f scripts/Makefile.build obj= 219 - # Usage: 220 - # $(Q)$(MAKE) $(build)=dir 221 - build := -f $(if $(KBUILD_SRC),$(srctree)/)scripts/Makefile.build obj 222 - 223 - # filechk is used to check if the content of a generated file is updated. 224 - # Sample usage: 225 - # define filechk_sample 226 - # echo $KERNELRELEASE 227 - # endef 228 - # version.h : Makefile 229 - # $(call filechk,sample) 230 - # The rule defined shall write to stdout the content of the new file. 231 - # The existing file will be compared with the new one. 232 - # - If no file exist it is created 233 - # - If the content differ the new file is used 234 - # - If they are equal no change, and no timestamp update 235 - 236 - define filechk 237 - $(Q)set -e; \ 238 - echo ' CHK $@'; \ 239 - mkdir -p $(dir $@); \ 240 - $(filechk_$(1)) $(2) > $@.tmp; \ 241 - if [ -r $@ ] && cmp -s $@ $@.tmp; then \ 242 - rm -f $@.tmp; \ 243 - else \ 244 - echo ' UPD $@'; \ 245 - mv -f $@.tmp $@; \ 246 - fi 247 - endef 248 182
+1 -1
scripts/Makefile.modinst
··· 5 5 .PHONY: __modinst 6 6 __modinst: 7 7 8 - include scripts/Makefile.lib 8 + include scripts/Kbuild.include 9 9 10 10 # 11 11
+1
scripts/Makefile.modpost
··· 36 36 _modpost: __modpost 37 37 38 38 include .config 39 + include scripts/Kbuild.include 39 40 include scripts/Makefile.lib 40 41 41 42 symverfile := $(objtree)/Module.symvers
+1 -1
usr/Makefile
··· 27 27 filechk_initramfs_list = $(CONFIG_SHELL) \ 28 28 $(srctree)/scripts/gen_initramfs_list.sh $(gen_initramfs_args) $(quotefixed_initramfs_source) 29 29 30 - $(obj)/initramfs_list: FORCE 30 + $(obj)/initramfs_list: $(obj)/Makefile FORCE 31 31 $(call filechk,initramfs_list) 32 32 33 33 quiet_cmd_cpio = CPIO $@