-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMakefile
73 lines (61 loc) · 2.1 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
PKG := github.com/syllabix/versioner
MAIN := cmd/versioner/*.go
BUILD_VERSION=`git describe --abbrev=0`
# Expose compile-time information as linker symbols
LDFLAGS += -X 'github.com/syllabix/versioner/internal/diagnostic.AppVersion=${BUILD_VERSION}'
LDFLAGS += -X 'github.com/syllabix/versioner/internal/diagnostic.BuildTimestamp=`date +%Y-%m-%dT%H:%M:%S%:z`'
LDFLAGS += -X 'github.com/syllabix/versioner/internal/diagnostic.CommitHash=`git rev-parse HEAD`'
LDFLAGS += -X 'github.com/syllabix/versioner/internal/diagnostic.GoVersion=`go version`'
# Omit symbol table and debug info, leads to a smaller binary
LDFLAGS += -s
GO_BUILD = CGO_ENABLED=0 go build -a -ldflags "$(LDFLAGS)"
.PHONY: help build test clean
## Print the help message.
# Parses this Makefile and prints targets that are preceded by "##" comments.
help:
@echo "" >&2
@echo "Available targets: " >&2
@echo "" >&2
@awk -F : '\
BEGIN { in_doc = 0; } \
/^##/ && in_doc == 0 { \
in_doc = 1; \
doc_first_line = $$0; \
sub(/^## */, "", doc_first_line); \
} \
$$0 !~ /^#/ && in_doc == 1 { \
in_doc = 0; \
if (NF <= 1) { \
next; \
} \
printf " %-15s %s\n", $$1, doc_first_line; \
} \
' <"$(abspath $(lastword $(MAKEFILE_LIST)))" \
| sort >&2
@echo "" >&2
## Build binary using the go link tool to set dianostic variables
build.darwin64:
$(mkdir -p ./build)
env GOOS=darwin GOARCH=amd64 $(GO_BUILD) -o ./build/darwin/versioner_darwin_amd64 $(PKG)/cmd/versioner
build.windows64:
$(mkdir -p ./build/windows)
env GOOS=windows GARCH=amd64 $(GO_BUILD) -o ./build/windows/versioner_windows_amd64.exe $(PKG)/cmd/versioner
build.linux64:
$(mkdir -p ./build/linux)
env GOOS=linux GARCH=amd64 $(GO_BUILD) -o ./build/linux/versioner_linux_amd64 $(PKG)/cmd/versioner
build:
$(MAKE) build.darwin64
$(MAKE) build.windows64
$(MAKE) build.linux64
## Build and run the binary
exec:
$(mkdir -p ./build)
$(GO_BUILD) -o ./build/versioner $(PKG)/cmd/versioner
build/versioner
## Run all tests.
test:
go test -race -cover -coverprofile=coverage.out ./...
## Removes generated files
clean:
rm -f ./coverage.out
rm -rf ./build