-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
81 lines (69 loc) · 1.98 KB
/
Makefile
File metadata and controls
81 lines (69 loc) · 1.98 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
APP_NAME := laclm
CMD_DIR := ./cmd/$(APP_NAME)
BIN_DIR := ./bin
BUILD_DIR := ./build
GOFILES := $(shell find . -name '*.go' -type f)
# Target platforms: OS_ARCH
TARGETS := \
linux_amd64 \
linux_arm64
.PHONY: all build build-cross clean run test lint vendor package
## Default target
all: build
## Build for local OS/arch using vendored deps
build: vendor $(GOFILES)
@echo "Building $(APP_NAME)..."
@mkdir -p $(BIN_DIR)
GOOS="" GOARCH="" go build -mod=vendor -o $(BIN_DIR)/$(APP_NAME) $(CMD_DIR)
## Build cross-compiled binaries for all Linux targets
build-cross: vendor $(GOFILES)
@echo "Cross building for targets: $(TARGETS)"
@mkdir -p $(BIN_DIR)
@for target in $(TARGETS); do \
OS=$${target%_*}; \
ARCH=$${target#*_}; \
OUT=$(BIN_DIR)/$(APP_NAME)-$$OS-$$ARCH; \
echo "Building $$OUT..."; \
GOOS=$$OS GOARCH=$$ARCH go build -mod=vendor -o $$OUT $(CMD_DIR); \
done
## Run the app
run: build
@echo "Running $(APP_NAME)..."
@$(BIN_DIR)/$(APP_NAME)
## Clean build and package directories
clean:
@echo "Cleaning..."
@rm -rf $(BIN_DIR) $(BUILD_DIR) vendor
## Run tests
test:
@echo "Running tests..."
go test ./...
## Lint (requires golangci-lint)
lint:
@if ! command -v golangci-lint >/dev/null 2>&1; then \
echo "Installing golangci-lint..."; \
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest; \
fi
@echo "Linting..."
@golangci-lint run
## Vendor dependencies
vendor:
@echo "Vendoring dependencies..."
go mod vendor
## Package full project source (with vendor) for each target
package: clean vendor
@echo "Packaging full source tarballs for: $(TARGETS)"
@mkdir -p $(BUILD_DIR)
@for target in $(TARGETS); do \
OS=$${target%_*}; \
ARCH=$${target#*_}; \
NAME=$(APP_NAME)-$$OS-$$ARCH; \
TARBALL=$$NAME-source.tar.gz; \
echo "Creating $$TARBALL..."; \
mkdir -p tmp/$$NAME; \
cp -r * tmp/$$NAME; \
rm -rf tmp/$$NAME/$(BUILD_DIR) tmp/$$NAME/$(BIN_DIR); \
gtar -czf $(BUILD_DIR)/$$TARBALL -C tmp $$NAME; \
rm -rf tmp/$$NAME; \
done
@rm -rf tmp