-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
64 lines (50 loc) · 2 KB
/
Makefile
File metadata and controls
64 lines (50 loc) · 2 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
APP_NAME := infra-cli
BUILD_DIR := bin
MODULE := github.com/jasonjacinth/infra-cli
# Build metadata — injected into the binary at link time via ldflags.
# VERSION can be overridden at invocation: make build VERSION=1.2.3
VERSION ?= 0.2.0
GIT_COMMIT := $(shell git rev-parse --short HEAD 2>/dev/null || echo "unknown")
BUILD_TIME := $(shell date -u '+%Y-%m-%dT%H:%M:%SZ')
# ldflags injects version, commit, and build time into the cmd package variables.
LDFLAGS := -ldflags "\
-X github.com/jasonjacinth/infra-cli/cmd.Version=$(VERSION) \
-X github.com/jasonjacinth/infra-cli/cmd.GitCommit=$(GIT_COMMIT) \
-X github.com/jasonjacinth/infra-cli/cmd.BuildTime=$(BUILD_TIME)"
.PHONY: build build-all clean run test vet help
## build: Compile the binary for the current platform into ./bin/
build:
@echo "Building $(APP_NAME) v$(VERSION) ($(GIT_COMMIT))..."
@mkdir -p $(BUILD_DIR)
go build $(LDFLAGS) -o $(BUILD_DIR)/$(APP_NAME) .
@echo "Binary built at $(BUILD_DIR)/$(APP_NAME)"
## build-all: Cross-compile binaries for macOS (arm64/amd64) and Linux (amd64)
build-all:
@echo "Cross-compiling $(APP_NAME) v$(VERSION)..."
@mkdir -p $(BUILD_DIR)
@echo " -> darwin/arm64 (macOS Apple Silicon)"
GOOS=darwin GOARCH=arm64 go build $(LDFLAGS) -o $(BUILD_DIR)/$(APP_NAME)-darwin-arm64 .
@echo " -> darwin/amd64 (macOS Intel)"
GOOS=darwin GOARCH=amd64 go build $(LDFLAGS) -o $(BUILD_DIR)/$(APP_NAME)-darwin-amd64 .
@echo " -> linux/amd64"
GOOS=linux GOARCH=amd64 go build $(LDFLAGS) -o $(BUILD_DIR)/$(APP_NAME)-linux-amd64 .
@echo ""
@echo "Binaries:"
@ls -lh $(BUILD_DIR)/$(APP_NAME)-*
## clean: Remove build artifacts
clean:
@echo "Cleaning..."
@rm -rf $(BUILD_DIR)
## run: Build and run with optional ARGS (e.g., make run ARGS="status --app my-service")
run: build
./$(BUILD_DIR)/$(APP_NAME) $(ARGS)
## test: Run all tests
test:
go test ./... -v
## vet: Run go vet for static analysis
vet:
go vet ./...
## help: Show this help message
help:
@echo "Available targets:"
@grep -E '^## ' Makefile | sed 's/## / /'