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