您的位置:首页 > 其它

英特尔DPDK开发者指南 – 开发环境

2014-09-10 14:10 148 查看
http://laplace.in/?p=1


25.0 源码组织结构

本段描述Intel® DPDK框架的源码组织结构。


25.1 Make文件和配置文件

注意: 在后续的描述中,环境变量
RTE_SDK
指向解压压缩包时产生的基础目录。可以跳到构建系统提供的有用的变量 查看其他变量的描述。

DPDK提供的Makefile在
$(RTE_SDK)/mk
目录中。

配置文件模板在
$(RTE_SDK)/config
目录。这些模板描述了对应的生成目标的选项。配置文件中同时还包含了一些关于DPDK
的开关项,包括DEBUG选项。用户应该查看配置文件并熟悉其中的选项。配置文件同时用来生成头文件,这些头文件会被生成在 新的build文件夹内。


25.2 库文件

库文件放在
$(RTE_SDK)/lib
目录中。习惯上,我们调用库的代码来提供API给应用程序。
通常,这里会产生一个静态库(.a),不过内核模块也在这个文件夹下。lib文件夹包括:

123456789101112131415161718lib+-- librte_cmdline # command line interface helper+-- librte_eal # environment abstraction layer+-- librte_ether # generic interface to poll mode driver+-- librte_hash # hash library+-- librte_kni # kernel NIC interface+-- librte_lpm # longest prefix match library+-- librte_malloc # malloc-like functions+-- librte_mbuf # packet and control mbuf manipulation library+-- librte_mempool # memory pool manager (fixedsized objects)+-- librte_meter # QoS metering library+-- librte_net # various IP-related headers+-- librte_pmd_e1000 # 1GbE poll mode drivers (igb and em)+-- librte_pmd_ixgbe # 10GbE poll mode driver+-- librte_power # power management library+-- librte_ring # software rings (act as lockless FIFOs)+-- librte_sched # QoS scheduler and dropper library`-- librte_timer # timer library

25.3 应用程序

应用程序是指代码中含有
main()
函数的程序。它们在
$(RTE_SDK)/app
$(RTE_SDK)/examples
目录中。
app
目录中是一些用来自动测试DPDK的简单程序。
examples
目录中则是一些显示如何使用库文件的样例程序。

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

app

+--
chkincs
#
test prog to check include depends

+--
test #
autotests, to validate DPDK features

`--
test-pmd #
test and bench poll mode driver examples

examples

+--
cmdline
#
使用cmdline库的示例

+--
dpdk_qat #
Example showing integration with Intel QuickAssist

+--
exception_path #
Sending packets to and from Linux ethernet device (TAP)

+--
helloworld #
Helloworld basic example

+--
ipv4_reassembly
#
Example showing IPv4 Reassembly

+--
ipv4_frag
#
Example showing IPv4 Fragmentation

+--
ipv4_multicast #
Example showing IPv4 Multicast

+--
kni
#
Kernel NIC Interface example

+--
l2fwd
#
L2 Forwarding example with and without SR-IOV

+--
l3fwd
#
L3 Forwarding example

+--
l3fwd-power
#
L3 Forwarding example with power management

+--
l3fwd-vf #
L3 Forwarding example with SR-IOV

+--
link_status_interrupt
#
Link status change interrupt example

+--
load_balancer
#
Load balancing across multiple cores/sockets

+--
multi_process
#
Example applications with multiple DPDK processes

+--
qos_meter
#
QoS metering example

+--
qos_sched
#
QoS scheduler and dropper example

+--
timer
#
Example of using librte_timer library

`--
vmdq_dcb #
Intel 82599 Ethernet Controller VMDQ and DCB receiving

