tags: Add the ability to make tags for all archs using "all"
[linux-2.6.git] / scripts / tags.sh
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:
8 # ARCH, SUBARCH, SRCARCH, srctree, src, obj
9
10 if [ "$KBUILD_VERBOSE" = "1" ]; then
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
20 # Do not use full path if we do not use O=.. builds
21 if [ "${KBUILD_SRC}" = "" ]; then
22         tree=
23 else
24         tree=${srctree}/
25 fi
26
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
36 # Detect if ALLSOURCE_ARCHS is set. If not, we assume SRCARCH
37 if [ "${ALLSOURCE_ARCHS}" = "" ]; then
38         ALLSOURCE_ARCHS=${SRCARCH}
39 elif [ "${ALLSOURCE_ARCHS}" = "all" ]; then
40         find_all_archs
41 fi
42
43 # find sources in arch/$ARCH
44 find_arch_sources()
45 {
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;
50 }
51
52 # find sources in arch/$1/include
53 find_arch_include_sources()
54 {
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
60 }
61
62 # find sources in include/
63 find_include_sources()
64 {
65         find ${tree}include $ignore -name config -prune -o -name "$1" -print;
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 \
74                -name "$1" -print;
75 }
76
77 find_sources()
78 {
79         find_arch_sources $1 "$2"
80 }
81
82 all_sources()
83 {
84         find_arch_include_sources ${SRCARCH} '*.[chS]'
85         if [ ! -z "$archinclude" ]; then
86                 find_arch_include_sources $archinclude '*.[chS]'
87         fi
88         find_include_sources '*.[chS]'
89         for arch in $ALLSOURCE_ARCHS
90         do
91                 find_sources $arch '*.[chS]'
92         done
93         find_other_sources '*.[chS]'
94 }
95
96 all_kconfigs()
97 {
98         for arch in $ALLSOURCE_ARCHS; do
99                 find_sources $arch 'Kconfig*'
100         done
101         find_other_sources 'Kconfig*'
102 }
103
104 all_defconfigs()
105 {
106         find_sources $ALLSOURCE_ARCHS "defconfig"
107 }
108
109 docscope()
110 {
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
118         cscope -b -f cscope.out
119 }
120
121 exuberant()
122 {
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                      \
129         -I DEFINE_TRACE,EXPORT_TRACEPOINT_SYMBOL,EXPORT_TRACEPOINT_SYMBOL_GPL \
130         --extra=+f --c-kinds=-px                                \
131         --regex-asm='/^ENTRY\(([^)]*)\).*/\1/'                  \
132         --regex-c='/^SYSCALL_DEFINE[[:digit:]]?\(([^,)]*).*/sys_\1/'
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 {
150         all_sources | xargs $1 -a                               \
151         --regex='/^ENTRY(\([^)]*\)).*/\1/'                      \
152         --regex='/^SYSCALL_DEFINE[0-9]?(\([^,)]*\).*/sys_\1/'
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)
177 if [ "${ARCH}" = "um" ]; then
178         if [ "$SUBARCH" = "i386" ]; then
179                 archinclude=x86
180         elif [ "$SUBARCH" = "x86_64" ]; then
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")
193                 rm -f tags
194                 xtags ctags
195                 ;;
196
197         "TAGS")
198                 rm -f TAGS
199                 xtags etags
200                 ;;
201 esac