tags.sh 4.9 KB
Newer Older
1 2 3 4 5 6 7
#!/bin/sh
# Generate tags or cscope files
# Usage tags.sh <mode>
#
# mode may be any of: tags, TAGS, cscope
#
# Uses the following environment variables:
M
Michal Marek 已提交
8
# ARCH, SUBARCH, SRCARCH, srctree, src, obj
9

10
if [ "$KBUILD_VERBOSE" = "1" ]; then
11 12 13 14 15 16 17 18 19
	set -x
fi

# This is a duplicate of RCS_FIND_IGNORE without escaped '()'
ignore="( -name SCCS -o -name BitKeeper -o -name .svn -o \
          -name CVS  -o -name .pc       -o -name .hg  -o \
          -name .git )                                   \
          -prune -o"

20
# Do not use full path if we do not use O=.. builds
21 22
# Use make O=. {tags|cscope}
# to force full paths for a non-O= build
23
if [ "${KBUILD_SRC}" = "" ]; then
24 25
	tree=
else
J
Jiri Slaby 已提交
26
	tree=${srctree}/
27 28
fi

29 30 31 32 33 34 35 36 37
# Find all available archs
find_all_archs()
{
	ALLSOURCE_ARCHS=""
	for arch in `ls ${tree}arch`; do
		ALLSOURCE_ARCHS="${ALLSOURCE_ARCHS} "${arch##\/}
	done
}

38 39 40
# Detect if ALLSOURCE_ARCHS is set. If not, we assume SRCARCH
if [ "${ALLSOURCE_ARCHS}" = "" ]; then
	ALLSOURCE_ARCHS=${SRCARCH}
41 42
elif [ "${ALLSOURCE_ARCHS}" = "all" ]; then
	find_all_archs
43 44
fi

45 46 47
# find sources in arch/$ARCH
find_arch_sources()
{
48 49 50 51
	for i in $archincludedir; do
		prune="$prune -wholename $i -prune -o"
	done
	find ${tree}arch/$1 $ignore $prune -name "$2" -print;
52 53 54 55 56
}

# find sources in arch/$1/include
find_arch_include_sources()
{
57 58 59 60 61
	include=$(find ${tree}arch/$1/ -name include -type d);
	if [ -n "$include" ]; then
		archincludedir="$archincludedir $include"
		find $include $ignore -name "$2" -print;
	fi
62 63 64 65 66
}

# find sources in include/
find_include_sources()
{
J
Jiri Slaby 已提交
67
	find ${tree}include $ignore -name config -prune -o -name "$1" -print;
68 69 70 71 72 73 74 75
}

# find sources in rest of tree
# we could benefit from a list of dirs to search in here
find_other_sources()
{
	find ${tree}* $ignore \
	     \( -name include -o -name arch -o -name '.tmp_*' \) -prune -o \
J
Jiri Slaby 已提交
76
	       -name "$1" -print;
77 78 79 80
}

find_sources()
{
J
Jiri Slaby 已提交
81
	find_arch_sources $1 "$2"
82 83 84 85
}

all_sources()
{
M
Michal Marek 已提交
86
	find_arch_include_sources ${SRCARCH} '*.[chS]'
87
	if [ ! -z "$archinclude" ]; then
J
Jiri Slaby 已提交
88
		find_arch_include_sources $archinclude '*.[chS]'
89
	fi
90
	find_include_sources '*.[chS]'
91 92 93 94
	for arch in $ALLSOURCE_ARCHS
	do
		find_sources $arch '*.[chS]'
	done
95
	find_other_sources '*.[chS]'
96 97 98 99
}

all_kconfigs()
{
100 101 102 103
	for arch in $ALLSOURCE_ARCHS; do
		find_sources $arch 'Kconfig*'
	done
	find_other_sources 'Kconfig*'
104 105 106 107
}

all_defconfigs()
{
108
	find_sources $ALLSOURCE_ARCHS "defconfig"
109 110 111 112
}

docscope()
{
113
	(echo \-k; echo \-q; all_sources) > cscope.files
114 115 116
	cscope -b -f cscope.out
}

117 118 119 120 121
dogtags()
{
	all_sources | gtags -f -
}

122 123 124 125 126 127 128 129
exuberant()
{
	all_sources | xargs $1 -a                               \
	-I __initdata,__exitdata,__acquires,__releases          \
	-I __read_mostly,____cacheline_aligned                  \
	-I ____cacheline_aligned_in_smp                         \
	-I ____cacheline_internodealigned_in_smp                \
	-I EXPORT_SYMBOL,EXPORT_SYMBOL_GPL                      \
S
Stefani Seibold 已提交
130
	-I DEFINE_TRACE,EXPORT_TRACEPOINT_SYMBOL,EXPORT_TRACEPOINT_SYMBOL_GPL \
131
	--extra=+f --c-kinds=+px                                \
132
	--regex-asm='/^ENTRY\(([^)]*)\).*/\1/'                  \
133 134
	--regex-c='/^SYSCALL_DEFINE[[:digit:]]?\(([^,)]*).*/sys_\1/' \
	--regex-c++='/^TRACE_EVENT\(([^,)]*).*/trace_\1/'		\
135
	--regex-c++='/^DEFINE_EVENT\([^,)]*, *([^,)]*).*/trace_\1/'
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152

	all_kconfigs | xargs $1 -a                              \
	--langdef=kconfig --language-force=kconfig              \
	--regex-kconfig='/^[[:blank:]]*(menu|)config[[:blank:]]+([[:alnum:]_]+)/\2/'

	all_kconfigs | xargs $1 -a                              \
	--langdef=kconfig --language-force=kconfig              \
	--regex-kconfig='/^[[:blank:]]*(menu|)config[[:blank:]]+([[:alnum:]_]+)/CONFIG_\2/'

	all_defconfigs | xargs -r $1 -a                         \
	--langdef=dotconfig --language-force=dotconfig          \
	--regex-dotconfig='/^#?[[:blank:]]*(CONFIG_[[:alnum:]_]+)/\1/'

}

emacs()
{
153 154
	all_sources | xargs $1 -a                               \
	--regex='/^ENTRY(\([^)]*\)).*/\1/'                      \
155 156 157
	--regex='/^SYSCALL_DEFINE[0-9]?(\([^,)]*\).*/sys_\1/'   \
	--regex='/^TRACE_EVENT(\([^,)]*\).*/trace_\1/'		\
	--regex='/^DEFINE_EVENT([^,)]*, *\([^,)]*\).*/trace_\1/'
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181

	all_kconfigs | xargs $1 -a                              \
	--regex='/^[ \t]*\(\(menu\)*config\)[ \t]+\([a-zA-Z0-9_]+\)/\3/'

	all_kconfigs | xargs $1 -a                              \
	--regex='/^[ \t]*\(\(menu\)*config\)[ \t]+\([a-zA-Z0-9_]+\)/CONFIG_\3/'

	all_defconfigs | xargs -r $1 -a                         \
	--regex='/^#?[ \t]?\(CONFIG_[a-zA-Z0-9_]+\)/\1/'
}

xtags()
{
	if $1 --version 2>&1 | grep -iq exuberant; then
		exuberant $1
	elif $1 --version 2>&1 | grep -iq emacs; then
		emacs $1
	else
		all_sources | xargs $1 -a
        fi
}


# Support um (which uses SUBARCH)
182 183
if [ "${ARCH}" = "um" ]; then
	if [ "$SUBARCH" = "i386" ]; then
184
		archinclude=x86
185
	elif [ "$SUBARCH" = "x86_64" ]; then
186 187 188 189 190 191 192 193 194 195 196
		archinclude=x86
	else
		archinclude=${SUBARCH}
	fi
fi

case "$1" in
	"cscope")
		docscope
		;;

197 198 199 200
	"gtags")
		dogtags
		;;

201
	"tags")
202
		rm -f tags
203 204 205 206
		xtags ctags
		;;

	"TAGS")
207
		rm -f TAGS
208 209 210
		xtags etags
		;;
esac