xref: /dpdk/devtools/build-tags.sh (revision 9cd9d3e702fba4700539c1a2eddac13dd14ecf70)
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="app buildtools drivers examples lib"
42
43skip_bsd="( -name freebsd ) -prune -o"
44skip_linux="( -name linux ) -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/linux" '*.[chS]'
71	find_sources "kernel/linux" '*.[chS]'
72}
73
74bsd_sources()
75{
76	find_sources "lib/librte_eal/freebsd" '*.[chS]'
77	find_sources "kernel/freebsd" '*.[chS]'
78}
79
80arm_common()
81{
82	find_sources "$source_dirs" '*neon*.[chS]'
83}
84
85arm_32_sources()
86{
87	arm_common
88	find_sources "lib/librte_eal/arm" '*.[chS]' \
89					"$skip_64b_files"
90}
91
92arm_64_sources()
93{
94	arm_common
95	find_sources "lib/librte_eal/arm" '*.[chS]' \
96					 "$skip_32b_files"
97	find_sources "$source_dirs" '*arm64.[chS]'
98}
99
100x86_common()
101{
102	find_sources "examples/performance-thread/common/arch/x86" '*.[chS]'
103	find_sources "$source_dirs" '*_sse*.[chS]'
104	find_sources "$source_dirs" '*_avx*.[chS]'
105	find_sources "$source_dirs" '*x86.[chS]'
106}
107
108x86_32_sources()
109{
110	x86_common
111	find_sources "lib/librte_eal/x86" '*.[chS]' \
112					"$skip_64b_files"
113}
114
115x86_64_sources()
116{
117	x86_common
118	find_sources "lib/librte_eal/x86" '*.[chS]' \
119					"$skip_32b_files"
120}
121
122ppc_64_sources()
123{
124	find_sources "lib/librte_eal/ppc" '*.[chS]'
125	find_sources "$source_dirs" '*altivec*.[chS]'
126}
127
128check_valid_target()
129{
130	if [ ! -f "config/defconfig_$1" ] ; then
131		echo "Invalid config: $1"
132		print_usage
133		exit 0
134	fi
135}
136
137if [ -n "$2" ]; then
138	check_valid_target $2
139
140	echo $2 | grep -q "linux" || linux=false
141	echo $2 | grep -q "bsd" || bsd=false
142	echo $2 | grep -q "x86_64-" || x86_64=false
143	echo $2 | grep -q "arm-" || arm_32=false
144	echo $2 | grep -q "arm64-" || arm_64=false
145	echo $2 | grep -q "ppc_64-" || ppc_64=false
146	echo $2 | grep -q -e "i686-" -e "x32-" || x86_32=false
147fi
148
149all_sources()
150{
151	common_sources
152	if $linux ; then linux_sources ; fi
153	if $bsd ; then bsd_sources ; fi
154	if $x86_64 ; then x86_64_sources ; fi
155	if $x86_32 ; then x86_32_sources ; fi
156	if $ppc_64 ; then ppc_64_sources ; fi
157	if $arm_32 ; then arm_32_sources ; fi
158	if $arm_64 ; then arm_64_sources ; fi
159}
160
161show_flags()
162{
163	if $verbose ; then
164		echo "mode:     $1"
165		echo "config:   $2"
166		echo "linux:    $linux"
167		echo "bsd:      $bsd"
168		echo "x86_32:   $x86_32"
169		echo "x86_64:   $x86_64"
170		echo "ppc_64:   $ppc_64"
171		echo "arm_32:   $arm_32"
172		echo "arm_64:   $arm_64"
173	fi
174}
175
176case "$1" in
177	"cscope")
178		show_flags $1 $2
179		all_sources > cscope.files
180		cscope -q -b -f cscope.out
181		;;
182	"gtags")
183		show_flags $1 $2
184		all_sources | gtags -i -f -
185		;;
186	"tags")
187		show_flags $1 $2
188		rm -f tags
189		all_sources | xargs ctags -a
190		;;
191	"etags")
192		show_flags $1 $2
193		rm -f TAGS
194		all_sources | xargs etags -a
195		;;
196	*)
197		echo "Invalid mode: $1"
198		print_usage
199		;;
200esac
201