-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathMakefile
More file actions
65 lines (55 loc) · 2.57 KB
/
Copy pathMakefile
File metadata and controls
65 lines (55 loc) · 2.57 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
.PHONY: help clean build build-for build-all version
# =============================================================================
# Variables
# =============================================================================
APP_NAME := danzo
VERSION ?= dev-build
GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)
CYAN := \033[0;36m
GREEN := \033[0;32m
NC := \033[0m
# =============================================================================
# Help
# =============================================================================
help: ## Show this help
@echo "$(CYAN)Available targets:$(NC)"
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf " $(GREEN)%-20s$(NC) %s\n", $$1, $$2}'
.DEFAULT_GOAL := help
clean: ## Remove built binaries
@rm -f $(APP_NAME) $(APP_NAME)-*
@echo "$(GREEN)Cleaned$(NC)"
# =============================================================================
# Build
# =============================================================================
build: ## Build binary for current platform
@go build -ldflags="-s -w -X 'github.com/tanq16/danzo/cmd.AppVersion=$(VERSION)'" -o $(APP_NAME) .
@echo "$(GREEN)Built: ./$(APP_NAME)$(NC)"
build-for: ## Build binary for specified GOOS/GOARCH
@CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) go build -ldflags="-s -w -X 'github.com/tanq16/danzo/cmd.AppVersion=$(VERSION)'" -o $(APP_NAME)-$(GOOS)-$(GOARCH) .
@echo "$(GREEN)Built: ./$(APP_NAME)-$(GOOS)-$(GOARCH)$(NC)"
build-all: ## Build all platform binaries
@$(MAKE) build-for GOOS=linux GOARCH=amd64
@$(MAKE) build-for GOOS=linux GOARCH=arm64
@$(MAKE) build-for GOOS=darwin GOARCH=amd64
@$(MAKE) build-for GOOS=darwin GOARCH=arm64
@$(MAKE) build-for GOOS=windows GOARCH=amd64
# =============================================================================
# Version
# =============================================================================
version: ## Calculate next version from commit message
@LATEST_TAG=$$(git tag --sort=-v:refname | head -n1 || echo "0.0.0"); \
LATEST_TAG=$${LATEST_TAG#v}; \
MAJOR=$$(echo "$$LATEST_TAG" | cut -d. -f1); \
MINOR=$$(echo "$$LATEST_TAG" | cut -d. -f2); \
PATCH=$$(echo "$$LATEST_TAG" | cut -d. -f3); \
MAJOR=$${MAJOR:-0}; MINOR=$${MINOR:-0}; PATCH=$${PATCH:-0}; \
COMMIT_MSG="$$(git log -1 --pretty=%B)"; \
if echo "$$COMMIT_MSG" | grep -q "\[major-release\]"; then \
MAJOR=$$((MAJOR + 1)); MINOR=0; PATCH=0; \
elif echo "$$COMMIT_MSG" | grep -q "\[minor-release\]"; then \
MINOR=$$((MINOR + 1)); PATCH=0; \
else \
PATCH=$$((PATCH + 1)); \
fi; \
echo "v$${MAJOR}.$${MINOR}.$${PATCH}"