common.mk 3.3 KB

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