`--
vmdq #
Example of VMDQ receiving for both Intel 10G (82599)

#
and 1G (82576, 82580 and I350) Ethernet Controllers

+--
vhost
#
Example of userspace vhost and switch

注意: 实际的examples目录也许会有额外的应用程序,请查看最新的DPDK源码包。


26.0 开发套件构建系统

DPDK需要一个构建系统来支持编译等活动。本节描述的是使用DPDK框架时的限制与机制。 其中有有两个用例:

编译DPDK库文件和示例程序。框架会产生指定的二进制库,其中包括了包含文件和示例程序

使用已安装的DPDK库来编译一个外部的程序或库


26.1 构建开发套件的二进制文件

下文提供了如何构建DPDK二进制文件的细节


26.1.1 构建目录的概念

安装完毕后,会有一个
构建目录
被创建出来(译注:如下文中的i686-default-linuxapp-gcc)。每一个构建
目录都包括包含文件、库文件、应用程序:

12345678910111213141516171819202122232425262728293031323334353637383940414243~/DPDK$ lsapp MAINTAINERSconfig MakefileCOPYRIGHT mkdoc scriptsexamples libtools x86_64-default-linuxapp-gccx86_64-default-linuxapp-icc i686-default-linuxapp-gcci686-default-linuxapp-icc... ~/DEV/DPDK$ ls i686-default-linuxapp-gccapp build hostapp include kmod lib Makefile ~/DEV/DPDK$ ls i686-default-linuxapp-gcc/app/chkincs dump_cfg test testpmdchkincs.map dump_cfg.map test.map testpmd.map ~/DEV/DPDK$ ls i686-default-linuxapp-gcc/lib/libethdev.a librte_hash.a librte_mbuf.a librte_pmd_ixgbe.alibrte_cmdline.a librte_lpm.a librte_mempool.a librte_ring.alibrte_eal.a librte_malloc.a librte_pmd_e1000.a librte_timer.a ~/DEV/DPDK$ ls i686-default-linuxapp-gcc/include/arch rte_cpuflags.h rte_memcpy.hcmdline_cirbuf.h rte_cycles.h rte_memory.hcmdline.h rte_debug.h rte_mempool.hcmdline_parse_etheraddr.h rte_eal.h rte_memzone.hcmdline_parse.h rte_errno.h rte_pci_dev_ids.hcmdline_parse_ipaddr.h rte_ethdev.h rte_pci.hcmdline_parse_num.h rte_ether.h rte_per_lcore.hcmdline_parse_portlist.h rte_fbk_hash.h rte_prefetch.hcmdline_parse_string.h rte_hash_crc.h rte_random.hcmdline_rdline.h rte_hash.h rte_ring.hcmdline_socket.h rte_interrupts.h rte_rwlock.hcmdline_vt100.h rte_ip.h rte_sctp.hexec-env rte_jhash.h rte_spinlock.hrte_alarm.h rte_launch.h rte_string_fns.hrte_atomic.h rte_lcore.h rte_tailq.hrte_branch_prediction.h rte_log.h rte_tcp.hrte_byteorder.h rte_lpm.h rte_timer.hrte_common.h rte_malloc.h rte_udp.hrte_config.h rte_mbuf.h
一个构建目录对应一个包含了架构、执行环境、工具链的配置文件。相同的源码通过不同的配置文件 It is possible to have several build directories sharing the same sources with different configurations. 例如,想用默认的配置文件模板
config/defconfig_x86_64-linuxapp
创建一个构建目录
my_sdk_build_dir
,我们可以:

1

2

cd
${RTE_SDK}

make
config
T=x86_64-default-linuxapp-gcc
O=my_sdk_build_dir

这会创建一个新目录
my_sdk_build_dir
。然后我们就可以编译它了:

12cd my_sdk_build_dirmake
这等同于执行:

1

make
O=my_sdk_build_dir

my_sdk_build_dir中的内容如下:

1234567891011121314151617181920212223242526272829303132-- .config # used configuration-- Makefile # wrapper that calls head Makefile # with $PWD as build directory-- build # All temporary files used during build +-- app # process, including .o, .d, and .cmd files. | `-- test # For libraries, we have the .a file. | +-- test.o # For applications, we have the elf file. | `-- ... `-- lib +-- librte_eal | `-- ... +-- librte_mempool | +-- mempool-file1.o | +-- .mempool-file1.o.cmd | +-- .mempool-file1.o.d | +-- mempool-file2.o | +-- .mempool-file2.o.cmd | +-- .mempool-file2.o.d | `-- mempool.a `-- ...-- include # All include files installed by libraries +-- librte_mempool.h # and applications are located in this +-- rte_eal.h # directory. The installed files can depend +-- rte_spinlock.h # on configuration if needed (environment, +-- rte_atomic.h # architecture, ...) `-- *.h ...-- lib # all compiled libraries are copied in this +-- librte_eal.a # directory +-- librte_mempool.a `-- *.a ...-- app # All compiled applications are installed +-- test # here. It includes the binary in elf format
参阅根make文件帮助获得能从DPDK根目录下执行的make命令的一些细节。

26.2 构建外部程序

本质上DPDK是一个开发套件,因此其第一要务是使用户能使用SDK创建应用程序。要想编译一个程序,用户必须 设置
RTE_SDK
RTE_TARGET
环境变量。

1

2

3

export
RTE_SDK=/opt/DPDK

export
RTE_TARGET=x86_64-default-linuxapp-gcc

cd
/path/to/my_app

对于一个新的程序,用户必须创建自己的Makefile,这个Makefile可能包含一些.mk文件, 比如:
${RTE_SDK}/mk/DPDK.vars.mk
${RTE_SDK}/mk/DPDK.app.mk
。根据您选择的目标(包括架构、
机器、执行环境、工具链等,这些目标定义在Makefile中或作为一个环境变量),在编译应用程序和库文件时, 框架会选择合适的.h头文件和.a库文件。目标文件在
${RTE_SDK}/arch-machine-execenv-toolchain
(译注:其中arch、machine、execenv、toolchain应该依据编译环境而改变,如arch可以为i686、x86_64,
toolchain可以为gcc、icc等),它会被环境变量
${RTE_BIN_SDK}
内在地引用。使用
make
命令即可编译应
用程序。编译结果会保存在
/path/to/my_app/build
目录。

examples
目录提供了一些示例程序


26.3 Makefile说明


26.3.1 DPDK Makefile的通用规则

DPDK的Makefile永远依照如下的格式:

在开始处包含
$(RTE_SDK)/mk/DPDK.vars.mk


为RTE构建系统定义指定的变量

包含指定的.mk文件
$(RTE_SDK)/mk/DPDK.XYZ.mk
,其中XYZ可以是app、lib、extapp、extlib、
obj、gnuconfigure等,具体应该用哪一个,完全取决于你想创建的项目的类型。请参阅Makefile类型

包含用户定义的规则和变量

下面是一个非常简单的外部应用的Makefile示例:

12345678include $(RTE_SDK)/mk/DPDK.vars.mk# binary nameAPP = helloworld# all source are stored in SRCS-ySRCS-y := main.cCFLAGS += -O3CFLAGS += $(WERROR_FLAGS)include $(RTE_SDK)/mk/DPDK.extapp.mk

26.3.2 Makefile类型

用户创建的Makefile中最后包含的.mk文件决定了这个Makefile的角色。注意用同一个Makefile是不可 能既创建库文件又创建应用程序的。因此用户必须在不同的目录中创建两个独立的Makefile。任何情况下 用户都应该把
rte.vars.mk
包含进来。

26.3.2.1 应用程序

这些Makefile产生二进制应用。rte.app.mk: 内部程序
rte.extapp.mk: 外部程序
rte.hostapp.mk: 宿主程序

26.3.2.2 静态库

创建.a静态库rte.lib.mk: 内部库
rte.extlib.mk: 外部库
rte.hostlib.mk: 宿主库

26.3.2.3 安装

rte.install.mk: 不创建任何东西,仅仅是用于向安装目录创建链接文件。对于从开发框架包含文件很有用。

26.3.2.4 内核模块

rte.module.mk: 用框架创建一个内核模块

26.3.2.5 目标文件

rte.obj.mk: 将许多目标文件合并为一个,在框架内使用
rte.extobj.mk: 将许多目标文件合并为一个,在框架外使用

26.3.2.6 杂项

rte.doc.mk: 开发框架的文档
rte.gnuconfigure.mk: 创建基于configure的程序
rte.subdir.mk: 在框架内创建许多目录

26.3.3 构建系统提供的有用的变量

RTE_SDK
: DPDK源码包的绝对路径。编译开发套件时框架会自动设置。当编译外部应用时,用户必须定义这个环境变量。
RTE_SRCDIR
: 源码的路径。当编译开发套件时
RTE_SRCDIR
等于
RTE_SDK
。编译外部应用时则指向外部应用的源码目录。
RTE_OUTPUT
: 输出文件的路径。通常情况下是
$(RTE_SRCDIR)/build
,通过make命令的
O=
选项可以重写该变量。
RTE_TARGET
: 一个标识了编译目标的字符串。格式为
arch-machine-execenv-toolchain
。编译SDK时是由构建系 统通过配置文件(.config)推理出来的。编译外部应用时则必须由用户在Makefile或环境变量中指定。
RTE_SDK_BIN
$(RTE_SDK)/$(RTE_TARGET)
的引用。
RTE_ARCH
: 定义架构(i686, x86_64)。和
CONFIG_RTE_ARCH
值相同,只是不需要双引号括起来。
RTE_MACHINE
: 定义目标机器。和
CONFIG_RTE_MACHINE
值相同,只是不需要双引号括起来。
RTE_TOOLCHAIN
: 定义工具链(gcc、icc)。和
CONFIG_RTE_TOOLCHAIN
值相同,只是不需要双引号括起来。
RTE_EXEC_ENV
: 定义执行环境(如linuxapp)。和
CONFIG_RTE_EXEC_ENV
值相同,只是不需要双引号括起来。
RTE_KERNELDIR
: 这个变量包含了用来编译内核模块的内核源码的绝对路径。内核头文件必须和执行应用程序的目 标机器相匹配。默认情况下,这个变量设置为
/lib/modules/$(shell uname -r)/build
。当编译机和目标机相同时, 这是正确的。 26.3.4 Variables that Can be Set/Overridden in a Makefile Only
VPATH
: The path list that the build system will search for sources. By default, RTE_SRCDIR will be included in VPATH.
CFLAGS
: Flags to use for C compilation. The user should use += to append data in this variable.
LDFLAGS
: Flags to use for linking. The user should use += to append data in this variable.
ASFLAGS
: Flags to use for assembly. The user should use += to append data in this variable.
CPPFLAGS
: Flags to use to give flags to C preprocessor (only useful when assembling .S files). The user should use += to append data in this variable.
LDLIBS
: In an application, the list of libraries to link with (for example, -L / path/to/libfoo -lfoo). The user should use += to append data in this variable.
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. The sources must be available from VPATH.
INSTALL-y-$(INSTPATH)
: A list of files to be installed in $(INSTPATH) . The files must be available from VPATH and will be copied in $(RTE_OUTPUT)/ $(INSTPATH) . Can be used in almost any RTE Makefile.
SYMLINK-y-$(INSTPATH)
: A list of files to be installed in $(INSTPATH) . The files must be available from VPATH and will be linked (symbolically) in $(RTE_OUTPUT)/$(INSTPATH). This variable can be used in almost any Intel ®DPDK Makefile.
PREBUILD
: A list of prerequisite actions to be taken before building. The user should use += to append data in this variable.
POSTBUILD
: A list of actions to be taken after the main build. The user should use += to append data in this variable.
PREINSTALL
: A list of prerequisite actions to be taken before installing. The user should use += to append data in this variable.
POSTINSTALL
: A list of actions to be taken after installing. The user should use += to append data in this variable.
PRECLEAN
: A list of prerequisite actions to be taken before cleaning. The user should use += to append data in this variable.
POSTCLEAN
: A list of actions to be taken after cleaning. The user should use += to append data in this variable.
DEPDIR-y
: Only used in the development kit framework to specify if the build of the current directory depends on build of another one. This is needed to support parallel builds correctly. 26.3.5 Variables that can be Set/Overridden by the User on the Command Line Only Some variables can be used to configure the build system behavior. They are documented in Development Kit Root Makefile Help and External Application/Library Makefile help.
WERROR_CFLAGS
: By default, this is set to a specific value that depends on the compiler. Users are encouraged to use this variable as follows: CFLAGS += $(WERROR_CFLAGS) This avoids the use of different cases depending on the compiler (icc or gcc ). Also, this variable can be overridden from the command line, which allows bypassing of the flags for testing purposes. 26.3.6 Variables that Can be Set/Ove rridden by the User in a Makefile or Command Line
CFLAGS_my_file.o
: Specific flags to add for C compilation of my_file.c.
LDFLAGS_my_app
: Specific flags to add when linking my_app.
NO_AUTOLIBS
: If set, the libraries provided by the framework will not be included in the LDLIBS variable automatically.
EXTRA_CFLAGS
: The content of this variable is appended after CFLAGS when compiling.
EXTRA_LDFLAGS
: The content of this variable is appended after LDFLAGS when linking.
EXTRA_ASFLAGS
: The content of this variable is appended after ASFLAGS when assembling.
EXTRA_CPPFLAGS
: The content of this variable is appended after CPPFLAGS when using a C preprocessor on assembly files.
27.0 开发套件的根Makefile帮助DPDK为目标提供根级的Makefile DPDK provides a root level Makefile with targets for configuration, building, cleaning, testing, installation and others. These targets are explained in the following sections. 27.1 配置目标 The configuration target requires the name of the target, which is specified using T=mytarget and it is mandatory. The list of available targets are in $(RTESDK)/ config (remove the defconfig prefix). Configuration targets also support the specific ation of the name of the output directory, using O=mybuilddir. This is an optional parameter, the default output directory is build. • config This will create a build directory, and generates a configuration from a template. A Makefile is also created in the new build directory. Example: make config O=mybuild T=x86_64-default-linuxapp-gcc27.2 构建目标 Build targets support the optional specificat ion of the name of the output directory, using O=mybuilddir. The default output directory is build. • all , build or just make Build the Intel ® DPDK in the output directory previously created by a make config. Example: make O=mybuild • clean Clean all objects created using make build. Example: make clean O=mybuild • %_sub Build a subdirectory only, without managing dependencies on other directories. Example: make lib/librte_eal_sub O=mybuild • %_clean Clean a subdirectory only. Example: make lib/librte_eal_clean O=mybuild27.3 安装目标 • install Build the Intel ® DPDK binary. Actually, this builds each supported target in a separate directory. The name of each directory is the name of the target. The name of the targets to install can be optionally specified using T=mytarget. The target name can contain wildcard characters. The list of available targets are in $(RTESDK)/config (remove the defconfig prefix). Example: make install T=x86_64- • uninstall Remove installed target directories.27.4 测试目标 • test Launch automatic tests for a build directory specified using O=mybuilddir. It is optional, the default output directory is build. Example: make test O=mybuild • testall Launch automatic tests for all installed target directories (after a make install). The name of the targets to test can be optionally specified using T=mytarget. The target name can contain wildcard ( ) characters. The list of available targets are in $(RTESDK)/config (remove the defconfig prefix). Examples: make testall, make testall T=x86_64-27.5 目标的文档 • doxydoc Generate the Doxygen documentation (pdf only).27.6 目标的依赖

