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