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