-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
58 lines (44 loc) · 1.75 KB
/
Makefile
File metadata and controls
58 lines (44 loc) · 1.75 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
.PHONY: build run clean test install size completion
BINARY=granit
MODULE=github.com/artaeon/granit
VERSION=0.1.0
BUILD_DIR=bin
COMMIT=$(shell git rev-parse --short HEAD 2>/dev/null || echo "dev")
DATE=$(shell date -u +%Y-%m-%dT%H:%M:%SZ)
LDFLAGS=-s -w -X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.date=$(DATE)
build:
@echo "Building $(BINARY)..."
@mkdir -p $(BUILD_DIR)
go build -ldflags="$(LDFLAGS)" -o $(BUILD_DIR)/$(BINARY) ./cmd/granit/
@echo "Built $(BUILD_DIR)/$(BINARY) ($$(du -h $(BUILD_DIR)/$(BINARY) | cut -f1))"
run:
go run ./cmd/granit/ $(ARGS)
clean:
@rm -rf $(BUILD_DIR)
@echo "Cleaned."
test:
go test ./...
install: build
@cp $(BUILD_DIR)/$(BINARY) $(GOPATH)/bin/$(BINARY) 2>/dev/null || \
cp $(BUILD_DIR)/$(BINARY) ~/go/bin/$(BINARY)
@echo "Installed $(BINARY) to ~/go/bin/ ($$(du -h $(BUILD_DIR)/$(BINARY) | cut -f1))"
size: build
@echo "Binary size: $$(du -h $(BUILD_DIR)/$(BINARY) | cut -f1)"
@echo "To compress further: upx --best $(BUILD_DIR)/$(BINARY)"
scan:
go run ./cmd/granit/ scan $(VAULT)
daily:
go run ./cmd/granit/ daily $(VAULT)
completion:
@echo "# Add one of these to your shell config:"
@echo "# granit completion bash >> ~/.bashrc"
@echo "# granit completion zsh >> ~/.zshrc"
@echo "# granit completion fish > ~/.config/fish/completions/granit.fish"
# Cross-compilation
build-all: build-linux build-darwin build-windows
build-linux:
GOOS=linux GOARCH=amd64 go build -ldflags="$(LDFLAGS)" -o $(BUILD_DIR)/$(BINARY)-linux-amd64 ./cmd/granit/
build-darwin:
GOOS=darwin GOARCH=arm64 go build -ldflags="$(LDFLAGS)" -o $(BUILD_DIR)/$(BINARY)-darwin-arm64 ./cmd/granit/
build-windows:
GOOS=windows GOARCH=amd64 go build -ldflags="$(LDFLAGS)" -o $(BUILD_DIR)/$(BINARY)-windows-amd64.exe ./cmd/granit/