test mbuf attach
[dpdk.git] / devtools / test-meson-builds.sh
1 #! /bin/sh -e
2 # SPDX-License-Identifier: BSD-3-Clause
3 # Copyright(c) 2018 Intel Corporation
4
5 # Run meson to auto-configure the various builds.
6 # * all builds get put in a directory whose name starts with "build-"
7 # * if a build-directory already exists we assume it was properly configured
8 # Run ninja after configuration is done.
9
10 # set pipefail option if possible
11 PIPEFAIL=""
12 set -o | grep -q pipefail && set -o pipefail && PIPEFAIL=1
13
14 srcdir=$(dirname $(readlink -f $0))/..
15 . $srcdir/devtools/load-devel-config
16
17 MESON=${MESON:-meson}
18 use_shared="--default-library=shared"
19 builds_dir=${DPDK_BUILD_TEST_DIR:-.}
20
21 if command -v gmake >/dev/null 2>&1 ; then
22         MAKE=gmake
23 else
24         MAKE=make
25 fi
26 if command -v ninja >/dev/null 2>&1 ; then
27         ninja_cmd=ninja
28 elif command -v ninja-build >/dev/null 2>&1 ; then
29         ninja_cmd=ninja-build
30 else
31         echo "ERROR: ninja is not found" >&2
32         exit 1
33 fi
34 if command -v ccache >/dev/null 2>&1 ; then
35         CCACHE=ccache
36 else
37         CCACHE=
38 fi
39
40 default_path=$PATH
41 default_pkgpath=$PKG_CONFIG_PATH
42 default_cppflags=$CPPFLAGS
43 default_cflags=$CFLAGS
44 default_ldflags=$LDFLAGS
45
46 load_env () # <target compiler>
47 {
48         targetcc=$1
49         export PATH=$default_path
50         export PKG_CONFIG_PATH=$default_pkgpath
51         export CPPFLAGS=$default_cppflags
52         export CFLAGS=$default_cflags
53         export LDFLAGS=$default_ldflags
54         unset DPDK_MESON_OPTIONS
55         if command -v $targetcc >/dev/null 2>&1 ; then
56                 DPDK_TARGET=$($targetcc -v 2>&1 | sed -n 's,^Target: ,,p')
57         else # toolchain not yet in PATH: its name should be enough
58                 DPDK_TARGET=$targetcc
59         fi
60         # config input: $DPDK_TARGET
61         . $srcdir/devtools/load-devel-config
62         # config output: $DPDK_MESON_OPTIONS, $PATH, $PKG_CONFIG_PATH, etc
63         command -v $targetcc >/dev/null 2>&1 || return 1
64 }
65
66 config () # <dir> <builddir> <meson options>
67 {
68         dir=$1
69         shift
70         builddir=$1
71         shift
72         if [ -f "$builddir/build.ninja" ] ; then
73                 # for existing environments, switch to debugoptimized if unset
74                 # so that ABI checks can run
75                 if ! $MESON configure $builddir |
76                                 awk '$1=="buildtype" {print $2}' |
77                                 grep -qw debugoptimized; then
78                         $MESON configure --buildtype=debugoptimized $builddir
79                 fi
80                 return
81         fi
82         options=
83         if echo $* | grep -qw -- '--default-library=shared' ; then
84                 options="$options -Dexamples=all"
85         else
86                 options="$options -Dexamples=l3fwd" # save disk space
87         fi
88         options="$options --buildtype=debugoptimized"
89         for option in $DPDK_MESON_OPTIONS ; do
90                 options="$options -D$option"
91         done
92         options="$options $*"
93         echo "$MESON $options $dir $builddir"
94         $MESON $options $dir $builddir
95 }
96
97 compile () # <builddir>
98 {
99         builddir=$1
100         if [ -n "$TEST_MESON_BUILD_VERY_VERBOSE" ] ; then
101                 # for full output from ninja use "-v"
102                 echo "$ninja_cmd -v -C $builddir"
103                 $ninja_cmd -v -C $builddir
104         elif [ -n "$TEST_MESON_BUILD_VERBOSE" ] ; then
105                 # for keeping the history of short cmds, pipe through cat
106                 echo "$ninja_cmd -C $builddir | cat"
107                 $ninja_cmd -C $builddir | cat
108         else
109                 echo "$ninja_cmd -C $builddir"
110                 $ninja_cmd -C $builddir
111         fi
112 }
113
114 install_target () # <builddir> <installdir>
115 {
116         rm -rf $2
117         if [ -n "$TEST_MESON_BUILD_VERY_VERBOSE$TEST_MESON_BUILD_VERBOSE" ]; then
118                 echo "DESTDIR=$2 $ninja_cmd -C $1 install"
119                 DESTDIR=$2 $ninja_cmd -C $1 install
120         else
121                 echo "DESTDIR=$2 $ninja_cmd -C $1 install >/dev/null"
122                 DESTDIR=$2 $ninja_cmd -C $1 install >/dev/null
123         fi
124 }
125
126 build () # <directory> <target compiler | cross file> <meson options>
127 {
128         targetdir=$1
129         shift
130         crossfile=
131         [ -r $1 ] && crossfile=$1 || targetcc=$1
132         shift
133         # skip build if compiler not available
134         command -v ${CC##* } >/dev/null 2>&1 || return 0
135         if [ -n "$crossfile" ] ; then
136                 cross="--cross-file $crossfile"
137                 targetcc=$(sed -n 's,^c[[:space:]]*=[[:space:]]*,,p' \
138                         $crossfile | tr -d "'" | tr -d '"')
139         else
140                 cross=
141         fi
142         load_env $targetcc || return 0
143         config $srcdir $builds_dir/$targetdir $cross --werror $*
144         compile $builds_dir/$targetdir
145         if [ -n "$DPDK_ABI_REF_VERSION" ]; then
146                 abirefdir=${DPDK_ABI_REF_DIR:-reference}/$DPDK_ABI_REF_VERSION
147                 if [ ! -d $abirefdir/$targetdir ]; then
148                         # clone current sources
149                         if [ ! -d $abirefdir/src ]; then
150                                 git clone --local --no-hardlinks \
151                                         --single-branch \
152                                         -b $DPDK_ABI_REF_VERSION \
153                                         $srcdir $abirefdir/src
154                         fi
155
156                         rm -rf $abirefdir/build
157                         config $abirefdir/src $abirefdir/build $cross \
158                                 -Dexamples= $*
159                         compile $abirefdir/build
160                         install_target $abirefdir/build $abirefdir/$targetdir
161                         $srcdir/devtools/gen-abi.sh $abirefdir/$targetdir
162
163                         # save disk space by removing static libs and apps
164                         find $abirefdir/$targetdir/usr/local -name '*.a' -delete
165                         rm -rf $abirefdir/$targetdir/usr/local/bin
166                         rm -rf $abirefdir/$targetdir/usr/local/share
167                 fi
168
169                 install_target $builds_dir/$targetdir \
170                         $(readlink -f $builds_dir/$targetdir/install)
171                 $srcdir/devtools/gen-abi.sh \
172                         $(readlink -f $builds_dir/$targetdir/install)
173                 $srcdir/devtools/check-abi.sh $abirefdir/$targetdir \
174                         $(readlink -f $builds_dir/$targetdir/install)
175         fi
176 }
177
178 if [ "$1" = "-vv" ] ; then
179         TEST_MESON_BUILD_VERY_VERBOSE=1
180 elif [ "$1" = "-v" ] ; then
181         TEST_MESON_BUILD_VERBOSE=1
182 fi
183 # we can't use plain verbose when we don't have pipefail option so up-level
184 if [ -z "$PIPEFAIL" -a -n "$TEST_MESON_BUILD_VERBOSE" ] ; then
185         echo "# Missing pipefail shell option, changing VERBOSE to VERY_VERBOSE"
186         TEST_MESON_BUILD_VERY_VERBOSE=1
187 fi
188
189 # shared and static linked builds with gcc and clang
190 for c in gcc clang ; do
191         command -v $c >/dev/null 2>&1 || continue
192         for s in static shared ; do
193                 export CC="$CCACHE $c"
194                 build build-$c-$s $c --default-library=$s
195                 unset CC
196         done
197 done
198
199 # test compilation with minimal x86 instruction set
200 # Set the install path for libraries to "lib" explicitly to prevent problems
201 # with pkg-config prefixes if installed in "lib/x86_64-linux-gnu" later.
202 default_machine='nehalem'
203 ok=$(cc -march=$default_machine -E - < /dev/null > /dev/null 2>&1 || echo false)
204 if [ "$ok" = "false" ] ; then
205         default_machine='corei7'
206 fi
207 build build-x86-default cc -Dlibdir=lib -Dmachine=$default_machine $use_shared
208
209 # x86 MinGW
210 build build-x86-mingw $srcdir/config/x86/cross-mingw -Dexamples=helloworld
211
212 # generic armv8a with clang as host compiler
213 f=$srcdir/config/arm/arm64_armv8_linux_gcc
214 export CC="clang"
215 build build-arm64-host-clang $f $use_shared
216 unset CC
217 # some gcc/arm configurations
218 for f in $srcdir/config/arm/arm64_[bdo]*gcc ; do
219         export CC="$CCACHE gcc"
220         build build-$(basename $f | tr '_' '-' | cut -d'-' -f-2) $f $use_shared
221         unset CC
222 done
223
224 # ppc configurations
225 for f in $srcdir/config/ppc/ppc* ; do
226         build build-$(basename $f | cut -d'-' -f-2) $f $use_shared
227 done
228
229 # Test installation of the x86-default target, to be used for checking
230 # the sample apps build using the pkg-config file for cflags and libs
231 build_path=$(readlink -f $builds_dir/build-x86-default)
232 export DESTDIR=$build_path/install
233 # No need to reinstall if ABI checks are enabled
234 if [ -z "$DPDK_ABI_REF_VERSION" ]; then
235         install_target $build_path $DESTDIR
236 fi
237
238 load_env cc
239 pc_file=$(find $DESTDIR -name libdpdk.pc)
240 export PKG_CONFIG_PATH=$(dirname $pc_file):$PKG_CONFIG_PATH
241
242 # if pkg-config defines the necessary flags, test building some examples
243 if pkg-config --define-prefix libdpdk >/dev/null 2>&1; then
244         export PKGCONF="pkg-config --define-prefix"
245         for example in cmdline helloworld l2fwd l3fwd skeleton timer; do
246                 echo "## Building $example"
247                 $MAKE -C $DESTDIR/usr/local/share/dpdk/examples/$example clean shared static
248         done
249 fi