summaryrefslogtreecommitdiffstats
path: root/Makefile
blob: 6c3f9617a3a1afffe60743d980d5b80d672ca212 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
# Copyright (c) 2021-2022 Cisco and/or its affiliates.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at:
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


export WS_ROOT=$(CURDIR)
SHELL := /bin/bash
FUNCTIONAL := tests/run-functional.sh
MKDIR := mkdir -p
RM := rm
VERSIONFILE := $(CURDIR)/versions.cmake
COMMIT_TEMPLATE_FILE = .git_commit_template.txt

# Docker stuff
DOCKER := docker
DEV_IMAGE := hicn-dev-img
DOCKERFILE := Dockerfile.dev
DEV_CONTAINER := hicn-dev

#
# OS Detection
#
ifeq ($(shell uname),Darwin)
OS_ID = macos
OPENSSL_ROOT=/usr/local/opt/openssl@1.1
else
OS_ID         = $(shell grep '^ID=' /etc/os-release | cut -f2- -d= | sed -e 's/\"//g')
OS_VERSION_ID = $(shell grep '^VERSION_ID=' /etc/os-release | cut -f2- -d= | sed -e 's/\"//g')
endif

#
# Git Repo detection
#
GIT_INFO = $(shell git -C . rev-parse 2>/dev/null; echo $$?)

ifeq ($(shell uname),Darwin)
BUILD_HICNPLUGIN := OFF
PUNTING := OFF
else
BUILD_HICNPLUGIN := ON
PUNTING := ON
endif

DEB_DEPENDS  = cmake ninja-build unzip python3-ply libasio-dev
DEB_DEPENDS += libconfig-dev libconfig++-dev libevent-dev
DEB_DEPENDS += llvm-11-tools llvm-11 clang-11 vpp-dev libvppinfra-dev
DEB_DEPENDS += vpp-plugin-core libcurl4-openssl-dev libssl-dev
DEB_DEPENDS += doxygen

DEBUG_DEPENDS = iproute2 iperf3 iputils-ping tcpdump gdb

MACOS_DEPENDS = asio libconfig ninja openssl@1.1

.PHONY = help
help:
	@echo "Targets"
	@echo " dep                 - install software dependencies"
	@echo " debug-tools         - install debug dependencies"
	@echo " build               - build debug binaries. Optional argument: INSTALL_DIR"
	@echo " build-release       - build release binaries"
	@echo " build-coverage      - build with coverage metainformation"
	@echo " wipe                - wipe debug binaries"
	@echo " wipe-release        - wipe release binaries"
	@echo " docs                - build documentation"
	@echo ""
	@echo "Make Arguments:"
	@echo " INSTALL_PREFIX=<path>   	- Install software at specified location."
	@echo " BUILD_PATH=<path>   		- Path of build folder."
	@echo " VPP_HOME=<path>         	- Path of VPP"
	@echo " OPENSSL_ROOT=<path>         	- Path of Openssl installation"
	@echo " ENABLE_RELY=<ON/OFF>         	- Enable/disable rely compilation"
	@echo " SONAR_BUILD_WRAPPER=<path>"	- Path of sonarqube build wrapper
	@echo " SONAR_OUT_DIR=<path>"		- Path of directory of sonarqube report
	@echo "Current Arguments:"
	@echo " INSTALL_PREFIX=$(INSTALL_PREFIX)"
	@echo " VPP_HOME=$(VPP_HOME)"
	@echo " OPENSSL_ROOT=$(OPENSSL_ROOT)"
	@echo " ENABLE_RELY=$(ENABLE_RELY)"
	@echo " SONAR_BUILD_WRAPPER=$(SONAR_BUILD_WRAPPER)"
	@echo " SONAR_OUT_DIR=$(SONAR_OUT_DIR)"

.PHONY = commit-template
commit-template:
ifeq ($(GIT_INFO),0)
	git config commit.template $(COMMIT_TEMPLATE_FILE)
endif

.PHONY = vpp-dep
vpp-dep:
	VERSION_PATH=$(VERSIONFILE) sudo -E $(SHELL) scripts/install-vpp.sh

.PHONY = dep
dep: vpp-dep
ifeq ($(shell uname),Darwin)
	brew install $(MACOS_DEPENDS)
else ifeq ($(filter ubuntu debian,$(OS_ID)),$(OS_ID))
	@sudo -E apt-get update
	@sudo -E apt-get $(APT_ARGS) -y install $(DEB_DEPENDS) --no-install-recommends
else
	@echo "Operating system not supported (yet)"
endif

.PHONY = deps
deps: dep

.PHONY = debug-tools
debug-tools:
	@sudo -E apt-get $(APT_ARGS) -y install $(DEBUG_DEPENDS) --no-install-recommends

define build_folder
	$(eval LOWER_BUILDTYPE=$(shell echo $(2) | tr A-Z a-z))
	$(eval BUILD_FOLDER=$(or $(BUILD_PATH), $(WS_ROOT)/build-$(LOWER_BUILDTYPE)-$(OS_ID)))
	$(1) := $$(BUILD_FOLDER)
endef

define install_folder
	$(eval LOWER_BUILDTYPE=$(shell echo $(2) | tr A-Z a-z))
	$(eval INSTALL_FOLDER=$(or $(INSTALL_PREFIX), $(WS_ROOT)/install-$(LOWER_BUILDTYPE)))
	$(1) := $$(INSTALL_FOLDER)
