2 # SPDX-License-Identifier: BSD-3-Clause
3 # Copyright(c) 2018 Intel Corporation
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.
10 # set pipefail option if possible
12 set -o | grep -q pipefail && set -o pipefail && PIPEFAIL=1
14 srcdir=$(dirname $(readlink -f $0))/..
15 . $srcdir/devtools/load-devel-config
18 use_shared="--default-library=shared"
19 builds_dir=${DPDK_BUILD_TEST_DIR:-.}
21 if command -v gmake >/dev/null 2>&1 ; then
26 if command -v ninja >/dev/null 2>&1 ; then
28 elif command -v ninja-build >/dev/null 2>&1 ; then
31 echo "ERROR: ninja is not found" >&2
34 if command -v ccache >/dev/null 2>&1 ; then
41 default_pkgpath=$PKG_CONFIG_PATH
42 default_cppflags=$CPPFLAGS
43 default_cflags=$CFLAGS
44 default_ldflags=$LDFLAGS
46 load_env () # <target compiler>
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
60 config () # <dir> <builddir> <meson options>
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
77 options="$options --werror -Dexamples=all"
78 options="$options --buildtype=debugoptimized"
79 for option in $DPDK_MESON_OPTIONS ; do
80 options="$options -D$option"
83 echo "$MESON $options $dir $builddir"
84 $MESON $options $dir $builddir
87 compile () # <builddir>
90 if [ -n "$TEST_MESON_BUILD_VERY_VERBOSE" ] ; then
91 # for full output from ninja use "-v"
92 echo "$ninja_cmd -v -C $builddir"
93 $ninja_cmd -v -C $builddir
94 elif [ -n "$TEST_MESON_BUILD_VERBOSE" ] ; then
95 # for keeping the history of short cmds, pipe through cat
96 echo "$ninja_cmd -C $builddir | cat"
97 $ninja_cmd -C $builddir | cat
99 echo "$ninja_cmd -C $builddir"
100 $ninja_cmd -C $builddir
104 install_target () # <builddir> <installdir>
107 if [ -n "$TEST_MESON_BUILD_VERY_VERBOSE$TEST_MESON_BUILD_VERBOSE" ]; then
108 echo "DESTDIR=$2 $ninja_cmd -C $1 install"
109 DESTDIR=$2 $ninja_cmd -C $1 install
111 echo "DESTDIR=$2 $ninja_cmd -C $1 install >/dev/null"
112 DESTDIR=$2 $ninja_cmd -C $1 install >/dev/null
116 build () # <directory> <target compiler> <meson options>
122 # skip build if compiler not available
123 command -v ${CC##* } >/dev/null 2>&1 || return 0
124 load_env $targetcc || return 0
125 config $srcdir $builds_dir/$targetdir $*
126 compile $builds_dir/$targetdir
127 if [ -n "$DPDK_ABI_REF_VERSION" ]; then
128 abirefdir=${DPDK_ABI_REF_DIR:-reference}/$DPDK_ABI_REF_VERSION
129 if [ ! -d $abirefdir/$targetdir ]; then
130 # clone current sources
131 if [ ! -d $abirefdir/src ]; then
132 git clone --local --no-hardlinks \
134 -b $DPDK_ABI_REF_VERSION \
135 $srcdir $abirefdir/src
138 rm -rf $abirefdir/build
139 config $abirefdir/src $abirefdir/build $*
140 compile $abirefdir/build
141 install_target $abirefdir/build $abirefdir/$targetdir
142 $srcdir/devtools/gen-abi.sh $abirefdir/$targetdir
145 install_target $builds_dir/$targetdir \
146 $(readlink -f $builds_dir/$targetdir/install)
147 $srcdir/devtools/gen-abi.sh \
148 $(readlink -f $builds_dir/$targetdir/install)
149 $srcdir/devtools/check-abi.sh $abirefdir/$targetdir \
150 $(readlink -f $builds_dir/$targetdir/install)
154 if [ "$1" = "-vv" ] ; then
155 TEST_MESON_BUILD_VERY_VERBOSE=1
156 elif [ "$1" = "-v" ] ; then
157 TEST_MESON_BUILD_VERBOSE=1
159 # we can't use plain verbose when we don't have pipefail option so up-level
160 if [ -z "$PIPEFAIL" -a -n "$TEST_MESON_BUILD_VERBOSE" ] ; then
161 echo "# Missing pipefail shell option, changing VERBOSE to VERY_VERBOSE"
162 TEST_MESON_BUILD_VERY_VERBOSE=1
165 # shared and static linked builds with gcc and clang
166 for c in gcc clang ; do
167 command -v $c >/dev/null 2>&1 || continue
168 for s in static shared ; do
169 export CC="$CCACHE $c"
170 build build-$c-$s $c --default-library=$s
175 # test compilation with minimal x86 instruction set
176 # Set the install path for libraries to "lib" explicitly to prevent problems
177 # with pkg-config prefixes if installed in "lib/x86_64-linux-gnu" later.
178 default_machine='nehalem'
179 ok=$(cc -march=$default_machine -E - < /dev/null > /dev/null 2>&1 || echo false)
180 if [ "$ok" = "false" ] ; then
181 default_machine='corei7'
183 build build-x86-default cc -Dlibdir=lib -Dmachine=$default_machine $use_shared
185 c=aarch64-linux-gnu-gcc
186 # generic armv8a with clang as host compiler
188 build build-arm64-host-clang $c $use_shared \
189 --cross-file $srcdir/config/arm/arm64_armv8_linux_gcc
191 # all gcc/arm configurations
192 for f in $srcdir/config/arm/arm64_[bdo]*gcc ; do
193 export CC="$CCACHE gcc"
194 build build-$(basename $f | tr '_' '-' | cut -d'-' -f-2) $c \
195 $use_shared --cross-file $f
199 # Test installation of the x86-default target, to be used for checking
200 # the sample apps build using the pkg-config file for cflags and libs
201 build_path=$(readlink -f $builds_dir/build-x86-default)
202 export DESTDIR=$build_path/install
203 # No need to reinstall if ABI checks are enabled
204 if [ -z "$DPDK_ABI_REF_VERSION" ]; then
205 install_target $build_path $DESTDIR
209 pc_file=$(find $DESTDIR -name libdpdk.pc)
210 export PKG_CONFIG_PATH=$(dirname $pc_file):$PKG_CONFIG_PATH
212 # if pkg-config defines the necessary flags, test building some examples
213 if pkg-config --define-prefix libdpdk >/dev/null 2>&1; then
214 export PKGCONF="pkg-config --define-prefix"
215 for example in cmdline helloworld l2fwd l3fwd skeleton timer; do
216 echo "## Building $example"
217 $MAKE -C $DESTDIR/usr/local/share/dpdk/examples/$example clean all