makefile.include 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. # -*- coding: utf-8; mode: makefile-gmake -*-
  2. # SPDX-License-Identifier: AGPL-3.0-or-later
  3. PHONY += make-help
  4. make-help:
  5. @echo 'options:'
  6. @echo ' make V=0|1 [targets] 0 => quiet build (default), 1 => verbose build'
  7. @echo ' make V=2 [targets] 2 => give reason for rebuild of target'
  8. ifeq ("$(origin V)", "command line")
  9. VERBOSE = $(V)
  10. endif
  11. ifndef VERBOSE
  12. VERBOSE = 0
  13. endif
  14. export VERBOSE
  15. ifeq ($(VERBOSE),1)
  16. quiet =
  17. Q =
  18. else
  19. quiet=quiet_
  20. Q = @
  21. endif
  22. # stolen from linux/scripts/Kbuild.include
  23. #
  24. # Convenient variables
  25. squote := '
  26. #' this comment is only for emacs highlighting
  27. # Find any prerequisites that is newer than target or that does not exist.
  28. # PHONY targets skipped in both cases.
  29. any-prereq = $(filter-out $(PHONY),$?) $(filter-out $(PHONY) $(wildcard $^),$^)
  30. #
  31. ###
  32. # why - tell why a a target got build
  33. # enabled by make V=2
  34. # Output (listed in the order they are checked):
  35. # (1) - due to target is PHONY
  36. # (2) - due to target missing
  37. # (3) - due to: file1.h file2.h
  38. # (4) - due to command line change
  39. # (5) - due to missing .cmd file
  40. # (6) - due to target not in $(targets)
  41. # (1) PHONY targets are always build
  42. # (2) No target, so we better build it
  43. # (3) Prerequisite is newer than target
  44. # (4) The command line stored in the file named dir/.target.cmd
  45. # differed from actual command line. This happens when compiler
  46. # options changes
  47. # (5) No dir/.target.cmd file (used to store command line)
  48. # (6) No dir/.target.cmd file and target not listed in $(targets)
  49. # This is a good hint that there is a bug in the kbuild file
  50. ifeq ($(VERBOSE),2)
  51. why = \
  52. $(if $(filter $@, $(PHONY)),- due to target is PHONY, \
  53. $(if $(wildcard $@), \
  54. $(if $(strip $(any-prereq)),- due to: $(any-prereq), \
  55. $(if $(arg-check), \
  56. $(if $(cmd_$@),- due to command line change, \
  57. $(if $(filter $@, $(targets)), \
  58. - due to missing .cmd file, \
  59. - due to $(notdir $@) not in $$(targets) \
  60. ) \
  61. ) \
  62. ) \
  63. ), \
  64. - due to target missing \
  65. ) \
  66. )
  67. echo-why = $(call escsq, $(strip $(why)))
  68. endif
  69. #
  70. ###
  71. # Escape single quote for use in echo statements
  72. escsq = $(subst $(squote),'\$(squote)',$1)
  73. #
  74. # echo command.
  75. # Short version is used, if $(quiet) equals `quiet_', otherwise full one.
  76. echo-cmd = $(if $($(quiet)cmd_$(1)),echo '$(call escsq,$($(quiet)cmd_$(1)))$(echo-why)';)
  77. #
  78. # printing commands
  79. cmd = @$(echo-cmd) $(cmd_$(1))
  80. .PHONY: $(PHONY)