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