toplevel: fix release name
[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 include $(TOPDIR)/include/host.mk
7
8 SCAN_TARGET ?= packageinfo
9 SCAN_NAME ?= package
10 SCAN_DIR ?= package
11 TARGET_STAMP:=$(TMP_DIR)/info/.files-$(SCAN_TARGET).stamp
12 FILELIST:=$(TMP_DIR)/info/.files-$(SCAN_TARGET)-$(SCAN_COOKIE)
13 OVERRIDELIST:=$(TMP_DIR)/info/.overrides-$(SCAN_TARGET)-$(SCAN_COOKIE)
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 $(SCAN_STAMP) $(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 } > $$@ || true
44 endef
45
46 $(OVERRIDELIST):
47 rm -f $(TMP_DIR)/info/.overrides-$(SCAN_TARGET)-*
48 touch $@
49
50 ifeq ($(SCAN_NAME),target)
51 GREP_STRING=BuildTarget
52 else
53 GREP_STRING=(Build/DefaultTargets|BuildPackage|.+Package)
54 endif
55
56 $(FILELIST): $(OVERRIDELIST)
57 rm -f $(TMP_DIR)/info/.files-$(SCAN_TARGET)-*
58 $(call 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 > $@
59
60 $(TMP_DIR)/info/.files-$(SCAN_TARGET).mk: $(FILELIST)
61 ( \
62 cat $< | awk '{print "$(SCAN_DIR)/" $$0 "/Makefile" }' | xargs grep -HE '^ *SCAN_DEPS *= *' | awk -F: '{ gsub(/^.*DEPS *= */, "", $$2); print "DEPS_" $$1 "=" $$2 }'; \
63 awk -F/ -v deps="$$DEPS" -v of="$(OVERRIDELIST)" ' \
64 BEGIN { \
65 while (getline < (of)) \
66 override[$$NF]=$$0; \
67 close(of) \
68 } \
69 { \
70 info=$$0; \
71 gsub(/\//, "_", info); \
72 dir=$$0; \
73 pkg=""; \
74 if($$NF in override) \
75 pkg=override[$$NF]; \
76 print "$$(eval $$(call PackageDir," info "," dir "," pkg "))"; \
77 } ' < $<; \
78 true; \
79 ) > $@
80
81 -include $(TMP_DIR)/info/.files-$(SCAN_TARGET).mk
82
83 $(TARGET_STAMP)::
84 +( \
85 $(NO_TRACE_MAKE) $(FILELIST); \
86 MD5SUM=$$(cat $(FILELIST) $(OVERRIDELIST) | (md5sum || md5) 2>/dev/null | awk '{print $$1}'); \
87 [ -f "$@.$$MD5SUM" ] || { \
88 rm -f $@.*; \
89 touch $@.$$MD5SUM; \
90 touch $@; \
91 } \
92 )
93
94 $(TMP_DIR)/.$(SCAN_TARGET): $(TARGET_STAMP) $(SCAN_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
100 FORCE:
101 .PHONY: FORCE
102 .NOTPARALLEL: