Kbuild.include 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. ####
  2. # kbuild: Generic definitions
  3. # Convinient variables
  4. comma := ,
  5. squote := '
  6. empty :=
  7. space := $(empty) $(empty)
  8. ###
  9. # The temporary file to save gcc -MD generated dependencies must not
  10. # contain a comma
  11. depfile = $(subst $(comma),_,$(@D)/.$(@F).d)
  12. ###
  13. # Escape single quote for use in echo statements
  14. escsq = $(subst $(squote),'\$(squote)',$1)
  15. ###
  16. # filechk is used to check if the content of a generated file is updated.
  17. # Sample usage:
  18. # define filechk_sample
  19. # echo $KERNELRELEASE
  20. # endef
  21. # version.h : Makefile
  22. # $(call filechk,sample)
  23. # The rule defined shall write to stdout the content of the new file.
  24. # The existing file will be compared with the new one.
  25. # - If no file exist it is created
  26. # - If the content differ the new file is used
  27. # - If they are equal no change, and no timestamp update
  28. # - stdin is piped in from the first prerequisite ($<) so one has
  29. # to specify a valid file as first prerequisite (often the kbuild file)
  30. define filechk
  31. $(Q)set -e; \
  32. echo ' CHK $@'; \
  33. mkdir -p $(dir $@); \
  34. $(filechk_$(1)) < $< > $@.tmp; \
  35. if [ -r $@ ] && cmp -s $@ $@.tmp; then \
  36. rm -f $@.tmp; \
  37. else \
  38. echo ' UPD $@'; \
  39. mv -f $@.tmp $@; \
  40. fi
  41. endef
  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. # If quiet is set, only print short version of command
  48. cmd = @$(if $($(quiet)cmd_$(1)),\
  49. echo ' $(call escsq,$($(quiet)cmd_$(1)))' &&) $(cmd_$(1))
  50. # Add $(obj)/ for paths that is not absolute
  51. objectify = $(foreach o,$(1),$(if $(filter /%,$(o)),$(o),$(obj)/$(o)))
  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. ifneq ($(KBUILD_NOCMDDEP),1)
  60. # Check if both arguments has same arguments. Result in empty string if equal
  61. # User may override this check using make KBUILD_NOCMDDEP=1
  62. arg-check = $(strip $(filter-out $(1), $(2)) $(filter-out $(2), $(1)) )
  63. endif
  64. # echo command. Short version is $(quiet) equals quiet, otherwise full command
  65. echo-cmd = $(if $($(quiet)cmd_$(1)), \
  66. echo ' $(call escsq,$($(quiet)cmd_$(1)))';)
  67. # function to only execute the passed command if necessary
  68. # >'< substitution is for echo to work, >$< substitution to preserve $ when reloading .cmd file
  69. # note: when using inline perl scripts [perl -e '...$$t=1;...'] in $(cmd_xxx) double $$ your perl vars
  70. #
  71. if_changed = $(if $(strip $? $(call arg-check, $(cmd_$(1)), $(cmd_$@)) ), \
  72. @set -e; \
  73. $(echo-cmd) \
  74. $(cmd_$(1)); \
  75. echo 'cmd_$@ := $(subst $$,$$$$,$(call escsq,$(cmd_$(1))))' > $(@D)/.$(@F).cmd)
  76. # execute the command and also postprocess generated .d dependencies
  77. # file
  78. if_changed_dep = $(if $(strip $? $(filter-out FORCE $(wildcard $^),$^)\
  79. $(call arg-check, $(cmd_$(1)), $(cmd_$@)) ), \
  80. @set -e; \
  81. $(echo-cmd) \
  82. $(cmd_$(1)); \
  83. scripts/basic/fixdep $(depfile) $@ '$(subst $$,$$$$,$(call escsq,$(cmd_$(1))))' > $(@D)/.$(@F).tmp; \
  84. rm -f $(depfile); \
  85. mv -f $(@D)/.$(@F).tmp $(@D)/.$(@F).cmd)
  86. # Usage: $(call if_changed_rule,foo)
  87. # will check if $(cmd_foo) changed, or any of the prequisites changed,
  88. # and if so will execute $(rule_foo)
  89. if_changed_rule = $(if $(strip $? $(call arg-check, $(cmd_$(1)), $(cmd_$@)) ),\
  90. @set -e; \
  91. $(rule_$(1)))