summaryrefslogtreecommitdiff
path: root/firmware/ctags.mk
blob: 12f31b4a2f961649536e0cef7dd6ff9a1d6a003a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
CTAGS  ?= /usr/bin/ctags-exuberant
CSCOPE ?= /usr/bin/cscope
MKID   ?= /usr/bin/mkid

#
# This requires GNUMake and that /bin/sh is bash.
# NOTES:
#   $${src:0:1} returns the first character in the variable.
#   nullglob: Stop *.h glob from being '*.h' if no headers present.
#

cscope.files:
	@echo "Generating ctags file list for $(TARGET)" 1>&2
	@set -e; \
	for src in $(SRC) $(CPPSRC); \
	do \
		if [ "$${src:0:1}" = "/" ]; \
		then \
			echo $${src}; \
		else \
			echo $(abspath $${src}); \
		fi; \
	done > $@
	@set -e; \
	shopt -s nullglob; \
	for inc in $(CURDIR) $(EXTRAINCDIRS); \
	do \
		for hdr in $${inc}/*.h; \
		do \
			if [ "$${hdr:0:1}" = "/" ]; \
			then \
				echo $${hdr}; \
			else \
				echo $(abspath $${hdr}); \
			fi; \
		done; \
	done >> $@
	@cat $@ | tr '\n' '\0' >$@.0

ctags: cscope.files
	@echo "Generating index files for $(TARGET)" 1>&2
	@${CTAGS} --totals --fields=+iaS --extra="+qf" --c++-kinds="+p" -L $< >tags.log 2>&1
	@rm tags.log
	@${CTAGS} -e --totals --fields=+iaS --extra="+qf" --c++-kinds="-p" -L $< >TAGS.log 2>&1
	@rm TAGS.log
	@$(CSCOPE) -b -q -i $<  >cscope.log 2>&1
	@rm cscope.log
	@$(MKID) --files0-from=$<.0

ctags_clean:
	rm -rf tags TAGS cscope* ID

.PHONY: ctags ctags_clean cscope.files