-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
60 lines (46 loc) · 1.73 KB
/
Copy pathMakefile
File metadata and controls
60 lines (46 loc) · 1.73 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
.PHONY: build test run clean lint fmt vet test-verbose test-coverage install build-full all
INSTALL_DIR ?= /usr/local/bin
BINARY_NAME=loom
BUILD_DIR=bin
build:
go build -o $(BUILD_DIR)/$(BINARY_NAME) .
build-full:
@echo "Building with version information..."
@VERSION=$$(git describe --tags --abbrev=0 2>/dev/null || echo "dev"); \
COMMIT=$$(git rev-parse --short HEAD 2>/dev/null || echo "unknown"); \
DATE=$$(date -u +%Y-%m-%dT%H:%M:%SZ); \
echo "Version: $$VERSION"; \
echo "Commit: $$COMMIT"; \
echo "Date: $$DATE"; \
go build -trimpath -ldflags="-s -w -X 'main.version=$$VERSION' -X 'main.commit=$$COMMIT' -X 'main.date=$$DATE'" -o $(BUILD_DIR)/$(BINARY_NAME) .
install:
@echo "Building and installing $(BINARY_NAME)..."
@EXISTING=$$(which $(BINARY_NAME) 2>/dev/null); \
DEST=$$([ -n "$$EXISTING" ] && dirname "$$EXISTING" || echo "$(INSTALL_DIR)"); \
VERSION=$$([ -n "$(VERSION)" ] && echo "$(VERSION)" || git describe --tags --abbrev=0 2>/dev/null || echo "dev"); \
COMMIT=$$(git rev-parse --short HEAD 2>/dev/null || echo "unknown"); \
DATE=$$(date -u +%Y-%m-%dT%H:%M:%SZ); \
echo "Version: $$VERSION"; \
echo "Commit: $$COMMIT"; \
echo "Date: $$DATE"; \
go build -trimpath -ldflags="-s -w -X 'main.version=$$VERSION' -X 'main.commit=$$COMMIT' -X 'main.date=$$DATE'" -o $(BUILD_DIR)/$(BINARY_NAME) .; \
install -m 755 $(BUILD_DIR)/$(BINARY_NAME) "$$DEST/$(BINARY_NAME)"; \
echo "Installed to $$DEST/$(BINARY_NAME)"
run:
go run .
test:
go test ./...
test-verbose:
go test -v ./...
test-coverage:
go test -coverprofile=coverage.out ./...
go tool cover -html=coverage.out -o coverage.html
clean:
rm -rf $(BUILD_DIR)
rm -f coverage.out coverage.html
fmt:
go fmt ./...
vet:
go vet ./...
lint: fmt vet
all: lint test build