scan.mk 3.5 KB

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