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