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