Back to home page

LXR

 
 

    


0001 #!/bin/bash
0002 # Generate tags or cscope files
0003 # Usage tags.sh <mode>
0004 #
0005 # mode may be any of: tags, TAGS, cscope
0006 #
0007 # Uses the following environment variables:
0008 # ARCH, SUBARCH, SRCARCH, srctree, src, obj
0009 
0010 if [ "$KBUILD_VERBOSE" = "1" ]; then
0011         set -x
0012 fi
0013 
0014 # RCS_FIND_IGNORE has escaped ()s -- remove them.
0015 ignore="$(echo "$RCS_FIND_IGNORE" | sed 's|\\||g' )"
0016 # tags and cscope files should also ignore MODVERSION *.mod.c files
0017 ignore="$ignore ( -name *.mod.c ) -prune -o"
0018 
0019 # Do not use full path if we do not use O=.. builds
0020 # Use make O=. {tags|cscope}
0021 # to force full paths for a non-O= build
0022 if [ "${KBUILD_SRC}" = "" ]; then
0023         tree=
0024 else
0025         tree=${srctree}/
0026 fi
0027 
0028 # ignore userspace tools
0029 ignore="$ignore ( -path ${tree}tools ) -prune -o"
0030 
0031 # Find all available archs
0032 find_all_archs()
0033 {
0034         ALLSOURCE_ARCHS=""
0035         for arch in `ls ${tree}arch`; do
0036                 ALLSOURCE_ARCHS="${ALLSOURCE_ARCHS} "${arch##\/}
0037         done
0038 }
0039 
0040 # Detect if ALLSOURCE_ARCHS is set. If not, we assume SRCARCH
0041 if [ "${ALLSOURCE_ARCHS}" = "" ]; then
0042         ALLSOURCE_ARCHS=${SRCARCH}
0043 elif [ "${ALLSOURCE_ARCHS}" = "all" ]; then
0044         find_all_archs
0045 fi
0046 
0047 # find sources in arch/$ARCH
0048 find_arch_sources()
0049 {
0050         for i in $archincludedir; do
0051                 prune="$prune -wholename $i -prune -o"
0052         done
0053         find ${tree}arch/$1 $ignore $subarchprune $prune -name "$2" \
0054                 -not -type l -print;
0055 }
0056 
0057 # find sources in arch/$1/include
0058 find_arch_include_sources()
0059 {
0060         include=$(find ${tree}arch/$1/ $subarchprune \
0061                                         -name include -type d -print);
0062         if [ -n "$include" ]; then
0063                 archincludedir="$archincludedir $include"
0064                 find $include $ignore -name "$2" -not -type l -print;
0065         fi
0066 }
0067 
0068 # find sources in include/
0069 find_include_sources()
0070 {
0071         find ${tree}include $ignore -name config -prune -o -name "$1" \
0072                 -not -type l -print;
0073 }
0074 
0075 # find sources in rest of tree
0076 # we could benefit from a list of dirs to search in here
0077 find_other_sources()
0078 {
0079         find ${tree}* $ignore \
0080              \( -name include -o -name arch -o -name '.tmp_*' \) -prune -o \
0081                -name "$1" -not -type l -print;
0082 }
0083 
0084 find_sources()
0085 {
0086         find_arch_sources $1 "$2"
0087 }
0088 
0089 all_sources()
0090 {
0091         find_arch_include_sources ${SRCARCH} '*.[chS]'
0092         if [ ! -z "$archinclude" ]; then
0093                 find_arch_include_sources $archinclude '*.[chS]'
0094         fi
0095         find_include_sources '*.[chS]'
0096         for arch in $ALLSOURCE_ARCHS
0097         do
0098                 find_sources $arch '*.[chS]'
0099         done
0100         find_other_sources '*.[chS]'
0101 }
0102 
0103 all_compiled_sources()
0104 {
0105         for i in $(all_sources); do
0106                 case "$i" in
0107                         *.[cS])
0108                                 j=${i/\.[cS]/\.o}
0109                                 if [ -e $j ]; then
0110                                         echo $i
0111                                 fi
0112                                 ;;
0113                         *)
0114                                 echo $i
0115                                 ;;
0116                 esac
0117         done
0118 }
0119 
0120 all_target_sources()
0121 {
0122         if [ -n "$COMPILED_SOURCE" ]; then
0123                 all_compiled_sources
0124         else
0125                 all_sources
0126         fi
0127 }
0128 
0129 all_kconfigs()
0130 {
0131         for arch in $ALLSOURCE_ARCHS; do
0132                 find_sources $arch 'Kconfig*'
0133         done
0134         find_other_sources 'Kconfig*'
0135 }
0136 
0137 docscope()
0138 {
0139         (echo \-k; echo \-q; all_target_sources) > cscope.files
0140         cscope -b -f cscope.out
0141 }
0142 
0143 dogtags()
0144 {
0145         all_target_sources | gtags -i -f -
0146 }
0147 
0148 # Basic regular expressions with an optional /kind-spec/ for ctags and
0149 # the following limitations:
0150 # - No regex modifiers
0151 # - Use \{0,1\} instead of \?, because etags expects an unescaped ?
0152 # - \s is not working with etags, use a space or [ \t]
0153 # - \w works, but does not match underscores in etags
0154 # - etags regular expressions have to match at the start of a line;
0155 #   a ^[^#] is prepended by setup_regex unless an anchor is already present
0156 regex_asm=(
0157         '/^\(ENTRY\|_GLOBAL\)(\([[:alnum:]_\\]*\)).*/\2/'
0158 )
0159 regex_c=(
0160         '/^SYSCALL_DEFINE[0-9](\([[:alnum:]_]*\).*/sys_\1/'
0161         '/^COMPAT_SYSCALL_DEFINE[0-9](\([[:alnum:]_]*\).*/compat_sys_\1/'
0162         '/^TRACE_EVENT(\([[:alnum:]_]*\).*/trace_\1/'
0163         '/^TRACE_EVENT(\([[:alnum:]_]*\).*/trace_\1_rcuidle/'
0164         '/^DEFINE_EVENT([^,)]*, *\([[:alnum:]_]*\).*/trace_\1/'
0165         '/^DEFINE_EVENT([^,)]*, *\([[:alnum:]_]*\).*/trace_\1_rcuidle/'
0166         '/^DEFINE_INSN_CACHE_OPS(\([[:alnum:]_]*\).*/get_\1_slot/'
0167         '/^DEFINE_INSN_CACHE_OPS(\([[:alnum:]_]*\).*/free_\1_slot/'
0168         '/^PAGEFLAG(\([[:alnum:]_]*\).*/Page\1/'
0169         '/^PAGEFLAG(\([[:alnum:]_]*\).*/SetPage\1/'
0170         '/^PAGEFLAG(\([[:alnum:]_]*\).*/ClearPage\1/'
0171         '/^TESTSETFLAG(\([[:alnum:]_]*\).*/TestSetPage\1/'
0172         '/^TESTPAGEFLAG(\([[:alnum:]_]*\).*/Page\1/'
0173         '/^SETPAGEFLAG(\([[:alnum:]_]*\).*/SetPage\1/'
0174         '/\<__SETPAGEFLAG(\([[:alnum:]_]*\).*/__SetPage\1/'
0175         '/\<TESTCLEARFLAG(\([[:alnum:]_]*\).*/TestClearPage\1/'
0176         '/\<__TESTCLEARFLAG(\([[:alnum:]_]*\).*/TestClearPage\1/'
0177         '/\<CLEARPAGEFLAG(\([[:alnum:]_]*\).*/ClearPage\1/'
0178         '/\<__CLEARPAGEFLAG(\([[:alnum:]_]*\).*/__ClearPage\1/'
0179         '/^__PAGEFLAG(\([[:alnum:]_]*\).*/__SetPage\1/'
0180         '/^__PAGEFLAG(\([[:alnum:]_]*\).*/__ClearPage\1/'
0181         '/^PAGEFLAG_FALSE(\([[:alnum:]_]*\).*/Page\1/'
0182         '/\<TESTSCFLAG(\([[:alnum:]_]*\).*/TestSetPage\1/'
0183         '/\<TESTSCFLAG(\([[:alnum:]_]*\).*/TestClearPage\1/'
0184         '/\<SETPAGEFLAG_NOOP(\([[:alnum:]_]*\).*/SetPage\1/'
0185         '/\<CLEARPAGEFLAG_NOOP(\([[:alnum:]_]*\).*/ClearPage\1/'
0186         '/\<__CLEARPAGEFLAG_NOOP(\([[:alnum:]_]*\).*/__ClearPage\1/'
0187         '/\<TESTCLEARFLAG_FALSE(\([[:alnum:]_]*\).*/TestClearPage\1/'
0188         '/^PAGE_MAPCOUNT_OPS(\([[:alnum:]_]*\).*/Page\1/'
0189         '/^PAGE_MAPCOUNT_OPS(\([[:alnum:]_]*\).*/__SetPage\1/'
0190         '/^PAGE_MAPCOUNT_OPS(\([[:alnum:]_]*\).*/__ClearPage\1/'
0191         '/^TASK_PFA_TEST([^,]*, *\([[:alnum:]_]*\))/task_\1/'
0192         '/^TASK_PFA_SET([^,]*, *\([[:alnum:]_]*\))/task_set_\1/'
0193         '/^TASK_PFA_CLEAR([^,]*, *\([[:alnum:]_]*\))/task_clear_\1/'
0194         '/^DEF_MMIO_\(IN\|OUT\)_[XD](\([[:alnum:]_]*\),[^)]*)/\2/'
0195         '/^DEBUGGER_BOILERPLATE(\([[:alnum:]_]*\))/\1/'
0196         '/^DEF_PCI_AC_\(\|NO\)RET(\([[:alnum:]_]*\).*/\2/'
0197         '/^PCI_OP_READ(\(\w*\).*[1-4])/pci_bus_read_config_\1/'
0198         '/^PCI_OP_WRITE(\(\w*\).*[1-4])/pci_bus_write_config_\1/'
0199         '/\<DEFINE_\(MUTEX\|SEMAPHORE\|SPINLOCK\)(\([[:alnum:]_]*\)/\2/v/'
0200         '/\<DEFINE_\(RAW_SPINLOCK\|RWLOCK\|SEQLOCK\)(\([[:alnum:]_]*\)/\2/v/'
0201         '/\<DECLARE_\(RWSEM\|COMPLETION\)(\([[:alnum:]_]\+\)/\2/v/'
0202         '/\<DECLARE_BITMAP(\([[:alnum:]_]*\)/\1/v/'
0203         '/\(^\|\s\)\(\|L\|H\)LIST_HEAD(\([[:alnum:]_]*\)/\3/v/'
0204         '/\(^\|\s\)RADIX_TREE(\([[:alnum:]_]*\)/\2/v/'
0205         '/\<DEFINE_PER_CPU([^,]*, *\([[:alnum:]_]*\)/\1/v/'
0206         '/\<DEFINE_PER_CPU_SHARED_ALIGNED([^,]*, *\([[:alnum:]_]*\)/\1/v/'
0207         '/\<DECLARE_WAIT_QUEUE_HEAD(\([[:alnum:]_]*\)/\1/v/'
0208         '/\<DECLARE_\(TASKLET\|WORK\|DELAYED_WORK\)(\([[:alnum:]_]*\)/\2/v/'
0209         '/\(^\s\)OFFSET(\([[:alnum:]_]*\)/\2/v/'
0210         '/\(^\s\)DEFINE(\([[:alnum:]_]*\)/\2/v/'
0211         '/\<DEFINE_HASHTABLE(\([[:alnum:]_]*\)/\1/v/'
0212 )
0213 regex_kconfig=(
0214         '/^[[:blank:]]*\(menu\|\)config[[:blank:]]\+\([[:alnum:]_]\+\)/\2/'
0215         '/^[[:blank:]]*\(menu\|\)config[[:blank:]]\+\([[:alnum:]_]\+\)/CONFIG_\2/'
0216 )
0217 setup_regex()
0218 {
0219         local mode=$1 lang tmp=() r
0220         shift
0221 
0222         regex=()
0223         for lang; do
0224                 case "$lang" in
0225                 asm)       tmp=("${regex_asm[@]}") ;;
0226                 c)         tmp=("${regex_c[@]}") ;;
0227                 kconfig)   tmp=("${regex_kconfig[@]}") ;;
0228                 esac
0229                 for r in "${tmp[@]}"; do
0230                         if test "$mode" = "exuberant"; then
0231                                 regex[${#regex[@]}]="--regex-$lang=${r}b"
0232                         else
0233                                 # Remove ctags /kind-spec/
0234                                 case "$r" in
0235                                 /*/*/?/)
0236                                         r=${r%?/}
0237                                 esac
0238                                 # Prepend ^[^#] unless already anchored
0239                                 case "$r" in
0240                                 /^*) ;;
0241                                 *)
0242                                         r="/^[^#]*${r#/}"
0243                                 esac
0244                                 regex[${#regex[@]}]="--regex=$r"
0245                         fi
0246                 done
0247         done
0248 }
0249 
0250 exuberant()
0251 {
0252         setup_regex exuberant asm c
0253         all_target_sources | xargs $1 -a                        \
0254         -I __initdata,__exitdata,__initconst,                   \
0255         -I __initdata_memblock                                  \
0256         -I __refdata,__attribute,__maybe_unused,__always_unused \
0257         -I __acquires,__releases,__deprecated                   \
0258         -I __read_mostly,__aligned,____cacheline_aligned        \
0259         -I ____cacheline_aligned_in_smp                         \
0260         -I __cacheline_aligned,__cacheline_aligned_in_smp       \
0261         -I ____cacheline_internodealigned_in_smp                \
0262         -I __used,__packed,__packed2__,__must_check,__must_hold \
0263         -I EXPORT_SYMBOL,EXPORT_SYMBOL_GPL,ACPI_EXPORT_SYMBOL   \
0264         -I DEFINE_TRACE,EXPORT_TRACEPOINT_SYMBOL,EXPORT_TRACEPOINT_SYMBOL_GPL \
0265         -I static,const                                         \
0266         --extra=+fq --c-kinds=+px --fields=+iaS --langmap=c:+.h \
0267         "${regex[@]}"
0268 
0269         setup_regex exuberant kconfig
0270         all_kconfigs | xargs $1 -a                              \
0271         --langdef=kconfig --language-force=kconfig "${regex[@]}"
0272 
0273 }
0274 
0275 emacs()
0276 {
0277         setup_regex emacs asm c
0278         all_target_sources | xargs $1 -a "${regex[@]}"
0279 
0280         setup_regex emacs kconfig
0281         all_kconfigs | xargs $1 -a "${regex[@]}"
0282 }
0283 
0284 xtags()
0285 {
0286         if $1 --version 2>&1 | grep -iq exuberant; then
0287                 exuberant $1
0288         elif $1 --version 2>&1 | grep -iq emacs; then
0289                 emacs $1
0290         else
0291                 all_target_sources | xargs $1 -a
0292         fi
0293 }
0294 
0295 # Support um (which uses SUBARCH)
0296 if [ "${ARCH}" = "um" ]; then
0297         if [ "$SUBARCH" = "i386" ]; then
0298                 archinclude=x86
0299         elif [ "$SUBARCH" = "x86_64" ]; then
0300                 archinclude=x86
0301         else
0302                 archinclude=${SUBARCH}
0303         fi
0304 elif [ "${SRCARCH}" = "arm" -a "${SUBARCH}" != "" ]; then
0305         subarchdir=$(find ${tree}arch/$SRCARCH/ -name "mach-*" -type d -o \
0306                                                         -name "plat-*" -type d);
0307         mach_suffix=$SUBARCH
0308         plat_suffix=$SUBARCH
0309 
0310         # Special cases when $plat_suffix != $mach_suffix
0311         case $mach_suffix in
0312                 "omap1" | "omap2")
0313                         plat_suffix="omap"
0314                         ;;
0315         esac
0316 
0317         if [ ! -d ${tree}arch/$SRCARCH/mach-$mach_suffix ]; then
0318                 echo "Warning: arch/arm/mach-$mach_suffix/ not found." >&2
0319                 echo "         Fix your \$SUBARCH appropriately" >&2
0320         fi
0321 
0322         for i in $subarchdir; do
0323                 case "$i" in
0324                         *"mach-"${mach_suffix})
0325                                 ;;
0326                         *"plat-"${plat_suffix})
0327                                 ;;
0328                         *)
0329                                 subarchprune="$subarchprune \
0330                                                 -wholename $i -prune -o"
0331                                 ;;
0332                 esac
0333         done
0334 fi
0335 
0336 remove_structs=
0337 case "$1" in
0338         "cscope")
0339                 docscope
0340                 ;;
0341 
0342         "gtags")
0343                 dogtags
0344                 ;;
0345 
0346         "tags")
0347                 rm -f tags
0348                 xtags ctags
0349                 remove_structs=y
0350                 ;;
0351 
0352         "TAGS")
0353                 rm -f TAGS
0354                 xtags etags
0355                 remove_structs=y
0356                 ;;
0357 esac
0358 
0359 # Remove structure forward declarations.
0360 if [ -n "$remove_structs" ]; then
0361     LANG=C sed -i -e '/^\([a-zA-Z_][a-zA-Z0-9_]*\)\t.*\t\/\^struct \1;.*\$\/;"\tx$/d' $1
0362 fi