1

depdirs

这个目标 This target is implicitly called by make config . Typically, there is no need for a user to call it, except if DEPDIRS-y variables have been updated in Makefiles. It will generate the file $(RTE_OUTPUT)/.depdirs. Example: make depdirs O=mybuild

1depgraph
This command generates a dot graph of dependencies. It can be displayed to debug circular dependency issues, or just to understand the dependencies. Example: make depgraph O=mybuild > /tmp/graph.dot && dotty /tmp/ graph.dot27.7 目标杂项

1

help

显示帮助

27.8 其他有用的命令行变量

The following variables can be specified on the command line: • V= Enable verbose build (show full compilation command line, and some intermediate commands). • D= Enable dependency debugging. This provides some useful information about why a target is built
or not. • EXTRA_CFLAGS= , EXTRA_LDFLAGS=, EXTRA_ASFLAGS=, EXTRA_CPPFLAGS= Append specific compilation, link or asm flags. • CROSS= Specify a cross toolchain header that will prefix all gcc/binutils applications. This only works when using gcc.

27.9 在构建目录make 以上描述的所有目标均在SDK的根
$(RTE_SDK)
被调用。在构建目录执行相同的Makefile目标也是可行的。
举例来说:

123cd $(RTE_SDK)make config O=mybuild T=x86_64-default-linuxapp-gccmake O=mybuild
这和下面的等价:

