New upstream version 18.02
[deb_dpdk.git] / doc / guides / prog_guide / dev_kit_build_system.rst
1 ..  SPDX-License-Identifier: BSD-3-Clause
2     Copyright(c) 2010-2014 Intel Corporation.
3
4 .. _Development_Kit_Build_System:
5
6 Development Kit Build System
7 ============================
8
9 The DPDK requires a build system for compilation activities and so on.
10 This section describes the constraints and the mechanisms used in the DPDK framework.
11
12 There are two use-cases for the framework:
13
14 *   Compilation of the DPDK libraries and sample applications;
15     the framework generates specific binary libraries,
16     include files and sample applications
17
18 *   Compilation of an external application or library, using an installed binary DPDK
19
20 Building the Development Kit Binary
21 -----------------------------------
22
23 The following provides details on how to build the DPDK binary.
24
25 Build Directory Concept
26 ~~~~~~~~~~~~~~~~~~~~~~~
27
28 After installation, a build directory structure is created.
29 Each build directory contains include files, libraries, and applications.
30
31 A build directory is specific to a configuration that includes architecture + execution environment + toolchain.
32 It is possible to have several build directories sharing the same sources with different configurations.
33
34 For instance, to create a new build directory called my_sdk_build_dir using the default configuration template config/defconfig_x86_64-linuxapp,
35 we use:
36
37 .. code-block:: console
38
39     cd ${RTE_SDK}
40     make config T=x86_64-native-linuxapp-gcc O=my_sdk_build_dir
41
42 This creates a new my_sdk_build_dir directory. After that, we can compile by doing:
43
44 .. code-block:: console
45
46     cd my_sdk_build_dir
47     make
48
49 which is equivalent to:
50
51 .. code-block:: console
52
53     make O=my_sdk_build_dir
54
55 The content of the my_sdk_build_dir is then:
56
57 ::
58
59     -- .config                         # used configuration
60
61     -- Makefile                        # wrapper that calls head Makefile
62                                        # with $PWD as build directory
63
64
65         -- build                              #All temporary files used during build
66         +--app                                # process, including . o, .d, and .cmd files.
67             |  +-- test                       # For libraries, we have the .a file.
68             |  +-- test.o                     # For applications, we have the elf file.
69             |  `-- ...
70             +-- lib
71                 +-- librte_eal
72                 |   `-- ...
73                 +-- librte_mempool
74                 |  +--  mempool-file1.o
75                 |  +--  .mempool-file1.o.cmd
76                 |  +--  .mempool-file1.o.d
77                 |  +--   mempool-file2.o
78                 |  +--  .mempool-file2.o.cmd
79                 |  +--  .mempool-file2.o.d
80                 |  `--  mempool.a
81                 `-- ...
82
83     -- include                # All include files installed by libraries
84         +-- librte_mempool.h  # and applications are located in this
85         +-- rte_eal.h         # directory. The installed files can depend
86         +-- rte_spinlock.h    # on configuration if needed (environment,
87         +-- rte_atomic.h      # architecture, ..)
88         `-- \*.h ...
89
90     -- lib                    # all compiled libraries are copied in this
91         +-- librte_eal.a      # directory
92         +-- librte_mempool.a
93         `-- \*.a ...
94
95     -- app                    # All compiled applications are installed
96     + --test                  # here. It includes the binary in elf format
97
98 Refer to
99 :ref:`Development Kit Root Makefile Help <Development_Kit_Root_Makefile_Help>`
100 for details about make commands that can be used from the root of DPDK.
101
102 Building External Applications
103 ------------------------------
104
105 Since DPDK is in essence a development kit, the first objective of end users will be to create an application using this SDK.
106 To compile an application, the user must set the RTE_SDK and RTE_TARGET environment variables.
107
108 .. code-block:: console
109
110     export RTE_SDK=/opt/DPDK
111     export RTE_TARGET=x86_64-native-linuxapp-gcc
112     cd /path/to/my_app
113
114 For a new application, the user must create their own Makefile that includes some .mk files, such as
115 ${RTE_SDK}/mk/rte.vars.mk, and ${RTE_SDK}/mk/ rte.app.mk.
116 This is described in
117 :ref:`Building Your Own Application <Building_Your_Own_Application>`.
118
119 Depending on the chosen target (architecture, machine, executive environment, toolchain) defined in the Makefile or as an environment variable,
120 the applications and libraries will compile using the appropriate .h files and will link with the appropriate .a files.
121 These files are located in ${RTE_SDK}/arch-machine-execenv-toolchain, which is referenced internally by ${RTE_BIN_SDK}.
122
123 To compile their application, the user just has to call make.
124 The compilation result will be located in /path/to/my_app/build directory.
125
126 Sample applications are provided in the examples directory.
127
128 .. _Makefile_Description:
129
130 Makefile Description
131 --------------------
132
133 General Rules For DPDK Makefiles
134 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
135
136 In the DPDK, Makefiles always follow the same scheme:
137
138 #. Include $(RTE_SDK)/mk/rte.vars.mk at the beginning.
139
140 #. Define specific variables for RTE build system.
141
142 #. Include a specific $(RTE_SDK)/mk/rte.XYZ.mk, where XYZ can be app, lib, extapp, extlib, obj, gnuconfigure,
143    and so on, depending on what kind of object you want to build.
144    :ref:`See Makefile Types <Makefile_Types>` below.
145
146 #. Include user-defined rules and variables.
147
148    The following is a very simple example of an external application Makefile:
149
150    ..  code-block:: make
151
152         include $(RTE_SDK)/mk/rte.vars.mk
153
154         # binary name
155         APP = helloworld
156
157         # all source are stored in SRCS-y
158         SRCS-y := main.c
159
160         CFLAGS += -O3
161         CFLAGS += $(WERROR_FLAGS)
162
163         include $(RTE_SDK)/mk/rte.extapp.mk
164
165 .. _Makefile_Types:
166
167 Makefile Types
168 ~~~~~~~~~~~~~~
169
170 Depending on the .mk file which is included at the end of the user Makefile, the Makefile will have a different role.
171 Note that it is not possible to build a library and an application in the same Makefile.
172 For that, the user must create two separate Makefiles, possibly in two different directories.
173
174 In any case, the rte.vars.mk file must be included in the user Makefile as soon as possible.
175
176 Application
177 ^^^^^^^^^^^
178
179 These Makefiles generate a binary application.
180
181 *   rte.app.mk: Application in the development kit framework
182
183 *   rte.extapp.mk: External application
184
185 *   rte.hostapp.mk: prerequisite tool to build dpdk
186
187 Library
188 ^^^^^^^
189
190 Generate a .a library.
191
192 *   rte.lib.mk: Library in the development kit framework
193
194 *   rte.extlib.mk: external library
195
196 *   rte.hostlib.mk: host library in the development kit framework
197
198 Install
199 ^^^^^^^
200
201 *   rte.install.mk: Does not build anything, it is only used to create links or copy files to the installation directory.
202     This is useful for including files in the development kit framework.
203
204 Kernel Module
205 ^^^^^^^^^^^^^
206
207 *   rte.module.mk: Build a kernel module in the development kit framework.
208
209 Objects
210 ^^^^^^^
211
212 *   rte.obj.mk: Object aggregation (merge several .o in one) in the development kit framework.
213
214 *   rte.extobj.mk: Object aggregation (merge several .o in one) outside the development kit framework.
215
216 Misc
217 ^^^^
218
219 *   rte.doc.mk: Documentation in the development kit framework
220
221 *   rte.gnuconfigure.mk: Build an application that is configure-based.
222
223 *   rte.subdir.mk: Build several directories in the development kit framework.
224
225 .. _Internally_Generated_Build_Tools:
226
227 Internally Generated Build Tools
228 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
229
230 ``app/dpdk-pmdinfogen``
231
232
233 ``dpdk-pmdinfogen`` scans an object (.o) file for various well known symbol names.
234 These well known symbol names are defined by various macros and used to export
235 important information about hardware support and usage for pmd files.  For
236 instance the macro:
237
238 .. code-block:: c
239
240    RTE_PMD_REGISTER_PCI(name, drv)
241
242 Creates the following symbol:
243
244 .. code-block:: c
245
246    static char this_pmd_name0[] __attribute__((used)) = "<name>";
247
248
249 Which ``dpdk-pmdinfogen`` scans for.  Using this information other relevant
250 bits of data can be exported from the object file and used to produce a
251 hardware support description, that ``dpdk-pmdinfogen`` then encodes into a
252 json formatted string in the following format:
253
254 .. code-block:: c
255
256    static char <name_pmd_string>="PMD_INFO_STRING=\"{'name' : '<name>', ...}\"";
257
258
259 These strings can then be searched for by external tools to determine the
260 hardware support of a given library or application.
261
262
263 .. _Useful_Variables_Provided_by_the_Build_System:
264
265 Useful Variables Provided by the Build System
266 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
267
268 *   RTE_SDK: The absolute path to the DPDK sources.
269     When compiling the development kit, this variable is automatically set by the framework.
270     It has to be defined by the user as an environment variable if compiling an external application.
271
272 *   RTE_SRCDIR: The path to the root of the sources. When compiling the development kit, RTE_SRCDIR = RTE_SDK.
273     When compiling an external application, the variable points to the root of external application sources.
274
275 *   RTE_OUTPUT: The path to which output files are written.
276     Typically, it is $(RTE_SRCDIR)/build, but it can be overridden by the O= option in the make command line.
277
278 *   RTE_TARGET: A string identifying the target for which we are building.
279     The format is arch-machine-execenv-toolchain.
280     When compiling the SDK, the target is deduced by the build system from the configuration (.config).
281     When building an external application, it must be specified by the user in the Makefile or as an environment variable.
282
283 *   RTE_SDK_BIN: References $(RTE_SDK)/$(RTE_TARGET).
284
285 *   RTE_ARCH: Defines the architecture (i686, x86_64).
286     It is the same value as CONFIG_RTE_ARCH  but without the double-quotes around the string.
287
288 *   RTE_MACHINE: Defines the machine.
289     It is the same value as CONFIG_RTE_MACHINE but without the double-quotes around the string.
290
291 *   RTE_TOOLCHAIN: Defines the toolchain (gcc , icc).
292     It is the same value as CONFIG_RTE_TOOLCHAIN but without the double-quotes around the string.
293
294 *   RTE_EXEC_ENV: Defines the executive environment (linuxapp).
295     It is the same value as CONFIG_RTE_EXEC_ENV but without the double-quotes around the string.
296
297 *   RTE_KERNELDIR: This variable contains the absolute path to the kernel sources that will be used to compile the kernel modules.
298     The kernel headers must be the same as the ones that will be used on the target machine (the machine that will run the application).
299     By default, the variable is set to /lib/modules/$(shell uname -r)/build,
300     which is correct when the target machine is also the build machine.
301
302 *   RTE_DEVEL_BUILD: Stricter options (stop on warning). It defaults to y in a git tree.
303
304 Variables that Can be Set/Overridden in a Makefile Only
305 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
306
307 *   VPATH: The path list that the build system will search for sources. By default, RTE_SRCDIR will be included in VPATH.
308
309 *   CFLAGS: Flags to use for C compilation. The user should use +=  to append data in this variable.
310
311 *   LDFLAGS: Flags to use for linking. The user should use +=  to append data in this variable.
312
313 *   ASFLAGS: Flags to use for assembly. The user should use +=  to append data in this variable.
314
315 *   CPPFLAGS: Flags to use to give flags to C preprocessor (only useful when assembling .S files).
316     The user should use += to append data in this variable.
317
318 *   LDLIBS: In an application, the list of libraries to link with (for example, -L  /path/to/libfoo -lfoo ).
319     The user should use  +=  to append data in this variable.
320
321 *   SRC-y: A list of source files (.c, .S, or .o  if the source is a binary) in case of application, library or object Makefiles.
322     The sources must be available from VPATH.
323
324 *   INSTALL-y-$(INSTPATH): A list of files to be installed in  $(INSTPATH).
325     The files must be available from VPATH and will be copied in $(RTE_OUTPUT)/$(INSTPATH). Can be used in almost any RTE Makefile.
326
327 *   SYMLINK-y-$(INSTPATH): A list of files to be installed in $(INSTPATH).
328     The files must be available from VPATH and will be linked (symbolically) in  $(RTE_OUTPUT)/$(INSTPATH).
329     This variable can be used in almost any DPDK Makefile.
330
331 *   PREBUILD: A list of prerequisite actions to be taken before building. The user should use +=  to append data in this variable.
332
333 *   POSTBUILD: A list of actions to be taken after the main build. The user should use += to append data in this variable.
334
335 *   PREINSTALL: A list of prerequisite actions to be taken before installing. The user should use += to append data in this variable.
336
337 *   POSTINSTALL: A list of actions to be taken after installing. The user should use += to append data in this variable.
338
339 *   PRECLEAN: A list of prerequisite actions to be taken before cleaning. The user should use += to append data in this variable.
340
341 *   POSTCLEAN: A list of actions to be taken after cleaning. The user should use += to append data in this variable.
342
343 *   DEPDIRS-$(DIR): Only used in the development kit framework to specify if the build of the current directory depends on build of another one.
344     This is needed to support parallel builds correctly.
345
346 Variables that can be Set/Overridden by the User on the Command Line Only
347 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
348
349 Some variables can be used to configure the build system behavior. They are documented in
350 :ref:`Development Kit Root Makefile Help <Development_Kit_Root_Makefile_Help>` and
351 :ref:`External Application/Library Makefile Help <External_Application/Library_Makefile_Help>`
352
353     *   WERROR_CFLAGS: By default, this is set to a specific value that depends on the compiler.
354         Users are encouraged to use this variable as follows:
355
356             CFLAGS += $(WERROR_CFLAGS)
357
358 This avoids the use of different cases depending on the compiler (icc or gcc).
359 Also, this variable can be overridden from the command line, which allows bypassing of the flags for testing purposes.
360
361 Variables that Can be Set/Overridden by the User in a Makefile or Command Line
362 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
363
364 *   CFLAGS_my_file.o: Specific flags to add for C compilation of my_file.c.
365
366 *   LDFLAGS_my_app: Specific flags to add when linking my_app.
367
368 *   EXTRA_CFLAGS: The content of this variable is appended after CFLAGS when compiling.
369
370 *   EXTRA_LDFLAGS: The content of this variable is appended after LDFLAGS when linking.
371
372 *   EXTRA_LDLIBS: The content of this variable is appended after LDLIBS when linking.
373
374 *   EXTRA_ASFLAGS: The content of this variable is appended after ASFLAGS when assembling.
375
376 *   EXTRA_CPPFLAGS: The content of this variable is appended after CPPFLAGS when using a C preprocessor on assembly files.