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