1
0

scan.mk 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. include $(TOPDIR)/include/verbose.mk
  2. include $(TOPDIR)/rules.mk
  3. TMP_DIR:=$(TOPDIR)/tmp
  4. all: $(TMP_DIR)/.$(SCAN_TARGET)
  5. SCAN_TARGET ?= packageinfo
  6. SCAN_NAME ?= package
  7. SCAN_DIR ?= package
  8. TARGET_STAMP:=$(TMP_DIR)/info/.files-$(SCAN_TARGET).stamp
  9. FILELIST:=$(TMP_DIR)/info/.files-$(SCAN_TARGET)-$(SCAN_COOKIE)
  10. OVERRIDELIST:=$(TMP_DIR)/info/.overrides-$(SCAN_TARGET)-$(SCAN_COOKIE)
  11. export ORIG_PATH:=$(if $(ORIG_PATH),$(ORIG_PATH),$(PATH))
  12. export PATH:=$(STAGING_DIR_HOST)/bin:$(PATH)
  13. define feedname
  14. $(if $(patsubst feeds/%,,$(1)),,$(word 2,$(subst /, ,$(1))))
  15. endef
  16. ifeq ($(SCAN_NAME),target)
  17. SCAN_DEPS=image/Makefile profiles/*.mk $(TOPDIR)/include/kernel*.mk $(TOPDIR)/include/target.mk image/*.mk
  18. else
  19. SCAN_DEPS=$(TOPDIR)/include/package*.mk
  20. ifneq ($(call feedname,$(SCAN_DIR)),)
  21. SCAN_DEPS += $(TOPDIR)/feeds/$(call feedname,$(SCAN_DIR))/*.mk
  22. endif
  23. endif
  24. ifeq ($(IS_TTY),1)
  25. ifneq ($(strip $(NO_COLOR)),1)
  26. define progress
  27. printf "\033[M\r$(1)" >&2;
  28. endef
  29. else
  30. define progress
  31. printf "\r$(1)" >&2;
  32. endef
  33. endif
  34. else
  35. define progress
  36. :;
  37. endef
  38. endif
  39. define PackageDir
  40. $(TMP_DIR)/.$(SCAN_TARGET): $(TMP_DIR)/info/.$(SCAN_TARGET)-$(1)
  41. $(TMP_DIR)/info/.$(SCAN_TARGET)-$(1): $(SCAN_DIR)/$(2)/Makefile $(foreach DEP,$(DEPS_$(SCAN_DIR)/$(2)/Makefile) $(SCAN_DEPS),$(wildcard $(if $(filter /%,$(DEP)),$(DEP),$(SCAN_DIR)/$(2)/$(DEP))))
  42. { \
  43. $$(call progress,Collecting $(SCAN_NAME) info: $(SCAN_DIR)/$(2)) \
  44. echo Source-Makefile: $(SCAN_DIR)/$(2)/Makefile; \
  45. $(if $(3),echo Override: $(3),true); \
  46. $(if $(findstring c,$(LIBRECMC_VERBOSE)),$(MAKE),$(NO_TRACE_MAKE) --no-print-dir) -r DUMP=1 FEED="$(call feedname,$(2))" -C $(SCAN_DIR)/$(2) $(SCAN_MAKEOPTS) \
  47. $(if $(findstring c,$(LIBRECMC_VERBOSE)),,2>/dev/null) || { \
  48. mkdir -p "$(TOPDIR)/logs/$(SCAN_DIR)/$(2)"; \
  49. $(NO_TRACE_MAKE) --no-print-dir -r DUMP=1 FEED="$(call feedname,$(2))" -C $(SCAN_DIR)/$(2) $(SCAN_MAKEOPTS) > $(TOPDIR)/logs/$(SCAN_DIR)/$(2)/dump.txt 2>&1; \
  50. $$(call progress,ERROR: please fix $(SCAN_DIR)/$(2)/Makefile - see logs/$(SCAN_DIR)/$(2)/dump.txt for details\n) \
  51. rm -f $$@; \
  52. }; \
  53. echo; \
  54. } > $$@.tmp
  55. mv $$@.tmp $$@
  56. endef
  57. $(OVERRIDELIST):
  58. rm -f $(TMP_DIR)/info/.overrides-$(SCAN_TARGET)-*
  59. touch $@
  60. ifeq ($(SCAN_NAME),target)
  61. GREP_STRING=BuildTarget
  62. else
  63. GREP_STRING=(Build/DefaultTargets|BuildPackage|KernelPackage)
  64. endif
  65. $(FILELIST): $(OVERRIDELIST)
  66. rm -f $(TMP_DIR)/info/.files-$(SCAN_TARGET)-*
  67. find -L $(SCAN_DIR) -mindepth 1 $(if $(SCAN_DEPTH),-maxdepth $(SCAN_DEPTH)) $(SCAN_EXTRA) -name Makefile | xargs grep -aHE 'call $(GREP_STRING)' | sed -e 's#^$(SCAN_DIR)/##' -e 's#/Makefile:.*##' | uniq | awk -v of=$(OVERRIDELIST) -f include/scan.awk > $@
  68. $(TMP_DIR)/info/.files-$(SCAN_TARGET).mk: $(FILELIST)
  69. ( \
  70. cat $< | awk '{print "$(SCAN_DIR)/" $$0 "/Makefile" }' | xargs grep -HE '^ *SCAN_DEPS *= *' | awk -F: '{ gsub(/^.*DEPS *= */, "", $$2); print "DEPS_" $$1 "=" $$2 }'; \
  71. awk -F/ -v deps="$$DEPS" -v of="$(OVERRIDELIST)" ' \
  72. BEGIN { \
  73. while (getline < (of)) \
  74. override[$$NF]=$$0; \
  75. close(of) \
  76. } \
  77. { \
  78. info=$$0; \
  79. gsub(/\//, "_", info); \
  80. dir=$$0; \
  81. pkg=""; \
  82. if($$NF in override) \
  83. pkg=override[$$NF]; \
  84. print "$$(eval $$(call PackageDir," info "," dir "," pkg "))"; \
  85. } ' < $<; \
  86. true; \
  87. ) > $@.tmp
  88. mv $@.tmp $@
  89. -include $(TMP_DIR)/info/.files-$(SCAN_TARGET).mk
  90. $(TARGET_STAMP)::
  91. +( \
  92. $(NO_TRACE_MAKE) $(FILELIST); \
  93. MD5SUM=$$(cat $(FILELIST) $(OVERRIDELIST) | $(MKHASH) md5 | awk '{print $$1}'); \
  94. [ -f "$@.$$MD5SUM" ] || { \
  95. rm -f $@.*; \
  96. touch $@.$$MD5SUM; \
  97. touch $@; \
  98. } \
  99. )
  100. $(TMP_DIR)/.$(SCAN_TARGET): $(TARGET_STAMP)
  101. $(call progress,Collecting $(SCAN_NAME) info: merging...)
  102. -cat $(FILELIST) | awk '{gsub(/\//, "_", $$0);print "$(TMP_DIR)/info/.$(SCAN_TARGET)-" $$0}' | xargs cat > $@ 2>/dev/null
  103. $(call progress,Collecting $(SCAN_NAME) info: done)
  104. echo
  105. FORCE:
  106. .PHONY: FORCE
  107. .NOTPARALLEL: