makefile.include 4.4 KB

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