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 compiler | cross file> <meson options>
154 [ -r $1 ] && crossfile=$1 || targetcc=$1
156 # skip build if compiler not available
157 command -v ${CC##* } >/dev/null 2>&1 || return 0
158 if [ -n "$crossfile" ] ; then
159 cross="--cross-file $crossfile"
160 targetcc=$(sed -n 's,^c[[:space:]]*=[[:space:]]*,,p' \
161 $crossfile | tr -d "'" | tr -d '"')
165 load_env $targetcc || return 0
166 config $srcdir $builds_dir/$targetdir $cross --werror $*
167 compile $builds_dir/$targetdir
168 if [ -n "$DPDK_ABI_REF_VERSION" ]; then
169 abirefdir=${DPDK_ABI_REF_DIR:-reference}/$DPDK_ABI_REF_VERSION
170 if [ ! -d $abirefdir/$targetdir ]; then
171 # clone current sources
172 if [ ! -d $abirefdir/src ]; then
173 git clone --local --no-hardlinks \
175 -b $DPDK_ABI_REF_VERSION \
176 $srcdir $abirefdir/src
179 rm -rf $abirefdir/build
180 config $abirefdir/src $abirefdir/build $cross \
182 compile $abirefdir/build
183 install_target $abirefdir/build $abirefdir/$targetdir
184 $srcdir/devtools/gen-abi.sh $abirefdir/$targetdir
186 # save disk space by removing static libs and apps
187 find $abirefdir/$targetdir/usr/local -name '*.a' -delete
188 rm -rf $abirefdir/$targetdir/usr/local/bin
189 rm -rf $abirefdir/$targetdir/usr/local/share
192 install_target $builds_dir/$targetdir \
193 $(readlink -f $builds_dir/$targetdir/install)
194 echo "Checking ABI compatibility of $targetdir" >&$verbose
195 echo $srcdir/devtools/gen-abi.sh \
196 $(readlink -f $builds_dir/$targetdir/install) >&$veryverbose
197 $srcdir/devtools/gen-abi.sh \
198 $(readlink -f $builds_dir/$targetdir/install) >&$veryverbose
199 echo $srcdir/devtools/check-abi.sh $abirefdir/$targetdir \
200 $(readlink -f $builds_dir/$targetdir/install) >&$veryverbose
201 $srcdir/devtools/check-abi.sh $abirefdir/$targetdir \
202 $(readlink -f $builds_dir/$targetdir/install) >&$verbose
206 # shared and static linked builds with gcc and clang
207 for c in gcc clang ; do
208 command -v $c >/dev/null 2>&1 || continue
209 for s in static shared ; do
210 export CC="$CCACHE $c"
211 build build-$c-$s $c --default-library=$s
216 # test compilation with minimal x86 instruction set
217 # Set the install path for libraries to "lib" explicitly to prevent problems
218 # with pkg-config prefixes if installed in "lib/x86_64-linux-gnu" later.
219 default_machine='nehalem'
220 if ! check_cc_flags "-march=$default_machine" ; then
221 default_machine='corei7'
223 build build-x86-default cc -Dlibdir=lib -Dmachine=$default_machine $use_shared
225 # 32-bit with default compiler
226 if check_cc_flags '-m32' ; then
227 if [ -d '/usr/lib/i386-linux-gnu' ] ; then
228 # 32-bit pkgconfig on Debian/Ubuntu
229 export PKG_CONFIG_LIBDIR='/usr/lib/i386-linux-gnu/pkgconfig'
230 elif [ -d '/usr/lib32' ] ; then
231 # 32-bit pkgconfig on Arch
232 export PKG_CONFIG_LIBDIR='/usr/lib32/pkgconfig'
234 # 32-bit pkgconfig on RHEL/Fedora (lib vs lib64)
235 export PKG_CONFIG_LIBDIR='/usr/lib/pkgconfig'
237 target_override='i386-pc-linux-gnu'
238 build build-32b cc -Dc_args='-m32' -Dc_link_args='-m32'
240 unset PKG_CONFIG_LIBDIR
244 build build-x86-mingw $srcdir/config/x86/cross-mingw -Dexamples=helloworld
246 # generic armv8a with clang as host compiler
247 f=$srcdir/config/arm/arm64_armv8_linux_gcc
249 build build-arm64-host-clang $f $use_shared
251 # some gcc/arm configurations
252 for f in $srcdir/config/arm/arm64_[bdo]*gcc ; do
253 export CC="$CCACHE gcc"
254 build build-$(basename $f | tr '_' '-' | cut -d'-' -f-2) $f $use_shared
259 for f in $srcdir/config/ppc/ppc* ; do
260 build build-$(basename $f | cut -d'-' -f-2) $f $use_shared
263 # Test installation of the x86-default target, to be used for checking
264 # the sample apps build using the pkg-config file for cflags and libs
266 build_path=$(readlink -f $builds_dir/build-x86-default)
267 export DESTDIR=$build_path/install
268 # No need to reinstall if ABI checks are enabled
269 if [ -z "$DPDK_ABI_REF_VERSION" ]; then
270 install_target $build_path $DESTDIR
272 pc_file=$(find $DESTDIR -name libdpdk.pc)
273 export PKG_CONFIG_PATH=$(dirname $pc_file):$PKG_CONFIG_PATH
274 libdir=$(dirname $(find $DESTDIR -name librte_eal.so))
275 export LD_LIBRARY_PATH=$libdir:$LD_LIBRARY_PATH
276 examples=${DPDK_BUILD_TEST_EXAMPLES:-"cmdline helloworld l2fwd l3fwd skeleton timer"}
277 # if pkg-config defines the necessary flags, test building some examples
278 if pkg-config --define-prefix libdpdk >/dev/null 2>&1; then
279 export PKGCONF="pkg-config --define-prefix"
280 for example in $examples; do
281 echo "## Building $example"
282 $MAKE -C $DESTDIR/usr/local/share/dpdk/examples/$example \
283 clean shared static >&$veryverbose