scan.mk 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. ifeq ($(IS_TTY),1)
  11. define progress
  12. printf "\033[M\r$(1)" >&2;
  13. endef
  14. else
  15. define progress
  16. :;
  17. endef
  18. endif
  19. define PackageDir
  20. $(TMP_DIR)/.$(SCAN_TARGET): $(TMP_DIR)/info/.$(SCAN_TARGET)-$(1)
  21. $(TMP_DIR)/info/.$(SCAN_TARGET)-$(1): $(SCAN_DIR)/$(2)/Makefile $(SCAN_STAMP) $(foreach DEP,$(DEPS_$(SCAN_DIR)/$(2)/Makefile) $(SCAN_DEPS),$(wildcard $(if $(filter /%,$(DEP)),$(DEP),$(SCAN_DIR)/$(2)/$(DEP))))
  22. { \
  23. $$(call progress,Collecting $(SCAN_NAME) info: $(SCAN_DIR)/$(2)) \
  24. echo Source-Makefile: $(SCAN_DIR)/$(2)/Makefile; \
  25. $(NO_TRACE_MAKE) --no-print-dir -r DUMP=1 -C $(SCAN_DIR)/$(2) $(SCAN_MAKEOPTS) 2>/dev/null || { \
  26. mkdir -p "$(TOPDIR)/logs/$(SCAN_DIR)/$(2)"; \
  27. $(NO_TRACE_MAKE) --no-print-dir -r DUMP=1 -C $(SCAN_DIR)/$(2) $(SCAN_MAKEOPTS) > $(TOPDIR)/logs/$(SCAN_DIR)/$(2)/dump.txt 2>&1; \
  28. $$(call progress,ERROR: please fix $(SCAN_DIR)/$(2)/Makefile - see logs/$(SCAN_DIR)/$(2)/dump.txt for details\n) \
  29. rm -f $$@; \
  30. }; \
  31. echo; \
  32. } > $$@ || true
  33. endef
  34. $(FILELIST):
  35. rm -f $(TMP_DIR)/info/.files-$(SCAN_TARGET)-*
  36. $(call FIND_L, $(SCAN_DIR)) $(SCAN_EXTRA) -mindepth 1 $(if $(SCAN_DEPTH),-maxdepth $(SCAN_DEPTH)) -name Makefile | xargs grep -HE 'call (Build/DefaultTargets|Build(Package|Target)|.+Package)' | sed -e 's#^$(SCAN_DIR)/##' -e 's#/Makefile:.*##' | uniq > $@
  37. $(TMP_DIR)/info/.files-$(SCAN_TARGET).mk: $(FILELIST)
  38. ( \
  39. cat $< | awk '{print "$(SCAN_DIR)/" $$0 "/Makefile" }' | xargs grep -HE '^ *SCAN_DEPS *= *' | awk -F: '{ gsub(/^.*DEPS *= */, "", $$2); print "DEPS_" $$1 "=" $$2 }'; \
  40. awk -v deps="$$DEPS" '{ \
  41. info=$$0; \
  42. gsub(/\//, "_", info); \
  43. print "$$(eval $$(call PackageDir," info "," $$0 "))"; \
  44. } ' < $<; \
  45. true; \
  46. ) > $@
  47. -include $(TMP_DIR)/info/.files-$(SCAN_TARGET).mk
  48. $(TARGET_STAMP)::
  49. +( \
  50. $(NO_TRACE_MAKE) $(FILELIST); \
  51. MD5SUM=$$(cat $(FILELIST) | (md5sum || md5) 2>/dev/null | awk '{print $$1}'); \
  52. [ -f "$@.$$MD5SUM" ] || { \
  53. rm -f $@.*; \
  54. touch $@.$$MD5SUM; \
  55. touch $@; \
  56. } \
  57. )
  58. $(TMP_DIR)/.$(SCAN_TARGET): $(TARGET_STAMP) $(SCAN_STAMP)
  59. $(call progress,Collecting $(SCAN_NAME) info: merging...)
  60. -cat $(FILELIST) | awk '{gsub(/\//, "_", $$0);print "$(TMP_DIR)/info/.$(SCAN_TARGET)-" $$0}' | xargs cat > $@ 2>/dev/null
  61. $(call progress,Collecting $(SCAN_NAME) info: done)
  62. echo
  63. FORCE:
  64. .PHONY: FORCE
  65. .NOTPARALLEL: