mk: optimize directory dependencies
[dpdk.git] / devtools / test-build.sh
1 #! /bin/sh -e
2
3 # BSD LICENSE
4 #
5 # Copyright 2015 6WIND S.A.
6 #
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
9 # are met:
10 #
11 #   * Redistributions of source code must retain the above copyright
12 #     notice, this list of conditions and the following disclaimer.
13 #   * Redistributions in binary form must reproduce the above copyright
14 #     notice, this list of conditions and the following disclaimer in
15 #     the documentation and/or other materials provided with the
16 #     distribution.
17 #   * Neither the name of 6WIND S.A. nor the names of its
18 #     contributors may be used to endorse or promote products derived
19 #     from this software without specific prior written permission.
20 #
21 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
33 default_path=$PATH
34
35 # Load config options:
36 # - AESNI_MULTI_BUFFER_LIB_PATH
37 # - ARMV8_CRYPTO_LIB_PATH
38 # - DPDK_BUILD_TEST_CONFIGS (defconfig1+option1+option2 defconfig2)
39 # - DPDK_DEP_ARCHIVE
40 # - DPDK_DEP_CFLAGS
41 # - DPDK_DEP_ISAL_CRYPTO (y/[n])
42 # - DPDK_DEP_LDFLAGS
43 # - DPDK_DEP_MOFED (y/[n])
44 # - DPDK_DEP_NUMA (y/[n])
45 # - DPDK_DEP_PCAP (y/[n])
46 # - DPDK_DEP_SSL (y/[n])
47 # - DPDK_DEP_SZE (y/[n])
48 # - DPDK_DEP_ZLIB (y/[n])
49 # - DPDK_MAKE_JOBS (int)
50 # - DPDK_NOTIFY (notify-send)
51 # - LIBSSO_SNOW3G_PATH
52 # - LIBSSO_KASUMI_PATH
53 # - LIBSSO_ZUC_PATH
54 . $(dirname $(readlink -e $0))/load-devel-config
55
56 print_usage () {
57         echo "usage: $(basename $0) [-h] [-jX] [-s] [config1 [config2] ...]]"
58 }
59
60 print_help () {
61         echo 'Test building several targets with different options'
62         echo
63         print_usage
64         cat <<- END_OF_HELP
65
66         options:
67                 -h    this help
68                 -jX   use X parallel jobs in "make"
69                 -s    short test with only first config without examples/doc
70                 -v    verbose build
71
72         config: defconfig[[~][+]option1[[~][+]option2...]]
73                 Example: x86_64-native-linuxapp-gcc+debug~RXTX_CALLBACKS
74                 The lowercase options are defined inside $(basename $0).
75                 The uppercase options can be the end of a defconfig option
76                 to enable if prefixed with '+' or to disable if prefixed with '~'.
77                 Default is to automatically enable most of the options.
78                 The external dependencies are setup with DPDK_DEP_* variables.
79                 If no config on command line, DPDK_BUILD_TEST_CONFIGS is used.
80         END_OF_HELP
81 }
82
83 J=$DPDK_MAKE_JOBS
84 short=false
85 unset verbose
86 maxerr=-Wfatal-errors
87 while getopts hj:sv ARG ; do
88         case $ARG in
89                 j ) J=$OPTARG ;;
90                 s ) short=true ;;
91                 v ) verbose='V=1' ;;
92                 h ) print_help ; exit 0 ;;
93                 ? ) print_usage ; exit 1 ;;
94         esac
95 done
96 shift $(($OPTIND - 1))
97 configs=${*:-$DPDK_BUILD_TEST_CONFIGS}
98
99 success=false
100 on_exit ()
101 {
102         if $success ; then
103                 [ "$DPDK_NOTIFY" != notify-send ] || \
104                         notify-send -u low --icon=dialog-information 'DPDK build' 'finished'
105         elif [ -z "$signal" ] ; then
106                 [ -z "$dir" ] || echo "failed to build $dir" >&2
107                 [ "$DPDK_NOTIFY" != notify-send ] || \
108                         notify-send -u low --icon=dialog-error 'DPDK build' 'failed'
109         fi
110 }
111 # catch manual interrupt to ignore notification
112 trap "signal=INT ; trap - INT ; kill -INT $$" INT
113 # notify result on exit
114 trap on_exit EXIT
115
116 cd $(dirname $(readlink -m $0))/..
117
118 reset_env ()
119 {
120         export PATH=$default_path
121         unset CROSS
122         unset DPDK_DEP_ARCHIVE
123         unset DPDK_DEP_CFLAGS
124         unset DPDK_DEP_ISAL_CRYPTO
125         unset DPDK_DEP_LDFLAGS
126         unset DPDK_DEP_MOFED
127         unset DPDK_DEP_NUMA
128         unset DPDK_DEP_PCAP
129         unset DPDK_DEP_SSL
130         unset DPDK_DEP_SZE
131         unset DPDK_DEP_ZLIB
132         unset AESNI_MULTI_BUFFER_LIB_PATH
133         unset ARMV8_CRYPTO_LIB_PATH
134         unset LIBSSO_SNOW3G_PATH
135         unset LIBSSO_KASUMI_PATH
136         unset LIBSSO_ZUC_PATH
137         unset PQOS_INSTALL_PATH
138 }
139
140 config () # <directory> <target> <options>
141 {
142         reconfig=false
143         if git rev-parse 2>&- && [ -n "$(git diff HEAD~ -- config)" ] ; then
144                 echo 'Default config may have changed'
145                 reconfig=true
146         fi
147         if [ ! -e $1/.config ] || $reconfig ; then
148                 echo "================== Configure $1"
149                 make T=$2 O=$1 config
150
151                 echo 'Customize configuration'
152                 # Built-in options (lowercase)
153                 ! echo $3 | grep -q '+default' || \
154                 sed -ri 's,(RTE_MACHINE=")native,\1default,' $1/.config
155                 echo $3 | grep -q '+next' || \
156                 sed -ri           's,(NEXT_ABI=)y,\1n,' $1/.config
157                 ! echo $3 | grep -q '+shared' || \
158                 sed -ri         's,(SHARED_LIB=)n,\1y,' $1/.config
159                 ! echo $3 | grep -q '+debug' || ( \
160                 sed -ri     's,(RTE_LOG_LEVEL=).*,\1RTE_LOG_DEBUG,' $1/.config
161                 sed -ri           's,(_DEBUG.*=)n,\1y,' $1/.config
162                 sed -ri            's,(_STAT.*=)n,\1y,' $1/.config
163                 sed -ri 's,(TEST_PMD_RECORD_.*=)n,\1y,' $1/.config )
164
165                 # Automatic configuration
166                 test "$DPDK_DEP_NUMA" != y || \
167                 sed -ri               's,(NUMA=)n,\1y,' $1/.config
168                 sed -ri    's,(LIBRTE_IEEE1588=)n,\1y,' $1/.config
169                 sed -ri             's,(BYPASS=)n,\1y,' $1/.config
170                 test "$DPDK_DEP_ARCHIVE" != y || \
171                 sed -ri       's,(RESOURCE_TAR=)n,\1y,' $1/.config
172                 test "$DPDK_DEP_MOFED" != y || \
173                 sed -ri           's,(MLX._PMD=)n,\1y,' $1/.config
174                 test "$DPDK_DEP_SZE" != y || \
175                 sed -ri       's,(PMD_SZEDATA2=)n,\1y,' $1/.config
176                 test "$DPDK_DEP_ZLIB" != y || \
177                 sed -ri          's,(BNX2X_PMD=)n,\1y,' $1/.config
178                 sed -ri            's,(NFP_PMD=)n,\1y,' $1/.config
179                 test "$DPDK_DEP_PCAP" != y || \
180                 sed -ri               's,(PCAP=)n,\1y,' $1/.config
181                 test -z "$ARMV8_CRYPTO_LIB_PATH" || \
182                 sed -ri   's,(PMD_ARMV8_CRYPTO=)n,\1y,' $1/.config
183                 test -z "$AESNI_MULTI_BUFFER_LIB_PATH" || \
184                 sed -ri       's,(PMD_AESNI_MB=)n,\1y,' $1/.config
185                 test "$DPDK_DEP_ISAL_CRYPTO" != y || \
186                 sed -ri      's,(PMD_AESNI_GCM=)n,\1y,' $1/.config
187                 test -z "$LIBSSO_SNOW3G_PATH" || \
188                 sed -ri         's,(PMD_SNOW3G=)n,\1y,' $1/.config
189                 test -z "$LIBSSO_KASUMI_PATH" || \
190                 sed -ri         's,(PMD_KASUMI=)n,\1y,' $1/.config
191                 test -z "$LIBSSO_ZUC_PATH" || \
192                 sed -ri            's,(PMD_ZUC=)n,\1y,' $1/.config
193                 test "$DPDK_DEP_SSL" != y || \
194                 sed -ri        's,(PMD_OPENSSL=)n,\1y,' $1/.config
195                 test "$DPDK_DEP_SSL" != y || \
196                 sed -ri            's,(PMD_QAT=)n,\1y,' $1/.config
197                 sed -ri           's,(SCHED_.*=)n,\1y,' $1/.config
198                 build_config_hook $1 $2 $3
199
200                 # Explicit enabler/disabler (uppercase)
201                 for option in $(echo $3 | sed 's,[~+], &,g') ; do
202                         pattern=$(echo $option | cut -c2-)
203                         if echo $option | grep -q '^~' ; then
204                                 sed -ri "s,($pattern=)y,\1n," $1/.config
205                         elif echo $option | grep -q '^+' ; then
206                                 sed -ri "s,($pattern=)n,\1y," $1/.config
207                         fi
208                 done
209         fi
210 }
211
212 # default empty hook to override in devel config
213 build_config_hook () # <directory> <target> <options>
214 {
215         :
216 }
217
218 for conf in $configs ; do
219         target=$(echo $conf | sed 's,[~+].*,,')
220         # reload config with DPDK_TARGET set
221         DPDK_TARGET=$target
222         reset_env
223         . $(dirname $(readlink -e $0))/load-devel-config
224
225         options=$(echo $conf | sed 's,[^~+]*,,')
226         dir=$conf
227         config $dir $target $options
228
229         echo "================== Build $dir"
230         make -j$J EXTRA_CFLAGS="$maxerr $DPDK_DEP_CFLAGS" \
231                 EXTRA_LDFLAGS="$DPDK_DEP_LDFLAGS" $verbose O=$dir
232         ! $short || break
233         echo "================== Build examples for $dir"
234         export RTE_SDK=$(pwd)
235         export RTE_TARGET=$dir
236         make -j$J -sC examples \
237                 EXTRA_LDFLAGS="$DPDK_DEP_LDFLAGS" $verbose \
238                 O=$(readlink -m $dir/examples)
239         ! echo $target | grep -q '^x86_64' || \
240         make -j$J -sC examples/performance-thread \
241                 EXTRA_LDFLAGS="$DPDK_DEP_LDFLAGS" $verbose \
242                 O=$(readlink -m $dir/examples/performance-thread)
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