scan.mk 3.3 KB

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