Commit | Line | Data |
---|---|---|
a680eedc SR |
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: | |
a8bac511 | 8 | # ARCH, SUBARCH, SRCARCH, srctree, src, obj |
a680eedc | 9 | |
a6ba0cb3 | 10 | if [ "$KBUILD_VERBOSE" = "1" ]; then |
a680eedc SR |
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 | ||
4431d4ce | 20 | # Do not use full path if we do not use O=.. builds |
a6ba0cb3 | 21 | if [ "${KBUILD_SRC}" = "" ]; then |
a680eedc SR |
22 | tree= |
23 | else | |
709cc372 | 24 | tree=${srctree}/ |
a680eedc SR |
25 | fi |
26 | ||
bc75cc6b JK |
27 | # Find all available archs |
28 | find_all_archs() | |
29 | { | |
30 | ALLSOURCE_ARCHS="" | |
31 | for arch in `ls ${tree}arch`; do | |
32 | ALLSOURCE_ARCHS="${ALLSOURCE_ARCHS} "${arch##\/} | |
33 | done | |
34 | } | |
35 | ||
4f628248 JS |
36 | # Detect if ALLSOURCE_ARCHS is set. If not, we assume SRCARCH |
37 | if [ "${ALLSOURCE_ARCHS}" = "" ]; then | |
38 | ALLSOURCE_ARCHS=${SRCARCH} | |
bc75cc6b JK |
39 | elif [ "${ALLSOURCE_ARCHS}" = "all" ]; then |
40 | find_all_archs | |
4f628248 JS |
41 | fi |
42 | ||
a680eedc SR |
43 | # find sources in arch/$ARCH |
44 | find_arch_sources() | |
45 | { | |
f81b1be4 GL |
46 | for i in $archincludedir; do |
47 | prune="$prune -wholename $i -prune -o" | |
48 | done | |
49 | find ${tree}arch/$1 $ignore $prune -name "$2" -print; | |
a680eedc SR |
50 | } |
51 | ||
52 | # find sources in arch/$1/include | |
53 | find_arch_include_sources() | |
54 | { | |
f81b1be4 GL |
55 | include=$(find ${tree}arch/$1/ -name include -type d); |
56 | if [ -n "$include" ]; then | |
57 | archincludedir="$archincludedir $include" | |
58 | find $include $ignore -name "$2" -print; | |
59 | fi | |
a680eedc SR |
60 | } |
61 | ||
62 | # find sources in include/ | |
63 | find_include_sources() | |
64 | { | |
709cc372 | 65 | find ${tree}include $ignore -name config -prune -o -name "$1" -print; |
a680eedc SR |
66 | } |
67 | ||
68 | # find sources in rest of tree | |
69 | # we could benefit from a list of dirs to search in here | |
70 | find_other_sources() | |
71 | { | |
72 | find ${tree}* $ignore \ | |
73 | \( -name include -o -name arch -o -name '.tmp_*' \) -prune -o \ | |
709cc372 | 74 | -name "$1" -print; |
a680eedc SR |
75 | } |
76 | ||
77 | find_sources() | |
78 | { | |
709cc372 | 79 | find_arch_sources $1 "$2" |
a680eedc SR |
80 | } |
81 | ||
82 | all_sources() | |
83 | { | |
a8bac511 | 84 | find_arch_include_sources ${SRCARCH} '*.[chS]' |
a680eedc | 85 | if [ ! -z "$archinclude" ]; then |
709cc372 | 86 | find_arch_include_sources $archinclude '*.[chS]' |
a680eedc | 87 | fi |
4f628248 | 88 | find_include_sources '*.[chS]' |
f81b1be4 GL |
89 | for arch in $ALLSOURCE_ARCHS |
90 | do | |
91 | find_sources $arch '*.[chS]' | |
92 | done | |
4f628248 | 93 | find_other_sources '*.[chS]' |
a680eedc SR |
94 | } |
95 | ||
96 | all_kconfigs() | |
97 | { | |
953fae66 AD |
98 | for arch in $ALLSOURCE_ARCHS; do |
99 | find_sources $arch 'Kconfig*' | |
100 | done | |
101 | find_other_sources 'Kconfig*' | |
a680eedc SR |
102 | } |
103 | ||
104 | all_defconfigs() | |
105 | { | |
4f628248 | 106 | find_sources $ALLSOURCE_ARCHS "defconfig" |
a680eedc SR |
107 | } |
108 | ||
109 | docscope() | |
110 | { | |
eb8f844c DV |
111 | # always use absolute paths for cscope, as recommended by cscope |
112 | # upstream | |
113 | case "$tree" in | |
114 | /*) ;; | |
115 | *) tree=$PWD/$tree ;; | |
116 | esac | |
117 | (cd /; echo \-k; echo \-q; all_sources) > cscope.files | |
a680eedc SR |
118 | cscope -b -f cscope.out |
119 | } | |
120 | ||
121 | exuberant() | |
122 | { | |
a680eedc SR |
123 | all_sources | xargs $1 -a \ |
124 | -I __initdata,__exitdata,__acquires,__releases \ | |
125 | -I __read_mostly,____cacheline_aligned \ | |
126 | -I ____cacheline_aligned_in_smp \ | |
127 | -I ____cacheline_internodealigned_in_smp \ | |
128 | -I EXPORT_SYMBOL,EXPORT_SYMBOL_GPL \ | |
7db86dc9 SS |
129 | -I DEFINE_TRACE,EXPORT_TRACEPOINT_SYMBOL,EXPORT_TRACEPOINT_SYMBOL_GPL \ |
130 | --extra=+f --c-kinds=-px \ | |
5123b327 RV |
131 | --regex-asm='/^ENTRY\(([^)]*)\).*/\1/' \ |
132 | --regex-c='/^SYSCALL_DEFINE[[:digit:]]?\(([^,)]*).*/sys_\1/' | |
a680eedc SR |
133 | |
134 | all_kconfigs | xargs $1 -a \ | |
135 | --langdef=kconfig --language-force=kconfig \ | |
136 | --regex-kconfig='/^[[:blank:]]*(menu|)config[[:blank:]]+([[:alnum:]_]+)/\2/' | |
137 | ||
138 | all_kconfigs | xargs $1 -a \ | |
139 | --langdef=kconfig --language-force=kconfig \ | |
140 | --regex-kconfig='/^[[:blank:]]*(menu|)config[[:blank:]]+([[:alnum:]_]+)/CONFIG_\2/' | |
141 | ||
142 | all_defconfigs | xargs -r $1 -a \ | |
143 | --langdef=dotconfig --language-force=dotconfig \ | |
144 | --regex-dotconfig='/^#?[[:blank:]]*(CONFIG_[[:alnum:]_]+)/\1/' | |
145 | ||
146 | } | |
147 | ||
148 | emacs() | |
149 | { | |
5123b327 RV |
150 | all_sources | xargs $1 -a \ |
151 | --regex='/^ENTRY(\([^)]*\)).*/\1/' \ | |
152 | --regex='/^SYSCALL_DEFINE[0-9]?(\([^,)]*\).*/sys_\1/' | |
a680eedc SR |
153 | |
154 | all_kconfigs | xargs $1 -a \ | |
155 | --regex='/^[ \t]*\(\(menu\)*config\)[ \t]+\([a-zA-Z0-9_]+\)/\3/' | |
156 | ||
157 | all_kconfigs | xargs $1 -a \ | |
158 | --regex='/^[ \t]*\(\(menu\)*config\)[ \t]+\([a-zA-Z0-9_]+\)/CONFIG_\3/' | |
159 | ||
160 | all_defconfigs | xargs -r $1 -a \ | |
161 | --regex='/^#?[ \t]?\(CONFIG_[a-zA-Z0-9_]+\)/\1/' | |
162 | } | |
163 | ||
164 | xtags() | |
165 | { | |
166 | if $1 --version 2>&1 | grep -iq exuberant; then | |
167 | exuberant $1 | |
168 | elif $1 --version 2>&1 | grep -iq emacs; then | |
169 | emacs $1 | |
170 | else | |
171 | all_sources | xargs $1 -a | |
172 | fi | |
173 | } | |
174 | ||
175 | ||
176 | # Support um (which uses SUBARCH) | |
a6ba0cb3 JS |
177 | if [ "${ARCH}" = "um" ]; then |
178 | if [ "$SUBARCH" = "i386" ]; then | |
a680eedc | 179 | archinclude=x86 |
a6ba0cb3 | 180 | elif [ "$SUBARCH" = "x86_64" ]; then |
a680eedc SR |
181 | archinclude=x86 |
182 | else | |
183 | archinclude=${SUBARCH} | |
184 | fi | |
185 | fi | |
186 | ||
187 | case "$1" in | |
188 | "cscope") | |
189 | docscope | |
190 | ;; | |
191 | ||
192 | "tags") | |
2e6cb8b0 | 193 | rm -f tags |
a680eedc SR |
194 | xtags ctags |
195 | ;; | |
196 | ||
197 | "TAGS") | |
2e6cb8b0 | 198 | rm -f TAGS |
a680eedc SR |
199 | xtags etags |
200 | ;; | |
201 | esac |