dpdk/devtools/test-meson-builds.sh
<<
>>
Prefs
   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_cppflags=$CPPFLAGS
  42default_cflags=$CFLAGS
  43default_ldflags=$LDFLAGS
  44default_meson_options=$DPDK_MESON_OPTIONS
  45
  46opt_verbose=
  47opt_vverbose=
  48if [ "$1" = "-v" ] ; then
  49        opt_verbose=y
  50elif [ "$1" = "-vv" ] ; then
  51        opt_verbose=y
  52        opt_vverbose=y
  53fi
  54# we can't use plain verbose when we don't have pipefail option so up-level
  55if [ -z "$PIPEFAIL" -a -n "$opt_verbose" ] ; then
  56        echo "# Missing pipefail shell option, changing VERBOSE to VERY_VERBOSE"
  57        opt_vverbose=y
  58fi
  59[ -n "$opt_verbose" ] && exec 8>&1 || exec 8>/dev/null
  60verbose=8
  61[ -n "$opt_vverbose" ] && exec 9>&1 || exec 9>/dev/null
  62veryverbose=9
  63
  64check_cc_flags () # <flag to check> <flag2> ...
  65{
  66        echo 'int main(void) { return 0; }' |
  67                cc $@ -x c - -o /dev/null 2> /dev/null
  68}
  69
  70load_env () # <target compiler>
  71{
  72        targetcc=$1
  73        # reset variables before target-specific config
  74        export PATH=$default_path
  75        unset PKG_CONFIG_PATH # global default makes no sense
  76        export CPPFLAGS=$default_cppflags
  77        export CFLAGS=$default_cflags
  78        export LDFLAGS=$default_ldflags
  79        export DPDK_MESON_OPTIONS=$default_meson_options
  80        # set target hint for use in the loaded config file
  81        if [ -n "$target_override" ] ; then
  82                DPDK_TARGET=$target_override
  83        elif command -v $targetcc >/dev/null 2>&1 ; then
  84                DPDK_TARGET=$($targetcc -v 2>&1 | sed -n 's,^Target: ,,p')
  85        else # toolchain not yet in PATH: its name should be enough
  86                DPDK_TARGET=$targetcc
  87        fi
  88        echo "Using DPDK_TARGET $DPDK_TARGET" >&$verbose
  89        # config input: $DPDK_TARGET
  90        . $srcdir/devtools/load-devel-config
  91        # config output: $DPDK_MESON_OPTIONS, $PATH, $PKG_CONFIG_PATH, etc
  92        command -v $targetcc >/dev/null 2>&1 || return 1
  93}
  94
  95config () # <dir> <builddir> <meson options>
  96{
  97        dir=$1
  98        shift
  99        builddir=$1
 100        shift
 101        if [ -f "$builddir/build.ninja" ] ; then
 102                # for existing environments, switch to debugoptimized if unset
 103                # so that ABI checks can run
 104                if ! $MESON configure $builddir |
 105                                awk '$1=="buildtype" {print $2}' |
 106                                grep -qw debugoptimized; then
 107                        $MESON configure --buildtype=debugoptimized $builddir
 108                fi
 109                return
 110        fi
 111        options=
 112        if echo $* | grep -qw -- '--default-library=shared' ; then
 113                options="$options -Dexamples=all"
 114        else
 115                options="$options -Dexamples=l3fwd" # save disk space
 116        fi
 117        options="$options --buildtype=debugoptimized"
 118        for option in $DPDK_MESON_OPTIONS ; do
 119                options="$options -D$option"
 120        done
 121        options="$options $*"
 122        echo "$MESON $options $dir $builddir" >&$verbose
 123        $MESON $options $dir $builddir
 124}
 125
 126compile () # <builddir>
 127{
 128        builddir=$1
 129        if [ -n "$opt_vverbose" ] ; then
 130                # for full output from ninja use "-v"
 131                echo "$ninja_cmd -v -C $builddir"
 132                $ninja_cmd -v -C $builddir
 133        elif [ -n "$opt_verbose" ] ; then
 134                # for keeping the history of short cmds, pipe through cat
 135                echo "$ninja_cmd -C $builddir | cat"
 136                $ninja_cmd -C $builddir | cat
 137        else
 138                $ninja_cmd -C $builddir
 139        fi
 140}
 141
 142install_target () # <builddir> <installdir>
 143{
 144        rm -rf $2
 145        echo "DESTDIR=$2 $ninja_cmd -C $1 install" >&$verbose
 146        DESTDIR=$2 $ninja_cmd -C $1 install >&$veryverbose
 147}
 148
 149build () # <directory> <target cc | cross file> <ABI check> [meson options]
 150{
 151        targetdir=$1
 152        shift
 153        crossfile=
 154        [ -r $1 ] && crossfile=$1 || targetcc=$1
 155        shift
 156        abicheck=$1
 157        shift
 158        # skip build if compiler not available
 159        command -v ${CC##* } >/dev/null 2>&1 || return 0
 160        if [ -n "$crossfile" ] ; then
 161                cross="--cross-file $crossfile"
 162                targetcc=$(sed -n 's,^c[[:space:]]*=[[:space:]]*,,p' \
 163                        $crossfile | cut -d ',' -f 2 | tr -d "'"'"] ')
 164        else
 165                cross=
 166        fi
 167        load_env $targetcc || return 0
 168        config $srcdir $builds_dir/$targetdir $cross --werror $*
 169        compile $builds_dir/$targetdir
 170        if [ -n "$DPDK_ABI_REF_VERSION" -a "$abicheck" = ABI ] ; then
 171                abirefdir=${DPDK_ABI_REF_DIR:-reference}/$DPDK_ABI_REF_VERSION
 172                if [ ! -d $abirefdir/$targetdir ]; then
 173                        # clone current sources
 174                        if [ ! -d $abirefdir/src ]; then
 175                                git clone --local --no-hardlinks \
 176                                        --single-branch \
 177                                        -b $DPDK_ABI_REF_VERSION \
 178                                        $srcdir $abirefdir/src
 179                        fi
 180
 181                        rm -rf $abirefdir/build
 182                        config $abirefdir/src $abirefdir/build $cross \
 183                                -Dexamples= $*
 184                        compile $abirefdir/build
 185                        install_target $abirefdir/build $abirefdir/$targetdir
 186                        $srcdir/devtools/gen-abi.sh $abirefdir/$targetdir
 187
 188                        # save disk space by removing static libs and apps
 189                        find $abirefdir/$targetdir/usr/local -name '*.a' -delete
 190                        rm -rf $abirefdir/$targetdir/usr/local/bin
 191                        rm -rf $abirefdir/$targetdir/usr/local/share
 192                fi
 193
 194                install_target $builds_dir/$targetdir \
 195                        $(readlink -f $builds_dir/$targetdir/install)
 196                echo "Checking ABI compatibility of $targetdir" >&$verbose
 197                echo $srcdir/devtools/gen-abi.sh \
 198                        $(readlink -f $builds_dir/$targetdir/install) >&$veryverbose
 199                $srcdir/devtools/gen-abi.sh \
 200                        $(readlink -f $builds_dir/$targetdir/install) >&$veryverbose
 201                echo $srcdir/devtools/check-abi.sh $abirefdir/$targetdir \
 202                        $(readlink -f $builds_dir/$targetdir/install) >&$veryverbose
 203                $srcdir/devtools/check-abi.sh $abirefdir/$targetdir \
 204                        $(readlink -f $builds_dir/$targetdir/install) >&$verbose
 205        fi
 206}
 207
 208# shared and static linked builds with gcc and clang
 209for c in gcc clang ; do
 210        command -v $c >/dev/null 2>&1 || continue
 211        for s in static shared ; do
 212                if [ $s = shared ] ; then
 213                        abicheck=ABI
 214                else
 215                        abicheck=skipABI # save time and disk space
 216                fi
 217                export CC="$CCACHE $c"
 218                build build-$c-$s $c $abicheck --default-library=$s
 219                unset CC
 220        done
 221done
 222
 223build build-mini cc skipABI $use_shared -Ddisable_libs=* \
 224        -Denable_drivers=net/null
 225
 226# test compilation with minimal x86 instruction set
 227# Set the install path for libraries to "lib" explicitly to prevent problems
 228# with pkg-config prefixes if installed in "lib/x86_64-linux-gnu" later.
 229generic_isa='nehalem'
 230if ! check_cc_flags "-march=$generic_isa" ; then
 231        generic_isa='corei7'
 232fi
 233build build-x86-generic cc skipABI -Dcheck_includes=true \
 234        -Dlibdir=lib -Dcpu_instruction_set=$generic_isa $use_shared
 235
 236# 32-bit with default compiler
 237if check_cc_flags '-m32' ; then
 238        if [ -d '/usr/lib/i386-linux-gnu' ] ; then
 239                # 32-bit pkgconfig on Debian/Ubuntu
 240                export PKG_CONFIG_LIBDIR='/usr/lib/i386-linux-gnu/pkgconfig'
 241        elif [ -d '/usr/lib32' ] ; then
 242                # 32-bit pkgconfig on Arch
 243                export PKG_CONFIG_LIBDIR='/usr/lib32/pkgconfig'
 244        else
 245                # 32-bit pkgconfig on RHEL/Fedora (lib vs lib64)
 246                export PKG_CONFIG_LIBDIR='/usr/lib/pkgconfig'
 247        fi
 248        target_override='i386-pc-linux-gnu'
 249        build build-32b cc ABI -Dc_args='-m32' -Dc_link_args='-m32' \
 250                        -Dcpp_args='-m32' -Dcpp_link_args='-m32'
 251        target_override=
 252        unset PKG_CONFIG_LIBDIR
 253fi
 254
 255# x86 MinGW
 256f=$srcdir/config/x86/cross-mingw
 257build build-x86-mingw $f skipABI -Dexamples=helloworld
 258
 259# generic armv8
 260f=$srcdir/config/arm/arm64_armv8_linux_gcc
 261build build-arm64-generic-gcc $f ABI $use_shared
 262
 263# IBM POWER
 264f=$srcdir/config/ppc/ppc64le-power8-linux-gcc
 265build build-ppc64-power8-gcc $f ABI $use_shared
 266
 267# generic RISC-V
 268f=$srcdir/config/riscv/riscv64_linux_gcc
 269build build-riscv64-generic-gcc $f ABI $use_shared
 270
 271# Test installation of the x86-generic target, to be used for checking
 272# the sample apps build using the pkg-config file for cflags and libs
 273load_env cc
 274build_path=$(readlink -f $builds_dir/build-x86-generic)
 275export DESTDIR=$build_path/install
 276install_target $build_path $DESTDIR
 277pc_file=$(find $DESTDIR -name libdpdk.pc)
 278export PKG_CONFIG_PATH=$(dirname $pc_file):$PKG_CONFIG_PATH
 279libdir=$(dirname $(find $DESTDIR -name librte_eal.so))
 280export LD_LIBRARY_PATH=$libdir:$LD_LIBRARY_PATH
 281examples=${DPDK_BUILD_TEST_EXAMPLES:-"cmdline helloworld l2fwd l3fwd skeleton timer"}
 282# if pkg-config defines the necessary flags, test building some examples
 283if pkg-config --define-prefix libdpdk >/dev/null 2>&1; then
 284        export PKGCONF="pkg-config --define-prefix"
 285        for example in $examples; do
 286                echo "## Building $example"
 287                [ $example = helloworld ] && static=static || static= # save disk space
 288                $MAKE -C $DESTDIR/usr/local/share/dpdk/examples/$example \
 289                        clean shared $static >&$veryverbose
 290        done
 291fi
 292