57d1af47ef0cf2ef942362087a37f1d13a0916eb
[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 MESON=${MESON:-meson}
16 use_shared="--default-library=shared"
17
18 if command -v gmake >/dev/null 2>&1 ; then
19         MAKE=gmake
20 else
21         MAKE=make
22 fi
23 if command -v ninja >/dev/null 2>&1 ; then
24         ninja_cmd=ninja
25 elif command -v ninja-build >/dev/null 2>&1 ; then
26         ninja_cmd=ninja-build
27 else
28         echo "ERROR: ninja is not found" >&2
29         exit 1
30 fi
31
32 build () # <directory> <meson options>
33 {
34         builddir=$1
35         shift
36         if command -v $CC >/dev/null 2>&1 ; then
37                 if [ ! -f "$builddir/build.ninja" ] ; then
38                         options="--werror -Dexamples=all $*"
39                         echo "$MESON $options $srcdir $builddir"
40                         $MESON $options $srcdir $builddir
41                         unset CC
42                 fi
43                 if [ -n "$TEST_MESON_BUILD_VERY_VERBOSE" ] ; then
44                         # for full output from ninja use "-v"
45                         echo "$ninja_cmd -v -C $builddir"
46                         $ninja_cmd -v -C $builddir
47                 elif [ -n "$TEST_MESON_BUILD_VERBOSE" ] ; then
48                         # for keeping the history of short cmds, pipe through cat
49                         echo "$ninja_cmd -C $builddir | cat"
50                         $ninja_cmd -C $builddir | cat
51                 else
52                         echo "$ninja_cmd -C $builddir"
53                         $ninja_cmd -C $builddir
54                 fi
55         fi
56 }
57
58 if [ "$1" = "-vv" ] ; then
59         TEST_MESON_BUILD_VERY_VERBOSE=1
60 elif [ "$1" = "-v" ] ; then
61         TEST_MESON_BUILD_VERBOSE=1
62 fi
63 # we can't use plain verbose when we don't have pipefail option so up-level
64 if [ -z "$PIPEFAIL" -a -n "$TEST_MESON_BUILD_VERBOSE" ] ; then
65         echo "# Missing pipefail shell option, changing VERBOSE to VERY_VERBOSE"
66         TEST_MESON_BUILD_VERY_VERBOSE=1
67 fi
68
69 # shared and static linked builds with gcc and clang
70 for c in gcc clang ; do
71         command -v $c >/dev/null 2>&1 || continue
72         for s in static shared ; do
73                 export CC="ccache $c"
74                 build build-$c-$s --default-library=$s
75         done
76 done
77
78 # test compilation with minimal x86 instruction set
79 default_machine='nehalem'
80 ok=$(cc -march=$default_machine -E - < /dev/null > /dev/null 2>&1 || echo false)
81 if [ "$ok" = "false" ] ; then
82         default_machine='corei7'
83 fi
84 build build-x86-default -Dmachine=$default_machine $use_shared
85
86 # enable cross compilation if gcc cross-compiler is found
87 c=aarch64-linux-gnu-gcc
88 if command -v $c >/dev/null 2>&1 ; then
89         # compile the general v8a also for clang to increase coverage
90         export CC="clang"
91         build build-arm64-host-clang $use_shared \
92                 --cross-file $srcdir/config/arm/arm64_armv8_linux_gcc
93
94         for f in $srcdir/config/arm/arm*gcc ; do
95                 export CC="ccache gcc"
96                 build build-$(basename $f | tr '_' '-' | cut -d'-' -f-2) \
97                         $use_shared --cross-file $f
98         done
99 fi
100
101 # Test installation of the x86-default target, to be used for checking
102 # the sample apps build using the pkg-config file for cflags and libs
103 build_path=build-x86-default
104 export DESTDIR=$(pwd)/$build_path/install-root
105 $ninja_cmd -C $build_path install
106
107 pc_file=$(find $DESTDIR -name libdpdk.pc)
108 export PKG_CONFIG_PATH=$(dirname $pc_file):$PKG_CONFIG_PATH
109
110 for example in cmdline helloworld l2fwd l3fwd skeleton timer; do
111         echo "## Building $example"
112         $MAKE -C $DESTDIR/usr/local/share/dpdk/examples/$example clean all
113 done