1
0

scan.mk 3.6 KB

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