-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
116 lines (100 loc) · 3.57 KB
/
Makefile
File metadata and controls
116 lines (100 loc) · 3.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
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
.PHONY: build clean test install lint release release-all help example-manifest example-build
BINARY_NAME := capsailer
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
BUILD_TIME := $(shell date +%FT%T%z)
GOFLAGS := -trimpath
LDFLAGS := -ldflags "-X 'main.Version=$(VERSION)' -X 'main.BuildTime=$(BUILD_TIME)'"
# Detect OS
ifeq ($(OS),Windows_NT)
BINARY_SUFFIX := .exe
RM := del /f
MKDIR := mkdir
else
BINARY_SUFFIX :=
RM := rm -f
MKDIR := mkdir -p
endif
# Set the binary path
BIN_DIR := bin
BINARY_PATH := $(BIN_DIR)/$(BINARY_NAME)$(BINARY_SUFFIX)
SRC_FILES := cmd/capsailer/main.go cmd/capsailer/commands.go
# Build variables for release
PLATFORMS := linux/amd64 linux/arm64 darwin/amd64 darwin/arm64 windows/amd64
RELEASE_DIR := release
# Default target
.DEFAULT_GOAL := build
# Display help information
help:
@echo "Capsailer Makefile"
@echo "Available targets:"
@echo " build - Build the binary for the current platform"
@echo " clean - Remove build artifacts"
@echo " test - Run unit tests"
@echo " lint - Run linting checks"
@echo " install - Install binary to /usr/local/bin"
@echo " release - Create release package for current platform"
@echo " release-all - Create release packages for all supported platforms"
@echo ""
@echo "Example usage targets:"
@echo " example-manifest - Copy example manifest to manifest.yaml"
@echo " example-build - Build a bundle from the example manifest"
# Create the bin directory
$(BIN_DIR):
$(MKDIR) $(BIN_DIR)
# Build the binary
build: $(BIN_DIR)
go build $(GOFLAGS) $(LDFLAGS) -o $(BINARY_PATH) $(SRC_FILES)
@echo "Binary built at $(BINARY_PATH)"
# Clean build artifacts
clean:
go clean
$(RM) $(BINARY_NAME)
$(RM) -r $(BIN_DIR)
$(RM) -r $(RELEASE_DIR)
$(RM) -r capsailer-build
$(RM) *.tar.gz
# Run unit tests
test:
go test -v ./...
# Run linting checks
lint:
@echo "Running linting checks..."
@echo "Running go vet..."
go vet ./...
@echo "Running go fmt..."
go fmt ./...
@echo "Linting completed successfully!"
# Install the binary to /usr/local/bin
install: build
cp $(BINARY_PATH) /usr/local/bin/
@echo "Installed $(BINARY_NAME) to /usr/local/bin/"
# Build a release for the current platform
release: build
@$(MKDIR) $(RELEASE_DIR)
tar -czf $(RELEASE_DIR)/$(BINARY_NAME)-$(VERSION)-$(shell go env GOOS)-$(shell go env GOARCH).tar.gz $(BINARY_PATH)
@echo "Release package created in $(RELEASE_DIR)/"
# Build releases for all platforms
release-all:
@$(MKDIR) $(RELEASE_DIR)
@echo "Building releases for all platforms..."
@for platform in $(PLATFORMS); do \
os=$$(echo $$platform | cut -d/ -f1); \
arch=$$(echo $$platform | cut -d/ -f2); \
binary_name=$(BINARY_NAME); \
if [ "$$os" = "windows" ]; then binary_name="$(BINARY_NAME).exe"; fi; \
echo "Building for $$os/$$arch..."; \
GOOS=$$os GOARCH=$$arch go build $(GOFLAGS) $(LDFLAGS) -o $(RELEASE_DIR)/$$binary_name $(SRC_FILES); \
if [ "$$os" = "windows" ]; then \
cd $(RELEASE_DIR) && zip $(BINARY_NAME)-$(VERSION)-$$os-$$arch.zip $$binary_name && rm $$binary_name; \
else \
cd $(RELEASE_DIR) && tar -czf $(BINARY_NAME)-$(VERSION)-$$os-$$arch.tar.gz $$binary_name && rm $$binary_name; \
fi; \
done
@echo "All release packages created in $(RELEASE_DIR)/"
# Example targets for convenience
example-manifest:
cp examples/manifest.yaml manifest.yaml
@echo "Copied example manifest to manifest.yaml"
example-build: build example-manifest
$(BINARY_PATH) build --manifest manifest.yaml --output capsailer-bundle.tar.gz
@echo "Bundle built as capsailer-bundle.tar.gz"