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