06f9d193d63272c30a3f13773111522118f1c05d
[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_USE_LIBBSD              ?= n
16 DPDK_DEBUG                   ?= n
17 DPDK_MLX4_PMD                ?= n
18 DPDK_MLX5_PMD                ?= n
19 DPDK_MLX5_COMMON_PMD         ?= n
20 DPDK_TAP_PMD                 ?= n
21 DPDK_FAILSAFE_PMD            ?= n
22 DPDK_MACHINE                 ?= default
23
24 dpdk_version                 ?= 20.08
25 dpdk_base_url                ?= http://fast.dpdk.org/rel
26 dpdk_tarball                 := dpdk-$(dpdk_version).tar.xz
27 dpdk_tarball_md5sum_20.08    := 64badd32cd6bc0761befc8f2402c2148
28 dpdk_tarball_md5sum          := $(dpdk_tarball_md5sum_$(dpdk_version))
29 dpdk_url                     := $(dpdk_base_url)/$(dpdk_tarball)
30 dpdk_tarball_strip_dirs      := 1
31
32 # Debug or release
33
34 DPDK_BUILD_TYPE:=release
35 ifeq ($(DPDK_DEBUG), y)
36 DPDK_BUILD_TYPE:=debug
37 endif
38
39 DPDK_DRIVERS_DISABLED := baseband/\*,   \
40         bus/dpaa,                                                       \
41         bus/ifpga,                                                      \
42         compress/isal,                                          \
43         compress/octeontx,                                      \
44         compress/zlib,                                          \
45         crypto/ccp,                                                     \
46         crypto/dpaa_sec,                                        \
47         crypto/openssl,                                         \
48         event/\*,                                                       \
49         mempool/dpaa,                                           \
50         net/af_packet,                                          \
51         net/bnx2x,                                                      \
52         net/bonding,                                            \
53         net/ipn3ke,                                                     \
54         net/liquidio,                                           \
55         net/pcap,                                                       \
56         net/pfe,                                                        \
57         net/sfc,                                                        \
58         net/softnic,                                            \
59         net/thunderx,                                           \
60         raw/ifpga,                                                      \
61         net/af_xdp                                                      
62
63 DPDK_LIBS_DISABLED := acl,                              \
64         bbdev,                                                          \
65         bitratestats,                                           \
66         bpf,                                                            \
67         cfgfile,                                                        \
68         distributor,                                            \
69         efd,                                                            \
70         fib,                                                            \
71         flow_classify,                                          \
72         graph,                                                          \
73         gro,                                                            \
74         gso,                                                            \
75         jobstats,                                                       \
76         kni,                                                            \
77         latencystats,                                           \
78         lpm,                                                            \
79         member,                                                         \
80         node,                                                           \
81         pipeline,                                                       \
82         port,                                                           \
83         power,                                                          \
84         rawdev,                                                         \
85         rib,                                                            \
86         table
87
88 # Adjust disabled pmd and libs depending on user provided variables
89 ifeq ($(DPDK_MLX4_PMD), n)
90         DPDK_DRIVERS_DISABLED += ,net/mlx4
91 endif
92 ifeq ($(DPDK_MLX5_PMD), n)
93         DPDK_DRIVERS_DISABLED += ,net/mlx5
94 endif
95 ifeq ($(DPDK_MLX5_COMMON_PMD), n)
96         DPDK_DRIVERS_DISABLED += ,common/mlx5
97 endif
98 ifeq ($(DPDK_TAP_PMD), n)
99         DPDK_DRIVERS_DISABLED += ,net/tap
100 endif
101 ifeq ($(DPDK_FAILSAFE_PMD), n)
102         DPDK_DRIVERS_DISABLED += ,net/failsafe
103 endif
104
105 # Sanitize DPDK_DRIVERS_DISABLED and DPDK_LIBS_DISABLED
106 DPDK_DRIVERS_DISABLED := $(shell echo $(DPDK_DRIVERS_DISABLED) | tr -d '\\\t ')
107 DPDK_LIBS_DISABLED := $(shell echo $(DPDK_LIBS_DISABLED) | tr -d '\\\t ')
108
109 HASH := \#
110 # post-meson-setup snippet to alter rte_build_config.h
111 define dpdk_config
112 if grep -q RTE_$(1) $(dpdk_src_dir)/config/rte_config.h ; then  \
113 sed -i -e 's/$(HASH)define RTE_$(1).*/$(HASH)define RTE_$(1) $(DPDK_$(1))/' \
114         $(dpdk_src_dir)/config/rte_config.h; \
115 elif grep -q RTE_$(1) $(dpdk_build_dir)/rte_build_config.h ; then \
116 sed -i -e 's/$(HASH)define RTE_$(1).*/$(HASH)define RTE_$(1) $(DPDK_$(1))/' \
117         $(dpdk_build_dir)/rte_build_config.h; \
118 else \
119 echo '$(HASH)define RTE_$(1) $(DPDK_$(1))' \
120         >> $(dpdk_build_dir)/rte_build_config.h ; \
121 fi
122 endef
123
124 define dpdk_config_def
125 if [[ "$(DPDK_$(1))" == "y" ]]; then \
126     if ! grep -q "RTE_$(1)" $(dpdk_build_dir)/rte_build_config.h \
127       $(dpdk_src_dir)/config/rte_config.h ; then \
128         echo '$(HASH)define RTE_$(1) 1' \
129           >> $(dpdk_build_dir)/rte_build_config.h ; \
130     fi; \
131 elif [[ "$(DPDK_$(1))" == "n" ]]; then \
132     sed -i '/$(HASH)define RTE_$(1) .*/d' $(dpdk_build_dir)/rte_build_config.h \
133       $(dpdk_src_dir)/config/rte_config.h ; \
134 fi
135 endef
136
137 DPDK_MESON_ARGS = \
138         --default-library static \
139         --libdir lib \
140         --prefix $(dpdk_install_dir) \
141         -Dtests=false \
142         "-Ddisable_drivers=$(DPDK_DRIVERS_DISABLED)" \
143         "-Ddisable_libs=$(DPDK_LIBS_DISABLED)" \
144         -Db_pie=true \
145         -Dmachine=$(DPDK_MACHINE) \
146         --buildtype=$(DPDK_BUILD_TYPE) 
147
148 define dpdk_config_cmds
149         cd $(dpdk_build_dir) && \
150         rm -rf ../dpdk-meson-venv && \
151         mkdir -p ../dpdk-meson-venv && \
152         python3 -m venv ../dpdk-meson-venv && \
153         source ../dpdk-meson-venv/bin/activate && \
154         pip3 install meson==0.54 && \
155         meson setup $(dpdk_src_dir) \
156                 $(dpdk_build_dir) \
157                 $(DPDK_MESON_ARGS) \
158                         | tee $(dpdk_config_log) && \
159         deactivate && \
160         echo "DPDK post meson configuration" && \
161         echo "Altering rte_build_config.h" && \
162         $(call dpdk_config,PKTMBUF_HEADROOM) && \
163         $(call dpdk_config_def,USE_LIBBSD)
164 endef
165
166 define dpdk_build_cmds
167         cd $(dpdk_build_dir) && \
168         source ../dpdk-meson-venv/bin/activate && \
169         meson compile -C . | tee $(dpdk_build_log) && \
170         deactivate
171 endef
172
173 define dpdk_install_cmds
174         cd $(dpdk_build_dir) && \
175         source ../dpdk-meson-venv/bin/activate && \
176         meson install && \
177         cd $(dpdk_install_dir)/lib && \
178         echo "GROUP ( $$(ls librte*.a ) )" > libdpdk.a && \
179         rm -rf librte*.so librte*.so.* dpdk/*/librte*.so dpdk/*/librte*.so.* && \
180         deactivate && \
181         rm -rf $(dpdk_build_dir)/../dpdk-meson-venv
182 endef
183
184 $(eval $(call package,dpdk))