1

2

3

4

5

cd
$(RTE_SDK)

make
config
O=mybuild
T=x86_64-default-linuxapp-gcc

cd
mybuild

#
现在不再需要指定 O= 了

make

27.10 编译用于调试

编译包含调试信息并且优化级别为0的DPDK框架及其示例程序,需要在编译前将
EXTRA_CFLAGS
变量设置为:

1export EXTRA_CFLAGS=’-O0 –g’
之后就可以像平常那样编译DPDK框架、示例程序甚至用户程序了:

1

2

make
install
T=x86_64-default-linuxapp-gcc

make
–C
examples/<theapp>


28.0 扩展DPDK

本节将会记述一个开发者如何扩展DPDK,例如提供一个新库、一个新目标或者支持一个新目标。


28.1 示例:为DPDK增加一个新库libfoo

给DPDK增加新库,过程如下:

增加一个新的配置选项:

12for f in config/*; do \echo CONFIG_RTE_LIBFOO=y >> $f; done
创建一个项目文件夹并创建源文件:

1

2

3

mkdir
${RTE_SDK}/lib/libfoo

touch
${RTE_SDK}/lib/libfoo/foo.c

touch
${RTE_SDK}/lib/libfoo/foo.h

给libfoo添加一个
foo()
函数。

在foo.c中定义:

1void foo(void) { }
在foo.h中声明:

1

extern
void
foo(void);

更新lib/Makefile:

1vi ${RTE_SDK}/lib/Makefile
在其中添加:

1

DIRS-$(CONFIG_RTE_LIBFOO)
+=
libfoo

为库创建一个新的Makefile,例如,可以从mempool库的Makefile文件派生一个:

12cp ${RTE_SDK}/lib/librte_mempool/Makefile ${RTE_SDK}/lib/libfoo/vi ${RTE_SDK}/lib/libfoo/Makefile
将其中的
librte_mempool
替换为
libfoo
rte_mempool
替换为
foo
更新
mk/DPDK.app.mk
,添加
-lfoo
LDLIBS
变量(确保其可用)。之后,当链接DPDK应用时就能自动使用这个编译选项了。
构建拥有新库的DPDK框架(这里只用一个目标作展示):

1

2

3

cd
${RTE_SDK}

make
config
T=x86_64-default-linuxapp-gcc

make

检查库是否被安装:

12ls build/libls build/include

28.1.1 示例: 在测试程序中使用libfoo

测试程序用来验证所有的DPDK功能是否有效。一旦你添加了新的库,就必须在测试程序用添加新的用例。首先应该添加一个
test_foo.c
文件。它包含foo.h并且从test_foo()调用foo(),当测试通过时test_foo()应该返回0。
Makefile、test.h和commands.c也都应该更新,以便执行测试用例。
测试报告的产生:
autotest.py
是一个用来产生测试报告的脚本,它在
${RTE_SDK}/doc/rst/test_report/autotests
目录下。这个脚本也应该更新。如果libfoo是一个新的测试族,
${RTE_SDK}/doc/rst/test_report/test_report.rst
中 的链接也应该更新。
构建拥有新测试程序的DPDK框架(这里只用一个目标作展示):

1

2

3

cd
${RTE_SDK}

make
config
T=x86_64-default-linuxapp-gcc

make


29.0 构建你自己的应用


29.1 在开发套件的目录中编译示例程序

当编译示例程序(比如hello_world)时,
RTE_SDK
RTE_TARGET
韩晶变量必须被export。

12345678~/DPDK$ cd examples/helloworld/~/DPDK/examples/helloworld$ export RTE_SDK=/home/user/DPDK~/DPDK/examples/helloworld$ export RTE_TARGET=x86_64-default-linuxapp-gcc~/DPDK/examples/helloworld$ makeCC main.oLD helloworldINSTALL-APP helloworldINSTALL-MAP helloworld.map
默认情况下,二进制文件会在build文件夹下生成。

1

2

~/DPDK/examples/helloworld$
ls
build/app

helloworld
helloworld.map


29.2 在开发套件之外构建你自己的应用

示例程序Hello World可以被复制到一个新的文件夹,以作为你开发的起始点:

123456789~$ cp -r DPDK/examples/helloworld my_rte_app~$ cd my_rte_app/~/my_rte_app$ export RTE_SDK=/home/user/DPDK~/my_rte_app$ export RTE_TARGET=x86_64-default-linuxapp-gcc~/my_rte_app$ makeCC main.oLD helloworldINSTALL-APP helloworldINSTALL-MAP helloworld.map

29.3 自定义Makefile

29.3.1 应用的Makefile

示例程序hello world的默认Makefile是一个不错的起始点,它包括:

1

2

$(RTE_SDK)/mk/DPDK.vars.mk #在开始处包含

$(RTE_SDK)/mk/DPDK.extapp.mk #在结尾处包含

用户必须定义一些变量

12APP: 应用的名字Contains the name of the application.SRCS-y: 源码列表(*.c、*.S)

29.3.2 库的Makefile

用同样的方法也能编译成库文件

1

2

$(RTE_SDK)/mk/DPDK.vars.mk #在开始处包含

$(RTE_SDK)/mk/DPDK.extlib.mk #在结尾处包含

和编译应用唯一的不同是,用LIB变量替代APP变量,LIB变量的内容是库的名字,比如,libfoo.a。


29.3.3 自定义Makefile的行为

一些变量可以用来自定义Makefile的行为。下面列出最常用的一些。请参阅构建系统提供的有用的变量 查看相关细节。

1234567VPATH: #构建系统搜索源码的路径列表。默认情况下RTE_SRCDIR会包含在VPATH中。CFLAGS_my_file.o: #对my_file.c指定的c编译选项。CFLAGS : #c编译器的flag选项。LDFLAGS: #链接器的flag选项。CPPFLAGS: #c预处理器的flag选项(仅当汇编.S文件时有用)。LDLIBS: #链接库列表(例如,-L /path/to/libfoo -lfoo)。NO_AUTOLIBS: #如果设置了该选项,LDLIBS不会自动包含由框架提供的库文件。

30.0 外部应用、外部库Makefile帮助

外部应用或库应该从
RTE_SDK
导入指定的Makefile,这些文件位于mk文件夹:

1

2

3

${RTE_SDK}/mk/DPDK.extapp.mk:
构建应用

${RTE_SDK}/mk/DPDK.extlib.mk:
构建静态库

{RTE_SDK}/mk/DPDK.extobj.mk: 构建目标文件


30.1 预备知识

下列变量必须定义:

${RTE_SDK}
: 指向DPDK的根目录

${RTE_TARGET}
: 编译目标的引用(比如,
x86_64-default-linuxapp-gcc



30.2 构建目标

构建目标支持通过
O=mybuilddir
选项指定输出文件夹,这是可选的。默认的输出目录是build。

all, “nothing” (meaning just make) 在指定目录创建应用或库。 举例:
make
 O=mybuild


clean 清除所有使用make构建的对象 举例:
make
 clean O=mybuild



30.3 帮助目标

help 显示帮助。


30.4 其他有用的命令行变量

以下变量可以在命令行中指定:

1

2

3

4

5

6

S=
#指定源码所在的文件夹,默认为当前文件夹。

M=
#指定输出路径被创建时所调用的Makefile,默认使用$(S)/Makefile。

V=
#允许详细构建(显示所有的命令行命令和中间命令)

D=
#允许依赖调试。这将提供一些有用的信息,比如一个目标被重新创建或不被创建的原因。

EXTRA_CFLAGS=, EXTRA_LDFLAGS=, EXTRA_ASFLAGS=, EXTRA_CPPFLAGS=
#附加的编译、链接或asm选项

CROSS=
#指定交叉编译的工具链头文件,这将前缀在所有gcc或binutils程序上(只在gcc下生效)。


30.5 从其他文件夹make

从其他文件夹执行Makefile也是可以的。通过指定源文件目录和输出文件目录即可实现:
1

2

3

export
RTE_SDK=/path/to/DPDK

export
RTE_TARGET=x86_64-default-linuxapp-icc

make
-f
/path/to/my_app/Makefile
S=/path/to/my_app
O=/path/to/build_dir

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: