2
0

subdir.mk 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #
  2. # Copyright (C) 2007 OpenWrt.org
  3. #
  4. # This is free software, licensed under the GNU General Public License v2.
  5. # See /LICENSE for more information.
  6. #
  7. ifeq ($(MAKECMDGOALS),prereq)
  8. SUBTARGETS:=prereq
  9. PREREQ_ONLY:=1
  10. else
  11. SUBTARGETS:=clean download prepare compile install update refresh prereq dist distcheck configure check
  12. endif
  13. subtarget-default = $(filter-out ., \
  14. $(if $($(1)/builddirs-$(2)),$($(1)/builddirs-$(2)), \
  15. $(if $($(1)/builddirs-default),$($(1)/builddirs-default), \
  16. $($(1)/builddirs))))
  17. define subtarget
  18. $(call warn_eval,$(1),t,T,$(1)/$(2): $($(1)/) $(foreach bd,$(call subtarget-default,$(1),$(2)),$(1)/$(bd)/$(2)))
  19. endef
  20. define ERROR
  21. ($(call MESSAGE, $(2)); $(if $(BUILD_LOG), echo "$(2)" >> $(BUILD_LOG_DIR)/$(1)/error.txt))
  22. endef
  23. lastdir=$(word $(words $(subst /, ,$(1))),$(subst /, ,$(1)))
  24. diralias=$(if $(findstring $(1),$(call lastdir,$(1))),,$(call lastdir,$(1)))
  25. # 1: subdir
  26. # 2: target
  27. # 3: build type
  28. # 4: build variant
  29. log_make = \
  30. $(if $(call debug,$(1),v),,@)+ \
  31. $(if $(BUILD_LOG), \
  32. set -o pipefail; \
  33. mkdir -p $(BUILD_LOG_DIR)/$(1)$(if $(4),/$(4));) \
  34. $$(SUBMAKE) -r -C $(1) $(if $(3),$(3)-)$(2) \
  35. BUILD_SUBDIR="$(1)" \
  36. BUILD_VARIANT="$(4)" \
  37. $(if $(BUILD_LOG),SILENT= 2>&1 | tee $(BUILD_LOG_DIR)/$(1)$(if $(4),/$(4))/$(if $(3),$(3)-)$(2).txt)
  38. # Parameters: <subdir>
  39. define subdir
  40. $(call warn,$(1),d,D $(1))
  41. $(foreach bd,$($(1)/builddirs),
  42. $(call warn,$(1),d,BD $(1)/$(bd))
  43. $(foreach target,$(SUBTARGETS),
  44. $(foreach btype,$(buildtypes-$(bd)),
  45. $(call warn_eval,$(1)/$(bd),t,T,$(1)/$(bd)/$(btype)/$(target): $(if $(QUILT),,$($(1)/$(bd)/$(btype)/$(target)) $(call $(1)//$(btype)/$(target),$(1)/$(bd)/$(btype))))
  46. $(call log_make,$(1)/$(bd),$(target),$(btype),$(filter-out __default,$(variant))) \
  47. $(if $(findstring $(bd),$($(1)/builddirs-ignore-$(btype)-$(target))), || $(call ERROR,$(1), ERROR: $(1)/$(bd) [$(btype)] failed to build.))
  48. $(if $(call diralias,$(bd)),$(call warn_eval,$(1)/$(bd),l,T,$(1)/$(call diralias,$(bd))/$(btype)/$(target): $(1)/$(bd)/$(btype)/$(target)))
  49. )
  50. $(call warn_eval,$(1)/$(bd),t,T,$(1)/$(bd)/$(target): $(if $(QUILT),,$($(1)/$(bd)/$(target)) $(call $(1)//$(target),$(1)/$(bd))))
  51. $(foreach variant,$(if $(BUILD_VARIANT),$(BUILD_VARIANT),$(if $(strip $($(1)/$(bd)/variants)),$($(1)/$(bd)/variants),$(if $($(1)/$(bd)/default-variant),$($(1)/$(bd)/default-variant),__default))),
  52. $(if $(BUILD_LOG),@mkdir -p $(BUILD_LOG_DIR)/$(1)/$(bd)/$(filter-out __default,$(variant)))
  53. $(call log_make,$(1)/$(bd),$(target),,$(filter-out __default,$(variant))) \
  54. $(if $(findstring $(bd),$($(1)/builddirs-ignore-$(target))), || $(call ERROR,$(1), ERROR: $(1)/$(bd) failed to build$(if $(filter-out __default,$(variant)), (build variant: $(variant))).))
  55. )
  56. $(if $(PREREQ_ONLY)$(DUMP_TARGET_DB),,
  57. # aliases
  58. $(if $(call diralias,$(bd)),$(call warn_eval,$(1)/$(bd),l,T,$(1)/$(call diralias,$(bd))/$(target): $(1)/$(bd)/$(target)))
  59. )
  60. )
  61. )
  62. $(foreach target,$(SUBTARGETS),$(call subtarget,$(1),$(target)))
  63. endef
  64. ifndef DUMP_TARGET_DB
  65. # Parameters: <subdir> <name> <target> <depends> <config options> <stampfile location>
  66. define stampfile
  67. $(1)/stamp-$(3):=$(if $(6),$(6),$(STAGING_DIR))/stamp/.$(2)_$(3)$(5)
  68. $$($(1)/stamp-$(3)): $(TMP_DIR)/.build $(4)
  69. @+$(SCRIPT_DIR)/timestamp.pl -n $$($(1)/stamp-$(3)) $(1) $(4) || \
  70. $(MAKE) $(if $(QUIET),--no-print-directory) $$($(1)/flags-$(3)) $(1)/$(3)
  71. @mkdir -p $$$$(dirname $$($(1)/stamp-$(3)))
  72. @touch $$($(1)/stamp-$(3))
  73. $$(if $(call debug,$(1),v),,.SILENT: $$($(1)/stamp-$(3)))
  74. .PRECIOUS: $$($(1)/stamp-$(3)) # work around a make bug
  75. $(1)//clean:=$(1)/stamp-$(3)/clean
  76. $(1)/stamp-$(3)/clean: FORCE
  77. @rm -f $$($(1)/stamp-$(3))
  78. endef
  79. endif