tags.sh 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  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. if [ -e $j ]; then
  97. echo $i
  98. fi
  99. ;;
  100. *)
  101. echo $i
  102. ;;
  103. esac
  104. done
  105. }
  106. all_target_sources()
  107. {
  108. if [ -n "$COMPILED_SOURCE" ]; then
  109. all_compiled_sources
  110. else
  111. all_sources
  112. fi
  113. }
  114. all_kconfigs()
  115. {
  116. for arch in $ALLSOURCE_ARCHS; do
  117. find_sources $arch 'Kconfig*'
  118. done
  119. find_other_sources 'Kconfig*'
  120. }
  121. all_defconfigs()
  122. {
  123. find_sources $ALLSOURCE_ARCHS "defconfig"
  124. }
  125. docscope()
  126. {
  127. (echo \-k; echo \-q; all_target_sources) > cscope.files
  128. cscope -b -f cscope.out
  129. }
  130. dogtags()
  131. {
  132. all_target_sources | gtags -i -f -
  133. }
  134. exuberant()
  135. {
  136. all_target_sources | xargs $1 -a \
  137. -I __initdata,__exitdata,__initconst, \
  138. -I __initdata_memblock \
  139. -I __refdata,__attribute,__maybe_unused,__always_unused \
  140. -I __acquires,__releases,__deprecated \
  141. -I __read_mostly,__aligned,____cacheline_aligned \
  142. -I ____cacheline_aligned_in_smp \
  143. -I __cacheline_aligned,__cacheline_aligned_in_smp \
  144. -I ____cacheline_internodealigned_in_smp \
  145. -I __used,__packed,__packed2__,__must_check,__must_hold \
  146. -I EXPORT_SYMBOL,EXPORT_SYMBOL_GPL,ACPI_EXPORT_SYMBOL \
  147. -I DEFINE_TRACE,EXPORT_TRACEPOINT_SYMBOL,EXPORT_TRACEPOINT_SYMBOL_GPL \
  148. -I static,const \
  149. --extra=+f --c-kinds=+px \
  150. --regex-asm='/^(ENTRY|_GLOBAL)\(([^)]*)\).*/\2/' \
  151. --regex-c='/^SYSCALL_DEFINE[[:digit:]]?\(([^,)]*).*/sys_\1/' \
  152. --regex-c='/^COMPAT_SYSCALL_DEFINE[[:digit:]]?\(([^,)]*).*/compat_sys_\1/' \
  153. --regex-c++='/^TRACE_EVENT\(([^,)]*).*/trace_\1/' \
  154. --regex-c++='/^DEFINE_EVENT\([^,)]*, *([^,)]*).*/trace_\1/' \
  155. --regex-c++='/PAGEFLAG\(([^,)]*).*/Page\1/' \
  156. --regex-c++='/PAGEFLAG\(([^,)]*).*/SetPage\1/' \
  157. --regex-c++='/PAGEFLAG\(([^,)]*).*/ClearPage\1/' \
  158. --regex-c++='/TESTSETFLAG\(([^,)]*).*/TestSetPage\1/' \
  159. --regex-c++='/TESTPAGEFLAG\(([^,)]*).*/Page\1/' \
  160. --regex-c++='/SETPAGEFLAG\(([^,)]*).*/SetPage\1/' \
  161. --regex-c++='/__SETPAGEFLAG\(([^,)]*).*/__SetPage\1/' \
  162. --regex-c++='/TESTCLEARFLAG\(([^,)]*).*/TestClearPage\1/' \
  163. --regex-c++='/__TESTCLEARFLAG\(([^,)]*).*/TestClearPage\1/' \
  164. --regex-c++='/CLEARPAGEFLAG\(([^,)]*).*/ClearPage\1/' \
  165. --regex-c++='/__CLEARPAGEFLAG\(([^,)]*).*/__ClearPage\1/' \
  166. --regex-c++='/__PAGEFLAG\(([^,)]*).*/__SetPage\1/' \
  167. --regex-c++='/__PAGEFLAG\(([^,)]*).*/__ClearPage\1/' \
  168. --regex-c++='/PAGEFLAG_FALSE\(([^,)]*).*/Page\1/' \
  169. --regex-c++='/TESTSCFLAG\(([^,)]*).*/TestSetPage\1/' \
  170. --regex-c++='/TESTSCFLAG\(([^,)]*).*/TestClearPage\1/' \
  171. --regex-c++='/SETPAGEFLAG_NOOP\(([^,)]*).*/SetPage\1/' \
  172. --regex-c++='/CLEARPAGEFLAG_NOOP\(([^,)]*).*/ClearPage\1/' \
  173. --regex-c++='/__CLEARPAGEFLAG_NOOP\(([^,)]*).*/__ClearPage\1/' \
  174. --regex-c++='/TESTCLEARFLAG_FALSE\(([^,)]*).*/TestClearPage\1/' \
  175. --regex-c++='/__TESTCLEARFLAG_FALSE\(([^,)]*).*/__TestClearPage\1/' \
  176. --regex-c++='/_PE\(([^,)]*).*/PEVENT_ERRNO__\1/' \
  177. --regex-c++='/TASK_PFA_TEST\([^,]*,\s*([^)]*)\)/task_\1/' \
  178. --regex-c++='/TASK_PFA_SET\([^,]*,\s*([^)]*)\)/task_set_\1/' \
  179. --regex-c++='/TASK_PFA_CLEAR\([^,]*,\s*([^)]*)\)/task_clear_\1/'\
  180. --regex-c='/PCI_OP_READ\((\w*).*[1-4]\)/pci_bus_read_config_\1/' \
  181. --regex-c='/PCI_OP_WRITE\((\w*).*[1-4]\)/pci_bus_write_config_\1/' \
  182. --regex-c='/DEFINE_(MUTEX|SEMAPHORE|SPINLOCK)\((\w*)/\2/v/' \
  183. --regex-c='/DEFINE_(RAW_SPINLOCK|RWLOCK|SEQLOCK)\((\w*)/\2/v/' \
  184. --regex-c='/DECLARE_(RWSEM|COMPLETION)\((\w*)/\2/v/' \
  185. --regex-c='/DECLARE_BITMAP\((\w*)/\1/v/' \
  186. --regex-c='/(^|\s)(|L|H)LIST_HEAD\((\w*)/\3/v/' \
  187. --regex-c='/(^|\s)RADIX_TREE\((\w*)/\2/v/' \
  188. --regex-c='/DEFINE_PER_CPU\(([^,]*,\s*)(\w*).*\)/\2/v/' \
  189. --regex-c='/DEFINE_PER_CPU_SHARED_ALIGNED\(([^,]*,\s*)(\w*).*\)/\2/v/' \
  190. --regex-c='/DECLARE_WAIT_QUEUE_HEAD\((\w*)/\1/v/' \
  191. --regex-c='/DECLARE_(TASKLET|WORK|DELAYED_WORK)\((\w*)/\2/v/' \
  192. --regex-c='/DEFINE_PCI_DEVICE_TABLE\((\w*)/\1/v/' \
  193. --regex-c='/(^\s)OFFSET\((\w*)/\2/v/' \
  194. --regex-c='/(^\s)DEFINE\((\w*)/\2/v/' \
  195. --regex-c='/DEFINE_HASHTABLE\((\w*)/\1/v/'
  196. all_kconfigs | xargs $1 -a \
  197. --langdef=kconfig --language-force=kconfig \
  198. --regex-kconfig='/^[[:blank:]]*(menu|)config[[:blank:]]+([[:alnum:]_]+)/\2/'
  199. all_kconfigs | xargs $1 -a \
  200. --langdef=kconfig --language-force=kconfig \
  201. --regex-kconfig='/^[[:blank:]]*(menu|)config[[:blank:]]+([[:alnum:]_]+)/CONFIG_\2/'
  202. all_defconfigs | xargs -r $1 -a \
  203. --langdef=dotconfig --language-force=dotconfig \
  204. --regex-dotconfig='/^#?[[:blank:]]*(CONFIG_[[:alnum:]_]+)/\1/'
  205. }
  206. emacs()
  207. {
  208. all_target_sources | xargs $1 -a \
  209. --regex='/^\(ENTRY\|_GLOBAL\)(\([^)]*\)).*/\2/' \
  210. --regex='/^SYSCALL_DEFINE[0-9]?(\([^,)]*\).*/sys_\1/' \
  211. --regex='/^COMPAT_SYSCALL_DEFINE[0-9]?(\([^,)]*\).*/compat_sys_\1/' \
  212. --regex='/^TRACE_EVENT(\([^,)]*\).*/trace_\1/' \
  213. --regex='/^DEFINE_EVENT([^,)]*, *\([^,)]*\).*/trace_\1/' \
  214. --regex='/PAGEFLAG(\([^,)]*\).*/Page\1/' \
  215. --regex='/PAGEFLAG(\([^,)]*\).*/SetPage\1/' \
  216. --regex='/PAGEFLAG(\([^,)]*\).*/ClearPage\1/' \
  217. --regex='/TESTSETFLAG(\([^,)]*\).*/TestSetPage\1/' \
  218. --regex='/TESTPAGEFLAG(\([^,)]*\).*/Page\1/' \
  219. --regex='/SETPAGEFLAG(\([^,)]*\).*/SetPage\1/' \
  220. --regex='/__SETPAGEFLAG(\([^,)]*\).*/__SetPage\1/' \
  221. --regex='/TESTCLEARFLAG(\([^,)]*\).*/TestClearPage\1/' \
  222. --regex='/__TESTCLEARFLAG(\([^,)]*\).*/TestClearPage\1/' \
  223. --regex='/CLEARPAGEFLAG(\([^,)]*\).*/ClearPage\1/' \
  224. --regex='/__CLEARPAGEFLAG(\([^,)]*\).*/__ClearPage\1/' \
  225. --regex='/__PAGEFLAG(\([^,)]*\).*/__SetPage\1/' \
  226. --regex='/__PAGEFLAG(\([^,)]*\).*/__ClearPage\1/' \
  227. --regex='/PAGEFLAG_FALSE(\([^,)]*\).*/Page\1/' \
  228. --regex='/TESTSCFLAG(\([^,)]*\).*/TestSetPage\1/' \
  229. --regex='/TESTSCFLAG(\([^,)]*\).*/TestClearPage\1/' \
  230. --regex='/SETPAGEFLAG_NOOP(\([^,)]*\).*/SetPage\1/' \
  231. --regex='/CLEARPAGEFLAG_NOOP(\([^,)]*\).*/ClearPage\1/' \
  232. --regex='/__CLEARPAGEFLAG_NOOP(\([^,)]*\).*/__ClearPage\1/' \
  233. --regex='/TESTCLEARFLAG_FALSE(\([^,)]*\).*/TestClearPage\1/' \
  234. --regex='/__TESTCLEARFLAG_FALSE(\([^,)]*\).*/__TestClearPage\1/' \
  235. --regex='/TASK_PFA_TEST\([^,]*,\s*([^)]*)\)/task_\1/' \
  236. --regex='/TASK_PFA_SET\([^,]*,\s*([^)]*)\)/task_set_\1/' \
  237. --regex='/TASK_PFA_CLEAR\([^,]*,\s*([^)]*)\)/task_clear_\1/' \
  238. --regex='/_PE(\([^,)]*\).*/PEVENT_ERRNO__\1/' \
  239. --regex='/PCI_OP_READ(\([a-z]*[a-z]\).*[1-4])/pci_bus_read_config_\1/' \
  240. --regex='/PCI_OP_WRITE(\([a-z]*[a-z]\).*[1-4])/pci_bus_write_config_\1/'\
  241. --regex='/[^#]*DEFINE_HASHTABLE(\([^,)]*\)/\1/'
  242. all_kconfigs | xargs $1 -a \
  243. --regex='/^[ \t]*\(\(menu\)*config\)[ \t]+\([a-zA-Z0-9_]+\)/\3/'
  244. all_kconfigs | xargs $1 -a \
  245. --regex='/^[ \t]*\(\(menu\)*config\)[ \t]+\([a-zA-Z0-9_]+\)/CONFIG_\3/'
  246. all_defconfigs | xargs -r $1 -a \
  247. --regex='/^#?[ \t]?\(CONFIG_[a-zA-Z0-9_]+\)/\1/'
  248. }
  249. xtags()
  250. {
  251. if $1 --version 2>&1 | grep -iq exuberant; then
  252. exuberant $1
  253. elif $1 --version 2>&1 | grep -iq emacs; then
  254. emacs $1
  255. else
  256. all_target_sources | xargs $1 -a
  257. fi
  258. }
  259. # Support um (which uses SUBARCH)
  260. if [ "${ARCH}" = "um" ]; then
  261. if [ "$SUBARCH" = "i386" ]; then
  262. archinclude=x86
  263. elif [ "$SUBARCH" = "x86_64" ]; then
  264. archinclude=x86
  265. else
  266. archinclude=${SUBARCH}
  267. fi
  268. elif [ "${SRCARCH}" = "arm" -a "${SUBARCH}" != "" ]; then
  269. subarchdir=$(find ${tree}arch/$SRCARCH/ -name "mach-*" -type d -o \
  270. -name "plat-*" -type d);
  271. for i in $subarchdir; do
  272. case "$i" in
  273. *"mach-"${SUBARCH})
  274. ;;
  275. *"plat-"${SUBARCH})
  276. ;;
  277. *)
  278. subarchprune="$subarchprune \
  279. -wholename $i -prune -o"
  280. ;;
  281. esac
  282. done
  283. fi
  284. remove_structs=
  285. case "$1" in
  286. "cscope")
  287. docscope
  288. ;;
  289. "gtags")
  290. dogtags
  291. ;;
  292. "tags")
  293. rm -f tags
  294. xtags ctags
  295. remove_structs=y
  296. ;;
  297. "TAGS")
  298. rm -f TAGS
  299. xtags etags
  300. remove_structs=y
  301. ;;
  302. esac
  303. # Remove structure forward declarations.
  304. if [ -n "$remove_structs" ]; then
  305. LANG=C sed -i -e '/^\([a-zA-Z_][a-zA-Z0-9_]*\)\t.*\t\/\^struct \1;.*\$\/;"\tx$/d' $1
  306. fi