dpdk: Support of DPDK v16.04
[vswitchperf.git] / src / dpdk / Makefile
1 # makefile to manage dpdk package
2 #
3
4 # Copyright 2015-2016 OPNFV
5 #
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9 #
10 #     http://www.apache.org/licenses/LICENSE-2.0
11 #
12 # Unless required by applicable law or agreed to in writing, software
13 # distributed under the License is distributed on an "AS IS" BASIS,
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 # See the License for the specific language governing permissions and
16 # limitations under the License.
17
18 #
19 # Contributors:
20 #   Aihua Li, Huawei Technologies.
21 #   Martin Klozik, Intel Corporation.
22
23 include ../mk/master.mk
24 include ../package-list.mk
25
26 .PHONY: install force_make
27
28 ifndef VHOST_USER
29     VHOST_USER = n
30 endif
31 WORK_DIR = dpdk
32 TAG_DONE_FLAG = $(WORK_DIR)/.$(DPDK_TAG).tag.done
33 DPDK_CUSE = ../../src_cuse/dpdk
34
35 # VHOST configuration options are stored in different files based on DPDK version
36 # v1.2.3r0-v1.6.0r2 - configuration inside config/defconfig_x86_64-default-linuxapp-gcc
37 # v1.7.0-rc1-v2.2.0 - configuration inside config/common_linuxapp
38 # v16 and newer - configuration split between config/common_linuxapp and config/common_base
39 DPDK_TAG_MAJOR = $(shell echo $(DPDK_TAG) | cut -d. -f1)
40 DPDK_TAG_MINOR = $(shell echo $(DPDK_TAG) | cut -d. -f2)
41 ifeq ($(DPDK_TAG_MAJOR),v1)
42 ifeq ($(DPDK_TAG_MINOR), $(filter $(DPDK_TAG_MINOR), 7 8))
43     DPDK_TARGET = x86_64-native-linuxapp-gcc
44     CONFIG_FILE_LINUXAPP = $(WORK_DIR)/config/common_linuxapp
45 else
46     DPDK_TARGET = x86_64-default-linuxapp-gcc
47     CONFIG_FILE_LINUXAPP = $(WORK_DIR)/config/defconfig_x86_64-default-linuxapp-gcc
48 endif
49 else
50 ifeq ($(DPDK_TAG_MAJOR),v2)
51     DPDK_TARGET = x86_64-native-linuxapp-gcc
52     CONFIG_FILE_LINUXAPP = $(WORK_DIR)/config/common_linuxapp
53 else
54     DPDK_TARGET = x86_64-native-linuxapp-gcc
55     CONFIG_FILE_BASE = $(WORK_DIR)/config/common_base
56     CONFIG_FILE_LINUXAPP = $(WORK_DIR)/config/common_linuxapp
57 endif
58 endif
59
60 all: force_make
61         @echo "Finished making $(WORK_DIR) "
62
63 INSTALL_TARGET = force_make
64
65 # modify CONFIG_FILE to enable VHOST_USER build and restore original CONFIG_FILE after the build
66 # DPDK v16 comments:
67 ## CONFIG_RTE_BUILD_COMBINE_LIBS has been obsoleted
68 ## CONFIG_RTE_LIBRTE_VHOST and CONFIG_RTE_LIBRTE_KNI are listed in both config_base and config_linuxapp,
69 ## values from config_linuxapp will be used, but options are modified at both places to avoid confusion.
70 force_make: $(TAG_DONE_FLAG)
71         $(AT)cd $(WORK_DIR) && git pull $(DPDK_URL) $(DPDK_TAG)
72 ifdef CONFIG_FILE_BASE
73         $(AT)sed -i -e 's/CONFIG_RTE_LIBRTE_VHOST_USER=.\+/CONFIG_RTE_LIBRTE_VHOST_USER=$(VHOST_USER)/g' $(CONFIG_FILE_BASE)
74         $(AT)sed -i -e 's/CONFIG_RTE_LIBRTE_VHOST=./CONFIG_RTE_LIBRTE_VHOST=y/g' $(CONFIG_FILE_BASE)
75         $(AT)sed -i -e 's/CONFIG_RTE_LIBRTE_KNI=./CONFIG_RTE_LIBRTE_KNI=n/g' $(CONFIG_FILE_BASE)
76 else
77         $(AT)sed -i -e 's/CONFIG_RTE_LIBRTE_VHOST_USER=.\+/CONFIG_RTE_LIBRTE_VHOST_USER=$(VHOST_USER)/g' $(CONFIG_FILE_LINUXAPP)
78         $(AT)sed -i -e 's/CONFIG_RTE_BUILD_COMBINE_LIBS=./CONFIG_RTE_BUILD_COMBINE_LIBS=y/g' $(CONFIG_FILE_LINUXAPP)
79 endif
80         $(AT)sed -i -e 's/CONFIG_RTE_LIBRTE_VHOST=./CONFIG_RTE_LIBRTE_VHOST=y/g' $(CONFIG_FILE_LINUXAPP)
81         $(AT)sed -i -e 's/CONFIG_RTE_LIBRTE_KNI=./CONFIG_RTE_LIBRTE_KNI=n/g' $(CONFIG_FILE_LINUXAPP)
82         $(AT)cd $(WORK_DIR); make install T=$(DPDK_TARGET) -j DESTDIR=$(WORK_DIR)
83         $(AT)cd `dirname $(CONFIG_FILE_LINUXAPP)` && git checkout `basename $(CONFIG_FILE_LINUXAPP)` && cd -
84 ifdef CONFIG_FILE_BASE
85         $(AT)cd `dirname $(CONFIG_FILE_BASE)` && git checkout `basename $(CONFIG_FILE_BASE)` && cd -
86 endif
87         $(AT)echo "VHOST_USER = $(VHOST_USER)"
88 ifeq ($(VHOST_USER),n)
89         $(AT)cd $(WORK_DIR)/lib/librte_vhost/eventfd_link; make
90 endif
91         @echo "Make done"
92
93 install: $(INSTALL_TARGET)
94         $(AT)sudo cp -a $(WORK_DIR)/$(DPDK_TARGET)/kmod $(INSTALL_DIR)/lib/modules/$(KERNEL_VERSION)
95         @echo "install done"
96
97 # hard way to clean and clobber
98 clean:
99         $(AT)cd $(WORK_DIR) && git clean -xfd *.o
100 clobber:
101         $(AT)rm -rf $(WORK_DIR)
102         $(AT)rm -rf $(DPDK_CUSE)
103
104 # distclean is for developer who would like to keep the
105 # clone git repo, saving time to fetch again from url
106 distclean:
107         $(AT)cd $(WORK_DIR) && git clean -xfd && git checkout -f
108
109 test:
110         @echo "Make test in $(WORK_DIR) (stub) "
111
112 sanity:
113         @echo "Make sanity in $(WORK_DIR) (stub) "
114
115 $(WORK_DIR):
116         $(AT)git clone $(DPDK_URL)
117         $(AT)mkdir -p $(DPDK_CUSE)
118         $(AT)cp -rf ./* $(DPDK_CUSE)
119
120 $(TAG_DONE_FLAG): $(WORK_DIR)
121         $(AT)cd $(WORK_DIR); git checkout $(DPDK_TAG)
122         $(AT)touch $@