devtools: test meson build with available compilers
[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 ninja >/dev/null 2>&1 ; then
19         ninja_cmd=ninja
20 elif command -v ninja-build >/dev/null 2>&1 ; then
21         ninja_cmd=ninja-build
22 else
23         echo "ERROR: ninja is not found" >&2
24         exit 1
25 fi
26
27 build () # <directory> <meson options>
28 {
29         builddir=$1
30         shift
31         if command -v $CC >/dev/null 2>&1 ; then
32                 if [ ! -f "$builddir/build.ninja" ] ; then
33                         options="--werror -Dexamples=all $*"
34                         echo "$MESON $options $srcdir $builddir"
35                         $MESON $options $srcdir $builddir
36                         unset CC
37                 fi
38                 if [ -n "$TEST_MESON_BUILD_VERY_VERBOSE" ] ; then
39                         # for full output from ninja use "-v"
40                         echo "$ninja_cmd -v -C $builddir"
41                         $ninja_cmd -v -C $builddir
42                 elif [ -n "$TEST_MESON_BUILD_VERBOSE" ] ; then
43                         # for keeping the history of short cmds, pipe through cat
44                         echo "$ninja_cmd -C $builddir | cat"
45                         $ninja_cmd -C $builddir | cat
46                 else
47                         echo "$ninja_cmd -C $builddir"
48                         $ninja_cmd -C $builddir
49                 fi
50         fi
51 }
52
53 if [ "$1" = "-vv" ] ; then
54         TEST_MESON_BUILD_VERY_VERBOSE=1
55 elif [ "$1" = "-v" ] ; then
56         TEST_MESON_BUILD_VERBOSE=1
57 fi
58 # we can't use plain verbose when we don't have pipefail option so up-level
59 if [ -z "$PIPEFAIL" -a -n "$TEST_MESON_BUILD_VERBOSE" ] ; then
60         echo "# Missing pipefail shell option, changing VERBOSE to VERY_VERBOSE"
61         TEST_MESON_BUILD_VERY_VERBOSE=1
62 fi
63
64 # shared and static linked builds with gcc and clang
65 for c in gcc clang ; do
66         command -v $c >/dev/null 2>&1 || continue
67         for s in static shared ; do
68                 export CC="ccache $c"
69                 build build-$c-$s --default-library=$s
70         done
71 done
72
73 # test compilation with minimal x86 instruction set
74 default_machine='nehalem'
75 ok=$(cc -march=$default_machine -E - < /dev/null > /dev/null 2>&1 || echo false)
76 if [ "$ok" = "false" ] ; then
77         default_machine='corei7'
78 fi
79 build build-x86-default -Dmachine=$default_machine $use_shared
80
81 # enable cross compilation if gcc cross-compiler is found
82 c=aarch64-linux-gnu-gcc
83 if command -v $c >/dev/null 2>&1 ; then
84         # compile the general v8a also for clang to increase coverage
85         export CC="clang"
86         build build-arm64-host-clang $use_shared \
87                 --cross-file $srcdir/config/arm/arm64_armv8_linux_gcc
88
89         for f in $srcdir/config/arm/arm*gcc ; do
90                 export CC="ccache gcc"
91                 build build-$(basename $f | tr '_' '-' | cut -d'-' -f-2) \
92                         $use_shared --cross-file $f
93         done
94 fi