blob: caa867dba16de32aad4a2494e2f3d04bdb3d6f86 [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:
Michal Mareka8bac512010-02-19 16:18:41 +01008# ARCH, SUBARCH, SRCARCH, srctree, src, obj
Sam Ravnborga680eed2008-12-03 22:24:13 +01009
Jiri Slabya6ba0cb2008-12-10 13:48:38 +010010if [ "$KBUILD_VERBOSE" = "1" ]; then
Sam Ravnborga680eed2008-12-03 22:24:13 +010011 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
John Kacur4431d4c2010-03-02 15:38:10 +010020# Do not use full path if we do not use O=.. builds
Jiri Slabya6ba0cb2008-12-10 13:48:38 +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
Jike Song4f628242009-01-05 14:57:03 +080027# Detect if ALLSOURCE_ARCHS is set. If not, we assume SRCARCH
28if [ "${ALLSOURCE_ARCHS}" = "" ]; then
29 ALLSOURCE_ARCHS=${SRCARCH}
30fi
31
Sam Ravnborga680eed2008-12-03 22:24:13 +010032# find sources in arch/$ARCH
33find_arch_sources()
34{
Guennadi Liakhovetskif81b1be2010-02-08 00:25:59 +010035 for i in $archincludedir; do
36 prune="$prune -wholename $i -prune -o"
37 done
38 find ${tree}arch/$1 $ignore $prune -name "$2" -print;
Sam Ravnborga680eed2008-12-03 22:24:13 +010039}
40
41# find sources in arch/$1/include
42find_arch_include_sources()
43{
Guennadi Liakhovetskif81b1be2010-02-08 00:25:59 +010044 include=$(find ${tree}arch/$1/ -name include -type d);
45 if [ -n "$include" ]; then
46 archincludedir="$archincludedir $include"
47 find $include $ignore -name "$2" -print;
48 fi
Sam Ravnborga680eed2008-12-03 22:24:13 +010049}
50
51# find sources in include/
52find_include_sources()
53{
Jiri Slaby709cc372008-12-10 13:10:13 +010054 find ${tree}include $ignore -name config -prune -o -name "$1" -print;
Sam Ravnborga680eed2008-12-03 22:24:13 +010055}
56
57# find sources in rest of tree
58# we could benefit from a list of dirs to search in here
59find_other_sources()
60{
61 find ${tree}* $ignore \
62 \( -name include -o -name arch -o -name '.tmp_*' \) -prune -o \
Jiri Slaby709cc372008-12-10 13:10:13 +010063 -name "$1" -print;
Sam Ravnborga680eed2008-12-03 22:24:13 +010064}
65
66find_sources()
67{
Jiri Slaby709cc372008-12-10 13:10:13 +010068 find_arch_sources $1 "$2"
Sam Ravnborga680eed2008-12-03 22:24:13 +010069}
70
71all_sources()
72{
Michal Mareka8bac512010-02-19 16:18:41 +010073 find_arch_include_sources ${SRCARCH} '*.[chS]'
Sam Ravnborga680eed2008-12-03 22:24:13 +010074 if [ ! -z "$archinclude" ]; then
Jiri Slaby709cc372008-12-10 13:10:13 +010075 find_arch_include_sources $archinclude '*.[chS]'
Sam Ravnborga680eed2008-12-03 22:24:13 +010076 fi
Jike Song4f628242009-01-05 14:57:03 +080077 find_include_sources '*.[chS]'
Guennadi Liakhovetskif81b1be2010-02-08 00:25:59 +010078 for arch in $ALLSOURCE_ARCHS
79 do
80 find_sources $arch '*.[chS]'
81 done
Jike Song4f628242009-01-05 14:57:03 +080082 find_other_sources '*.[chS]'
Sam Ravnborga680eed2008-12-03 22:24:13 +010083}
84
85all_kconfigs()
86{
Alexey Dobriyan953fae62009-02-11 13:24:09 -080087 for arch in $ALLSOURCE_ARCHS; do
88 find_sources $arch 'Kconfig*'
89 done
90 find_other_sources 'Kconfig*'
Sam Ravnborga680eed2008-12-03 22:24:13 +010091}
92
93all_defconfigs()
94{
Jike Song4f628242009-01-05 14:57:03 +080095 find_sources $ALLSOURCE_ARCHS "defconfig"
Sam Ravnborga680eed2008-12-03 22:24:13 +010096}
97
98docscope()
99{
Daniel Vettereb8f8442009-11-26 13:34:12 +0100100 # always use absolute paths for cscope, as recommended by cscope
101 # upstream
102 case "$tree" in
103 /*) ;;
104 *) tree=$PWD/$tree ;;
105 esac
106 (cd /; echo \-k; echo \-q; all_sources) > cscope.files
Sam Ravnborga680eed2008-12-03 22:24:13 +0100107 cscope -b -f cscope.out
108}
109
110exuberant()
111{
Sam Ravnborga680eed2008-12-03 22:24:13 +0100112 all_sources | xargs $1 -a \
113 -I __initdata,__exitdata,__acquires,__releases \
114 -I __read_mostly,____cacheline_aligned \
115 -I ____cacheline_aligned_in_smp \
116 -I ____cacheline_internodealigned_in_smp \
117 -I EXPORT_SYMBOL,EXPORT_SYMBOL_GPL \
Stefani Seibold7db86dc2009-09-18 12:49:24 -0700118 -I DEFINE_TRACE,EXPORT_TRACEPOINT_SYMBOL,EXPORT_TRACEPOINT_SYMBOL_GPL \
119 --extra=+f --c-kinds=-px \
Rabin Vincent5123b322009-01-25 18:39:12 +0530120 --regex-asm='/^ENTRY\(([^)]*)\).*/\1/' \
121 --regex-c='/^SYSCALL_DEFINE[[:digit:]]?\(([^,)]*).*/sys_\1/'
Sam Ravnborga680eed2008-12-03 22:24:13 +0100122
123 all_kconfigs | xargs $1 -a \
124 --langdef=kconfig --language-force=kconfig \
125 --regex-kconfig='/^[[:blank:]]*(menu|)config[[:blank:]]+([[:alnum:]_]+)/\2/'
126
127 all_kconfigs | xargs $1 -a \
128 --langdef=kconfig --language-force=kconfig \
129 --regex-kconfig='/^[[:blank:]]*(menu|)config[[:blank:]]+([[:alnum:]_]+)/CONFIG_\2/'
130
131 all_defconfigs | xargs -r $1 -a \
132 --langdef=dotconfig --language-force=dotconfig \
133 --regex-dotconfig='/^#?[[:blank:]]*(CONFIG_[[:alnum:]_]+)/\1/'
134
135}
136
137emacs()
138{
Rabin Vincent5123b322009-01-25 18:39:12 +0530139 all_sources | xargs $1 -a \
140 --regex='/^ENTRY(\([^)]*\)).*/\1/' \
141 --regex='/^SYSCALL_DEFINE[0-9]?(\([^,)]*\).*/sys_\1/'
Sam Ravnborga680eed2008-12-03 22:24:13 +0100142
143 all_kconfigs | xargs $1 -a \
144 --regex='/^[ \t]*\(\(menu\)*config\)[ \t]+\([a-zA-Z0-9_]+\)/\3/'
145
146 all_kconfigs | xargs $1 -a \
147 --regex='/^[ \t]*\(\(menu\)*config\)[ \t]+\([a-zA-Z0-9_]+\)/CONFIG_\3/'
148
149 all_defconfigs | xargs -r $1 -a \
150 --regex='/^#?[ \t]?\(CONFIG_[a-zA-Z0-9_]+\)/\1/'
151}
152
153xtags()
154{
155 if $1 --version 2>&1 | grep -iq exuberant; then
156 exuberant $1
157 elif $1 --version 2>&1 | grep -iq emacs; then
158 emacs $1
159 else
160 all_sources | xargs $1 -a
161 fi
162}
163
164
165# Support um (which uses SUBARCH)
Jiri Slabya6ba0cb2008-12-10 13:48:38 +0100166if [ "${ARCH}" = "um" ]; then
167 if [ "$SUBARCH" = "i386" ]; then
Sam Ravnborga680eed2008-12-03 22:24:13 +0100168 archinclude=x86
Jiri Slabya6ba0cb2008-12-10 13:48:38 +0100169 elif [ "$SUBARCH" = "x86_64" ]; then
Sam Ravnborga680eed2008-12-03 22:24:13 +0100170 archinclude=x86
171 else
172 archinclude=${SUBARCH}
173 fi
174fi
175
176case "$1" in
177 "cscope")
178 docscope
179 ;;
180
181 "tags")
Matt Kraai2e6cb8b2009-04-21 20:38:23 -0700182 rm -f tags
Sam Ravnborga680eed2008-12-03 22:24:13 +0100183 xtags ctags
184 ;;
185
186 "TAGS")
Matt Kraai2e6cb8b2009-04-21 20:38:23 -0700187 rm -f TAGS
Sam Ravnborga680eed2008-12-03 22:24:13 +0100188 xtags etags
189 ;;
190esac