mempool: fix slow allocation of large mempools
[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 abi_ref_build_dir=${DPDK_ABI_REF_BUILD_DIR:-reference}
20 builds_dir=${DPDK_BUILD_TEST_DIR:-.}
21
22 if command -v gmake >/dev/null 2>&1 ; then
23         MAKE=gmake
24 else
25         MAKE=make
26 fi
27 if command -v ninja >/dev/null 2>&1 ; then
28         ninja_cmd=ninja
29 elif command -v ninja-build >/dev/null 2>&1 ; then
30         ninja_cmd=ninja-build
31 else
32         echo "ERROR: ninja is not found" >&2
33         exit 1
34 fi
35 if command -v ccache >/dev/null 2>&1 ; then
36         CCACHE=ccache
37 else
38         CCACHE=
39 fi
40
41 default_path=$PATH
42 default_pkgpath=$PKG_CONFIG_PATH
43 default_cppflags=$CPPFLAGS
44 default_cflags=$CFLAGS
45 default_ldflags=$LDFLAGS
46
47 load_env () # <target compiler>
48 {
49         targetcc=$1
50         export PATH=$default_path
51         export PKG_CONFIG_PATH=$default_pkgpath
52         export CPPFLAGS=$default_cppflags
53         export CFLAGS=$default_cflags
54         export LDFLAGS=$default_ldflags
55         unset DPDK_MESON_OPTIONS
56         command -v $targetcc >/dev/null 2>&1 || return 1
57         DPDK_TARGET=$($targetcc -v 2>&1 | sed -n 's,^Target: ,,p')
58         . $srcdir/devtools/load-devel-config
59 }
60
61 build () # <directory> <target compiler> <meson options>
62 {
63         builddir=$builds_dir/$1
64         shift
65         targetcc=$1
66         shift
67         # skip build if compiler not available
68         command -v ${CC##* } >/dev/null 2>&1 || return 0
69         load_env $targetcc || return 0
70         if [ ! -f "$builddir/build.ninja" ] ; then
71                 options="--werror -Dexamples=all"
72                 for option in $DPDK_MESON_OPTIONS ; do
73                         options="$options -D$option"
74                 done
75                 options="$options $*"
76                 echo "$MESON $options $srcdir $builddir"
77                 $MESON $options $srcdir $builddir
78                 unset CC
79         fi
80         if [ -n "$TEST_MESON_BUILD_VERY_VERBOSE" ] ; then
81                 # for full output from ninja use "-v"
82                 echo "$ninja_cmd -v -C $builddir"
83                 $ninja_cmd -v -C $builddir
84         elif [ -n "$TEST_MESON_BUILD_VERBOSE" ] ; then
85                 # for keeping the history of short cmds, pipe through cat
86                 echo "$ninja_cmd -C $builddir | cat"
87                 $ninja_cmd -C $builddir | cat
88         else
89                 echo "$ninja_cmd -C $builddir"
90                 $ninja_cmd -C $builddir
91         fi
92
93         if [ -d $abi_ref_build_dir/$1/dump ]; then
94                 $srcdir/devtools/check-abi-dump.sh $builddir
95                         $abi_ref_build_dir/$1/dump
96         fi
97 }
98
99 if [ "$1" = "-vv" ] ; then
100         TEST_MESON_BUILD_VERY_VERBOSE=1
101 elif [ "$1" = "-v" ] ; then
102         TEST_MESON_BUILD_VERBOSE=1
103 fi
104 # we can't use plain verbose when we don't have pipefail option so up-level
105 if [ -z "$PIPEFAIL" -a -n "$TEST_MESON_BUILD_VERBOSE" ] ; then
106         echo "# Missing pipefail shell option, changing VERBOSE to VERY_VERBOSE"
107         TEST_MESON_BUILD_VERY_VERBOSE=1
108 fi
109
110 # shared and static linked builds with gcc and clang
111 for c in gcc clang ; do
112         command -v $c >/dev/null 2>&1 || continue
113         for s in static shared ; do
114                 export CC="$CCACHE $c"
115                 build build-$c-$s $c --default-library=$s
116         done
117 done
118
119 # test compilation with minimal x86 instruction set
120 # Set the install path for libraries to "lib" explicitly to prevent problems
121 # with pkg-config prefixes if installed in "lib/x86_64-linux-gnu" later.
122 default_machine='nehalem'
123 ok=$(cc -march=$default_machine -E - < /dev/null > /dev/null 2>&1 || echo false)
124 if [ "$ok" = "false" ] ; then
125         default_machine='corei7'
126 fi
127 build build-x86-default cc -Dlibdir=lib -Dmachine=$default_machine $use_shared
128
129 c=aarch64-linux-gnu-gcc
130 # generic armv8a with clang as host compiler
131 export CC="clang"
132 build build-arm64-host-clang $c $use_shared \
133         --cross-file $srcdir/config/arm/arm64_armv8_linux_gcc
134 # all gcc/arm configurations
135 for f in $srcdir/config/arm/arm64_[bdo]*gcc ; do
136         export CC="$CCACHE gcc"
137         build build-$(basename $f | tr '_' '-' | cut -d'-' -f-2) $c \
138                 $use_shared --cross-file $f
139 done
140
141 # Test installation of the x86-default target, to be used for checking
142 # the sample apps build using the pkg-config file for cflags and libs
143 build_path=$(readlink -f $builds_dir/build-x86-default)
144 export DESTDIR=$build_path/install-root
145 $ninja_cmd -C $build_path install
146
147 load_env cc
148 pc_file=$(find $DESTDIR -name libdpdk.pc)
149 export PKG_CONFIG_PATH=$(dirname $pc_file):$PKG_CONFIG_PATH
150
151 # if pkg-config defines the necessary flags, test building some examples
152 if pkg-config --define-prefix libdpdk >/dev/null 2>&1; then
153         export PKGCONF="pkg-config --define-prefix"
154         for example in cmdline helloworld l2fwd l3fwd skeleton timer; do
155                 echo "## Building $example"
156                 $MAKE -C $DESTDIR/usr/local/share/dpdk/examples/$example clean all
157         done
158 fi