makefile.include 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. # -*- coding: utf-8; mode: makefile-gmake -*-
  2. make-help:
  3. @echo ' make V=0|1 [targets] 0 => quiet build (default), 1 => verbose build'
  4. @echo ' make V=2 [targets] 2 => give reason for rebuild of target'
  5. quiet_cmd_common_clean = CLEAN $@
  6. cmd_common_clean = \
  7. rm -rf tests/build ;\
  8. find . -name '*.orig' -exec rm -f {} + ;\
  9. find . -name '*.rej' -exec rm -f {} + ;\
  10. find . -name '*~' -exec rm -f {} + ;\
  11. find . -name '*.bak' -exec rm -f {} + ;\
  12. FMT = cat
  13. ifeq ($(shell which fmt >/dev/null 2>&1; echo $$?), 0)
  14. FMT = fmt
  15. endif
  16. # MS-Windows
  17. #
  18. # For a minimal *make-environment*, I'am using the gnu-tools from:
  19. #
  20. # - GNU MCU Eclipse Windows Build Tools, which brings 'make', 'rm' etc.
  21. # https://github.com/gnu-mcu-eclipse/windows-build-tools/releases
  22. #
  23. # - git for Windows, which brings 'find', 'grep' etc.
  24. # https://git-scm.com/download/win
  25. # normpath
  26. #
  27. # System-dependent normalization of the path name
  28. #
  29. # usage: $(call normpath,/path/to/file)
  30. normpath = $1
  31. ifeq ($(OS),Windows_NT)
  32. normpath = $(subst /,\,$1)
  33. endif
  34. # stolen from linux/Makefile
  35. #
  36. ifeq ("$(origin V)", "command line")
  37. KBUILD_VERBOSE = $(V)
  38. endif
  39. ifndef KBUILD_VERBOSE
  40. KBUILD_VERBOSE = 0
  41. endif
  42. ifeq ($(KBUILD_VERBOSE),1)
  43. quiet =
  44. Q =
  45. else
  46. quiet=quiet_
  47. Q = @
  48. endif
  49. # stolen from linux/scripts/Kbuild.include
  50. #
  51. # Convenient variables
  52. comma := ,
  53. quote := "
  54. #" this comment is only for emacs highlighting
  55. squote := '
  56. #' this comment is only for emacs highlighting
  57. empty :=
  58. space := $(empty) $(empty)
  59. space_escape := _-_SPACE_-_
  60. # Find any prerequisites that is newer than target or that does not exist.
  61. # PHONY targets skipped in both cases.
  62. any-prereq = $(filter-out $(PHONY),$?) $(filter-out $(PHONY) $(wildcard $^),$^)
  63. #
  64. ###
  65. # why - tell why a a target got build
  66. # enabled by make V=2
  67. # Output (listed in the order they are checked):
  68. # (1) - due to target is PHONY
  69. # (2) - due to target missing
  70. # (3) - due to: file1.h file2.h
  71. # (4) - due to command line change
  72. # (5) - due to missing .cmd file
  73. # (6) - due to target not in $(targets)
  74. # (1) PHONY targets are always build
  75. # (2) No target, so we better build it
  76. # (3) Prerequisite is newer than target
  77. # (4) The command line stored in the file named dir/.target.cmd
  78. # differed from actual command line. This happens when compiler
  79. # options changes
  80. # (5) No dir/.target.cmd file (used to store command line)
  81. # (6) No dir/.target.cmd file and target not listed in $(targets)
  82. # This is a good hint that there is a bug in the kbuild file
  83. ifeq ($(KBUILD_VERBOSE),2)
  84. why = \
  85. $(if $(filter $@, $(PHONY)),- due to target is PHONY, \
  86. $(if $(wildcard $@), \
  87. $(if $(strip $(any-prereq)),- due to: $(any-prereq), \
  88. $(if $(arg-check), \
  89. $(if $(cmd_$@),- due to command line change, \
  90. $(if $(filter $@, $(targets)), \
  91. - due to missing .cmd file, \
  92. - due to $(notdir $@) not in $$(targets) \
  93. ) \
  94. ) \
  95. ) \
  96. ), \
  97. - due to target missing \
  98. ) \
  99. )
  100. echo-why = $(call escsq, $(strip $(why)))
  101. endif
  102. #
  103. ###
  104. # Escape single quote for use in echo statements
  105. escsq = $(subst $(squote),'\$(squote)',$1)
  106. #
  107. # echo command.
  108. # Short version is used, if $(quiet) equals `quiet_', otherwise full one.
  109. echo-cmd = $(if $($(quiet)cmd_$(1)),echo '$(call escsq,$($(quiet)cmd_$(1)))$(echo-why)';)
  110. #
  111. # printing commands
  112. cmd = @$(echo-cmd) $(cmd_$(1))