af_xdp: AF_XDP input plugin
[vpp.git] / build / external / Makefile
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 DL_CACHE_DIR = $(HOME)/Downloads
18 MAKE ?= make
19 MAKE_ARGS ?= -j
20 BUILD_DIR        ?= $(CURDIR)/_build
21 INSTALL_DIR      ?= $(CURDIR)/_install
22 PKG_VERSION ?= $(shell git describe --abbrev=0 | cut -d- -f1 | cut -dv -f2 | cut -d. -f1,2)
23 PKG_SUFFIX ?= $(shell git log --oneline v$(PKG_VERSION)-rc0.. . | wc -l)
24 JOBS := $(if $(shell [ -f /proc/cpuinfo ] && head /proc/cpuinfo),\
25         $(shell grep -c ^processor /proc/cpuinfo), 2)
26
27 B := $(BUILD_DIR)
28 I := $(INSTALL_DIR)
29
30 ifneq ($(shell which cmake3),)
31 CMAKE?=cmake3
32 else
33 CMAKE?=cmake
34 endif
35
36 include packages.mk
37 include packages/nasm.mk
38 include packages/ipsec-mb.mk
39 include packages/quicly.mk
40 include packages/dpdk.mk
41 include packages/rdma-core.mk
42 include packages/libbpf.mk
43
44 .PHONY: clean
45 clean:
46         @rm -rf $(B) $(I)
47
48 .PHONY: install
49 install: dpdk-install rdma-core-install quicly-install libbpf-install
50
51 .PHONY: config
52 config: dpdk-config rdma-core-config
53
54 ##############################################################################
55 # .deb packaging
56 ##############################################################################
57
58 DEB_VER := $(PKG_VERSION)
59 DEB_ARCH=$(shell dpkg --print-architecture 2> /dev/null)
60 DEV_DEB=vpp-ext-deps_$(DEB_VER)-$(PKG_SUFFIX)_$(DEB_ARCH).deb
61 INSTALLED_VER=$(shell dpkg-query --showformat='$${Version}' --show vpp-ext-deps 2> /dev/null)
62
63 .PHONY: build-deb install-deb check-deb
64
65 deb/debian/changelog: Makefile
66         @echo "vpp-ext-deps ($(DEB_VER)-$(PKG_SUFFIX)) unstable; urgency=low" > $@
67         @echo "" >> $@
68         @echo "  * Version $(DEB_VER)" >> $@
69         @echo "" >> $@
70         @echo " -- VPP Dev <vpp-dev@lists.fd.io>  $(shell date -R)" >> $@
71
72 $(DEV_DEB): deb/debian/changelog
73         @cd deb && dpkg-buildpackage -b -uc -us
74         git clean -fdx deb
75
76 build-deb: $(DEV_DEB)
77
78 install-deb:
79 ifneq ($(INSTALLED_VER),$(DEB_VER)-$(PKG_SUFFIX))
80         @make $(DEV_DEB)
81         @sudo dpkg -i $(DEV_DEB)
82 else
83         @echo "=========================================================="
84         @echo " Up-to-date vpp-ext-deps package already installed"
85         @echo "=========================================================="
86 endif
87
88 check-deb:
89 ifneq ($(INSTALLED_VER),$(DEB_VER)-$(PKG_SUFFIX))
90         @echo "=========================================================="
91         @echo " Out of date vpp-ext-deps package installed."
92         @echo " Installed: $(INSTALLED_VER)"
93         @echo " Needed: $(DEB_VER)-$(PKG_SUFFIX)"
94         @echo ""
95         @echo " Please upgrade by invoking 'make install-ext-deps'"
96         @echo " from the top level directory."
97         @echo "=========================================================="
98 endif
99
100 ##############################################################################
101 # .rpm packaging
102 ##############################################################################
103
104 RPM_VER := $(PKG_VERSION)
105 RPM_ARCH=$(shell rpm --eval "%{_arch}" 2> /dev/null)
106 DEV_RPM=vpp-ext-deps-$(RPM_VER)-$(PKG_SUFFIX).$(RPM_ARCH).rpm
107 INSTALLED_RPM_VER=$(shell rpm -q --queryformat '%{VERSION}-%{RELEASE}' vpp-ext-deps 2> /dev/null | grep -v "not inst")
108
109 .PHONY: build-rpm install-rpm check-rpm
110
111 $(DEV_RPM): Makefile rpm/vpp-ext-deps.spec
112         @rpmbuild -bb \
113           --define "_topdir $(CURDIR)/rpm" \
114           --define "_version $(RPM_VER)" \
115           --define "_release $(PKG_SUFFIX)" \
116           $(CURDIR)/rpm/vpp-ext-deps.spec
117         mv rpm/RPMS/$(RPM_ARCH)/*.rpm .
118         @git clean -fdx rpm
119
120 build-rpm: $(DEV_RPM)
121
122 install-rpm:
123 ifneq ($(INSTALLED_RPM_VER),$(RPM_VER)-$(PKG_SUFFIX))
124         @$(MAKE) $(DEV_RPM)
125         sudo rpm -e vpp-ext-deps || true
126         sudo rpm -Uih --force $(DEV_RPM)
127 else
128         @echo "=========================================================="
129         @echo " Up-to-date vpp-ext-deps package already installed"
130         @echo "=========================================================="
131 endif
132
133 check-rpm:
134 ifneq ($(INSTALLED_RPM_VER),$(RPM_VER)-$(PKG_SUFFIX))
135         @echo "=========================================================="
136         @echo " Out of date vpp-ext-deps package installed."
137         @echo " Installed: $(INSTALLED_RPM_VER)"
138         @echo " Needed: $(RPM_VER)-$(PKG_SUFFIX)"
139         @echo ""
140         @echo " Please upgrade by invoking 'make install-ext-deps'"
141         @echo " from the top level directory."
142         @echo "=========================================================="
143 endif
144
145 ##############################################################################
146 # ebuild support
147 ##############################################################################
148
149 .PHONY: ebuild-build ebuild-install
150
151 ebuild-build:
152 ifeq ($(INSTALLED_VER)$(INSTALLED_RPM_VER),)
153         @echo "=========================================================="
154         @echo "Building vpp-ext-deps from source. Consider installing"
155         @echo "development package by invoking 'make install-ext-deps'"
156         @echo "from the top level directory"
157         @echo "=========================================================="
158         make config
159 else
160 ifneq ($(INSTALLED_VER),)
161         make check-deb
162 endif
163 ifneq ($(INSTALLED_RPM_VER),)
164         make check-rpm
165 endif
166 endif
167
168 ebuild-install:
169 ifeq ($(INSTALLED_VER)$(INSTALLED_RPM_VER),)
170         make install
171 endif