rewritten template parser for awx - uses @for, @if, @else, @end for basic flow control
[librecmc/librecmc.git] / include / scan.mk
1 include $(TOPDIR)/include/verbose.mk
2
3 SCAN_TARGET ?= packageinfo
4 SCAN_NAME ?= package
5 SCAN_DIR ?= package
6 SCAN_DEPS ?= include/package.mk
7
8 ifeq ($(IS_TTY),1)
9   define progress
10         printf "\033[M\r$(1)" >&2;
11   endef
12 else
13   define progress
14         :
15   endef
16 endif
17
18 SCAN = $(patsubst $(SCAN_DIR)/%/Makefile,%,$(wildcard $(SCAN_DIR)/*/Makefile))
19 tmp/.$(SCAN_TARGET):
20         @($(call progress,Collecting $(SCAN_NAME) info: merging...))
21         for file in $(SCAN); do \
22                 cat tmp/info/.$(SCAN_TARGET)-$$file; \
23         done > $@
24         @($(call progress,Collecting $(SCAN_NAME) info: done))
25         @echo
26
27 ifneq ($(SCAN_EXTRA),)
28 SCAN_STAMP=tmp/info/.scan-$(SCAN_TARGET)-$(shell ls $(SCAN_EXTRA) 2>/dev/null | (md5sum || md5) 2>/dev/null | cut -d' ' -f1)
29 $(SCAN_STAMP):
30         rm -f tmp/info/.scan-$(SCAN_TARGET)-*
31         touch $@
32 endif
33
34 # FIXME: generate this dynamically?
35 ifeq ($(SCAN_TARGET),packageinfo)
36 tmp/info/.packageinfo-kernel: $(wildcard package/kernel/modules/*.mk)
37 endif
38
39 define scanfiles
40 $(foreach FILE,$(SCAN),
41   tmp/.$(SCAN_TARGET): tmp/info/.$(SCAN_TARGET)-$(FILE) $(SCAN_DEPS)
42   tmp/info/.$(SCAN_TARGET)-$(FILE): $(SCAN_DIR)/$(FILE)/Makefile $(SCAN_STAMP)
43         grep -E 'include (\$$$$\(INCLUDE_DIR\)|\$$$$\(TOPDIR\)/include)/' $(SCAN_DIR)/$(FILE)/Makefile >/dev/null && { \
44                 $$(call progress,Collecting $(SCAN_NAME) info: $(SCAN_DIR)/$(FILE)) \
45                 echo Source-Makefile: $(SCAN_DIR)/$(FILE)/Makefile; \
46                 $(NO_TRACE_MAKE) --no-print-dir DUMP=1 -C $(SCAN_DIR)/$(FILE) 3>/dev/null || echo "ERROR: please fix $(SCAN_DIR)/$(FILE)/Makefile" >&2; \
47                 echo; \
48         } > $$@ || true
49 )
50
51 endef
52 $(eval $(call scanfiles))
53
54 FORCE:
55 .PHONY: FORCE