diff options
author | Sam Ravnborg <sam@ravnborg.org> | 2008-12-03 16:24:13 -0500 |
---|---|---|
committer | Sam Ravnborg <sam@ravnborg.org> | 2008-12-03 16:24:13 -0500 |
commit | a680eedc6c621c75695c68198533fc3c98f4053b (patch) | |
tree | c2d1751b5d7ff84aa664e4442ee1e8e2b053c6b9 | |
parent | f6682f915760ccfe57ef1b6cd5ff2d8f2bf8c1d4 (diff) |
tags and cscope support really belongs in a shell script
as they do not benefit from the make functionality.
Moving the support to a shell script has several benefits:
- The readability of the code has increased a lot
- More people is able to extend the tags support
- We see less changes to the top-level Makefile
The shell script version includes improvements from:
Alexey Dobriyan <adobriyan@gmail.com> (jump to kconfig symbols)
Alexey Dobriyan <adobriyan@gmail.com> (drop ./ in paths)
Ian Campbell <ijc@hellion.org.uk> (simplified find algorithms)
This version has a few caveats:
=> It does not support ALLSOURCE_ARCHS
- it is easy to add if it is really used
=> It assumes all archs have moved to arch/$ARCH/include
- until that happens we have a few additional hits in the archs
Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
Cc: Alexey Dobriyan <adobriyan@gmail.com>
Tested-by: Ian Campbell <ijc@hellion.org.uk>
-rw-r--r-- | Makefile | 117 | ||||
-rwxr-xr-x | scripts/tags.sh | 160 |
2 files changed, 163 insertions, 114 deletions
@@ -1409,123 +1409,12 @@ endif # KBUILD_EXTMOD | |||
1409 | 1409 | ||
1410 | # Generate tags for editors | 1410 | # Generate tags for editors |
1411 | # --------------------------------------------------------------------------- | 1411 | # --------------------------------------------------------------------------- |
1412 | quiet_cmd_tags = GEN $@ | ||
1413 | cmd_tags = $(CONFIG_SHELL) $(srctree)/scripts/tags.sh $@ | ||
1412 | 1414 | ||
1413 | #We want __srctree to totally vanish out when KBUILD_OUTPUT is not set | 1415 | tags TAGS cscope: FORCE |
1414 | #(which is the most common case IMHO) to avoid unneeded clutter in the big tags file. | ||
1415 | #Adding $(srctree) adds about 20M on i386 to the size of the output file! | ||
1416 | |||
1417 | ifeq ($(src),$(obj)) | ||
1418 | __srctree = | ||
1419 | else | ||
1420 | __srctree = $(srctree)/ | ||
1421 | endif | ||
1422 | |||
1423 | ifeq ($(ALLSOURCE_ARCHS),) | ||
1424 | ifeq ($(ARCH),um) | ||
1425 | ALLINCLUDE_ARCHS := $(ARCH) $(SUBARCH) | ||
1426 | else | ||
1427 | ALLINCLUDE_ARCHS := $(SRCARCH) | ||
1428 | endif | ||
1429 | else | ||
1430 | #Allow user to specify only ALLSOURCE_PATHS on the command line, keeping existing behaviour. | ||
1431 | ALLINCLUDE_ARCHS := $(ALLSOURCE_ARCHS) | ||
1432 | endif | ||
1433 | |||
1434 | ALLSOURCE_ARCHS := $(SRCARCH) | ||
1435 | |||
1436 | define find-sources | ||
1437 | ( for arch in $(ALLSOURCE_ARCHS) ; do \ | ||
1438 | find $(__srctree)arch/$${arch} $(RCS_FIND_IGNORE) \ | ||
1439 | -wholename $(__srctree)arch/$${arch}/include/asm -type d -prune \ | ||
1440 | -o -name $1 -print; \ | ||
1441 | done ; \ | ||
1442 | find $(__srctree)security/selinux/include $(RCS_FIND_IGNORE) \ | ||
1443 | -name $1 -print; \ | ||
1444 | find $(__srctree)include $(RCS_FIND_IGNORE) \ | ||
1445 | \( -name config -o -name 'asm-*' \) -prune \ | ||
1446 | -o -name $1 -print; \ | ||
1447 | for arch in $(ALLINCLUDE_ARCHS) ; do \ | ||
1448 | test -e $(__srctree)include/asm-$${arch} && \ | ||
1449 | find $(__srctree)include/asm-$${arch} $(RCS_FIND_IGNORE) \ | ||
1450 | -name $1 -print; \ | ||
1451 | test -e $(__srctree)arch/$${arch}/include/asm && \ | ||
1452 | find $(__srctree)arch/$${arch}/include/asm $(RCS_FIND_IGNORE) \ | ||
1453 | -name $1 -print; \ | ||
1454 | done ; \ | ||
1455 | find $(__srctree)include/asm-generic $(RCS_FIND_IGNORE) \ | ||
1456 | -name $1 -print; \ | ||
1457 | find $(__srctree) $(RCS_FIND_IGNORE) \ | ||
1458 | \( -name include -o -name arch -o -name '.tmp_*' \) -prune -o \ | ||
1459 | -name $1 -print; \ | ||
1460 | ) | ||
1461 | endef | ||
1462 | |||
1463 | define all-sources | ||
1464 | $(call find-sources,'*.[chS]') | ||
1465 | endef | ||
1466 | define all-kconfigs | ||
1467 | $(call find-sources,'Kconfig*') | ||
1468 | endef | ||
1469 | define all-defconfigs | ||
1470 | $(call find-sources,'defconfig') | ||
1471 | endef | ||
1472 | |||
1473 | define xtags | ||
1474 | if $1 --version 2>&1 | grep -iq exuberant; then \ | ||
1475 | $(all-sources) | xargs $1 -a \ | ||
1476 | -I __initdata,__exitdata,__acquires,__releases \ | ||
1477 | -I __read_mostly,____cacheline_aligned,____cacheline_aligned_in_smp,____cacheline_internodealigned_in_smp \ | ||
1478 | -I EXPORT_SYMBOL,EXPORT_SYMBOL_GPL \ | ||
1479 | --extra=+f --c-kinds=+px \ | ||
1480 | --regex-asm='/^ENTRY\(([^)]*)\).*/\1/'; \ | ||
1481 | $(all-kconfigs) | xargs $1 -a \ | ||
1482 | --langdef=kconfig \ | ||
1483 | --language-force=kconfig \ | ||
1484 | --regex-kconfig='/^[[:blank:]]*(menu|)config[[:blank:]]+([[:alnum:]_]+)/\2/'; \ | ||
1485 | $(all-defconfigs) | xargs -r $1 -a \ | ||
1486 | --langdef=dotconfig \ | ||
1487 | --language-force=dotconfig \ | ||
1488 | --regex-dotconfig='/^#?[[:blank:]]*(CONFIG_[[:alnum:]_]+)/\1/'; \ | ||
1489 | elif $1 --version 2>&1 | grep -iq emacs; then \ | ||
1490 | $(all-sources) | xargs $1 -a; \ | ||
1491 | $(all-kconfigs) | xargs $1 -a \ | ||
1492 | --regex='/^[ \t]*\(\(menu\)*config\)[ \t]+\([a-zA-Z0-9_]+\)/\3/'; \ | ||
1493 | $(all-defconfigs) | xargs -r $1 -a \ | ||
1494 | --regex='/^#?[ \t]?\(CONFIG_[a-zA-Z0-9_]+\)/\1/'; \ | ||
1495 | else \ | ||
1496 | $(all-sources) | xargs $1 -a; \ | ||
1497 | fi | ||
1498 | endef | ||
1499 | |||
1500 | quiet_cmd_cscope-file = FILELST cscope.files | ||
1501 | cmd_cscope-file = (echo \-k; echo \-q; $(all-sources)) > cscope.files | ||
1502 | |||
1503 | quiet_cmd_cscope = MAKE cscope.out | ||
1504 | cmd_cscope = cscope -b -f cscope.out | ||
1505 | |||
1506 | cscope: FORCE | ||
1507 | $(call cmd,cscope-file) | ||
1508 | $(call cmd,cscope) | ||
1509 | |||
1510 | quiet_cmd_TAGS = MAKE $@ | ||
1511 | define cmd_TAGS | ||
1512 | rm -f $@; \ | ||
1513 | $(call xtags,etags) | ||
1514 | endef | ||
1515 | |||
1516 | TAGS: FORCE | ||
1517 | $(call cmd,TAGS) | ||
1518 | |||
1519 | quiet_cmd_tags = MAKE $@ | ||
1520 | define cmd_tags | ||
1521 | rm -f $@; \ | ||
1522 | $(call xtags,ctags) | ||
1523 | endef | ||
1524 | |||
1525 | tags: FORCE | ||
1526 | $(call cmd,tags) | 1416 | $(call cmd,tags) |
1527 | 1417 | ||
1528 | |||
1529 | # Scripts to check various things for consistency | 1418 | # Scripts to check various things for consistency |
1530 | # --------------------------------------------------------------------------- | 1419 | # --------------------------------------------------------------------------- |
1531 | 1420 | ||
diff --git a/scripts/tags.sh b/scripts/tags.sh new file mode 100755 index 000000000000..47274dc5d823 --- /dev/null +++ b/scripts/tags.sh | |||
@@ -0,0 +1,160 @@ | |||
1 | #!/bin/sh | ||
2 | # Generate tags or cscope files | ||
3 | # Usage tags.sh <mode> | ||
4 | # | ||
5 | # mode may be any of: tags, TAGS, cscope | ||
6 | # | ||
7 | # Uses the following environment variables: | ||
8 | # ARCH, SUBARCH, srctree, src, obj | ||
9 | |||
10 | if [ $KBUILD_VERBOSE == 1 ]; then | ||
11 | set -x | ||
12 | fi | ||
13 | |||
14 | # This is a duplicate of RCS_FIND_IGNORE without escaped '()' | ||
15 | ignore="( -name SCCS -o -name BitKeeper -o -name .svn -o \ | ||
16 | -name CVS -o -name .pc -o -name .hg -o \ | ||
17 | -name .git ) \ | ||
18 | -prune -o" | ||
19 | |||
20 | # Do not use full path is we do not use O=.. builds | ||
21 | if [ ${src} == ${obj} ]; then | ||
22 | tree= | ||
23 | else | ||
24 | tree=${srctree} | ||
25 | fi | ||
26 | |||
27 | # find sources in arch/$ARCH | ||
28 | find_arch_sources() | ||
29 | { | ||
30 | find ${tree}arch/$1 $ignore -name $2 -print; | ||
31 | } | ||
32 | |||
33 | # find sources in arch/$1/include | ||
34 | find_arch_include_sources() | ||
35 | { | ||
36 | find ${tree}arch/$1/include $ignore -name $2 -print; | ||
37 | } | ||
38 | |||
39 | # find sources in include/ | ||
40 | find_include_sources() | ||
41 | { | ||
42 | find ${tree}include $ignore -name config -prune -o -name $1 -print; | ||
43 | } | ||
44 | |||
45 | # find sources in rest of tree | ||
46 | # we could benefit from a list of dirs to search in here | ||
47 | find_other_sources() | ||
48 | { | ||
49 | find ${tree}* $ignore \ | ||
50 | \( -name include -o -name arch -o -name '.tmp_*' \) -prune -o \ | ||
51 | -name $1 -print; | ||
52 | } | ||
53 | |||
54 | find_sources() | ||
55 | { | ||
56 | find_arch_sources $1 $2 | ||
57 | find_include_sources $2 | ||
58 | find_other_sources $2 | ||
59 | } | ||
60 | |||
61 | all_sources() | ||
62 | { | ||
63 | find_sources $SRCARCH *.[chS] | ||
64 | if [ ! -z "$archinclude" ]; then | ||
65 | find_arch_include_sources $archinclude *.[chS] | ||
66 | fi | ||
67 | } | ||
68 | |||
69 | all_kconfigs() | ||
70 | { | ||
71 | find_sources $SRCARCH "Kconfig*" | ||
72 | } | ||
73 | |||
74 | all_defconfigs() | ||
75 | { | ||
76 | find_sources $SRCARCH "defconfig" | ||
77 | } | ||
78 | |||
79 | docscope() | ||
80 | { | ||
81 | (echo \-k; echo \-q; all_sources) > cscope.files | ||
82 | cscope -b -f cscope.out | ||
83 | } | ||
84 | |||
85 | exuberant() | ||
86 | { | ||
87 | all_sources > all | ||
88 | all_sources | xargs $1 -a \ | ||
89 | -I __initdata,__exitdata,__acquires,__releases \ | ||
90 | -I __read_mostly,____cacheline_aligned \ | ||
91 | -I ____cacheline_aligned_in_smp \ | ||
92 | -I ____cacheline_internodealigned_in_smp \ | ||
93 | -I EXPORT_SYMBOL,EXPORT_SYMBOL_GPL \ | ||
94 | --extra=+f --c-kinds=+px \ | ||
95 | --regex-asm='/^ENTRY\(([^)]*)\).*/\1/' | ||
96 | |||
97 | all_kconfigs | xargs $1 -a \ | ||
98 | --langdef=kconfig --language-force=kconfig \ | ||
99 | --regex-kconfig='/^[[:blank:]]*(menu|)config[[:blank:]]+([[:alnum:]_]+)/\2/' | ||
100 | |||
101 | all_kconfigs | xargs $1 -a \ | ||
102 | --langdef=kconfig --language-force=kconfig \ | ||
103 | --regex-kconfig='/^[[:blank:]]*(menu|)config[[:blank:]]+([[:alnum:]_]+)/CONFIG_\2/' | ||
104 | |||
105 | all_defconfigs | xargs -r $1 -a \ | ||
106 | --langdef=dotconfig --language-force=dotconfig \ | ||
107 | --regex-dotconfig='/^#?[[:blank:]]*(CONFIG_[[:alnum:]_]+)/\1/' | ||
108 | |||
109 | } | ||
110 | |||
111 | emacs() | ||
112 | { | ||
113 | all_sources | xargs $1 -a | ||
114 | |||
115 | all_kconfigs | xargs $1 -a \ | ||
116 | --regex='/^[ \t]*\(\(menu\)*config\)[ \t]+\([a-zA-Z0-9_]+\)/\3/' | ||
117 | |||
118 | all_kconfigs | xargs $1 -a \ | ||
119 | --regex='/^[ \t]*\(\(menu\)*config\)[ \t]+\([a-zA-Z0-9_]+\)/CONFIG_\3/' | ||
120 | |||
121 | all_defconfigs | xargs -r $1 -a \ | ||
122 | --regex='/^#?[ \t]?\(CONFIG_[a-zA-Z0-9_]+\)/\1/' | ||
123 | } | ||
124 | |||
125 | xtags() | ||
126 | { | ||
127 | if $1 --version 2>&1 | grep -iq exuberant; then | ||
128 | exuberant $1 | ||
129 | elif $1 --version 2>&1 | grep -iq emacs; then | ||
130 | emacs $1 | ||
131 | else | ||
132 | all_sources | xargs $1 -a | ||
133 | fi | ||
134 | } | ||
135 | |||
136 | |||
137 | # Support um (which uses SUBARCH) | ||
138 | if [ ${ARCH} == um ]; then | ||
139 | if [ $SUBARCH == i386 ]; then | ||
140 | archinclude=x86 | ||
141 | elif [ $SUBARCH == x86_64 ]; then | ||
142 | archinclude=x86 | ||
143 | else | ||
144 | archinclude=${SUBARCH} | ||
145 | fi | ||
146 | fi | ||
147 | |||
148 | case "$1" in | ||
149 | "cscope") | ||
150 | docscope | ||
151 | ;; | ||
152 | |||
153 | "tags") | ||
154 | xtags ctags | ||
155 | ;; | ||
156 | |||
157 | "TAGS") | ||
158 | xtags etags | ||
159 | ;; | ||
160 | esac | ||