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
46 check_cc_flags () # <flag to check> <flag2> ...
48 echo 'int main(void) { return 0; }' |
49 cc $@ -x c - -o /dev/null 2> /dev/null
52 load_env () # <target compiler>
55 # reset variables before target-specific config
56 export PATH=$default_path
57 unset PKG_CONFIG_PATH # global default makes no sense
58 export CPPFLAGS=$default_cppflags
59 export CFLAGS=$default_cflags
60 export LDFLAGS=$default_ldflags
61 export DPDK_MESON_OPTIONS=$default_meson_options
62 # set target hint for use in the loaded config file
63 if [ -n "$target_override" ] ; then
64 DPDK_TARGET=$target_override
65 elif command -v $targetcc >/dev/null 2>&1 ; then
66 DPDK_TARGET=$($targetcc -v 2>&1 | sed -n 's,^Target: ,,p')
67 else # toolchain not yet in PATH: its name should be enough
70 echo "Using DPDK_TARGET $DPDK_TARGET"
71 # config input: $DPDK_TARGET
72 . $srcdir/devtools/load-devel-config
73 # config output: $DPDK_MESON_OPTIONS, $PATH, $PKG_CONFIG_PATH, etc
74 command -v $targetcc >/dev/null 2>&1 || return 1
77 config () # <dir> <builddir> <meson options>
83 if [ -f "$builddir/build.ninja" ] ; then
84 # for existing environments, switch to debugoptimized if unset
85 # so that ABI checks can run
86 if ! $MESON configure $builddir |
87 awk '$1=="buildtype" {print $2}' |
88 grep -qw debugoptimized; then
89 $MESON configure --buildtype=debugoptimized $builddir
94 if echo $* | grep -qw -- '--default-library=shared' ; then
95 options="$options -Dexamples=all"
97 options="$options -Dexamples=l3fwd" # save disk space
99 options="$options --buildtype=debugoptimized"
100 for option in $DPDK_MESON_OPTIONS ; do
101 options="$options -D$option"
103 options="$options $*"
104 echo "$MESON $options $dir $builddir"
105 $MESON $options $dir $builddir
108 compile () # <builddir>
111 if [ -n "$TEST_MESON_BUILD_VERY_VERBOSE" ] ; then
112 # for full output from ninja use "-v"
113 echo "$ninja_cmd -v -C $builddir"
114 $ninja_cmd -v -C $builddir
115 elif [ -n "$TEST_MESON_BUILD_VERBOSE" ] ; then
116 # for keeping the history of short cmds, pipe through cat
117 echo "$ninja_cmd -C $builddir | cat"
118 $ninja_cmd -C $builddir | cat
120 echo "$ninja_cmd -C $builddir"
121 $ninja_cmd -C $builddir
125 install_target () # <builddir> <installdir>
128 if [ -n "$TEST_MESON_BUILD_VERY_VERBOSE$TEST_MESON_BUILD_VERBOSE" ]; then
129 echo "DESTDIR=$2 $ninja_cmd -C $1 install"
130 DESTDIR=$2 $ninja_cmd -C $1 install
132 echo "DESTDIR=$2 $ninja_cmd -C $1 install >/dev/null"
133 DESTDIR=$2 $ninja_cmd -C $1 install >/dev/null
137 build () # <directory> <target compiler | cross file> <meson options>
142 [ -r $1 ] && crossfile=$1 || targetcc=$1
144 # skip build if compiler not available
145 command -v ${CC##* } >/dev/null 2>&1 || return 0
146 if [ -n "$crossfile" ] ; then
147 cross="--cross-file $crossfile"
148 targetcc=$(sed -n 's,^c[[:space:]]*=[[:space:]]*,,p' \
149 $crossfile | tr -d "'" | tr -d '"')
153 load_env $targetcc || return 0
154 config $srcdir $builds_dir/$targetdir $cross --werror $*
155 compile $builds_dir/$targetdir
156 if [ -n "$DPDK_ABI_REF_VERSION" ]; then
157 abirefdir=${DPDK_ABI_REF_DIR:-reference}/$DPDK_ABI_REF_VERSION
158 if [ ! -d $abirefdir/$targetdir ]; then
159 # clone current sources
160 if [ ! -d $abirefdir/src ]; then
161 git clone --local --no-hardlinks \
163 -b $DPDK_ABI_REF_VERSION \
164 $srcdir $abirefdir/src
167 rm -rf $abirefdir/build
168 config $abirefdir/src $abirefdir/build $cross \
170 compile $abirefdir/build
171 install_target $abirefdir/build $abirefdir/$targetdir
172 $srcdir/devtools/gen-abi.sh $abirefdir/$targetdir
174 # save disk space by removing static libs and apps
175 find $abirefdir/$targetdir/usr/local -name '*.a' -delete
176 rm -rf $abirefdir/$targetdir/usr/local/bin
177 rm -rf $abirefdir/$targetdir/usr/local/share
180 install_target $builds_dir/$targetdir \
181 $(readlink -f $builds_dir/$targetdir/install)
182 $srcdir/devtools/gen-abi.sh \
183 $(readlink -f $builds_dir/$targetdir/install)
184 $srcdir/devtools/check-abi.sh $abirefdir/$targetdir \
185 $(readlink -f $builds_dir/$targetdir/install)
189 if [ "$1" = "-vv" ] ; then
190 TEST_MESON_BUILD_VERY_VERBOSE=1
191 elif [ "$1" = "-v" ] ; then
192 TEST_MESON_BUILD_VERBOSE=1
194 # we can't use plain verbose when we don't have pipefail option so up-level
195 if [ -z "$PIPEFAIL" -a -n "$TEST_MESON_BUILD_VERBOSE" ] ; then
196 echo "# Missing pipefail shell option, changing VERBOSE to VERY_VERBOSE"
197 TEST_MESON_BUILD_VERY_VERBOSE=1
200 # shared and static linked builds with gcc and clang
201 for c in gcc clang ; do
202 command -v $c >/dev/null 2>&1 || continue
203 for s in static shared ; do
204 export CC="$CCACHE $c"
205 build build-$c-$s $c --default-library=$s
210 # test compilation with minimal x86 instruction set
211 # Set the install path for libraries to "lib" explicitly to prevent problems
212 # with pkg-config prefixes if installed in "lib/x86_64-linux-gnu" later.
213 default_machine='nehalem'
214 if ! check_cc_flags "-march=$default_machine" ; then
215 default_machine='corei7'
217 build build-x86-default cc -Dlibdir=lib -Dmachine=$default_machine $use_shared
219 # 32-bit with default compiler
220 if check_cc_flags '-m32' ; then
221 if [ -d '/usr/lib/i386-linux-gnu' ] ; then
222 # 32-bit pkgconfig on Debian/Ubuntu
223 export PKG_CONFIG_LIBDIR='/usr/lib/i386-linux-gnu/pkgconfig'
224 elif [ -d '/usr/lib32' ] ; then
225 # 32-bit pkgconfig on Arch
226 export PKG_CONFIG_LIBDIR='/usr/lib32/pkgconfig'
228 # 32-bit pkgconfig on RHEL/Fedora (lib vs lib64)
229 export PKG_CONFIG_LIBDIR='/usr/lib/pkgconfig'
231 target_override='i386-pc-linux-gnu'
232 build build-32b cc -Dc_args='-m32' -Dc_link_args='-m32'
234 unset PKG_CONFIG_LIBDIR
238 build build-x86-mingw $srcdir/config/x86/cross-mingw -Dexamples=helloworld
240 # generic armv8a with clang as host compiler
241 f=$srcdir/config/arm/arm64_armv8_linux_gcc
243 build build-arm64-host-clang $f $use_shared
245 # some gcc/arm configurations
246 for f in $srcdir/config/arm/arm64_[bdo]*gcc ; do
247 export CC="$CCACHE gcc"
248 build build-$(basename $f | tr '_' '-' | cut -d'-' -f-2) $f $use_shared
253 for f in $srcdir/config/ppc/ppc* ; do
254 build build-$(basename $f | cut -d'-' -f-2) $f $use_shared
257 # Test installation of the x86-default target, to be used for checking
258 # the sample apps build using the pkg-config file for cflags and libs
259 build_path=$(readlink -f $builds_dir/build-x86-default)
260 export DESTDIR=$build_path/install
261 # No need to reinstall if ABI checks are enabled
262 if [ -z "$DPDK_ABI_REF_VERSION" ]; then
263 install_target $build_path $DESTDIR
267 pc_file=$(find $DESTDIR -name libdpdk.pc)
268 export PKG_CONFIG_PATH=$(dirname $pc_file):$PKG_CONFIG_PATH
270 # if pkg-config defines the necessary flags, test building some examples
271 if pkg-config --define-prefix libdpdk >/dev/null 2>&1; then
272 export PKGCONF="pkg-config --define-prefix"
273 for example in cmdline helloworld l2fwd l3fwd skeleton timer; do
274 echo "## Building $example"
275 $MAKE -C $DESTDIR/usr/local/share/dpdk/examples/$example clean shared static