endef

define configure
	$(eval $(call build_folder,BUILD_FOLDER,$(1)))
	$(eval PREFIX=$(or $(INSTALL_PREFIX), $(WS_ROOT)/install-$(LOWER_BUILDTYPE)))
	$(eval COVERAGE=$(or $(COVERAGE), OFF))
	$(eval VPP_HOME=$(or $(VPP_HOME), /usr))
	$(eval ENABLE_RELY=$(or $(ENABLE_RELY), OFF))
	$(MKDIR) $(BUILD_FOLDER)
	cmake \
		-B $(BUILD_FOLDER) \
		-S $(WS_ROOT) \
		-G Ninja \
		-DCMAKE_INSTALL_PREFIX=$(PREFIX) \
		-DCMAKE_BUILD_TYPE=$(1) \
		-DBUILD_HICNLIGHT=ON \
		-DBUILD_APPS=ON \
		-DBUILD_SYSREPOPLUGIN=OFF \
		-DBUILD_EXTRAS=OFF \
		-DBUILD_TELEMETRY=OFF \
		-DBUILD_CTRL=ON \
		-DBUILD_HICNPLUGIN=$(BUILD_HICNPLUGIN) \
		-DVPP_HOME=$(VPP_HOME) \
		-DCOVERAGE=$(COVERAGE) \
		-DENABLE_RELY=$(ENABLE_RELY) \
		-DOPENSSL_ROOT_DIR=$(OPENSSL_ROOT) \
		-DBUILD_TESTS=ON
endef

define install
	$(eval $(call build_folder,BUILD_FOLDER,$(1)))
	cmake --build $(BUILD_FOLDER) -- -j 4 install
endef

define build
	$(eval $(call build_folder,BUILD_FOLDER,$(1)))
	cmake --build $(BUILD_FOLDER) -- -j 4
endef

define build_coverage
	$(eval $(call build_folder,BUILD_FOLDER,$(1)))
	$(eval SONAR_OUT_DIR=$(or $(SONAR_OUT_DIR), $(WS_ROOT)/sonarqube-output))
	$(SONAR_BUILD_WRAPPER) --out-dir $(SONAR_OUT_DIR) cmake --build $(BUILD_FOLDER) -- install
endef

define package
	$(eval $(call build_folder,BUILD_FOLDER,$(1)))
	cmake --build $(BUILD_FOLDER) -- package
endef

.PHONY: configure-debug
configure-debug:
	$(call configure,Debug,)

.PHONY: configure-release
configure-release:
	$(call configure,Release,)

.PHONY = build
build: configure-debug
	$(call build,Debug,)

.PHONY = build-coverage
build-coverage:
ifndef SONAR_BUILD_WRAPPER
	$(error SONAR_BUILD_WRAPPER is not set)
endif
	$(eval COVERAGE := ON)
	$(call configure,Debug,)
	$(call build_coverage,Debug,)

.PHONY = build-release
build-release: configure-release
	$(call build,Release,)

.PHONY = package
package: build
	$(call package,Debug,)

.PHONY = package-release
package-release: build-release
	$(call package,Release,)

.PHONY = install
install: build
	$(call install,Debug,)

.PHONY = install-release
install-release: build-release
	$(call install,Release,)

define wipe
	$(eval $(call build_folder,BUILD_FOLDER,$(1)))
	$(eval $(call install_folder,INSTALL_FOLDER,$(1)))
	$(RM) -rf $(BUILD_FOLDER)
	$(RM) -rf $(INSTALL_FOLDER)
endef

.PHONY = wipe
wipe:
	$(call wipe,Debug,)

.PHONY = wipe-release
wipe-release:
	$(call wipe,Release,)

define test
	$(eval $(call build_folder,BUILD_FOLDER,$(1)))
	cmake --build $(BUILD_FOLDER) -- test
endef

.PHONY = test-debug
test-debug: build
	$(call test, Debug,)

.PHONY = test
test: build-release
	$(call test, Release,)

.PHONY = functional
functional:
	$(SHELL) $(FUNCTIONAL)

define documentation
	python3 -m pip install --user virtualenv
	python3 -m virtualenv env
	(source $(WS_ROOT)/env/bin/activate; \
	pip install -r $(WS_ROOT)/docs/etc/requirements.txt; \
	cd docs; \
	make html )
endef

.PHONY = doc
doc:
	$(call documentation,)


.PHONY = docker
docker:
	$(DOCKER) build -t $(DEV_IMAGE) -f $(DOCKERFILE) ${PWD}
ifeq ($(strip $(shell $(DOCKER) ps -q -f name=$(DEV_CONTAINER))),)
ifneq ($(shell $(DOCKER) ps -aq -f status=exited -f name=$(DEV_CONTAINER)),)
	docker rm $(DEV_CONTAINER)
endif
	$(DOCKER) run -dv ${PWD}:/workspace -w /workspace --name $(DEV_CONTAINER) --entrypoint=tail $(DEV_IMAGE) -f /dev/null
endif
	$(DOCKER) exec -it $(DEV_CONTAINER) bash

.PHONY = wipe-docker
wipe-docker:
	$(DOCKER) rm --force $(DEV_CONTAINER)