-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRules.mak
100 lines (78 loc) · 1.57 KB
/
Rules.mak
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
# CGo binding for Avahi
#
# Copyright (C) 2024 and up by Alexander Pevzner ([email protected])
# See LICENSE for license terms and conditions
#
# Common part for Makefiles
# ----- Environment -----
TOPDIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
GOFILES := $(wildcard *.go)
GOTESTS := $(wildcard *_test.go)
PACKAGE := $(shell basename $(shell pwd))
# ----- Parameters -----
GO := go
GOTAGS := $(shell which gotags 2>/dev/null)
GOLINT := $(shell which golint 2>/dev/null)
# ----- Common targets -----
.PHONY: all
.PHONY: clean
.PHONY: cover
.PHONY: tags
.PHONY: test
.PHONY: vet
# Recursive targets
all: subdirs_all do_all
clean: subdirs_clean do_clean
lint: subdirs_lint do_lint
test: subdirs_test do_test
vet: subdirs_vet do_vet
# Non-recursive targets
cover: do_cover
# Dependencies
do_all: tags
# Default actions
tags:
do_all:
do_clean:
do_cover:
do_lint:
do_test:
do_vet:
# Conditional actions
ifneq ($(GOFILES),)
do_all:
$(GO) build
ifneq ($(GOTESTS),)
$(GO) test -c
rm -f $(PACKAGE).test
endif
do_cover:
ifneq ($(GOTESTS),)
go test -coverprofile=coverage.out
go tool cover -html=coverage.out
rm -f coverage.out
endif
do_lint:
ifneq ($(GOLINT),)
$(GOLINT) -set_exit_status
endif
do_test:
ifneq ($(GOTESTS),)
$(GO) test
endif
do_vet:
$(GO) vet
endif
ifneq ($(GOTAGS),)
tags:
cd $(TOPDIR); gotags -R . > tags
endif
ifneq ($(CLEAN),)
do_clean:
rm -f $(CLEAN)
endif
# ----- Subdirs handling
subdirs_all subdirs_lint subdirs_test subdirs_vet subdirs_clean:
@for i in $(SUBDIRS); do \
$(MAKE) -C $$i $(subst subdirs_,,$@) || exit 1; \
done