blob: 4a34ec591e8c05f224f4900028f0e25f99e9eeba [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
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
20# Do not use full path is 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{
Jiri Slaby709cc372008-12-10 13:10:13 +010035 find ${tree}arch/$1 $ignore -name "$2" -print;
Sam Ravnborga680eed2008-12-03 22:24:13 +010036}
37
38# find sources in arch/$1/include
39find_arch_include_sources()
40{
Jiri Slaby709cc372008-12-10 13:10:13 +010041 find ${tree}arch/$1/include $ignore -name "$2" -print;
Sam Ravnborga680eed2008-12-03 22:24:13 +010042}
43
44# find sources in include/
45find_include_sources()
46{
Jiri Slaby709cc372008-12-10 13:10:13 +010047 find ${tree}include $ignore -name config -prune -o -name "$1" -print;
Sam Ravnborga680eed2008-12-03 22:24:13 +010048}
49
50# find sources in rest of tree
51# we could benefit from a list of dirs to search in here
52find_other_sources()
53{
54 find ${tree}* $ignore \
55 \( -name include -o -name arch -o -name '.tmp_*' \) -prune -o \
Jiri Slaby709cc372008-12-10 13:10:13 +010056 -name "$1" -print;
Sam Ravnborga680eed2008-12-03 22:24:13 +010057}
58
59find_sources()
60{
Jiri Slaby709cc372008-12-10 13:10:13 +010061 find_arch_sources $1 "$2"
Sam Ravnborga680eed2008-12-03 22:24:13 +010062}
63
64all_sources()
65{
Jike Song4f628242009-01-05 14:57:03 +080066 for arch in $ALLSOURCE_ARCHS
67 do
68 find_sources $arch '*.[chS]'
69 done
Sam Ravnborga680eed2008-12-03 22:24:13 +010070 if [ ! -z "$archinclude" ]; then
Jiri Slaby709cc372008-12-10 13:10:13 +010071 find_arch_include_sources $archinclude '*.[chS]'
Sam Ravnborga680eed2008-12-03 22:24:13 +010072 fi
Jike Song4f628242009-01-05 14:57:03 +080073 find_include_sources '*.[chS]'
74 find_other_sources '*.[chS]'
Sam Ravnborga680eed2008-12-03 22:24:13 +010075}
76
77all_kconfigs()
78{
Alexey Dobriyan953fae62009-02-11 13:24:09 -080079 for arch in $ALLSOURCE_ARCHS; do
80 find_sources $arch 'Kconfig*'
81 done
82 find_other_sources 'Kconfig*'
Sam Ravnborga680eed2008-12-03 22:24:13 +010083}
84
85all_defconfigs()
86{
Jike Song4f628242009-01-05 14:57:03 +080087 find_sources $ALLSOURCE_ARCHS "defconfig"
Sam Ravnborga680eed2008-12-03 22:24:13 +010088}
89
90docscope()
91{
92 (echo \-k; echo \-q; all_sources) > cscope.files
93 cscope -b -f cscope.out
94}
95
96exuberant()
97{
Sam Ravnborga680eed2008-12-03 22:24:13 +010098 all_sources | xargs $1 -a \
99 -I __initdata,__exitdata,__acquires,__releases \
100 -I __read_mostly,____cacheline_aligned \
101 -I ____cacheline_aligned_in_smp \
102 -I ____cacheline_internodealigned_in_smp \
103 -I EXPORT_SYMBOL,EXPORT_SYMBOL_GPL \
104 --extra=+f --c-kinds=+px \
Rabin Vincent5123b322009-01-25 18:39:12 +0530105 --regex-asm='/^ENTRY\(([^)]*)\).*/\1/' \
106 --regex-c='/^SYSCALL_DEFINE[[:digit:]]?\(([^,)]*).*/sys_\1/'
Sam Ravnborga680eed2008-12-03 22:24:13 +0100107
108 all_kconfigs | xargs $1 -a \
109 --langdef=kconfig --language-force=kconfig \
110 --regex-kconfig='/^[[:blank:]]*(menu|)config[[:blank:]]+([[:alnum:]_]+)/\2/'
111
112 all_kconfigs | xargs $1 -a \
113 --langdef=kconfig --language-force=kconfig \
114 --regex-kconfig='/^[[:blank:]]*(menu|)config[[:blank:]]+([[:alnum:]_]+)/CONFIG_\2/'
115
116 all_defconfigs | xargs -r $1 -a \
117 --langdef=dotconfig --language-force=dotconfig \
118 --regex-dotconfig='/^#?[[:blank:]]*(CONFIG_[[:alnum:]_]+)/\1/'
119
120}
121
122emacs()
123{
Rabin Vincent5123b322009-01-25 18:39:12 +0530124 all_sources | xargs $1 -a \
125 --regex='/^ENTRY(\([^)]*\)).*/\1/' \
126 --regex='/^SYSCALL_DEFINE[0-9]?(\([^,)]*\).*/sys_\1/'
Sam Ravnborga680eed2008-12-03 22:24:13 +0100127
128 all_kconfigs | xargs $1 -a \
129 --regex='/^[ \t]*\(\(menu\)*config\)[ \t]+\([a-zA-Z0-9_]+\)/\3/'
130
131 all_kconfigs | xargs $1 -a \
132 --regex='/^[ \t]*\(\(menu\)*config\)[ \t]+\([a-zA-Z0-9_]+\)/CONFIG_\3/'
133
134 all_defconfigs | xargs -r $1 -a \
135 --regex='/^#?[ \t]?\(CONFIG_[a-zA-Z0-9_]+\)/\1/'
136}
137
138xtags()
139{
140 if $1 --version 2>&1 | grep -iq exuberant; then
141 exuberant $1
142 elif $1 --version 2>&1 | grep -iq emacs; then
143 emacs $1
144 else
145 all_sources | xargs $1 -a
146 fi
147}
148
149
150# Support um (which uses SUBARCH)
Jiri Slabya6ba0cb2008-12-10 13:48:38 +0100151if [ "${ARCH}" = "um" ]; then
152 if [ "$SUBARCH" = "i386" ]; then
Sam Ravnborga680eed2008-12-03 22:24:13 +0100153 archinclude=x86
Jiri Slabya6ba0cb2008-12-10 13:48:38 +0100154 elif [ "$SUBARCH" = "x86_64" ]; then
Sam Ravnborga680eed2008-12-03 22:24:13 +0100155 archinclude=x86
156 else
157 archinclude=${SUBARCH}
158 fi
159fi
160
161case "$1" in
162 "cscope")
163 docscope
164 ;;
165
166 "tags")
Matt Kraai2e6cb8b2009-04-21 20:38:23 -0700167 rm -f tags
Sam Ravnborga680eed2008-12-03 22:24:13 +0100168 xtags ctags
169 ;;
170
171 "TAGS")
Matt Kraai2e6cb8b2009-04-21 20:38:23 -0700172 rm -f TAGS
Sam Ravnborga680eed2008-12-03 22:24:13 +0100173 xtags etags
174 ;;
175esac