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