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