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))/.. 15. $srcdir/devtools/load-devel-config 16 17MESON=${MESON:-meson} 18use_shared="--default-library=shared" 19builds_dir=${DPDK_BUILD_TEST_DIR:-.} 20 21if command -v gmake >/dev/null 2>&1 ; then 22 MAKE=gmake 23else 24 MAKE=make 25fi 26if command -v ninja >/dev/null 2>&1 ; then 27 ninja_cmd=ninja 28elif command -v ninja-build >/dev/null 2>&1 ; then 29 ninja_cmd=ninja-build 30else 31 echo "ERROR: ninja is not found" >&2 32 exit 1 33fi 34if command -v ccache >/dev/null 2>&1 ; then 35 CCACHE=ccache 36else 37 CCACHE= 38fi 39 40default_path=$PATH 41default_pkgpath=$PKG_CONFIG_PATH 42default_cppflags=$CPPFLAGS 43default_cflags=$CFLAGS 44default_ldflags=$LDFLAGS 45 46load_env () # <target compiler> 47{ 48 targetcc=$1 49 export PATH=$default_path 50 export PKG_CONFIG_PATH=$default_pkgpath 51 export CPPFLAGS=$default_cppflags 52 export CFLAGS=$default_cflags 53 export LDFLAGS=$default_ldflags 54 unset DPDK_MESON_OPTIONS 55 command -v $targetcc >/dev/null 2>&1 || return 1 56 DPDK_TARGET=$($targetcc -v 2>&1 | sed -n 's,^Target: ,,p') 57 . $srcdir/devtools/load-devel-config 58} 59 60config () # <dir> <builddir> <meson options> 61{ 62 dir=$1 63 shift 64 builddir=$1 65 shift 66 if [ -f "$builddir/build.ninja" ] ; then 67 # for existing environments, switch to debugoptimized if unset 68 # so that ABI checks can run 69 if ! $MESON configure $builddir | 70 awk '$1=="buildtype" {print $2}' | 71 grep -qw debugoptimized; then 72 $MESON configure --buildtype=debugoptimized $builddir 73 fi 74 return 75 fi 76 options= 77 options="$options --werror" 78 if echo $* | grep -qw -- '--default-library=shared' ; then 79 options="$options -Dexamples=all" 80 else 81 options="$options -Dexamples=l3fwd" # save disk space 82 fi 83 options="$options --buildtype=debugoptimized" 84 for option in $DPDK_MESON_OPTIONS ; do 85 options="$options -D$option" 86 done 87 options="$options $*" 88 echo "$MESON $options $dir $builddir" 89 $MESON $options $dir $builddir 90} 91 92compile () # <builddir> 93{ 94 builddir=$1 95 if [ -n "$TEST_MESON_BUILD_VERY_VERBOSE" ] ; then 96 # for full output from ninja use "-v" 97 echo "$ninja_cmd -v -C $builddir" 98 $ninja_cmd -v -C $builddir 99 elif [ -n "$TEST_MESON_BUILD_VERBOSE" ] ; then 100 # for keeping the history of short cmds, pipe through cat 101 echo "$ninja_cmd -C $builddir | cat" 102 $ninja_cmd -C $builddir | cat 103 else 104 echo "$ninja_cmd -C $builddir" 105 $ninja_cmd -C $builddir 106 fi 107} 108 109install_target () # <builddir> <installdir> 110{ 111 rm -rf $2 112 if [ -n "$TEST_MESON_BUILD_VERY_VERBOSE$TEST_MESON_BUILD_VERBOSE" ]; then 113 echo "DESTDIR=$2 $ninja_cmd -C $1 install" 114 DESTDIR=$2 $ninja_cmd -C $1 install 115 else 116 echo "DESTDIR=$2 $ninja_cmd -C $1 install >/dev/null" 117 DESTDIR=$2 $ninja_cmd -C $1 install >/dev/null 118 fi 119} 120 121build () # <directory> <target compiler> <meson options> 122{ 123 targetdir=$1 124 shift 125 targetcc=$1 126 shift 127 # skip build if compiler not available 128 command -v ${CC##* } >/dev/null 2>&1 || return 0 129 load_env $targetcc || return 0 130 config $srcdir $builds_dir/$targetdir $* 131 compile $builds_dir/$targetdir 132 if [ -n "$DPDK_ABI_REF_VERSION" ]; then 133 abirefdir=${DPDK_ABI_REF_DIR:-reference}/$DPDK_ABI_REF_VERSION 134 if [ ! -d $abirefdir/$targetdir ]; then 135 # clone current sources 136 if [ ! -d $abirefdir/src ]; then 137 git clone --local --no-hardlinks \ 138 --single-branch \ 139 -b $DPDK_ABI_REF_VERSION \ 140 $srcdir $abirefdir/src 141 fi 142 143 rm -rf $abirefdir/build 144 config $abirefdir/src $abirefdir/build $* 145 compile $abirefdir/build 146 install_target $abirefdir/build $abirefdir/$targetdir 147 $srcdir/devtools/gen-abi.sh $abirefdir/$targetdir 148 fi 149 150 install_target $builds_dir/$targetdir \ 151 $(readlink -f $builds_dir/$targetdir/install) 152 $srcdir/devtools/gen-abi.sh \ 153 $(readlink -f $builds_dir/$targetdir/install) 154 $srcdir/devtools/check-abi.sh $abirefdir/$targetdir \ 155 $(readlink -f $builds_dir/$targetdir/install) 156 fi 157} 158 159if [ "$1" = "-vv" ] ; then 160 TEST_MESON_BUILD_VERY_VERBOSE=1 161elif [ "$1" = "-v" ] ; then 162 TEST_MESON_BUILD_VERBOSE=1 163fi 164# we can't use plain verbose when we don't have pipefail option so up-level 165if [ -z "$PIPEFAIL" -a -n "$TEST_MESON_BUILD_VERBOSE" ] ; then 166 echo "# Missing pipefail shell option, changing VERBOSE to VERY_VERBOSE" 167 TEST_MESON_BUILD_VERY_VERBOSE=1 168fi 169 170# shared and static linked builds with gcc and clang 171for c in gcc clang ; do 172 command -v $c >/dev/null 2>&1 || continue 173 for s in static shared ; do 174 export CC="$CCACHE $c" 175 build build-$c-$s $c --default-library=$s 176 unset CC 177 done 178done 179 180# test compilation with minimal x86 instruction set 181# Set the install path for libraries to "lib" explicitly to prevent problems 182# with pkg-config prefixes if installed in "lib/x86_64-linux-gnu" later. 183default_machine='nehalem' 184ok=$(cc -march=$default_machine -E - < /dev/null > /dev/null 2>&1 || echo false) 185if [ "$ok" = "false" ] ; then 186 default_machine='corei7' 187fi 188build build-x86-default cc -Dlibdir=lib -Dmachine=$default_machine $use_shared 189 190c=aarch64-linux-gnu-gcc 191# generic armv8a with clang as host compiler 192export CC="clang" 193build build-arm64-host-clang $c $use_shared \ 194 --cross-file $srcdir/config/arm/arm64_armv8_linux_gcc 195unset CC 196# all gcc/arm configurations 197for f in $srcdir/config/arm/arm64_[bdo]*gcc ; do 198 export CC="$CCACHE gcc" 199 build build-$(basename $f | tr '_' '-' | cut -d'-' -f-2) $c \ 200 $use_shared --cross-file $f 201 unset CC 202done 203 204# Test installation of the x86-default target, to be used for checking 205# the sample apps build using the pkg-config file for cflags and libs 206build_path=$(readlink -f $builds_dir/build-x86-default) 207export DESTDIR=$build_path/install 208# No need to reinstall if ABI checks are enabled 209if [ -z "$DPDK_ABI_REF_VERSION" ]; then 210 install_target $build_path $DESTDIR 211fi 212 213load_env cc 214pc_file=$(find $DESTDIR -name libdpdk.pc) 215export PKG_CONFIG_PATH=$(dirname $pc_file):$PKG_CONFIG_PATH 216 217# if pkg-config defines the necessary flags, test building some examples 218if pkg-config --define-prefix libdpdk >/dev/null 2>&1; then 219 export PKGCONF="pkg-config --define-prefix" 220 for example in cmdline helloworld l2fwd l3fwd skeleton timer; do 221 echo "## Building $example" 222 $MAKE -C $DESTDIR/usr/local/share/dpdk/examples/$example clean all 223 done 224fi 225