40fa48201868ff1961acc37c06c8e7f40712042a
[barometer.git] / src / dpdk / Makefile
1 # makefile to manage dpdk package
2 #
3
4 # Copyright 2015-2017 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 #   Christian Trautman, Red Hat Inc.
23 #   Maryam Tahhan, Intel Corporation.
24
25 include ../mk/master.mk
26 include ../package-list.mk
27 include /etc/os-release
28
29 .PHONY: install force_make
30
31 WORK_DIR = dpdk
32 TAG_DONE_FLAG = $(WORK_DIR)/.$(DPDK_TAG).tag.done
33
34 # VHOST configuration options are stored in different files based on DPDK version
35 # v1.2.3r0-v1.6.0r2 - configuration inside config/defconfig_x86_64-default-linuxapp-gcc
36 # v1.7.0-rc1-v2.2.0 - configuration inside config/common_linuxapp
37 # v16 and newer - configuration split between config/common_linuxapp and config/common_base
38 DPDK_TAG_MAJOR = $(shell echo $(DPDK_TAG) | cut -d. -f1)
39 DPDK_TAG_MINOR = $(shell echo $(DPDK_TAG) | cut -d. -f2)
40 ifeq ($(DPDK_TAG_MAJOR),v1)
41 ifeq ($(DPDK_TAG_MINOR), $(filter $(DPDK_TAG_MINOR), 7 8))
42     DPDK_TARGET = x86_64-native-linuxapp-gcc
43     CONFIG_FILE_LINUXAPP = $(WORK_DIR)/config/common_linuxapp
44 else
45     DPDK_TARGET = x86_64-default-linuxapp-gcc
46     CONFIG_FILE_LINUXAPP = $(WORK_DIR)/config/defconfig_x86_64-default-linuxapp-gcc
47 endif
48 else
49 ifeq ($(DPDK_TAG_MAJOR),v2)
50     DPDK_TARGET = x86_64-native-linuxapp-gcc
51     CONFIG_FILE_LINUXAPP = $(WORK_DIR)/config/common_linuxapp
52 else
53     DPDK_TARGET = x86_64-native-linuxapp-gcc
54     CONFIG_FILE_BASE = $(WORK_DIR)/config/common_base
55     CONFIG_FILE_LINUXAPP = $(WORK_DIR)/config/common_linuxapp
56 endif
57 endif
58
59 all: force_make install
60         @echo "Finished making $(WORK_DIR) "
61
62 INSTALL_TARGET = force_make
63
64 # modify CONFIG_FILE to enable SHARED_LIB build and restore original CONFIG_FILE after the build
65 # DPDK v16 comments:
66 ## CONFIG_RTE_BUILD_COMBINE_LIBS has been obsoleted
67 ## CONFIG_RTE_LIBRTE_KNI is listed in both config_base and config_linuxapp,
68 ## values from config_linuxapp will be used, but options are modified at both places to avoid confusion.
69 force_make: $(TAG_DONE_FLAG)
70         $(AT)cd $(WORK_DIR) && git pull $(DPDK_URL) $(DPDK_TAG)
71 ifdef CONFIG_FILE_BASE
72         $(AT)sed -i -e 's/CONFIG_RTE_BUILD_SHARED_LIB=./CONFIG_RTE_BUILD_SHARED_LIB=y/g' $(CONFIG_FILE_BASE)
73         $(AT)sed -i -e 's/CONFIG_RTE_EAL_PMD_PATH=.*/CONFIG_RTE_EAL_PMD_PATH=\"\/usr\/lib\/dpdk-pmd\/\"/g' $(CONFIG_FILE_BASE)
74         $(AT)sed -i -e 's/CONFIG_RTE_LIBRTE_KNI=./CONFIG_RTE_LIBRTE_KNI=n/g' $(CONFIG_FILE_BASE)
75 else
76         $(AT)sed -i -e 's/CONFIG_RTE_BUILD_SHARED_LIB=./CONFIG_RTE_BUILD_SHARED_LIB=y/g' $(CONFIG_FILE_LINUXAPP)
77         $(AT)sed -i -e 's/CONFIG_RTE_EAL_PMD_PATH=.*/CONFIG_RTE_EAL_PMD_PATH=\"\/usr\/lib\/dpdk-pmd\/\"/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 # do not build kernel module under docker
81 ifdef DOCKER
82         $(AT)sed -i -e 's/CONFIG_RTE_EAL_IGB_UIO=y/CONFIG_RTE_EAL_IGB_UIO=n/' $(CONFIG_FILE_LINUXAPP)
83         $(AT)sed -i -e 's/CONFIG_RTE_KNI_KMOD=y/CONFIG_RTE_KNI_KMOD=n/' $(CONFIG_FILE_LINUXAPP)
84 endif
85 # CentOS 7.3 specific config changes to compile
86 ifeq ($(ID),"centos")
87 ifeq ($(VERSION_ID),"7")
88         $(AT)sed -i.bak s@'SRCS-y += ethtool/igb/igb_main.c'@'#SRCS-y += ethtool/igb/igb_main.c'@g $(WORK_DIR)/lib/librte_eal/linuxapp/kni/Makefile
89 endif
90 endif
91 # RHEL 7.3 specific config changes to compile
92 ifeq ($(ID),"rhel")
93 ifeq ($(VERSION_ID),"7.3")
94         $(AT)sed -i.bak s@'SRCS-y += ethtool/igb/igb_main.c'@'#SRCS-y += ethtool/igb/igb_main.c'@g $(WORK_DIR)/lib/librte_eal/linuxapp/kni/Makefile
95 endif
96 endif
97         $(AT)sed -i -e 's/CONFIG_RTE_LIBRTE_KNI=./CONFIG_RTE_LIBRTE_KNI=n/g' $(CONFIG_FILE_LINUXAPP)
98         $(AT)cd $(WORK_DIR); make config T=$(DPDK_TARGET) -j; make -j DESTDIR=$(WORK_DIR)
99         $(AT)cd `dirname $(CONFIG_FILE_LINUXAPP)` && git checkout `basename $(CONFIG_FILE_LINUXAPP)` && cd -
100         @echo "Make done"
101
102 install: $(INSTALL_TARGET)
103         $(AT)cd $(WORK_DIR); sudo make -j install prefix=/usr; cd -
104         $(AT)sudo mkdir -p /usr/lib/dpdk-pmd
105         $(AT)find /usr/lib -type f -name 'librte_pmd*' | while read path; do sudo ln -fs $$path /usr/lib/dpdk-pmd/$$(echo $$path | grep -o 'librte_.*so'); done
106 # under docker there won't be kernel module available
107 ifndef DOCKER
108         $(AT)sudo cp -a $(WORK_DIR)/build/kmod $(INSTALL_DIR)/lib/modules/$(KERNEL_VERSION)
109 endif
110         @echo "install done"
111
112 # hard way to clean and clobber
113 clean:
114         $(AT)cd $(WORK_DIR) && git clean -xfd *.o
115 clobber:
116         $(AT)rm -rf $(WORK_DIR)
117
118 # distclean is for developer who would like to keep the
119 # clone git repo, saving time to fetch again from url
120 distclean:
121         $(AT)cd $(WORK_DIR) && git clean -xfd && git checkout -f
122
123 test:
124         @echo "Make test in $(WORK_DIR) (stub) "
125
126 sanity:
127         @echo "Make sanity in $(WORK_DIR) (stub) "
128
129 $(WORK_DIR):
130         $(AT)git clone $(DPDK_URL)
131
132 $(TAG_DONE_FLAG): $(WORK_DIR)
133         $(AT)cd $(WORK_DIR); git checkout $(DPDK_TAG)
134         $(AT)touch $@