-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
101 lines (84 loc) · 2.66 KB
/
Makefile
File metadata and controls
101 lines (84 loc) · 2.66 KB
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
# Makefile for enma
# Variables
BUILD_DIR = $(CURDIR)/build
CMD_DIRS = $(wildcard cmd/*)
BINARY_NAME = enma
VERSION = $(shell git describe --tags --always)
LDFLAGS += -X "main.version=$(VERSION)"
PLATFORMS := linux/amd64 darwin/amd64 windows/amd64
GO := GO111MODULE=on CGO_ENABLED=0 go
# Argments
tag =
# Default target
.PHONY: all
all: help
# Build all artifacts
.PHONY: build
build: clean
@mkdir -p $(BUILD_DIR)
@$(GO) build -o $(BUILD_DIR)/$(BINARY_NAME) -ldflags "$(LDFLAGS)"
@chmod 755 $(BUILD_DIR)/$(BINARY_NAME)
# Build artifacts for all platforms and release
.PHONY: release-build
release-build: clean $(PLATFORMS)
@echo "Release files are created in the $(BUILD_DIR) directory."
# Build each platform
$(PLATFORMS):
@mkdir -p $(BUILD_DIR)
GOOS=$(word 1,$(subst /, ,$@)) GOARCH=$(word 2,$(subst /, ,$@)) \
$(GO) build -o $(BUILD_DIR)/$(word 1,$(subst /, ,$@))-$(word 2,$(subst /, ,$@))/$(BINARY_NAME)\
-ldflags "$(LDFAGS)" .
chmod 755 $(BUILD_DIR)/$(word 1,$(subst /, ,$@))-$(word 2,$(subst /, ,$@))/$(BINARY_NAME)
# Run go test for each directory
.PHONY: test
test:
@$(GO) test $(CURDIR)/...
# Run go test with verbose output and clear test cache
.PHONY: test-verbose
test-verbose:
@$(GO) clean -testcache
@$(GO) test -v $(CURDIR)/...
# Install application. Use `go install`
.PHONY: install
install:
@echo "Installing enma..."
@$(GO) install -ldflags "$(LDFLAGS)"
# Clean build artifacts
.PHONY: clean
clean:
@rm -rf $(BUILD_DIR)
# Install dev tools
.PHONY: dev-tools
dev-tools:
go install "github.com/magicdrive/goreg@latest"
go install "github.com/magicdrive/kirke@latest"
# Execute goreg -w to entire gofile.
.PHONY: goreg
goreg:
git ls-files | grep -e '.go$$' | xargs -I GOFILE goreg -w GOFILE
# Publish to github.com
.PHONY: publish
publish: test-verbose
@if [ -z "$(tag)" ]; then \
echo "Error: version is not set. Please set it and try again."; \
echo "ex) make publish tag=v0.0.1"; \
echo ; \
echo ; \
exit 1; \
fi
git tag $(tag)
git push origin $(tag)
# Show help
.PHONY: help
help:
@echo "Makefile commands:"
@echo " make build - Build all artifacts"
@echo " make release-build - Build artifacts for multiple platforms with version info"
@echo " make install - Install application. Use `go install`"
@echo " make test - Run go test"
@echo " make test-verbose - Run go test -v with go clean -testcache"
@echo " make clean - Remove build artifacts"
@echo " make dev-tools - Install dev tools"
@echo " make goreg - Execute goreg -w to entire gofile"
@echo " make publish tag=<tag> - Publish to github.com"
@echo " make help - Show this message"