1#!/bin/sh -e 2# SPDX-License-Identifier: BSD-3-Clause 3# Copyright(c) 2017 Cavium, Inc 4# 5 6# 7# Generate tags or gtags or cscope or etags files 8# 9 10verbose=false 11linux=true 12bsd=true 13x86_32=true 14x86_64=true 15ppc_64=true 16arm_32=true 17arm_64=true 18 19print_usage() 20{ 21 echo "Usage: $(basename $0) [-h] [-v] tags|cscope|gtags|etags [config]" 22 echo "Valid configs are:" 23 make showconfigs | sed 's,^,\t,' 24} 25 26# Move to the root of the git tree 27cd $(dirname $0)/.. 28 29while getopts hv ARG ; do 30 case $ARG in 31 v ) verbose=true ;; 32 h ) print_usage; exit 0 ;; 33 ? ) print_usage; exit 1 ;; 34 esac 35done 36shift $(($OPTIND - 1)) 37 38#ignore version control files 39ignore="( -name .svn -o -name CVS -o -name .hg -o -name .git ) -prune -o" 40 41source_dirs="test app buildtools drivers examples lib" 42 43skip_bsd="( -name bsdapp ) -prune -o" 44skip_linux="( -name linuxapp ) -prune -o" 45skip_arch="( -name arch ) -prune -o" 46skip_sse="( -name *_sse*.[chS] ) -prune -o" 47skip_avx="( -name *_avx*.[chS] ) -prune -o" 48skip_neon="( -name *_neon*.[chS] ) -prune -o" 49skip_altivec="( -name *_altivec*.[chS] ) -prune -o" 50skip_arm64="( -name *arm64*.[chS] ) -prune -o" 51skip_x86="( -name *x86*.[chS] ) -prune -o" 52skip_32b_files="( -name *_32.h ) -prune -o" 53skip_64b_files="( -name *_64.h ) -prune -o" 54 55skiplist="$skip_bsd $skip_linux $skip_arch $skip_sse $skip_avx \ 56 $skip_neon $skip_altivec $skip_x86 $skip_arm64" 57 58find_sources() 59{ 60 find $1 $ignore $3 -name $2 -not -type l -print 61} 62 63common_sources() 64{ 65 find_sources "$source_dirs" '*.[chS]' "$skiplist" 66} 67 68linux_sources() 69{ 70 find_sources "lib/librte_eal/linuxapp" '*.[chS]' 71} 72 73bsd_sources() 74{ 75 find_sources "lib/librte_eal/bsdapp" '*.[chS]' 76} 77 78arm_common() 79{ 80 find_sources "lib/librte_eal/common/arch/arm" '*.[chS]' 81 find_sources "$source_dirs" '*neon*.[chS]' 82} 83 84arm_32_sources() 85{ 86 arm_common 87 find_sources "lib/librte_eal/common/include/arch/arm" '*.[chS]' \ 88 "$skip_64b_files" 89} 90 91arm_64_sources() 92{ 93 arm_common 94 find_sources "lib/librte_eal/common/include/arch/arm" '*.[chS]' \ 95 "$skip_32b_files" 96 find_sources "$source_dirs" '*arm64.[chS]' 97} 98 99x86_common() 100{ 101 find_sources "lib/librte_eal/common/arch/x86" '*.[chS]' 102 103 find_sources "examples/performance-thread/common/arch/x86" '*.[chS]' 104 find_sources "$source_dirs" '*_sse*.[chS]' 105 find_sources "$source_dirs" '*_avx*.[chS]' 106 find_sources "$source_dirs" '*x86.[chS]' 107} 108 109x86_32_sources() 110{ 111 x86_common 112 find_sources "lib/librte_eal/common/include/arch/x86" '*.[chS]' \ 113 "$skip_64b_files" 114} 115 116x86_64_sources() 117{ 118 x86_common 119 find_sources "lib/librte_eal/common/include/arch/x86" '*.[chS]' \ 120 "$skip_32b_files" 121} 122 123ppc_64_sources() 124{ 125 find_sources "lib/librte_eal/common/arch/ppc_64" '*.[chS]' 126 find_sources "lib/librte_eal/common/include/arch/ppc_64" '*.[chS]' 127 find_sources "$source_dirs" '*altivec*.[chS]' 128} 129 130check_valid_target() 131{ 132 cfgfound=false 133 allconfigs=$(make showconfigs) 134 for cfg in $allconfigs ; do 135 if [ "$cfg" = "$1" ] ; then 136 cfgfound=true 137 fi 138 done 139 if ! $cfgfound ; then 140 echo "Invalid config: $1" 141 print_usage 142 exit 0 143 fi 144} 145 146if [ -n "$2" ]; then 147 check_valid_target $2 148 149 echo $2 | grep -q "linuxapp-" || linux=false 150 echo $2 | grep -q "bsdapp-" || bsd=false 151 echo $2 | grep -q "x86_64-" || x86_64=false 152 echo $2 | grep -q "arm-" || arm_32=false 153 echo $2 | grep -q "arm64-" || arm_64=false 154 echo $2 | grep -q "ppc_64-" || ppc_64=false 155 echo $2 | grep -q -e "i686-" -e "x32-" || x86_32=false 156fi 157 158all_sources() 159{ 160 common_sources 161 if $linux ; then linux_sources ; fi 162 if $bsd ; then bsd_sources ; fi 163 if $x86_64 ; then x86_64_sources ; fi 164 if $x86_32 ; then x86_32_sources ; fi 165 if $ppc_64 ; then ppc_64_sources ; fi 166 if $arm_32 ; then arm_32_sources ; fi 167 if $arm_64 ; then arm_64_sources ; fi 168} 169 170show_flags() 171{ 172 if $verbose ; then 173 echo "mode: $1" 174 echo "config: $2" 175 echo "linux: $linux" 176 echo "bsd: $bsd" 177 echo "x86_32: $x86_32" 178 echo "x86_64: $x86_64" 179 echo "ppc_64: $ppc_64" 180 echo "arm_32: $arm_32" 181 echo "arm_64: $arm_64" 182 fi 183} 184 185case "$1" in 186 "cscope") 187 show_flags $1 $2 188 all_sources > cscope.files 189 cscope -q -b -f cscope.out 190 ;; 191 "gtags") 192 show_flags $1 $2 193 all_sources | gtags -i -f - 194 ;; 195 "tags") 196 show_flags $1 $2 197 rm -f tags 198 all_sources | xargs ctags -a 199 ;; 200 "etags") 201 show_flags $1 $2 202 rm -f TAGS 203 all_sources | xargs etags -a 204 ;; 205 *) 206 echo "Invalid mode: $1" 207 print_usage 208 ;; 209esac 210