New upstream version 18.02
[deb_dpdk.git] / doc / guides / prog_guide / extend_dpdk.rst
1 ..  SPDX-License-Identifier: BSD-3-Clause
2     Copyright(c) 2010-2014 Intel Corporation.
3
4 Extending the DPDK
5 =========================
6
7 This chapter describes how a developer can extend the DPDK to provide a new library,
8 a new target, or support a new target.
9
10 Example: Adding a New Library libfoo
11 ------------------------------------
12
13 To add a new library to the DPDK, proceed as follows:
14
15 #. Add a new configuration option:
16
17    .. code-block:: bash
18
19         for f in config/\*; do \
20             echo CONFIG_RTE_LIBFOO=y >> $f; done
21
22 #. Create a new directory with sources:
23
24    .. code-block:: console
25
26         mkdir ${RTE_SDK}/lib/libfoo
27         touch ${RTE_SDK}/lib/libfoo/foo.c
28         touch ${RTE_SDK}/lib/libfoo/foo.h
29
30 #. Add a foo() function in libfoo.
31
32     Definition is in foo.c:
33
34     .. code-block:: c
35
36         void foo(void)
37         {
38         }
39
40     Declaration is in foo.h:
41
42     .. code-block:: c
43
44         extern void foo(void);
45
46
47 #. Update lib/Makefile:
48
49     .. code-block:: console
50
51         vi ${RTE_SDK}/lib/Makefile
52         # add:
53         # DIRS-$(CONFIG_RTE_LIBFOO) += libfoo
54
55 #. Create a new Makefile for this library, for example, derived from mempool Makefile:
56
57     .. code-block:: console
58
59         cp ${RTE_SDK}/lib/librte_mempool/Makefile ${RTE_SDK}/lib/libfoo/
60
61         vi ${RTE_SDK}/lib/libfoo/Makefile
62         # replace:
63         # librte_mempool -> libfoo
64         # rte_mempool -> foo
65
66
67 #. Update mk/DPDK.app.mk, and add -lfoo in LDLIBS variable when the option is enabled.
68    This will automatically add this flag when linking a DPDK application.
69
70
71 #. Build the DPDK with the new library (we only show a specific target here):
72
73     .. code-block:: console
74
75         cd ${RTE_SDK}
76         make config T=x86_64-native-linuxapp-gcc
77         make
78
79
80 #. Check that the library is installed:
81
82     .. code-block:: console
83
84         ls build/lib
85         ls build/include
86
87 Example: Using libfoo in the Test Application
88 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
89
90 The test application is used to validate all functionality of the DPDK.
91 Once you have added a library, a new test case should be added in the test application.
92
93 *   A new test_foo.c file should be added, that includes foo.h and calls the foo() function from test_foo().
94     When the test passes, the test_foo() function should return 0.
95
96 *   Makefile, test.h and commands.c must be updated also, to handle the new test case.
97
98 *   Test report generation: autotest.py is a script that is used to generate the test report that is available in the
99     ${RTE_SDK}/doc/rst/test_report/autotests directory. This script must be updated also.
100     If libfoo is in a new test family, the links in ${RTE_SDK}/doc/rst/test_report/test_report.rst must be updated.
101
102 *   Build the DPDK with the updated test application (we only show a specific target here):
103
104
105     .. code-block:: console
106
107         cd ${RTE_SDK}
108         make config T=x86_64-native-linuxapp-gcc
109         make