-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathmakefile
83 lines (66 loc) · 2.63 KB
/
makefile
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
# README
#
# This file is intended as an example for users of `gow`. It was adapted from a
# larger Go project. At the time of writing, `gow` does not support its own
# configuration files. For complex use cases, users are expected to use Make or
# another similar tool.
#
# Despite being primarily an example, this file contains actual working rules
# convenient for hacking on `gow`.
# This variable `MAKEFLAGS` is special: it modifies Make's own behaviors.
#
# `--silent` causes Make to execute rules without additional verbose logging.
# Without this, we would have to prefix each line in each rule with `@` to
# suppress logging.
#
# `--always-make` makes all rules "abstract". It causes Make to execute each
# rule without checking for an existing file matching the pattern represented
# by the rule name. This is equivalent to marking every rule with `.PHONY`, but
# keeps our makefile cleaner. In projects where some rule names are file names
# or artifact path patterns, this should be removed, and abstract rules should
# be explicitly marked with `.PHONY`.
MAKEFLAGS := --silent --always-make
# Shortcut for executing rules concurrently. See usage examples below.
# The flag `-f` with `lastword` allows to use the last Makefile
# insted of the default Makefile. This feature is not used in `gow`,
# but provided as an example for the case of multiple Makefiles.
MAKE_CONC := $(MAKE) -j 128 -f $(lastword $(MAKEFILE_LIST)) clear=$(or $(clear),false)
VERB := $(if $(filter false,$(verb)),,-v)
CLEAR := $(if $(filter false,$(clear)),,-c)
GO_SRC := .
GO_PKG := ./$(or $(pkg),$(GO_SRC)/...)
GO_FLAGS := -tags=$(tags) -mod=mod
GO_RUN_ARGS := $(GO_FLAGS) $(GO_SRC) $(run)
GO_TEST_FAIL := $(if $(filter false,$(fail)),,-failfast)
GO_TEST_SHORT := $(if $(filter true,$(short)), -short,)
GO_TEST_FLAGS := -count=1 $(GO_FLAGS) $(VERB) $(GO_TEST_FAIL) $(GO_TEST_SHORT)
GO_TEST_PATTERNS := -run="$(run)"
GO_TEST_ARGS := $(GO_PKG) $(GO_TEST_FLAGS) $(GO_TEST_PATTERNS)
# Only one `gow` per terminal is allowed to use raw mode.
# Otherwise they conflict with each other.
GOW_HOTKEYS := -r=$(if $(filter 0,$(MAKELEVEL)),true,false)
GOW_FLAGS := $(CLEAR) $(VERB) $(GOW_HOTKEYS)
# Expects an existing stable version of `gow`.
GOW := gow $(GOW_FLAGS)
watch:
$(MAKE_CONC) dev.test.w dev.vet.w
all:
$(MAKE_CONC) test vet
dev.test.w:
go run $(GO_RUN_ARGS) $(GOW_FLAGS) test $(GO_TEST_FLAGS)
test.w:
$(GOW) test $(GO_TEST_ARGS)
test:
go test $(GO_TEST_ARGS)
dev.vet.w:
go run $(GO_RUN_ARGS) $(GOW_FLAGS) vet $(GO_FLAGS)
vet.w:
$(GOW) vet $(GO_FLAGS)
vet:
go vet $(GO_FLAGS)
run.w:
$(GOW) run $(GO_RUN_ARGS)
run:
go run $(GO_RUN_ARGS)
install:
go install $(GO_FLAGS) $(GO_SRC)