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