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