blob: 3c814ba0fa85850a53099b96ef630675ff0b68ce [file] [log] [blame]
Sam Ravnborga680eed2008-12-03 22:24:13 +01001#!/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
10if [ $KBUILD_VERBOSE == 1 ]; then
11 set -x
12fi
13
14# This is a duplicate of RCS_FIND_IGNORE without escaped '()'
15ignore="( -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
Jiri Slaby709cc372008-12-10 13:10:13 +010021if [ "${KBUILD_SRC}" == "" ]; then
Sam Ravnborga680eed2008-12-03 22:24:13 +010022 tree=
23else
Jiri Slaby709cc372008-12-10 13:10:13 +010024 tree=${srctree}/
Sam Ravnborga680eed2008-12-03 22:24:13 +010025fi
26
27# find sources in arch/$ARCH
28find_arch_sources()
29{
Jiri Slaby709cc372008-12-10 13:10:13 +010030 find ${tree}arch/$1 $ignore -name "$2" -print;
Sam Ravnborga680eed2008-12-03 22:24:13 +010031}
32
33# find sources in arch/$1/include
34find_arch_include_sources()
35{
Jiri Slaby709cc372008-12-10 13:10:13 +010036 find ${tree}arch/$1/include $ignore -name "$2" -print;
Sam Ravnborga680eed2008-12-03 22:24:13 +010037}
38
39# find sources in include/
40find_include_sources()
41{
Jiri Slaby709cc372008-12-10 13:10:13 +010042 find ${tree}include $ignore -name config -prune -o -name "$1" -print;
Sam Ravnborga680eed2008-12-03 22:24:13 +010043}
44
45# find sources in rest of tree
46# we could benefit from a list of dirs to search in here
47find_other_sources()
48{
49 find ${tree}* $ignore \
50 \( -name include -o -name arch -o -name '.tmp_*' \) -prune -o \
Jiri Slaby709cc372008-12-10 13:10:13 +010051 -name "$1" -print;
Sam Ravnborga680eed2008-12-03 22:24:13 +010052}
53
54find_sources()
55{
Jiri Slaby709cc372008-12-10 13:10:13 +010056 find_arch_sources $1 "$2"
57 find_include_sources "$2"
58 find_other_sources "$2"
Sam Ravnborga680eed2008-12-03 22:24:13 +010059}
60
61all_sources()
62{
Jiri Slaby709cc372008-12-10 13:10:13 +010063 find_sources $SRCARCH '*.[chS]'
Sam Ravnborga680eed2008-12-03 22:24:13 +010064 if [ ! -z "$archinclude" ]; then
Jiri Slaby709cc372008-12-10 13:10:13 +010065 find_arch_include_sources $archinclude '*.[chS]'
Sam Ravnborga680eed2008-12-03 22:24:13 +010066 fi
67}
68
69all_kconfigs()
70{
Jiri Slaby709cc372008-12-10 13:10:13 +010071 find_sources $SRCARCH 'Kconfig*'
Sam Ravnborga680eed2008-12-03 22:24:13 +010072}
73
74all_defconfigs()
75{
76 find_sources $SRCARCH "defconfig"
77}
78
79docscope()
80{
81 (echo \-k; echo \-q; all_sources) > cscope.files
82 cscope -b -f cscope.out
83}
84
85exuberant()
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
111emacs()
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
125xtags()
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)
138if [ ${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
146fi
147
148case "$1" in
149 "cscope")
150 docscope
151 ;;
152
153 "tags")
154 xtags ctags
155 ;;
156
157 "TAGS")
158 xtags etags
159 ;;
160esac