ef84383d55a7fd26da8daed6128c92c86151933a
[vpp.git] / build / external / packages / dpdk.mk
1 # Copyright (c) 2020 Cisco and/or its affiliates.
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at:
5 #
6 #     http://www.apache.org/licenses/LICENSE-2.0
7 #
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
13
14 DPDK_PKTMBUF_HEADROOM        ?= 128
15 DPDK_DEBUG                   ?= n
16 DPDK_MLX4_PMD                ?= n
17 DPDK_MLX5_PMD                ?= n
18 DPDK_MLX5_COMMON_PMD         ?= n
19 DPDK_TAP_PMD                 ?= n
20 DPDK_FAILSAFE_PMD            ?= n
21 DPDK_MACHINE                 ?= default
22
23 dpdk_version                 ?= 20.08
24 dpdk_base_url                ?= http://fast.dpdk.org/rel
25 dpdk_tarball                 := dpdk-$(dpdk_version).tar.xz
26 dpdk_tarball_md5sum_20.08    := 64badd32cd6bc0761befc8f2402c2148
27 dpdk_tarball_md5sum          := $(dpdk_tarball_md5sum_$(dpdk_version))
28 dpdk_url                     := $(dpdk_base_url)/$(dpdk_tarball)
29 dpdk_tarball_strip_dirs      := 1
30
31 # Debug or release
32
33 DPDK_BUILD_TYPE:=release
34 ifeq ($(DPDK_DEBUG), y)
35 DPDK_BUILD_TYPE:=debug
36 endif
37
38 DPDK_DRIVERS_DISABLED := baseband/\*,   \
39         bus/dpaa,                                                       \
40         bus/ifpga,                                                      \
41         compress/\*,                                            \
42         crypto/ccp,                                                     \
43         crypto/dpaa_sec,                                        \
44         crypto/openssl,                                         \
45         event/\*,                                                       \
46         mempool/dpaa,                                           \
47         net/af_packet,                                          \
48         net/bnx2x,                                                      \
49         net/bonding,                                            \
50         net/ipn3ke,                                                     \
51         net/liquidio,                                           \
52         net/pcap,                                                       \
53         net/pfe,                                                        \
54         net/sfc,                                                        \
55         net/softnic,                                            \
56         net/thunderx,                                           \
57         raw/ifpga,                                                      \
58         net/af_xdp                                                      
59
60 DPDK_LIBS_DISABLED := acl,                              \
61         bbdev,                                                          \
62         bitratestats,                                           \
63         bpf,                                                            \
64         cfgfile,                                                        \
65         distributor,                                            \
66         efd,                                                            \
67         fib,                                                            \
68         flow_classify,                                          \
69         graph,                                                          \
70         gro,                                                            \
71         gso,                                                            \
72         jobstats,                                                       \
73         kni,                                                            \
74         latencystats,                                           \
75         lpm,                                                            \
76         member,                                                         \
77         node,                                                           \
78         pipeline,                                                       \
79         port,                                                           \
80         power,                                                          \
81         rawdev,                                                         \
82         rib,                                                            \
83         table
84
85 # Adjust disabled pmd and libs depending on user provided variables
86 ifeq ($(DPDK_MLX4_PMD), n)
87         DPDK_DRIVERS_DISABLED += ,net/mlx4
88 endif
89 ifeq ($(DPDK_MLX5_PMD), n)
90         DPDK_DRIVERS_DISABLED += ,net/mlx5
91 endif
92 ifeq ($(DPDK_MLX5_COMMON_PMD), n)
93         DPDK_DRIVERS_DISABLED += ,common/mlx5
94 endif
95 ifeq ($(DPDK_TAP_PMD), n)
96         DPDK_DRIVERS_DISABLED += ,net/tap
97 endif
98 ifeq ($(DPDK_FAILSAFE_PMD), n)
99         DPDK_DRIVERS_DISABLED += ,net/failsafe
100 endif
101
102 # Sanitize DPDK_DRIVERS_DISABLED and DPDK_LIBS_DISABLED
103 DPDK_DRIVERS_DISABLED := $(shell echo $(DPDK_DRIVERS_DISABLED) | tr -d '\\\t ')
104 DPDK_LIBS_DISABLED := $(shell echo $(DPDK_LIBS_DISABLED) | tr -d '\\\t ')
105
106 HASH := \#
107 # post-meson-setup snippet to alter rte_build_config.h
108 define dpdk_config
109 if grep -q RTE_$(1) $(dpdk_src_dir)/config/rte_config.h ; then  \
110 sed -i -e 's/$(HASH)define RTE_$(1).*/$(HASH)define RTE_$(1) $(DPDK_$(1))/' \
111         $(dpdk_src_dir)/config/rte_config.h; \
112 elif grep -q RTE_$(1) $(dpdk_build_dir)/rte_build_config.h ; then \
113 sed -i -e 's/$(HASH)define RTE_$(1).*/$(HASH)define RTE_$(1) $(DPDK_$(1))/' \
114         $(dpdk_build_dir)/rte_build_config.h; \
115 else \
116 echo '$(HASH)define RTE_$(1) $(DPDK_$(1))' \
117         >> $(dpdk_build_dir)/rte_build_config.h ; \
118 fi
119 endef
120
121 DPDK_MESON_ARGS = \
122         --default-library static \
123         --libdir lib \
124         --prefix $(dpdk_install_dir) \
125         -Dtests=false \
126         "-Ddisable_drivers=$(DPDK_DRIVERS_DISABLED)" \
127         "-Ddisable_libs=$(DPDK_LIBS_DISABLED)" \
128         -Db_pie=true \
129         -Dmachine=$(DPDK_MACHINE) \
130         --buildtype=$(DPDK_BUILD_TYPE) 
131
132 define dpdk_config_cmds
133         cd $(dpdk_build_dir) && \
134         rm -rf ../dpdk-meson-venv && \
135         mkdir -p ../dpdk-meson-venv && \
136         python3 -m venv ../dpdk-meson-venv && \
137         source ../dpdk-meson-venv/bin/activate && \
138         pip3 install meson==0.54 && \
139         meson setup $(dpdk_src_dir) \
140                 $(dpdk_build_dir) \
141                 $(DPDK_MESON_ARGS) \
142                         | tee $(dpdk_config_log) && \
143         deactivate && \
144         echo "DPDK post meson configuration" && \
145         echo "Altering rte_build_config.h" && \
146         $(call dpdk_config,PKTMBUF_HEADROOM) 
147 endef
148
149 define dpdk_build_cmds
150         cd $(dpdk_build_dir) && \
151         source ../dpdk-meson-venv/bin/activate && \
152         meson compile -C . | tee $(dpdk_build_log) && \
153         deactivate
154 endef
155
156 define dpdk_install_cmds
157         cd $(dpdk_build_dir) && \
158         source ../dpdk-meson-venv/bin/activate && \
159         meson install && \
160         cd $(dpdk_install_dir)/lib && \
161         echo "GROUP ( $$(ls librte*.a ) )" > libdpdk.a && \
162         rm -rf librte*.so librte*.so.* dpdk/*/librte*.so dpdk/*/librte*.so.* && \
163         deactivate && \
164         rm -rf $(dpdk_build_dir)/../dpdk-meson-venv
165 endef
166
167 $(eval $(call package,dpdk))