]> rtime.felk.cvut.cz Git - omk.git/blob - snippets/sources-list
Consider even cscope target as consumer of SOURCES_LIST.
[omk.git] / snippets / sources-list
1
2 # Rules that creates the list of files which are used during
3 # compilation. The list reflects conditional compilation depending on
4 # config.omk and other variables.
5
6 SOURCES_LIST_FN=sources.txt
7 ifndef SOURCES_LIST
8 SOURCES_LIST_DIR:=$(RELATIVE_DIR)
9 SOURCES_LIST:=$(OUTPUT_DIR)/$(SOURCES_LIST_DIR)/$(SOURCES_LIST_FN)
10 SOURCES_LIST_D := $(LOCAL_BUILD_DIR)/$(SOURCES_LIST_FN).d
11 export SOURCES_LIST SOURCES_LIST_DIR SOURCES_LIST_D
12 endif
13
14 ifneq ($(filter sources-list TAGS tags cscope,$(MAKECMDGOALS)),)
15 NEED_SOURCES_LIST=y
16 endif
17
18 ifeq ($(NEED_SOURCES_LIST),y) # avoid execution of find command bellow if it is not useful
19 .PHONY: sources-list
20 sources-list: $(SOURCES_LIST)
21
22 $(SOURCES_LIST): $(CONFIG_FILES) $(shell find -name $(MAKEFILE_OMK))
23         @$(call mkdir_def,$(dir $(SOURCES_LIST_D)))
24         @echo -n "" > "$(SOURCES_LIST).tmp"
25         @echo -n "" > "$(SOURCES_LIST_D).tmp"
26         @$(MAKE) --no-print-directory sources-list-pass
27         @echo "# Automatically generated list of files in '$(RELATIVE_DIR)' that are used during OMK compilation" > "$(SOURCES_LIST).tmp2"
28         @cat "$(SOURCES_LIST).tmp"|sort|uniq >> "$(SOURCES_LIST).tmp2"
29         @rm "$(SOURCES_LIST).tmp"
30         @mv "$(SOURCES_LIST).tmp2" "$(SOURCES_LIST)"
31         @echo "$(SOURCES_LIST): \\" > "$(SOURCES_LIST_D).tmp2"
32         @cat "$(SOURCES_LIST_D).tmp"|grep -v "$(SOURCES_LIST_D).tmp"|sort|uniq|\
33                 sed -e 's/$$/\\/' >> "$(SOURCES_LIST_D).tmp2"
34         @rm "$(SOURCES_LIST_D).tmp"
35         @mv "$(SOURCES_LIST_D).tmp2" "$(SOURCES_LIST_D)"
36 endif
37
38 $(eval $(call omk_pass_template,sources-list-pass,$$(LOCAL_BUILD_DIR),,always))
39
40 sources-list-pass-local:
41         @$(foreach m,$(MAKEFILE_LIST),echo '  $(m)' >> "$(SOURCES_LIST_D).tmp";)
42         @$(foreach h,$(include_HEADERS) $(nobase_include_HEADERS) $(kernel_HEADERS),\
43           echo "$(addsuffix /,$(RELATIVE_DIR:$(SOURCES_LIST_DIR)/%=%))$(h)" >> "$(SOURCES_LIST).tmp";)
44         @$(foreach ch,$(config_include_HEADERS), \
45           echo "$(USER_INCLUDE_DIR:$(OUTPUT_DIR)/$(addsuffix /,$(SOURCES_LIST_DIR))%=%)/$(ch)" >> "$(SOURCES_LIST).tmp";)
46         @$(foreach h,$(renamed_include_HEADERS),echo '$(h)'|sed -e 's|\(.*\)->.*|$(addsuffix /,$(RELATIVE_DIR:$(SOURCES_LIST_DIR)/%=%))\1|' >> "$(SOURCES_LIST).tmp";)
47         @$(foreach bin,$(lib_LIBRARIES) $(shared_LIBRARIES) $(bin_PROGRAMS) $(test_PROGRAMS) $(utils_PROGRAMS) \
48           $(kernel_LIBRARIES) $(rtlinux_LIBRARIES) $(kernel_MODULES),\
49           $(foreach src,$(filter-out %.o,$($(bin)_SOURCES)),echo "$(addsuffix /,$(RELATIVE_DIR:$(SOURCES_LIST_DIR)/%=%))$(src)" >> "$(SOURCES_LIST).tmp";))
50
51 ############ TAGS ###########
52
53 ifeq ($(MAKECMDGOALS),TAGS)
54 ETAGS=etags
55 TAGS_CMD = $(ETAGS)
56 TAGS: $(SOURCES_LIST)
57         @$(MAKE) --no-print-directory do-tags
58 endif
59 ifeq ($(MAKECMDGOALS),tags) 
60 CTAGS=ctags -N
61 TAGS_CMD = $(CTAGS)
62 tags: $(SOURCES_LIST)
63         @$(MAKE) --no-print-directory do-tags
64 endif
65 export TAGS_CMD
66
67 ifeq ($(MAKECMDGOALS),do-tags)
68 .PHONY: do-tags
69 do-tags: $(shell sed -e '/^\#/d' $(SOURCES_LIST))
70         @$(QUIET_CMD_ECHO) "  TAGS    $(SOURCES_LIST_FN)"
71         $(Q)$(TAGS_CMD) $^
72 endif
73
74 ############ CSCOPE ###########
75
76 cscope: $(SOURCES_LIST)
77         @$(QUIET_CMD_ECHO) "  CSCOPE  < $(SOURCES_LIST_FN)"
78         $(Q)sed -e '/^#/d' $(SOURCES_LIST)|cscope -b -i-
79 #FIXME: see doc to -i in cscope(1)
80
81 # Local Variables:
82 # mode:makefile
83 # End: