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