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