common.mk 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. # Functionality common to both top-level project makefile (project.mk)
  2. # and component makefiles (component_wrapper.mk)
  3. #
  4. # Include project config makefile, if it exists.
  5. #
  6. # (Note that we only rebuild this makefile automatically for some
  7. # targets, see project_config.mk for details.)
  8. SDKCONFIG_MAKEFILE ?= $(abspath $(BUILD_DIR_BASE)/include/config/auto.conf)
  9. -include $(SDKCONFIG_MAKEFILE)
  10. export SDKCONFIG_MAKEFILE # sub-makes (like bootloader) will reuse this path
  11. # BATCH_BUILD flag disables interactive terminal features, defaults to verbose build
  12. ifdef BATCH_BUILD
  13. V ?= 1
  14. endif
  15. #Handling of V=1/VERBOSE=1 flag
  16. #
  17. # if V=1, $(summary) does nothing and $(details) will echo extra details
  18. # if V is unset or not 1, $(summary) echoes a summary and $(details) does nothing
  19. VERBOSE ?=
  20. V ?= $(VERBOSE)
  21. ifeq ("$(V)","1")
  22. summary := @true
  23. details := @echo
  24. else
  25. summary := @echo
  26. details := @true
  27. # disable echoing of commands, directory names
  28. MAKEFLAGS += --silent
  29. endif # $(V)==1
  30. ifdef CONFIG_MAKE_WARN_UNDEFINED_VARIABLES
  31. MAKEFLAGS += --warn-undefined-variables
  32. endif
  33. # General make utilities
  34. # convenience variable for printing an 80 asterisk wide separator line
  35. SEPARATOR:="*******************************************************************************"
  36. # macro to remove quotes from an argument, ie $(call dequote,$(CONFIG_BLAH))
  37. define dequote
  38. $(subst ",,$(1))
  39. endef
  40. # " comment kept here to keep syntax highlighting happy
  41. # macro to keep an absolute path as-is, but resolve a relative path
  42. # against a particular parent directory
  43. #
  44. # $(1) path to resolve
  45. # $(2) directory to resolve non-absolute path against
  46. #
  47. # Path and directory don't have to exist (definition of a "relative
  48. # path" is one that doesn't start with /)
  49. #
  50. # $(2) can contain a trailing forward slash or not, result will not
  51. # double any path slashes.
  52. #
  53. # example $(call resolvepath,$(CONFIG_PATH),$(CONFIG_DIR))
  54. define resolvepath
  55. $(abspath $(foreach dir,$(1),$(if $(filter /%,$(dir)),$(dir),$(subst //,/,$(2)/$(dir)))))
  56. endef
  57. # macro to include a target only if it's on the list of targets that make
  58. # was invoked with
  59. #
  60. # This allows you to have something like an "order-only phony prerequisite",
  61. # ie a prerequisite that determines an order phony targets have to run in.
  62. #
  63. # Because normal order-only prerequisites don't work with phony targets.
  64. #
  65. # example $(call prereq_if_explicit,erase_flash)
  66. define prereq_if_explicit
  67. $(filter $(1),$(MAKECMDGOALS))
  68. endef
  69. # macro to kill duplicate items in a list without messing up the sort order of the list.
  70. # Will only keep the unique items; if there are non-unique items in the list, it will remove
  71. # the later recurring ones so only the first one remains.
  72. # Copied from http://stackoverflow.com/questions/16144115/makefile-remove-duplicate-words-without-sorting
  73. define uniq
  74. $(if $1,$(firstword $1) $(call uniq,$(filter-out $(firstword $1),$1)))
  75. endef
  76. # macro to strip leading ../s from a path
  77. # Given $(1) which is a directory, remove any leading ../s from it
  78. # (recursively keeps removing ../ until not found)
  79. # if the path contains nothing but ../.., a single . is returned (cwd)
  80. define stripLeadingParentDirs
  81. $(foreach path,$(1),$(if $(subst ..,,$(path)),$(if $(filter ../%,$(path)),$(call stripLeadingParentDirs,$(patsubst ../%,%,$(path))),$(path)),.))
  82. endef