New upstream version 18.02
[deb_dpdk.git] / doc / guides / prog_guide / build_app.rst
1 ..  SPDX-License-Identifier: BSD-3-Clause
2     Copyright(c) 2010-2014 Intel Corporation.
3
4 .. _Building_Your_Own_Application:
5
6 Building Your Own Application
7 =============================
8
9 Compiling a Sample Application in the Development Kit Directory
10 ---------------------------------------------------------------
11
12 When compiling a sample application (for example, hello world), the following variables must be exported:
13 RTE_SDK and RTE_TARGET.
14
15 .. code-block:: console
16
17     ~/DPDK$ cd examples/helloworld/
18     ~/DPDK/examples/helloworld$ export RTE_SDK=/home/user/DPDK
19     ~/DPDK/examples/helloworld$ export RTE_TARGET=x86_64-native-linuxapp-gcc
20     ~/DPDK/examples/helloworld$ make
21         CC main.o
22         LD helloworld
23         INSTALL-APP helloworld
24         INSTALL-MAP helloworld.map
25
26 The binary is generated in the build directory by default:
27
28 .. code-block:: console
29
30     ~/DPDK/examples/helloworld$ ls build/app
31     helloworld helloworld.map
32
33 Build Your Own Application Outside the Development Kit
34 ------------------------------------------------------
35
36 The sample application (Hello World) can be duplicated in a new directory as a starting point for your development:
37
38 .. code-block:: console
39
40     ~$ cp -r DPDK/examples/helloworld my_rte_app
41     ~$ cd my_rte_app/
42     ~/my_rte_app$ export RTE_SDK=/home/user/DPDK
43     ~/my_rte_app$ export RTE_TARGET=x86_64-native-linuxapp-gcc
44     ~/my_rte_app$ make
45         CC main.o
46         LD helloworld
47         INSTALL-APP helloworld
48         INSTALL-MAP helloworld.map
49
50 Customizing Makefiles
51 ---------------------
52
53 Application Makefile
54 ~~~~~~~~~~~~~~~~~~~~
55
56 The default makefile provided with the Hello World sample application is a good starting point. It includes:
57
58 *   $(RTE_SDK)/mk/rte.vars.mk at the beginning
59
60 *   $(RTE_SDK)/mk/rte.extapp.mk at the end
61
62 The user must define several variables:
63
64 *   APP: Contains the name of the application.
65
66 *   SRCS-y: List of source files (\*.c, \*.S).
67
68 Library Makefile
69 ~~~~~~~~~~~~~~~~
70
71 It is also possible to build a library in the same way:
72
73 *   Include $(RTE_SDK)/mk/rte.vars.mk at the beginning.
74
75 *   Include $(RTE_SDK)/mk/rte.extlib.mk  at the end.
76
77 The only difference is that APP should be replaced by LIB, which contains the name of the library. For example, libfoo.a.
78
79 Customize Makefile Actions
80 ~~~~~~~~~~~~~~~~~~~~~~~~~~
81
82 Some variables can be defined to customize Makefile actions. The most common are listed below. Refer to
83 :ref:`Makefile Description <Makefile_Description>` section in
84 :ref:`Development Kit Build System <Development_Kit_Build_System>`
85
86 chapter for details.
87
88 *   VPATH: The path list where the build system will search for sources. By default,
89     RTE_SRCDIR will be included in VPATH.
90
91 *   CFLAGS_my_file.o: The specific flags to add for C compilation of my_file.c.
92
93 *   CFLAGS: The flags to use for C compilation.
94
95 *   LDFLAGS: The flags to use for linking.
96
97 *   CPPFLAGS: The flags to use to provide flags to the C preprocessor (only useful when assembling .S files)
98
99 *   LDLIBS: A list of libraries to link with (for example, -L /path/to/libfoo - lfoo)