devtools: support FreeBSD
[dpdk.git] / devtools / test-build.sh
1 #! /bin/sh -e
2 # SPDX-License-Identifier: BSD-3-Clause
3 # Copyright 2015 6WIND S.A.
4
5 default_path=$PATH
6
7 # Load config options:
8 # - ARMV8_CRYPTO_LIB_PATH
9 # - DPDK_BUILD_TEST_CONFIGS (defconfig1+option1+option2 defconfig2)
10 # - DPDK_DEP_ARCHIVE
11 # - DPDK_DEP_CFLAGS
12 # - DPDK_DEP_ELF (y/[n])
13 # - DPDK_DEP_ISAL (y/[n])
14 # - DPDK_DEP_JSON (y/[n])
15 # - DPDK_DEP_LDFLAGS
16 # - DPDK_DEP_MLX (y/[n])
17 # - DPDK_DEP_NUMA ([y]/n)
18 # - DPDK_DEP_PCAP (y/[n])
19 # - DPDK_DEP_SSL (y/[n])
20 # - DPDK_DEP_IPSEC_MB (y/[n])
21 # - DPDK_DEP_SZE (y/[n])
22 # - DPDK_DEP_NFB (y/[n])
23 # - DPDK_DEP_ZLIB (y/[n])
24 # - DPDK_MAKE_JOBS (int)
25 # - DPDK_NOTIFY (notify-send)
26 # - FLEXRAN_SDK
27 # - LIBMUSDK_PATH
28 # - LIBSSO_SNOW3G_PATH
29 # - LIBSSO_KASUMI_PATH
30 # - LIBSSO_ZUC_PATH
31 . $(dirname $(readlink -f $0))/load-devel-config
32
33 print_usage () {
34         echo "usage: $(basename $0) [-h] [-jX] [-s] [config1 [config2] ...]]"
35 }
36
37 print_help () {
38         echo 'Test building several targets with different options'
39         echo
40         print_usage
41         cat <<- END_OF_HELP
42
43         options:
44                 -h    this help
45                 -jX   use X parallel jobs in "make"
46                 -s    short test only first config without tests|examples|doc
47                 -v    verbose build
48
49         config: defconfig[[~][+]option1[[~][+]option2...]]
50                 Example: x86_64-native-linux-gcc+debug~RXTX_CALLBACKS
51                 The lowercase options are defined inside $(basename $0).
52                 The uppercase options can be the end of a defconfig option
53                 to enable if prefixed with '+' or to disable if prefixed with '~'.
54                 Default is to automatically enable most of the options.
55                 The external dependencies are setup with DPDK_DEP_* variables.
56                 If no config on command line, DPDK_BUILD_TEST_CONFIGS is used.
57         END_OF_HELP
58 }
59
60 [ -z $MAKE ] && command -v gmake > /dev/null && MAKE=gmake
61 [ -z $MAKE ] && command -v make > /dev/null && MAKE=make
62 [ -z $MAKE ] && echo "Cannot find make or gmake" && exit 1
63
64 J=$DPDK_MAKE_JOBS
65 short=false
66 unset verbose
67 maxerr=-Wfatal-errors
68 while getopts hj:sv ARG ; do
69         case $ARG in
70                 j ) J=$OPTARG ;;
71                 s ) short=true ;;
72                 v ) verbose='V=1' ;;
73                 h ) print_help ; exit 0 ;;
74                 ? ) print_usage ; exit 1 ;;
75         esac
76 done
77 shift $(($OPTIND - 1))
78 configs=${*:-$DPDK_BUILD_TEST_CONFIGS}
79
80 success=false
81 on_exit ()
82 {
83         if $success ; then
84                 [ "$DPDK_NOTIFY" != notify-send ] || \
85                         notify-send -u low --icon=dialog-information 'DPDK build' 'finished'
86         elif [ -z "$signal" ] ; then
87                 [ -z "$dir" ] || echo "failed to build $dir" >&2
88                 [ "$DPDK_NOTIFY" != notify-send ] || \
89                         notify-send -u low --icon=dialog-error 'DPDK build' 'failed'
90         fi
91 }
92 # catch manual interrupt to ignore notification
93 trap "signal=INT ; trap - INT ; kill -INT $$" INT
94 # notify result on exit
95 trap on_exit EXIT
96
97 cd $(dirname $(readlink -f $0))/..
98
99 reset_env ()
100 {
101         export PATH=$default_path
102         unset CROSS
103         unset DPDK_DEP_ARCHIVE
104         unset DPDK_DEP_CFLAGS
105         unset DPDK_DEP_ELF
106         unset DPDK_DEP_ISAL
107         unset DPDK_DEP_JSON
108         unset DPDK_DEP_LDFLAGS
109         unset DPDK_DEP_MLX
110         unset DPDK_DEP_NUMA
111         unset DPDK_DEP_PCAP
112         unset DPDK_DEP_SSL
113         unset DPDK_DEP_IPSEC_MB
114         unset DPDK_DEP_SZE
115         unset DPDK_DEP_ZLIB
116         unset ARMV8_CRYPTO_LIB_PATH
117         unset FLEXRAN_SDK
118         unset LIBMUSDK_PATH
119         unset LIBSSO_SNOW3G_PATH
120         unset LIBSSO_KASUMI_PATH
121         unset LIBSSO_ZUC_PATH
122         unset PQOS_INSTALL_PATH
123 }
124
125 config () # <directory> <target> <options>
126 {
127         reconfig=false
128         if git rev-parse 2>&- && [ -n "$(git diff HEAD~ -- config)" ] ; then
129                 echo 'Default config may have changed'
130                 reconfig=true
131         fi
132         if [ ! -e $1/.config ] || $reconfig ; then
133                 echo "================== Configure $1"
134                 ${MAKE} T=$2 O=$1 config
135
136                 echo 'Customize configuration'
137                 # Built-in options (lowercase)
138                 ! echo $3 | grep -q '+default' || \
139                 sed -ri="" 's,(RTE_MACHINE=")native,\1default,' $1/.config
140                 echo $3 | grep -q '+next' || \
141                 sed -ri=""           's,(NEXT_ABI=)y,\1n,' $1/.config
142                 ! echo $3 | grep -q '+shared' || \
143                 sed -ri=""         's,(SHARED_LIB=)n,\1y,' $1/.config
144                 ! echo $3 | grep -q '+debug' || ( \
145                 sed -ri=""  's,(RTE_LOG_DP_LEVEL=).*,\1RTE_LOG_DEBUG,' $1/.config
146                 sed -ri=""           's,(_DEBUG.*=)n,\1y,' $1/.config
147                 sed -ri=""            's,(_STAT.*=)n,\1y,' $1/.config
148                 sed -ri="" 's,(TEST_PMD_RECORD_.*=)n,\1y,' $1/.config )
149
150                 # Automatic configuration
151                 test "$DPDK_DEP_NUMA" != n || \
152                 sed -ri=""             's,(NUMA.*=)y,\1n,' $1/.config
153                 sed -ri=""    's,(LIBRTE_IEEE1588=)n,\1y,' $1/.config
154                 sed -ri=""             's,(BYPASS=)n,\1y,' $1/.config
155                 test "$DPDK_DEP_ARCHIVE" != y || \
156                 sed -ri=""       's,(RESOURCE_TAR=)n,\1y,' $1/.config
157                 test "$DPDK_DEP_ISAL" != y || \
158                 sed -ri=""           's,(PMD_ISAL=)n,\1y,' $1/.config
159                 test "$DPDK_DEP_MLX" != y || \
160                 sed -ri=""           's,(MLX._PMD=)n,\1y,' $1/.config
161                 test "$DPDK_DEP_SZE" != y || \
162                 sed -ri=""       's,(PMD_SZEDATA2=)n,\1y,' $1/.config
163                 test "$DPDK_DEP_ZLIB" != y || \
164                 sed -ri=""          's,(BNX2X_PMD=)n,\1y,' $1/.config
165                 test "$DPDK_DEP_ZLIB" != y || \
166                 sed -ri=""           's,(PMD_ZLIB=)n,\1y,' $1/.config
167                 test "$DPDK_DEP_ZLIB" != y || \
168                 sed -ri=""   's,(COMPRESSDEV_TEST=)n,\1y,' $1/.config
169                 test "$DPDK_DEP_PCAP" != y || \
170                 sed -ri=""               's,(PCAP=)n,\1y,' $1/.config
171                 test -z "$ARMV8_CRYPTO_LIB_PATH" || \
172                 sed -ri=""   's,(PMD_ARMV8_CRYPTO=)n,\1y,' $1/.config
173                 test "$DPDK_DEP_IPSEC_MB" != y || \
174                 sed -ri=""       's,(PMD_AESNI_MB=)n,\1y,' $1/.config
175                 test "$DPDK_DEP_IPSEC_MB" != y || \
176                 sed -ri=""      's,(PMD_AESNI_GCM=)n,\1y,' $1/.config
177                 test -z "$LIBSSO_SNOW3G_PATH" || \
178                 sed -ri=""         's,(PMD_SNOW3G=)n,\1y,' $1/.config
179                 test -z "$LIBSSO_KASUMI_PATH" || \
180                 sed -ri=""         's,(PMD_KASUMI=)n,\1y,' $1/.config
181                 test -z "$LIBSSO_ZUC_PATH" || \
182                 sed -ri=""            's,(PMD_ZUC=)n,\1y,' $1/.config
183                 test "$DPDK_DEP_SSL" != y || \
184                 sed -ri=""            's,(PMD_CCP=)n,\1y,' $1/.config
185                 test "$DPDK_DEP_SSL" != y || \
186                 sed -ri=""        's,(PMD_OPENSSL=)n,\1y,' $1/.config
187                 test "$DPDK_DEP_SSL" != y || \
188                 sed -ri=""            's,(QAT_SYM=)n,\1y,' $1/.config
189                 test -z "$FLEXRAN_SDK" || \
190                 sed -ri=""     's,(BBDEV_TURBO_SW=)n,\1y,' $1/.config
191                 sed -ri=""           's,(SCHED_.*=)n,\1y,' $1/.config
192                 test -z "$LIBMUSDK_PATH" || \
193                 sed -ri=""   's,(PMD_MVSAM_CRYPTO=)n,\1y,' $1/.config
194                 test -z "$LIBMUSDK_PATH" || \
195                 sed -ri=""          's,(MVPP2_PMD=)n,\1y,' $1/.config
196                 test -z "$LIBMUSDK_PATH" || \
197                 sed -ri=""         's,(MVNETA_PMD=)n,\1y,' $1/.config
198                 test "$DPDK_DEP_ELF" != y || \
199                 sed -ri=""            's,(BPF_ELF=)n,\1y,' $1/.config
200                 test "$DPDK_DEP_JSON" != y || \
201                 sed -ri=""          's,(TELEMETRY=)n,\1y,' $1/.config
202                 build_config_hook $1 $2 $3
203
204                 # Explicit enabler/disabler (uppercase)
205                 for option in $(echo $3 | sed 's,[~+], &,g') ; do
206                         pattern=$(echo $option | cut -c2-)
207                         if echo $option | grep -q '^~' ; then
208                                 sed -ri="" "s,($pattern=)y,\1n," $1/.config
209                         elif echo $option | grep -q '^+' ; then
210                                 sed -ri="" "s,($pattern=)n,\1y," $1/.config
211                         fi
212                 done
213         fi
214 }
215
216 # default empty hook to override in devel config
217 build_config_hook () # <directory> <target> <options>
218 {
219         :
220 }
221
222 for conf in $configs ; do
223         target=$(echo $conf | sed 's,[~+].*,,')
224         # reload config with DPDK_TARGET set
225         DPDK_TARGET=$target
226         reset_env
227         . $(dirname $(readlink -f $0))/load-devel-config
228
229         options=$(echo $conf | sed 's,[^~+]*,,')
230         dir=$conf
231         config $dir $target $options
232
233         echo "================== Build $dir"
234         ${MAKE} -j$J EXTRA_CFLAGS="$maxerr $DPDK_DEP_CFLAGS" \
235                 EXTRA_LDFLAGS="$DPDK_DEP_LDFLAGS" $verbose O=$dir
236         ! $short || break
237         echo "================== Build examples for $dir"
238         export RTE_SDK=$(pwd)
239         export RTE_TARGET=$dir
240         ${MAKE} -j$J -sC examples \
241                 EXTRA_LDFLAGS="$DPDK_DEP_LDFLAGS" $verbose \
242                 O=$(readlink -f $dir)/examples
243         unset RTE_TARGET
244         echo "################## $dir done."
245         unset dir
246 done
247
248 if ! $short ; then
249         mkdir -p .check
250         echo "================== Build doxygen HTML API"
251         ${MAKE} doc-api-html >/dev/null 2>.check/doc.txt
252         echo "================== Build sphinx HTML guides"
253         ${MAKE} doc-guides-html >/dev/null 2>>.check/doc.txt
254         echo "================== Check docs"
255         diff -u /dev/null .check/doc.txt
256 fi
257
258 success=true