942da2bae92a35b762c2e6e4b129e664ac40b51d
[deb_dpdk.git] / devtools / build-tags.sh
1 #!/bin/sh -e
2 # Generate tags or gtags or cscope or etags files
3 #
4 #   BSD LICENSE
5 #
6 #   Copyright 2017 Cavium, Inc
7 #
8 #   Redistribution and use in source and binary forms, with or without
9 #   modification, are permitted provided that the following conditions
10 #   are met:
11 #
12 #     * Redistributions of source code must retain the above copyright
13 #       notice, this list of conditions and the following disclaimer.
14 #     * Redistributions in binary form must reproduce the above copyright
15 #       notice, this list of conditions and the following disclaimer in
16 #       the documentation and/or other materials provided with the
17 #       distribution.
18 #     * Neither the name of Cavium, Inc nor the names of its
19 #       contributors may be used to endorse or promote products derived
20 #       from this software without specific prior written permission.
21 #
22 #   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 #   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 #   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 #   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 #   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 #   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 #   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 #   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 #   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 #   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 #   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
34 verbose=false
35 linux=true
36 bsd=true
37 x86_32=true
38 x86_64=true
39 ppc_64=true
40 arm_32=true
41 arm_64=true
42
43 print_usage()
44 {
45         echo "Usage: $(basename $0) [-h] [-v] tags|cscope|gtags|etags [config]"
46         echo "Valid configs are:"
47         make showconfigs | sed 's,^,\t,'
48 }
49
50 # Move to the root of the git tree
51 cd $(dirname $0)/..
52
53 while getopts hv ARG ; do
54         case $ARG in
55                 v ) verbose=true ;;
56                 h ) print_usage; exit 0 ;;
57                 ? ) print_usage; exit 1 ;;
58         esac
59 done
60 shift $(($OPTIND - 1))
61
62 #ignore version control files
63 ignore="( -name .svn -o -name CVS -o -name .hg -o -name .git ) -prune -o"
64
65 source_dirs="test app buildtools drivers examples lib"
66
67 skip_bsd="( -name bsdapp ) -prune -o"
68 skip_linux="( -name linuxapp ) -prune -o"
69 skip_arch="( -name arch ) -prune -o"
70 skip_sse="( -name *_sse*.[chS] ) -prune -o"
71 skip_avx="( -name *_avx*.[chS] ) -prune -o"
72 skip_neon="( -name *_neon*.[chS] ) -prune -o"
73 skip_altivec="( -name *_altivec*.[chS] ) -prune -o"
74 skip_arm64="( -name *arm64*.[chS] ) -prune -o"
75 skip_x86="( -name *x86*.[chS] ) -prune -o"
76 skip_32b_files="( -name *_32.h ) -prune -o"
77 skip_64b_files="( -name *_64.h ) -prune -o"
78
79 skiplist="$skip_bsd $skip_linux $skip_arch $skip_sse $skip_avx \
80                  $skip_neon $skip_altivec $skip_x86 $skip_arm64"
81
82 find_sources()
83 {
84         find $1 $ignore $3 -name $2 -not -type l -print
85 }
86
87 common_sources()
88 {
89         find_sources "$source_dirs" '*.[chS]' "$skiplist"
90 }
91
92 linux_sources()
93 {
94         find_sources "lib/librte_eal/linuxapp" '*.[chS]'
95 }
96
97 bsd_sources()
98 {
99         find_sources "lib/librte_eal/bsdapp" '*.[chS]'
100 }
101
102 arm_common()
103 {
104         find_sources "lib/librte_eal/common/arch/arm" '*.[chS]'
105         find_sources "$source_dirs" '*neon*.[chS]'
106 }
107
108 arm_32_sources()
109 {
110         arm_common
111         find_sources "lib/librte_eal/common/include/arch/arm" '*.[chS]' \
112                                         "$skip_64b_files"
113 }
114
115 arm_64_sources()
116 {
117         arm_common
118         find_sources "lib/librte_eal/common/include/arch/arm" '*.[chS]' \
119                                          "$skip_32b_files"
120         find_sources "$source_dirs" '*arm64.[chS]'
121 }
122
123 x86_common()
124 {
125         find_sources "lib/librte_eal/common/arch/x86" '*.[chS]'
126
127         find_sources "examples/performance-thread/common/arch/x86" '*.[chS]'
128         find_sources "$source_dirs" '*_sse*.[chS]'
129         find_sources "$source_dirs" '*_avx*.[chS]'
130         find_sources "$source_dirs" '*x86.[chS]'
131 }
132
133 x86_32_sources()
134 {
135         x86_common
136         find_sources "lib/librte_eal/common/include/arch/x86" '*.[chS]' \
137                                         "$skip_64b_files"
138 }
139
140 x86_64_sources()
141 {
142         x86_common
143         find_sources "lib/librte_eal/common/include/arch/x86" '*.[chS]' \
144                                         "$skip_32b_files"
145 }
146
147 ppc_64_sources()
148 {
149         find_sources "lib/librte_eal/common/arch/ppc_64" '*.[chS]'
150         find_sources "lib/librte_eal/common/include/arch/ppc_64" '*.[chS]'
151         find_sources "$source_dirs" '*altivec*.[chS]'
152 }
153
154 check_valid_target()
155 {
156         cfgfound=false
157         allconfigs=$(make showconfigs)
158         for cfg in $allconfigs ; do
159                 if [ "$cfg" = "$1" ] ; then
160                         cfgfound=true
161                 fi
162         done
163         if ! $cfgfound ; then
164                 echo "Invalid config: $1"
165                 print_usage
166                 exit 0
167         fi
168 }
169
170 if [ -n "$2" ]; then
171         check_valid_target $2
172
173         echo $2 | grep -q "linuxapp-" || linux=false
174         echo $2 | grep -q "bsdapp-" || bsd=false
175         echo $2 | grep -q "x86_64-" || x86_64=false
176         echo $2 | grep -q "arm-" || arm_32=false
177         echo $2 | grep -q "arm64-" || arm_64=false
178         echo $2 | grep -q "ppc_64-" || ppc_64=false
179         echo $2 | grep -q -e "i686-" -e "x32-" || x86_32=false
180 fi
181
182 all_sources()
183 {
184         common_sources
185         if $linux ; then linux_sources ; fi
186         if $bsd ; then bsd_sources ; fi
187         if $x86_64 ; then x86_64_sources ; fi
188         if $x86_32 ; then x86_32_sources ; fi
189         if $ppc_64 ; then ppc_64_sources ; fi
190         if $arm_32 ; then arm_32_sources ; fi
191         if $arm_64 ; then arm_64_sources ; fi
192 }
193
194 show_flags()
195 {
196         if $verbose ; then
197                 echo "mode:     $1"
198                 echo "config:   $2"
199                 echo "linux:    $linux"
200                 echo "bsd:      $bsd"
201                 echo "x86_32:   $x86_32"
202                 echo "x86_64:   $x86_64"
203                 echo "ppc_64:   $ppc_64"
204                 echo "arm_32:   $arm_32"
205                 echo "arm_64:   $arm_64"
206         fi
207 }
208
209 case "$1" in
210         "cscope")
211                 show_flags $1 $2
212                 all_sources > cscope.files
213                 cscope -q -b -f cscope.out
214                 ;;
215         "gtags")
216                 show_flags $1 $2
217                 all_sources | gtags -i -f -
218                 ;;
219         "tags")
220                 show_flags $1 $2
221                 rm -f tags
222                 all_sources | xargs ctags -a
223                 ;;
224         "etags")
225                 show_flags $1 $2
226                 rm -f TAGS
227                 all_sources | xargs etags -a
228                 ;;
229         *)
230                 echo "Invalid mode: $1"
231                 print_usage
232                 ;;
233 esac