1.. SPDX-License-Identifier: BSD-3-Clause 2 Copyright(c) 2018 Intel Corporation. 3 4Installing DPDK Using the meson build system 5============================================ 6 7Summary 8-------- 9For many platforms, compiling and installing DPDK should work using the 10following set of commands:: 11 12 meson build 13 cd build 14 ninja 15 ninja install 16 17This will compile DPDK in the ``build`` subdirectory, and then install the 18resulting libraries, drivers and header files onto the system - generally 19in /usr/local. A package-config file, ``libdpdk.pc``, for DPDK will also 20be installed to allow ease of compiling and linking with applications. 21 22After installation, to use DPDK, the necessary CFLAG and LDFLAG variables 23can be got from pkg-config:: 24 25 pkg-config --cflags libdpdk 26 pkg-config --libs libdpdk 27 28More detail on each of these steps can be got from the following sections. 29 30 31Getting the Tools 32------------------ 33 34The ``meson`` tool is used to configure a DPDK build. On most Linux 35distributions this can be got using the local package management system, 36e.g. ``dnf install meson`` or ``apt-get install meson``. If meson is not 37available as a suitable package, it can also be installed using the Python 383 ``pip`` tool, e.g. ``pip3 install meson``. Version 0.49.2 of meson is 39required - if the version packaged is too old, the latest version is 40generally available from "pip". 41 42The other dependency for building is the ``ninja`` tool, which acts similar 43to make and performs the actual build using information provided by meson. 44Installing meson will, in many cases, also install ninja, but, if not 45already installed, it too is generally packaged by most Linux distributions. 46If not available as a package, it can be downloaded as source or binary from 47https://ninja-build.org/ 48 49It is best advised to go over the following links for the complete dependencies: 50 51* :doc:`Linux <../linux_gsg/sys_reqs>` 52* :doc:`FreeBSD <../freebsd_gsg/build_dpdk>` 53* :doc:`Windows <../windows_gsg/build_dpdk>` 54 55 56Configuring the Build 57---------------------- 58 59To configure a build, run the meson tool, passing the path to the directory 60to be used for the build e.g. ``meson build``, as shown above. If calling 61meson from somewhere other than the root directory of the DPDK project the 62path to the root directory should be passed as the first parameter, and the 63build path as the second. For example, to build DPDK in /tmp/dpdk-build:: 64 65 user@host:/tmp$ meson ~user/dpdk dpdk-build 66 67Meson will then configure the build based on settings in the project's 68meson.build files, and by checking the build environment for e.g. compiler 69properties or the presence of dependencies, such as libpcap, or openssl 70libcrypto libraries. Once done, meson writes a ``build.ninja`` file in the 71build directory to be used to do the build itself when ninja is called. 72 73Tuning of the build is possible, both as part of the original meson call, 74or subsequently using ``meson configure`` command (``mesonconf`` in some 75older versions). Some options, such as ``buildtype``, or ``werror`` are 76built into meson, while others, such as ``max_lcores``, or the list of 77examples to build, are DPDK-specific. To have a list of all options 78available run ``meson configure`` in the build directory. 79 80Examples of adjusting the defaults when doing initial meson configuration. 81Project-specific options are passed used -Doption=value:: 82 83 meson --werror werrorbuild # build with warnings as errors 84 85 meson --buildtype=debug debugbuild # build for debugging 86 87 meson -Dexamples=l3fwd,l2fwd fwdbuild # build some examples as 88 # part of the normal DPDK build 89 90 meson -Dmax_lcores=8 smallbuild # scale build for smaller systems 91 92 meson -Denable_docs=true fullbuild # build and install docs 93 94 meson -Dmachine=generic # use builder-independent baseline -march 95 96 meson -Ddisable_drivers=event/*,net/tap # disable tap driver and all 97 # eventdev PMDs for a smaller build 98 99 meson -Denable_trace_fp=true tracebuild # build with fast path traces 100 # enabled 101 102Examples of setting some of the same options using meson configure:: 103 104 meson configure -Dwerror=true 105 106 meson configure -Dbuildtype=debug 107 108 meson configure -Dexamples=l3fwd,l2fwd 109 110 meson configure -Dmax_lcores=8 111 112 meson configure -Denable_trace_fp=true 113 114.. note:: 115 116 once meson has been run to configure a build in a directory, it 117 cannot be run again on the same directory. Instead ``meson configure`` 118 should be used to change the build settings within the directory, and when 119 ``ninja`` is called to do the build itself, it will trigger the necessary 120 re-scan from meson. 121 122.. note:: 123 machine=generic uses a config that works on all supported architectures 124 regardless of the capabilities of the machine where the build is happening. 125 126As well as those settings taken from ``meson configure``, other options 127such as the compiler to use can be passed via environment variables. For 128example:: 129 130 CC=clang meson clang-build 131 132.. note:: 133 134 for more comprehensive overriding of compilers or other environment 135 settings, the tools for cross-compilation may be considered. However, for 136 basic overriding of the compiler etc., the above form works as expected. 137 138 139Performing the Build 140--------------------- 141 142Use ``ninja`` to perform the actual build inside the build folder 143previously configured. In most cases no arguments are necessary. 144 145Ninja accepts a number of flags which are similar to make. For example, to 146call ninja from outside the build folder, you can use ``ninja -C build``. 147Ninja also runs parallel builds by default, but you can limit this using 148the ``-j`` flag, e.g. ``ninja -j1 -v`` to do the build one step at a time, 149printing each command on a new line as it runs. 150 151 152Installing the Compiled Files 153------------------------------ 154 155Use ``ninja install`` to install the required DPDK files onto the system. 156The install prefix defaults to ``/usr/local`` but can be used as with other 157options above. The environment variable ``DESTDIR`` can be used to adjust 158the root directory for the install, for example when packaging. 159 160With the base install directory, the individual directories for libraries 161and headers are configurable. By default, the following will be the 162installed layout:: 163 164 headers -> /usr/local/include 165 libraries -> /usr/local/lib64 166 drivers -> /usr/local/lib64/dpdk/drivers 167 libdpdk.pc -> /usr/local/lib64/pkgconfig 168 169For the drivers, these will also be symbolically linked into the library 170install directory, so that ld.so can find them in cases where one driver may 171depend on another, e.g. a NIC PMD depending upon the PCI bus driver. Within 172the EAL, the default search path for drivers will be set to the configured 173driver install path, so dynamically-linked applications can be run without 174having to pass in ``-d /path/to/driver`` options for standard drivers. 175 176 177Cross Compiling DPDK 178-------------------- 179 180To cross-compile DPDK on a desired target machine we can use the following 181command:: 182 183 meson cross-build --cross-file <target_machine_configuration> 184 185For example if the target machine is arm64 we can use the following 186command:: 187 188 meson arm-build --cross-file config/arm/arm64_armv8_linux_gcc 189 190where config/arm/arm64_armv8_linux_gcc contains settings for the compilers 191and other build tools to be used, as well as characteristics of the target 192machine. 193 194Using the DPDK within an Application 195------------------------------------- 196 197To compile and link against DPDK within an application, pkg-config should 198be used to query the correct parameters. Examples of this are given in the 199makefiles for the example applications included with DPDK. They demonstrate 200how to link either against the DPDK shared libraries, or against the static 201versions of the same. 202 203From examples/helloworld/Makefile:: 204 205 PC_FILE := $(shell pkg-config --path libdpdk) 206 CFLAGS += -O3 $(shell pkg-config --cflags libdpdk) 207 LDFLAGS_SHARED = $(shell pkg-config --libs libdpdk) 208 LDFLAGS_STATIC = $(shell pkg-config --static --libs libdpdk) 209 210 build/$(APP)-shared: $(SRCS-y) Makefile $(PC_FILE) | build 211 $(CC) $(CFLAGS) $(SRCS-y) -o $@ $(LDFLAGS) $(LDFLAGS_SHARED) 212 213 build/$(APP)-static: $(SRCS-y) Makefile $(PC_FILE) | build 214 $(CC) $(CFLAGS) $(SRCS-y) -o $@ $(LDFLAGS) $(LDFLAGS_STATIC) 215 216 build: 217 @mkdir -p $@ 218