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