Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1 | # Copyright (c) 2015 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 | # Scripts require non-POSIX parts of bash |
| 15 | SHELL := /bin/bash |
| 16 | |
| 17 | DPDK_BUILD_DIR ?= $(CURDIR)/_build |
| 18 | DPDK_INSTALL_DIR ?= $(CURDIR)/_install |
Damjan Marion | 1901020 | 2016-03-24 17:17:47 +0100 | [diff] [blame] | 19 | DPDK_PKTMBUF_HEADROOM ?= 128 |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 20 | DPDK_DOWNLOAD_DIR ?= $(HOME)/Downloads |
| 21 | DPDK_MARCH ?= native |
| 22 | DPDK_DEBUG ?= n |
| 23 | |
| 24 | B := $(DPDK_BUILD_DIR) |
| 25 | I := $(DPDK_INSTALL_DIR) |
Dave Barach | fed985c | 2016-04-25 08:51:21 -0400 | [diff] [blame] | 26 | DPDK_VERSION ?= 16.04 |
Ed Warnicke | 5961130 | 2016-05-05 15:19:49 -0500 | [diff] [blame] | 27 | DPDK_BASE_URL ?= https://nexus.fd.io/content/repositories/thirdparty/ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 28 | DPDK_TARBALL := dpdk-$(DPDK_VERSION).tar.gz |
Damjan Marion | dab123b | 2016-03-29 16:43:58 +0200 | [diff] [blame] | 29 | DPDK_TAR_URL := $(DPDK_BASE_URL)/$(DPDK_TARBALL) |
Damjan Marion | bce6b6a | 2015-12-16 04:27:37 +0100 | [diff] [blame] | 30 | DPDK_2.1.0_TARBALL_MD5_CKSUM := 205a0d12bfd6eb717d57506272f43519 |
| 31 | DPDK_2.2.0_TARBALL_MD5_CKSUM := 22e2fd68cd5504f43fe9a5a6fd6dd938 |
Damjan Marion | c42552d | 2016-04-12 05:10:25 +0200 | [diff] [blame] | 32 | DPDK_16.04_TARBALL_MD5_CKSUM := 0728d506d7f56eb64233e824fa3c098a |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 33 | DPDK_SOURCE := $(B)/dpdk-$(DPDK_VERSION) |
Damjan Marion | e39a7b8 | 2016-04-26 14:54:57 +0200 | [diff] [blame] | 34 | |
| 35 | ifneq (,$(findstring clang,$(CC))) |
| 36 | DPDK_CC=clang |
| 37 | else |
| 38 | DPDK_CC=gcc |
| 39 | endif |
| 40 | |
| 41 | DPDK_TARGET := x86_64-native-linuxapp-$(DPDK_CC) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 42 | JOBS := $(shell grep processor /proc/cpuinfo | wc -l) |
| 43 | |
| 44 | # compiler/linker custom arguments |
| 45 | DPDK_CPU_CFLAGS := -pie -fPIC |
Jean-Mickael Guerin | 966a8b8 | 2016-03-02 19:05:05 +0100 | [diff] [blame] | 46 | DPDK_CPU_LDFLAGS := |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 47 | DPDK_EXTRA_LDFLAGS := -g |
| 48 | |
| 49 | ifeq ($(DPDK_DEBUG),n) |
Damjan Marion | e39a7b8 | 2016-04-26 14:54:57 +0200 | [diff] [blame] | 50 | DPDK_EXTRA_CFLAGS := -g |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 51 | else |
Damjan Marion | e39a7b8 | 2016-04-26 14:54:57 +0200 | [diff] [blame] | 52 | DPDK_EXTRA_CFLAGS := -g -O0 |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 53 | endif |
| 54 | |
| 55 | # translate gcc march values to DPDK arch |
| 56 | ifeq ($(DPDK_MARCH),native) |
| 57 | DPDK_MACHINE:=native # autodetect host CPU |
| 58 | else ifeq ($(DPDK_MARCH),corei7) |
| 59 | DPDK_MACHINE:=nhm # Nehalem / Westmere |
| 60 | else ifeq ($(DPDK_MARCH),corei7-avx) |
| 61 | DPDK_MACHINE:=snb # Sandy Bridge |
| 62 | else ifeq ($(DPDK_MARCH),core-avx-i) |
| 63 | DPDK_MACHINE:=ivb # Ivy Bridge |
| 64 | else ifeq ($(DPDK_MARCH),core-avx2) |
| 65 | DPDK_MACHINE:=hsw # Haswell |
| 66 | else |
| 67 | $(error Unknown DPDK_MARCH) |
| 68 | endif |
| 69 | |
| 70 | # assemble DPDK make arguments |
| 71 | DPDK_MAKE_ARGS := -C $(DPDK_SOURCE) -j $(JOBS) \ |
| 72 | T=$(DPDK_TARGET) \ |
| 73 | RTE_CONFIG_TEMPLATE=../custom-config \ |
| 74 | RTE_OUTPUT=$(I) \ |
| 75 | EXTRA_CFLAGS="$(DPDK_EXTRA_CFLAGS)" \ |
| 76 | EXTRA_LDFLAGS="$(DPDK_EXTRA_LDFLAGS)" \ |
| 77 | CPU_CFLAGS="$(DPDK_CPU_CFLAGS)" \ |
| 78 | CPU_LDFLAGS="$(DPDK_CPU_LDFLAGS)" |
| 79 | |
| 80 | DPDK_SOURCE_FILES := $(shell [ -e $(DPDK_SOURCE) ] && find $(DPDK_SOURCE) -name "*.[chS]") |
| 81 | |
| 82 | define set |
| 83 | @if grep -q CONFIG_$1 $@ ; \ |
| 84 | then sed -i -e 's/.*\(CONFIG_$1=\).*/\1$2/' $@ ; \ |
| 85 | else echo CONFIG_$1=$2 >> $@ ; \ |
| 86 | fi |
| 87 | endef |
| 88 | |
| 89 | all: build |
| 90 | |
| 91 | $(B)/custom-config: $(B)/.patch.ok Makefile |
Damjan Marion | 106f0ed | 2016-04-26 10:44:28 +0200 | [diff] [blame] | 92 | @echo --- generating custom config from $(DPDK_SOURCE)/config/defconfig_$(DPDK_TARGET) --- |
| 93 | @cpp -undef -ffreestanding -x assembler-with-cpp $(DPDK_SOURCE)/config/defconfig_$(DPDK_TARGET) $@ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 94 | $(call set,RTE_MACHINE,$(DPDK_MACHINE)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 95 | @# modify options |
Damjan Marion | 13f0718 | 2016-02-05 06:44:54 -0800 | [diff] [blame] | 96 | $(call set,RTE_MAX_LCORE,256) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 97 | $(call set,RTE_PKTMBUF_HEADROOM,$(DPDK_PKTMBUF_HEADROOM)) |
| 98 | $(call set,RTE_LIBEAL_USE_HPET,y) |
| 99 | $(call set,RTE_BUILD_COMBINE_LIBS,y) |
| 100 | $(call set,RTE_LIBRTE_I40E_16BYTE_RX_DESC,y) |
| 101 | $(call set,RTE_LIBRTE_I40E_ITR_INTERVAL,16) |
| 102 | @# enable debug init for device drivers |
| 103 | $(call set,RTE_LIBRTE_I40E_DEBUG_INIT,$(DPDK_DEBUG)) |
| 104 | $(call set,RTE_LIBRTE_IXGBE_DEBUG_INIT,$(DPDK_DEBUG)) |
| 105 | $(call set,RTE_LIBRTE_E1000_DEBUG_INIT,$(DPDK_DEBUG)) |
| 106 | $(call set,RTE_LIBRTE_VIRTIO_DEBUG_INIT,$(DPDK_DEBUG)) |
| 107 | $(call set,RTE_LIBRTE_VMXNET3_DEBUG_INIT,$(DPDK_DEBUG)) |
John Lo | d9bf9ab | 2016-02-25 11:17:55 -0500 | [diff] [blame] | 108 | $(call set,RTE_LIBRTE_PMD_BOND,y) |
| 109 | $(call set,RTE_LIBRTE_IP_FRAG,y) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 110 | @# not needed |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 111 | $(call set,RTE_LIBRTE_TIMER,n) |
| 112 | $(call set,RTE_LIBRTE_CFGFILE,n) |
| 113 | $(call set,RTE_LIBRTE_LPM,n) |
| 114 | $(call set,RTE_LIBRTE_ACL,n) |
| 115 | $(call set,RTE_LIBRTE_POWER,n) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 116 | $(call set,RTE_LIBRTE_DISTRIBUTOR,n) |
| 117 | $(call set,RTE_LIBRTE_REORDER,n) |
| 118 | $(call set,RTE_LIBRTE_PORT,n) |
| 119 | $(call set,RTE_LIBRTE_TABLE,n) |
| 120 | $(call set,RTE_LIBRTE_PIPELINE,n) |
| 121 | $(call set,RTE_KNI_KMOD,n) |
| 122 | @rm -f .config.ok |
| 123 | |
| 124 | $(CURDIR)/$(DPDK_TARBALL): |
| 125 | @mkdir -p $(B) |
| 126 | @if [ -e $(DPDK_DOWNLOAD_DIR)/$(DPDK_TARBALL) ] ; \ |
| 127 | then cp $(DPDK_DOWNLOAD_DIR)/$(DPDK_TARBALL) $(CURDIR) ; \ |
| 128 | else curl -o $(CURDIR)/$(DPDK_TARBALL) -LO $(DPDK_TAR_URL) ; \ |
| 129 | fi |
| 130 | @rm -f $(B)/.download.ok |
| 131 | |
| 132 | $(B)/.download.ok: $(CURDIR)/$(DPDK_TARBALL) |
| 133 | @openssl md5 $< | cut -f 2 -d " " - > $(B)/$(DPDK_TARBALL).md5sum |
Damjan Marion | bce6b6a | 2015-12-16 04:27:37 +0100 | [diff] [blame] | 134 | @([ "$$(<$(B)/$(DPDK_TARBALL).md5sum)" = "$(DPDK_$(DPDK_VERSION)_TARBALL_MD5_CKSUM)" ] || \ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 135 | ( echo "Bad Checksum! Please remove $< and retry" && \ |
| 136 | rm $(B)/$(DPDK_TARBALL).md5sum && false )) |
| 137 | @touch $@ |
| 138 | |
| 139 | .PHONY: download |
| 140 | download: $(B)/.download.ok |
| 141 | |
| 142 | $(B)/.extract.ok: $(B)/.download.ok |
| 143 | @echo --- extracting $(DPDK_TARBALL) --- |
| 144 | @tar --directory $(B) --extract --file $(CURDIR)/$(DPDK_TARBALL) --gzip |
| 145 | @touch $@ |
| 146 | |
| 147 | .PHONY: extract |
| 148 | extract: $(B)/.extract.ok |
| 149 | |
| 150 | $(B)/.patch.ok: $(B)/.extract.ok |
Damjan Marion | 0df78dd | 2016-03-29 22:37:02 +0200 | [diff] [blame] | 151 | ifneq ($(wildcard $(CURDIR)/dpdk-$(DPDK_VERSION)_patches/*.patch),) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 152 | @echo --- patching --- |
| 153 | for f in $(CURDIR)/dpdk-$(DPDK_VERSION)_patches/*.patch ; do \ |
| 154 | echo Applying patch: $$(basename $$f) ; \ |
| 155 | patch -p1 -d $(DPDK_SOURCE) < $$f ; \ |
| 156 | done |
Damjan Marion | 0df78dd | 2016-03-29 22:37:02 +0200 | [diff] [blame] | 157 | endif |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 158 | @touch $@ |
| 159 | |
| 160 | .PHONY: patch |
| 161 | patch: $(B)/.patch.ok |
| 162 | |
| 163 | $(B)/.config.ok: $(B)/.patch.ok $(B)/custom-config |
| 164 | @make $(DPDK_MAKE_ARGS) config |
| 165 | @touch $@ |
| 166 | |
| 167 | .PHONY: config |
| 168 | config: $(B)/.config.ok |
| 169 | |
| 170 | $(B)/.build.ok: $(DPDK_SOURCE_FILES) |
| 171 | @if [ ! -e $(B)/.config.ok ] ; then echo 'Please run "make config" first' && false ; fi |
| 172 | @make $(DPDK_MAKE_ARGS) install |
| 173 | @dkms/create_deb_manifest.sh $(DPDK_VERSION) $(subst $(realpath ..)/,,$(B)) |
| 174 | @touch $@ |
| 175 | |
| 176 | .PHONY: build |
| 177 | build: $(B)/.build.ok |
| 178 | |
| 179 | .PHONY: clean |
| 180 | clean: |
| 181 | @rm -rf $(B) $(I) |
| 182 | |