makefile.include 3.5 KB

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