tags.sh 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  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. # RCS_FIND_IGNORE has escaped ()s -- remove them.
  13. ignore="$(echo "$RCS_FIND_IGNORE" | sed 's|\\||g' )"
  14. # tags and cscope files should also ignore MODVERSION *.mod.c files
  15. ignore="$ignore ( -name *.mod.c ) -prune -o"
  16. # Do not use full path if we do not use O=.. builds
  17. # Use make O=. {tags|cscope}
  18. # to force full paths for a non-O= build
  19. if [ "${KBUILD_SRC}" = "" ]; then
  20. tree=
  21. else
  22. tree=${srctree}/
  23. fi
  24. # ignore userspace tools
  25. ignore="$ignore ( -path ${tree}tools ) -prune -o"
  26. # Find all available archs
  27. find_all_archs()
  28. {
  29. ALLSOURCE_ARCHS=""
  30. for arch in `ls ${tree}arch`; do
  31. ALLSOURCE_ARCHS="${ALLSOURCE_ARCHS} "${arch##\/}
  32. done
  33. }
  34. # Detect if ALLSOURCE_ARCHS is set. If not, we assume SRCARCH
  35. if [ "${ALLSOURCE_ARCHS}" = "" ]; then
  36. ALLSOURCE_ARCHS=${SRCARCH}
  37. elif [ "${ALLSOURCE_ARCHS}" = "all" ]; then
  38. find_all_archs
  39. fi
  40. # find sources in arch/$ARCH
  41. find_arch_sources()
  42. {
  43. for i in $archincludedir; do
  44. prune="$prune -wholename $i -prune -o"
  45. done
  46. find ${tree}arch/$1 $ignore $subarchprune $prune -name "$2" \
  47. -not -type l -print;
  48. }
  49. # find sources in arch/$1/include
  50. find_arch_include_sources()
  51. {
  52. include=$(find ${tree}arch/$1/ $subarchprune \
  53. -name include -type d -print);
  54. if [ -n "$include" ]; then
  55. archincludedir="$archincludedir $include"
  56. find $include $ignore -name "$2" -not -type l -print;
  57. fi
  58. }
  59. # find sources in include/
  60. find_include_sources()
  61. {
  62. find ${tree}include $ignore -name config -prune -o -name "$1" \
  63. -not -type l -print;
  64. }
  65. # find sources in rest of tree
  66. # we could benefit from a list of dirs to search in here
  67. find_other_sources()
  68. {
  69. find ${tree}* $ignore \
  70. \( -name include -o -name arch -o -name '.tmp_*' \) -prune -o \
  71. -name "$1" -not -type l -print;
  72. }
  73. find_sources()
  74. {
  75. find_arch_sources $1 "$2"
  76. }
  77. all_sources()
  78. {
  79. find_arch_include_sources ${SRCARCH} '*.[chS]'
  80. if [ ! -z "$archinclude" ]; then
  81. find_arch_include_sources $archinclude '*.[chS]'
  82. fi
  83. find_include_sources '*.[chS]'
  84. for arch in $ALLSOURCE_ARCHS
  85. do
  86. find_sources $arch '*.[chS]'
  87. done
  88. find_other_sources '*.[chS]'
  89. }
  90. all_compiled_sources()
  91. {
  92. for i in $(all_sources); do
  93. case "$i" in
  94. *.[cS])
  95. j=${i/\.[cS]/\.o}
  96. j="${j#$tree}"
  97. if [ -e $j ]; then
  98. echo $i
  99. fi
  100. ;;
  101. *)
  102. echo $i
  103. ;;
  104. esac
  105. done
  106. }
  107. all_target_sources()
  108. {
  109. if [ -n "$COMPILED_SOURCE" ]; then
  110. all_compiled_sources
  111. else
  112. all_sources
  113. fi
  114. }
  115. all_kconfigs()
  116. {
  117. for arch in $ALLSOURCE_ARCHS; do
  118. find_sources $arch 'Kconfig*'
  119. done
  120. find_other_sources 'Kconfig*'
  121. }
  122. all_defconfigs()
  123. {
  124. find_sources $ALLSOURCE_ARCHS "defconfig"
  125. }
  126. docscope()
  127. {
  128. (echo \-k; echo \-q; all_target_sources) > cscope.files
  129. cscope -b -f cscope.out
  130. }
  131. dogtags()
  132. {
  133. all_target_sources | gtags -i -f -
  134. }
  135. exuberant()
  136. {
  137. all_target_sources | xargs $1 -a \
  138. -I __initdata,__exitdata,__initconst, \
  139. -I __initdata_memblock \
  140. -I __refdata,__attribute,__maybe_unused,__always_unused \
  141. -I __acquires,__releases,__deprecated \
  142. -I __read_mostly,__aligned,____cacheline_aligned \
  143. -I ____cacheline_aligned_in_smp \
  144. -I __cacheline_aligned,__cacheline_aligned_in_smp \
  145. -I ____cacheline_internodealigned_in_smp \
  146. -I __used,__packed,__packed2__,__must_check,__must_hold \
  147. -I EXPORT_SYMBOL,EXPORT_SYMBOL_GPL,ACPI_EXPORT_SYMBOL \
  148. -I DEFINE_TRACE,EXPORT_TRACEPOINT_SYMBOL,EXPORT_TRACEPOINT_SYMBOL_GPL \
  149. -I static,const \
  150. --extra=+f --c-kinds=+px \
  151. --regex-asm='/^(ENTRY|_GLOBAL)\(([^)]*)\).*/\2/' \
  152. --regex-c='/^SYSCALL_DEFINE[[:digit:]]?\(([^,)]*).*/sys_\1/' \
  153. --regex-c='/^COMPAT_SYSCALL_DEFINE[[:digit:]]?\(([^,)]*).*/compat_sys_\1/' \
  154. --regex-c++='/^TRACE_EVENT\(([^,)]*).*/trace_\1/' \
  155. --regex-c++='/^TRACE_EVENT\(([^,)]*).*/trace_\1_rcuidle/' \
  156. --regex-c++='/^DEFINE_EVENT\([^,)]*, *([^,)]*).*/trace_\1/' \
  157. --regex-c++='/^DEFINE_EVENT\([^,)]*, *([^,)]*).*/trace_\1_rcuidle/' \
  158. --regex-c++='/PAGEFLAG\(([^,)]*).*/Page\1/' \
  159. --regex-c++='/PAGEFLAG\(([^,)]*).*/SetPage\1/' \
  160. --regex-c++='/PAGEFLAG\(([^,)]*).*/ClearPage\1/' \
  161. --regex-c++='/TESTSETFLAG\(([^,)]*).*/TestSetPage\1/' \
  162. --regex-c++='/TESTPAGEFLAG\(([^,)]*).*/Page\1/' \
  163. --regex-c++='/SETPAGEFLAG\(([^,)]*).*/SetPage\1/' \
  164. --regex-c++='/__SETPAGEFLAG\(([^,)]*).*/__SetPage\1/' \
  165. --regex-c++='/TESTCLEARFLAG\(([^,)]*).*/TestClearPage\1/' \
  166. --regex-c++='/__TESTCLEARFLAG\(([^,)]*).*/TestClearPage\1/' \
  167. --regex-c++='/CLEARPAGEFLAG\(([^,)]*).*/ClearPage\1/' \
  168. --regex-c++='/__CLEARPAGEFLAG\(([^,)]*).*/__ClearPage\1/' \
  169. --regex-c++='/__PAGEFLAG\(([^,)]*).*/__SetPage\1/' \
  170. --regex-c++='/__PAGEFLAG\(([^,)]*).*/__ClearPage\1/' \
  171. --regex-c++='/PAGEFLAG_FALSE\(([^,)]*).*/Page\1/' \
  172. --regex-c++='/TESTSCFLAG\(([^,)]*).*/TestSetPage\1/' \
  173. --regex-c++='/TESTSCFLAG\(([^,)]*).*/TestClearPage\1/' \
  174. --regex-c++='/SETPAGEFLAG_NOOP\(([^,)]*).*/SetPage\1/' \
  175. --regex-c++='/CLEARPAGEFLAG_NOOP\(([^,)]*).*/ClearPage\1/' \
  176. --regex-c++='/__CLEARPAGEFLAG_NOOP\(([^,)]*).*/__ClearPage\1/' \
  177. --regex-c++='/TESTCLEARFLAG_FALSE\(([^,)]*).*/TestClearPage\1/' \
  178. --regex-c++='/__TESTCLEARFLAG_FALSE\(([^,)]*).*/__TestClearPage\1/' \
  179. --regex-c++='/_PE\(([^,)]*).*/PEVENT_ERRNO__\1/' \
  180. --regex-c++='/TASK_PFA_TEST\([^,]*,\s*([^)]*)\)/task_\1/' \
  181. --regex-c++='/TASK_PFA_SET\([^,]*,\s*([^)]*)\)/task_set_\1/' \
  182. --regex-c++='/TASK_PFA_CLEAR\([^,]*,\s*([^)]*)\)/task_clear_\1/'\
  183. --regex-c++='/DEF_MMIO_(IN|OUT)_(X|D)\(([^,]*),\s*[^)]*\)/\3/' \
  184. --regex-c++='/DEBUGGER_BOILERPLATE\(([^,]*)\)/\1/' \
  185. --regex-c='/PCI_OP_READ\((\w*).*[1-4]\)/pci_bus_read_config_\1/' \
  186. --regex-c='/PCI_OP_WRITE\((\w*).*[1-4]\)/pci_bus_write_config_\1/' \
  187. --regex-c='/DEFINE_(MUTEX|SEMAPHORE|SPINLOCK)\((\w*)/\2/v/' \
  188. --regex-c='/DEFINE_(RAW_SPINLOCK|RWLOCK|SEQLOCK)\((\w*)/\2/v/' \
  189. --regex-c='/DECLARE_(RWSEM|COMPLETION)\((\w*)/\2/v/' \
  190. --regex-c='/DECLARE_BITMAP\((\w*)/\1/v/' \
  191. --regex-c='/(^|\s)(|L|H)LIST_HEAD\((\w*)/\3/v/' \
  192. --regex-c='/(^|\s)RADIX_TREE\((\w*)/\2/v/' \
  193. --regex-c='/DEFINE_PER_CPU\(([^,]*,\s*)(\w*).*\)/\2/v/' \
  194. --regex-c='/DEFINE_PER_CPU_SHARED_ALIGNED\(([^,]*,\s*)(\w*).*\)/\2/v/' \
  195. --regex-c='/DECLARE_WAIT_QUEUE_HEAD\((\w*)/\1/v/' \
  196. --regex-c='/DECLARE_(TASKLET|WORK|DELAYED_WORK)\((\w*)/\2/v/' \
  197. --regex-c='/DEFINE_PCI_DEVICE_TABLE\((\w*)/\1/v/' \
  198. --regex-c='/(^\s)OFFSET\((\w*)/\2/v/' \
  199. --regex-c='/(^\s)DEFINE\((\w*)/\2/v/' \
  200. --regex-c='/DEFINE_HASHTABLE\((\w*)/\1/v/'
  201. all_kconfigs | xargs $1 -a \
  202. --langdef=kconfig --language-force=kconfig \
  203. --regex-kconfig='/^[[:blank:]]*(menu|)config[[:blank:]]+([[:alnum:]_]+)/\2/'
  204. all_kconfigs | xargs $1 -a \
  205. --langdef=kconfig --language-force=kconfig \
  206. --regex-kconfig='/^[[:blank:]]*(menu|)config[[:blank:]]+([[:alnum:]_]+)/CONFIG_\2/'
  207. all_defconfigs | xargs -r $1 -a \
  208. --langdef=dotconfig --language-force=dotconfig \
  209. --regex-dotconfig='/^#?[[:blank:]]*(CONFIG_[[:alnum:]_]+)/\1/'
  210. }
  211. emacs()
  212. {
  213. all_target_sources | xargs $1 -a \
  214. --regex='/^\(ENTRY\|_GLOBAL\)(\([^)]*\)).*/\2/' \
  215. --regex='/^SYSCALL_DEFINE[0-9]?(\([^,)]*\).*/sys_\1/' \
  216. --regex='/^COMPAT_SYSCALL_DEFINE[0-9]?(\([^,)]*\).*/compat_sys_\1/' \
  217. --regex='/^TRACE_EVENT(\([^,)]*\).*/trace_\1/' \
  218. --regex='/^TRACE_EVENT(\([^,)]*\).*/trace_\1_rcuidle/' \
  219. --regex='/^DEFINE_EVENT([^,)]*, *\([^,)]*\).*/trace_\1/' \
  220. --regex='/^DEFINE_EVENT([^,)]*, *\([^,)]*\).*/trace_\1_rcuidle/' \
  221. --regex='/PAGEFLAG(\([^,)]*\).*/Page\1/' \
  222. --regex='/PAGEFLAG(\([^,)]*\).*/SetPage\1/' \
  223. --regex='/PAGEFLAG(\([^,)]*\).*/ClearPage\1/' \
  224. --regex='/TESTSETFLAG(\([^,)]*\).*/TestSetPage\1/' \
  225. --regex='/TESTPAGEFLAG(\([^,)]*\).*/Page\1/' \
  226. --regex='/SETPAGEFLAG(\([^,)]*\).*/SetPage\1/' \
  227. --regex='/__SETPAGEFLAG(\([^,)]*\).*/__SetPage\1/' \
  228. --regex='/TESTCLEARFLAG(\([^,)]*\).*/TestClearPage\1/' \
  229. --regex='/__TESTCLEARFLAG(\([^,)]*\).*/TestClearPage\1/' \
  230. --regex='/CLEARPAGEFLAG(\([^,)]*\).*/ClearPage\1/' \
  231. --regex='/__CLEARPAGEFLAG(\([^,)]*\).*/__ClearPage\1/' \
  232. --regex='/__PAGEFLAG(\([^,)]*\).*/__SetPage\1/' \
  233. --regex='/__PAGEFLAG(\([^,)]*\).*/__ClearPage\1/' \
  234. --regex='/PAGEFLAG_FALSE(\([^,)]*\).*/Page\1/' \
  235. --regex='/TESTSCFLAG(\([^,)]*\).*/TestSetPage\1/' \
  236. --regex='/TESTSCFLAG(\([^,)]*\).*/TestClearPage\1/' \
  237. --regex='/SETPAGEFLAG_NOOP(\([^,)]*\).*/SetPage\1/' \
  238. --regex='/CLEARPAGEFLAG_NOOP(\([^,)]*\).*/ClearPage\1/' \
  239. --regex='/__CLEARPAGEFLAG_NOOP(\([^,)]*\).*/__ClearPage\1/' \
  240. --regex='/TESTCLEARFLAG_FALSE(\([^,)]*\).*/TestClearPage\1/' \
  241. --regex='/__TESTCLEARFLAG_FALSE(\([^,)]*\).*/__TestClearPage\1/' \
  242. --regex='/TASK_PFA_TEST\([^,]*,\s*([^)]*)\)/task_\1/' \
  243. --regex='/TASK_PFA_SET\([^,]*,\s*([^)]*)\)/task_set_\1/' \
  244. --regex='/TASK_PFA_CLEAR\([^,]*,\s*([^)]*)\)/task_clear_\1/' \
  245. --regex='/_PE(\([^,)]*\).*/PEVENT_ERRNO__\1/' \
  246. --regex='/PCI_OP_READ(\([a-z]*[a-z]\).*[1-4])/pci_bus_read_config_\1/' \
  247. --regex='/PCI_OP_WRITE(\([a-z]*[a-z]\).*[1-4])/pci_bus_write_config_\1/'\
  248. --regex='/[^#]*DEFINE_HASHTABLE(\([^,)]*\)/\1/'
  249. all_kconfigs | xargs $1 -a \
  250. --regex='/^[ \t]*\(\(menu\)*config\)[ \t]+\([a-zA-Z0-9_]+\)/\3/'
  251. all_kconfigs | xargs $1 -a \
  252. --regex='/^[ \t]*\(\(menu\)*config\)[ \t]+\([a-zA-Z0-9_]+\)/CONFIG_\3/'
  253. all_defconfigs | xargs -r $1 -a \
  254. --regex='/^#?[ \t]?\(CONFIG_[a-zA-Z0-9_]+\)/\1/'
  255. }
  256. xtags()
  257. {
  258. if $1 --version 2>&1 | grep -iq exuberant; then
  259. exuberant $1
  260. elif $1 --version 2>&1 | grep -iq emacs; then
  261. emacs $1
  262. else
  263. all_target_sources | xargs $1 -a
  264. fi
  265. }
  266. # Support um (which uses SUBARCH)
  267. if [ "${ARCH}" = "um" ]; then
  268. if [ "$SUBARCH" = "i386" ]; then
  269. archinclude=x86
  270. elif [ "$SUBARCH" = "x86_64" ]; then
  271. archinclude=x86
  272. else
  273. archinclude=${SUBARCH}
  274. fi
  275. elif [ "${SRCARCH}" = "arm" -a "${SUBARCH}" != "" ]; then
  276. subarchdir=$(find ${tree}arch/$SRCARCH/ -name "mach-*" -type d -o \
  277. -name "plat-*" -type d);
  278. for i in $subarchdir; do
  279. case "$i" in
  280. *"mach-"${SUBARCH})
  281. ;;
  282. *"plat-"${SUBARCH})
  283. ;;
  284. *)
  285. subarchprune="$subarchprune \
  286. -wholename $i -prune -o"
  287. ;;
  288. esac
  289. done
  290. fi
  291. remove_structs=
  292. case "$1" in
  293. "cscope")
  294. docscope
  295. ;;
  296. "gtags")
  297. dogtags
  298. ;;
  299. "tags")
  300. rm -f tags
  301. xtags ctags
  302. remove_structs=y
  303. ;;
  304. "TAGS")
  305. rm -f TAGS
  306. xtags etags
  307. remove_structs=y
  308. ;;
  309. esac
  310. # Remove structure forward declarations.
  311. if [ -n "$remove_structs" ]; then
  312. LANG=C sed -i -e '/^\([a-zA-Z_][a-zA-Z0-9_]*\)\t.*\t\/\^struct \1;.*\$\/;"\tx$/d' $1
  313. fi