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_cppflags=$CPPFLAGS
42 default_cflags=$CFLAGS
43 default_ldflags=$LDFLAGS
44 default_meson_options=$DPDK_MESON_OPTIONS
48 if [ "$1" = "-v" ] ; then
50 elif [ "$1" = "-vv" ] ; then
54 # we can't use plain verbose when we don't have pipefail option so up-level
55 if [ -z "$PIPEFAIL" -a -n "$opt_verbose" ] ; then
56 echo "# Missing pipefail shell option, changing VERBOSE to VERY_VERBOSE"
59 [ -n "$opt_verbose" ] && exec 8>&1 || exec 8>/dev/null
61 [ -n "$opt_vverbose" ] && exec 9>&1 || exec 9>/dev/null
64 check_cc_flags () # <flag to check> <flag2> ...
66 echo 'int main(void) { return 0; }' |
67 cc $@ -x c - -o /dev/null 2> /dev/null
70 load_env () # <target compiler>
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
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
95 config () # <dir> <builddir> <meson options>
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
112 if echo $* | grep -qw -- '--default-library=shared' ; then
113 options="$options -Dexamples=all"
115 options="$options -Dexamples=l3fwd" # save disk space
117 options="$options --buildtype=debugoptimized"
118 for option in $DPDK_MESON_OPTIONS ; do
119 options="$options -D$option"
121 options="$options $*"
122 echo "$MESON $options $dir $builddir" >&$verbose
123 $MESON $options $dir $builddir
126 compile () # <builddir>
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
138 $ninja_cmd -C $builddir
142 install_target () # <builddir> <installdir>
145 echo "DESTDIR=$2 $ninja_cmd -C $1 install" >&$verbose
146 DESTDIR=$2 $ninja_cmd -C $1 install >&$veryverbose
149 build () # <directory> <target cc | cross file> <ABI check> [meson options]
154 [ -r $1 ] && crossfile=$1 || targetcc=$1
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 '"')
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 \
177 -b $DPDK_ABI_REF_VERSION \
178 $srcdir $abirefdir/src
181 rm -rf $abirefdir/build
182 config $abirefdir/src $abirefdir/build $cross \
184 compile $abirefdir/build
185 install_target $abirefdir/build $abirefdir/$targetdir
186 $srcdir/devtools/gen-abi.sh $abirefdir/$targetdir
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
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
208 # shared and static linked builds with gcc and clang
209 for 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
215 abicheck=skipABI # save time and disk space
217 export CC="$CCACHE $c"
218 build build-$c-$s $c $abicheck --default-library=$s
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.
226 generic_machine='nehalem'
227 if ! check_cc_flags "-march=$generic_machine" ; then
228 generic_machine='corei7'
230 build build-x86-generic cc skipABI -Dcheck_includes=true \
231 -Dlibdir=lib -Dmachine=$generic_machine $use_shared
233 # 32-bit with default compiler
234 if 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'
242 # 32-bit pkgconfig on RHEL/Fedora (lib vs lib64)
243 export PKG_CONFIG_LIBDIR='/usr/lib/pkgconfig'
245 target_override='i386-pc-linux-gnu'
246 build build-32b cc ABI -Dc_args='-m32' -Dc_link_args='-m32'
248 unset PKG_CONFIG_LIBDIR
252 build build-x86-mingw $srcdir/config/x86/cross-mingw skipABI \
253 -Dexamples=helloworld
255 # generic armv8a with clang as host compiler
256 f=$srcdir/config/arm/arm64_armv8_linux_gcc
258 build build-arm64-host-clang $f ABI $use_shared
260 # some gcc/arm configurations
261 for 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
269 for f in $srcdir/config/ppc/ppc* ; do
270 targetdir=build-$(basename $f | cut -d'-' -f-2)
271 build $targetdir $f ABI $use_shared
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
277 build_path=$(readlink -f $builds_dir/build-x86-generic)
278 export DESTDIR=$build_path/install
279 install_target $build_path $DESTDIR
280 pc_file=$(find $DESTDIR -name libdpdk.pc)
281 export PKG_CONFIG_PATH=$(dirname $pc_file):$PKG_CONFIG_PATH
282 libdir=$(dirname $(find $DESTDIR -name librte_eal.so))
283 export LD_LIBRARY_PATH=$libdir:$LD_LIBRARY_PATH
284 examples=${DPDK_BUILD_TEST_EXAMPLES:-"cmdline helloworld l2fwd l3fwd skeleton timer"}
285 # if pkg-config defines the necessary flags, test building some examples
286 if 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