tags.sh 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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. if [ "$KBUILD_VERBOSE" = "1" ]; then
  10. set -x
  11. fi
  12. # This is a duplicate of RCS_FIND_IGNORE without escaped '()'
  13. ignore="( -name SCCS -o -name BitKeeper -o -name .svn -o \
  14. -name CVS -o -name .pc -o -name .hg -o \
  15. -name .git ) \
  16. -prune -o"
  17. # Do not use full path if we do not use O=.. builds
  18. # Use make O=. {tags|cscope}
  19. # to force full paths for a non-O= build
  20. if [ "${KBUILD_SRC}" = "" ]; then
  21. tree=
  22. else
  23. tree=${srctree}/
  24. fi
  25. # Find all available archs
  26. find_all_archs()
  27. {
  28. ALLSOURCE_ARCHS=""
  29. for arch in `ls ${tree}arch`; do
  30. ALLSOURCE_ARCHS="${ALLSOURCE_ARCHS} "${arch##\/}
  31. done
  32. }
  33. # Detect if ALLSOURCE_ARCHS is set. If not, we assume SRCARCH
  34. if [ "${ALLSOURCE_ARCHS}" = "" ]; then
  35. ALLSOURCE_ARCHS=${SRCARCH}
  36. elif [ "${ALLSOURCE_ARCHS}" = "all" ]; then
  37. find_all_archs
  38. fi
  39. # find sources in arch/$ARCH
  40. find_arch_sources()
  41. {
  42. for i in $archincludedir; do
  43. prune="$prune -wholename $i -prune -o"
  44. done
  45. find ${tree}arch/$1 $ignore $prune -name "$2" -print;
  46. }
  47. # find sources in arch/$1/include
  48. find_arch_include_sources()
  49. {
  50. include=$(find ${tree}arch/$1/ -name include -type d);
  51. if [ -n "$include" ]; then
  52. archincludedir="$archincludedir $include"
  53. find $include $ignore -name "$2" -print;
  54. fi
  55. }
  56. # find sources in include/
  57. find_include_sources()
  58. {
  59. find ${tree}include $ignore -name config -prune -o -name "$1" -print;
  60. }
  61. # find sources in rest of tree
  62. # we could benefit from a list of dirs to search in here
  63. find_other_sources()
  64. {
  65. find ${tree}* $ignore \
  66. \( -name include -o -name arch -o -name '.tmp_*' \) -prune -o \
  67. -name "$1" -print;
  68. }
  69. find_sources()
  70. {
  71. find_arch_sources $1 "$2"
  72. }
  73. all_sources()
  74. {
  75. find_arch_include_sources ${SRCARCH} '*.[chS]'
  76. if [ ! -z "$archinclude" ]; then
  77. find_arch_include_sources $archinclude '*.[chS]'
  78. fi
  79. find_include_sources '*.[chS]'
  80. for arch in $ALLSOURCE_ARCHS
  81. do
  82. find_sources $arch '*.[chS]'
  83. done
  84. find_other_sources '*.[chS]'
  85. }
  86. all_kconfigs()
  87. {
  88. for arch in $ALLSOURCE_ARCHS; do
  89. find_sources $arch 'Kconfig*'
  90. done
  91. find_other_sources 'Kconfig*'
  92. }
  93. all_defconfigs()
  94. {
  95. find_sources $ALLSOURCE_ARCHS "defconfig"
  96. }
  97. docscope()
  98. {
  99. (echo \-k; echo \-q; all_sources) > cscope.files
  100. cscope -b -f cscope.out
  101. }
  102. dogtags()
  103. {
  104. all_sources | gtags -f -
  105. }
  106. exuberant()
  107. {
  108. all_sources | xargs $1 -a \
  109. -I __initdata,__exitdata,__acquires,__releases \
  110. -I __read_mostly,____cacheline_aligned \
  111. -I ____cacheline_aligned_in_smp \
  112. -I ____cacheline_internodealigned_in_smp \
  113. -I EXPORT_SYMBOL,EXPORT_SYMBOL_GPL \
  114. -I DEFINE_TRACE,EXPORT_TRACEPOINT_SYMBOL,EXPORT_TRACEPOINT_SYMBOL_GPL \
  115. --extra=+f --c-kinds=+px \
  116. --regex-asm='/^ENTRY\(([^)]*)\).*/\1/' \
  117. --regex-c='/^SYSCALL_DEFINE[[:digit:]]?\(([^,)]*).*/sys_\1/' \
  118. --regex-c++='/^TRACE_EVENT\(([^,)]*).*/trace_\1/' \
  119. --regex-c++='/^DEFINE_EVENT\([^,)]*, *([^,)]*).*/trace_\1/'
  120. all_kconfigs | xargs $1 -a \
  121. --langdef=kconfig --language-force=kconfig \
  122. --regex-kconfig='/^[[:blank:]]*(menu|)config[[:blank:]]+([[:alnum:]_]+)/\2/'
  123. all_kconfigs | xargs $1 -a \
  124. --langdef=kconfig --language-force=kconfig \
  125. --regex-kconfig='/^[[:blank:]]*(menu|)config[[:blank:]]+([[:alnum:]_]+)/CONFIG_\2/'
  126. all_defconfigs | xargs -r $1 -a \
  127. --langdef=dotconfig --language-force=dotconfig \
  128. --regex-dotconfig='/^#?[[:blank:]]*(CONFIG_[[:alnum:]_]+)/\1/'
  129. }
  130. emacs()
  131. {
  132. all_sources | xargs $1 -a \
  133. --regex='/^ENTRY(\([^)]*\)).*/\1/' \
  134. --regex='/^SYSCALL_DEFINE[0-9]?(\([^,)]*\).*/sys_\1/' \
  135. --regex='/^TRACE_EVENT(\([^,)]*\).*/trace_\1/' \
  136. --regex='/^DEFINE_EVENT([^,)]*, *\([^,)]*\).*/trace_\1/'
  137. all_kconfigs | xargs $1 -a \
  138. --regex='/^[ \t]*\(\(menu\)*config\)[ \t]+\([a-zA-Z0-9_]+\)/\3/'
  139. all_kconfigs | xargs $1 -a \
  140. --regex='/^[ \t]*\(\(menu\)*config\)[ \t]+\([a-zA-Z0-9_]+\)/CONFIG_\3/'
  141. all_defconfigs | xargs -r $1 -a \
  142. --regex='/^#?[ \t]?\(CONFIG_[a-zA-Z0-9_]+\)/\1/'
  143. }
  144. xtags()
  145. {
  146. if $1 --version 2>&1 | grep -iq exuberant; then
  147. exuberant $1
  148. elif $1 --version 2>&1 | grep -iq emacs; then
  149. emacs $1
  150. else
  151. all_sources | xargs $1 -a
  152. fi
  153. }
  154. # Support um (which uses SUBARCH)
  155. if [ "${ARCH}" = "um" ]; then
  156. if [ "$SUBARCH" = "i386" ]; then
  157. archinclude=x86
  158. elif [ "$SUBARCH" = "x86_64" ]; then
  159. archinclude=x86
  160. else
  161. archinclude=${SUBARCH}
  162. fi
  163. fi
  164. case "$1" in
  165. "cscope")
  166. docscope
  167. ;;
  168. "gtags")
  169. dogtags
  170. ;;
  171. "tags")
  172. rm -f tags
  173. xtags ctags
  174. ;;
  175. "TAGS")
  176. rm -f TAGS
  177. xtags etags
  178. ;;
  179. esac