forked from emissary-ingress/emissary
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.mk
127 lines (107 loc) · 3.68 KB
/
common.mk
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
# Copyright 2018 Datawire. All rights reserved.
#
# Makefile snippet for bits common bits we "always" want.
#
## Eager inputs ##
# (none)
## Lazy inputs ##
# (none)
## Outputs ##
# - Variable: GOOS
# - Variable: GOARCH
# - .PHONY Target: all
# - .PHONY Target: build
# - .PHONY Target: check
# - .PHONY Target: lint
# - .PHONY Target: format
# - .PHONY Target: clean
# - .PHONY Target: clobber
# - Alias: bin/% -> bin_$(GOHOSTOS)_$(GOHOSTARCH)/%
## common.mk targets ##
# (N/A)
#
# Dependencies of `clobber` MUST NOT depend on programs in
# `$(build-aux.bindir)/`.
ifeq ($(words $(filter $(abspath $(lastword $(MAKEFILE_LIST))),$(abspath $(MAKEFILE_LIST)))),1)
_common.mk := $(lastword $(MAKEFILE_LIST))
include $(dir $(_common.mk))prelude.mk
#
# Variables
# If $@ is bin_GOOS_GOARCH/BINNAME, or bin_GOOS_GOARCH/DIR/BINNAME,
# set GOOS and GOARCH accordingly, otherwise inherit from the
# environment.
#
# Possible values of GOOS/GOARCH:
# https://golang.org/doc/install/source#environment
_GOOS = $(call lazyonce,_GOOS,$(shell go env GOOS))
_GOARCH = $(call lazyonce,_GOARCH,$(shell go env GOARCH))
export GOOS = $(if $(filter bin_%,$(@D)),$(word 2,$(subst _, ,$(firstword $(subst /, ,$(@D))))),$(_GOOS))
export GOARCH = $(if $(filter bin_%,$(@D)),$(word 3,$(subst _, ,$(firstword $(subst /, ,$(@D))))),$(_GOARCH))
#
# User-facing targets
# To the extent reasonable, use target names that agree with the GNU
# standards.
#
# https://www.gnu.org/prep/standards/standards.html#Makefile-Conventions
all: build
.PHONY: all
build: ## (Common) Build the software
.PHONY: build
check: ## (Common) Check whether the software works; run the tests
.PHONY: check
lint: ## (Common) Perform static analysis of the software
.PHONY: lint
format: ## (Common) Apply automatic formatting+cleanup to source code
.PHONY: format
clean: ## (Common) Delete all files that are normally created by building the software
.PHONY: clean
# XXX: Rename this to maintainer-clean, per GNU?
clobber: ## (Common) Delete all files that this Makefile can re-generate
clobber: clean
.PHONY: clobber
#
# Targets: Default behavior
clean: _common_clean
_common_clean:
rm -rf -- bin_*
rm -f bin test-suite.tap
.PHONY: _common_clean
bin/%: bin_$(GOHOSTOS)_$(GOHOSTARCH)/% | bin
@test -e $@ && test -f $@ && test -x $@
bin:
@rm -f $@
ln -s bin_$(GOHOSTOS)_$(GOHOSTARCH)/ $@
check: lint build
$(MAKE) -f $(firstword $(MAKEFILE_LIST)) test-suite.tap.summary
test-suite.tap: $(TAP_DRIVER)
@$(TAP_DRIVER) cat $(sort $(filter %.tap,$^)) > $@
%.tap.summary: %.tap $(TAP_DRIVER)
@$(TAP_DRIVER) summarize $<
%.tap: %.tap.gen $(TAP_DRIVER) FORCE
@{ $(abspath $<) || true; } 2>&1 | tee $@ | $(TAP_DRIVER) stream -n $<
%.log: %.test FORCE
@$(abspath $<) >$@ 2>&1; echo :exit-status: $$? >>$@
%.tap: %.log %.test $(TAP_DRIVER)
@{ \
printf '%s\n' 'TAP version 13' '1..1' && \
sed 's/^/#/' < $< && \
sed -n '$${ s/^:exit-status: 0$$/ok 1/; s/^:exit-status: 77$$/ok 1 # SKIP/; s/^:exit-status: .*/not ok 1/; p; }' < $<; \
} | tee $@ | $(TAP_DRIVER) stream -n $*.test
#
# Configure how Make works
# Turn off .INTERMEDIATE file removal by marking all files as
# .SECONDARY. .INTERMEDIATE file removal is a space-saving hack from
# a time when drives were small; on modern computers with plenty of
# storage, it causes nothing but headaches.
#
# https://news.ycombinator.com/item?id=16486331
.SECONDARY:
# If a recipe errors, remove the target it was building. This
# prevents outdated/incomplete results of failed runs from tainting
# future runs. The only reason .DELETE_ON_ERROR is off by default is
# for historical compatibility.
#
# If for some reason this behavior is not desired for a specific
# target, mark that target as .PRECIOUS.
.DELETE_ON_ERROR:
endif