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 | tr -d "'" | 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 223# test compilation with minimal x86 instruction set 224# Set the install path for libraries to "lib" explicitly to prevent problems 225# with pkg-config prefixes if installed in "lib/x86_64-linux-gnu" later. 226generic_machine='nehalem' 227if ! check_cc_flags "-march=$generic_machine" ; then 228 generic_machine='corei7' 229fi 230build build-x86-generic cc skipABI -Dcheck_includes=true \ 231 -Dlibdir=lib -Dmachine=$generic_machine $use_shared 232 233# 32-bit with default compiler 234if check_cc_flags '-m32' ; then 235 if [ -d '/usr/lib/i386-linux-gnu' ] ; then 236 # 32-bit pkgconfig on Debian/Ubuntu 237 export PKG_CONFIG_LIBDIR='/usr/lib/i386-linux-gnu/pkgconfig' 238 elif [ -d '/usr/lib32' ] ; then 239 # 32-bit pkgconfig on Arch 240 export PKG_CONFIG_LIBDIR='/usr/lib32/pkgconfig' 241 else 242 # 32-bit pkgconfig on RHEL/Fedora (lib vs lib64) 243 export PKG_CONFIG_LIBDIR='/usr/lib/pkgconfig' 244 fi 245 target_override='i386-pc-linux-gnu' 246 build build-32b cc ABI -Dc_args='-m32' -Dc_link_args='-m32' 247 target_override= 248 unset PKG_CONFIG_LIBDIR 249fi 250 251# x86 MinGW 252build build-x86-mingw $srcdir/config/x86/cross-mingw skipABI \ 253 -Dexamples=helloworld 254 255# generic armv8a with clang as host compiler 256f=$srcdir/config/arm/arm64_armv8_linux_gcc 257export CC="clang" 258build build-arm64-host-clang $f ABI $use_shared 259unset CC 260# some gcc/arm configurations 261for f in $srcdir/config/arm/arm64_[bdo]*gcc ; do 262 export CC="$CCACHE gcc" 263 targetdir=build-$(basename $f | tr '_' '-' | cut -d'-' -f-2) 264 build $targetdir $f skipABI $use_shared 265 unset CC 266done 267 268# ppc configurations 269for f in $srcdir/config/ppc/ppc* ; do 270 targetdir=build-$(basename $f | cut -d'-' -f-2) 271 build $targetdir $f ABI $use_shared 272done 273 274# Test installation of the x86-generic target, to be used for checking 275# the sample apps build using the pkg-config file for cflags and libs 276load_env cc 277build_path=$(readlink -f $builds_dir/build-x86-generic) 278export DESTDIR=$build_path/install 279install_target $build_path $DESTDIR 280pc_file=$(find $DESTDIR -name libdpdk.pc) 281export PKG_CONFIG_PATH=$(dirname $pc_file):$PKG_CONFIG_PATH 282libdir=$(dirname $(find $DESTDIR -name librte_eal.so)) 283export LD_LIBRARY_PATH=$libdir:$LD_LIBRARY_PATH 284examples=${DPDK_BUILD_TEST_EXAMPLES:-"cmdline helloworld l2fwd l3fwd skeleton timer"} 285# if pkg-config defines the necessary flags, test building some examples 286if pkg-config --define-prefix libdpdk >/dev/null 2>&1; then 287 export PKGCONF="pkg-config --define-prefix" 288 for example in $examples; do 289 echo "## Building $example" 290 [ $example = helloworld ] && static=static || static= # save disk space 291 $MAKE -C $DESTDIR/usr/local/share/dpdk/examples/$example \ 292 clean shared $static >&$veryverbose 293 done 294fi 295