summaryrefslogtreecommitdiffstats
path: root/Makefile
blob: c02ac77d70fdafc240f77eabfd0a1c34682559ca (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
# Copyright (c) 2021, Dell Inc. or its subsidiaries.  All rights reserved.
# SPDX-License-Identifier: Apache-2.0
# See the LICENSE file for details.
#
# This file is part of NVMe STorage Appliance Services (nvme-stas).
#
# Authors: Martin Belanger <Martin.Belanger@dell.com>
#
.DEFAULT_GOAL     := stas
BUILD-DIR         := .build
DEB-PKG-DIR       := ${BUILD-DIR}/deb-pkg
RPM-BUILDROOT-DIR := ${BUILD-DIR}/rpmbuild

ifneq (,$(strip $(filter $(MAKECMDGOALS),rpm deb dist)))
  XTRA-MESON-OPTS := --wrap-mode=nodownload
endif

.PHONY: update-subprojects
update-subprojects:
	meson subprojects update

${BUILD-DIR}:
	BUILD_DIR=${BUILD-DIR} ./configure ${XTRA-MESON-OPTS}
	@echo "Configuration located in: $@"
	@echo "-------------------------------------------------------"

.PHONY: stas
stas: ${BUILD-DIR}
	meson compile -C ${BUILD-DIR}

.PHONY: clean
clean:
ifneq ("$(wildcard ${BUILD-DIR})","")
	meson compile --clean -C ${BUILD-DIR}
endif

.PHONY: purge
purge:
ifneq ("$(wildcard ${BUILD-DIR})","")
	rm -rf ${BUILD-DIR}
endif

.PHONY: install
install: stas
	sudo meson $@ -C ${BUILD-DIR} --skip-subprojects

.PHONY: uninstall
uninstall: ${BUILD-DIR}
	sudo ninja $@ -C ${BUILD-DIR}

.PHONY: dist
dist: stas
	meson $@ -C ${BUILD-DIR} --formats gztar

.PHONY: test
test: stas
	meson $@ -C ${BUILD-DIR} --suite nvme-stas

################################################################################
.PHONY: loc
loc:
	@cloc --by-file --exclude-dir=${BUILD-DIR},doc,subprojects,test,utils,debian,obj-x86_64-linux-gnu,.github --exclude-lang=Markdown,"NAnt script",XML,"Bourne Again Shell",make,"Bourne Shell",Meson,YAML,XSLT .

.PHONY: loc-full
loc-full:
	@cloc --by-file --exclude-dir=${BUILD-DIR},subprojects,debian,obj-x86_64-linux-gnu,.github .

.PHONY: black
black:
	black --diff --color --line-length 120 --skip-string-normalization --extend-exclude="(subprojects|debian|.build)" .

# Coverage requirements:
#   pip install coverage
.PHONY: coverage
coverage: stas
	cd ${BUILD-DIR} && ./coverage.sh

################################################################################
# Debian (*.deb)
# Use "DEB_BUILD_OPTIONS=nocheck make deb" to skip unit testing.
# This requires: sudo apt install -y debhelper dh-python
ifeq (deb,$(strip $(MAKECMDGOALS)))
  ifneq (SUCCESS,$(shell dpkg -s debhelper dh-python > /dev/null 2>&1 && echo "SUCCESS" || echo "FAIL"))
    $(error Missing packages. Run -> "sudo apt install -y debhelper dh-python")
  endif
endif

.PHONY: deb
deb: ${BUILD-DIR}
	mkdir -p ${DEB-PKG-DIR}
	dpkg-buildpackage -us -uc
	@mv ../nvme-stas_*.deb ${DEB-PKG-DIR}
	@mv ../nvme-stas_*.buildinfo ${DEB-PKG-DIR}
	@mv ../nvme-stas_*.changes ${DEB-PKG-DIR}
	@mv ../nvme-stas_*.dsc ${DEB-PKG-DIR}
	@mv ../nvme-stas_*.tar.gz ${DEB-PKG-DIR}
	@echo "======================================================="
	@echo "Debian packages located in: ${DEB-PKG-DIR}/"


################################################################################
# RedHat (*.rpm)
${BUILD-DIR}/nvme-stas.spec: ${BUILD-DIR} nvme-stas.spec.in
	meson --wrap-mode=nodownload --reconfigure ${BUILD-DIR}

${RPM-BUILDROOT-DIR}: ${BUILD-DIR}/nvme-stas.spec
	rpmbuild -ba $< --build-in-place --clean --nocheck --define "_topdir $(abspath ${BUILD-DIR}/rpmbuild)"
	@echo "======================================================="
	@echo "RPM packages located in: ${RPM-BUILDROOT-DIR}/"

.PHONY: rpm
rpm: ${RPM-BUILDROOT-DIR}