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