-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
50 lines (41 loc) · 1.21 KB
/
Makefile
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
# Go parameters
GOCMD = go
GOBUILD = $(GOCMD) build
GOCLEAN = $(GOCMD) clean
GOTEST = $(GOCMD) test
GOGET = $(GOCMD) get
SWAG = swag
# Name of binary
BINARY_NAME = phoenix-go
BUILD_DIR = bin
# Platforms for cross-compilation
PLATFORMS = linux/amd64 linux/arm64 darwin/amd64 darwin/arm64 windows/amd64 windows/arm64
# Build the binary
build:
CGO_ENABLED=0 $(GOBUILD) -ldflags "-s -w" -o $(BUILD_DIR)/$(BINARY_NAME) cmd/main.go
# Clean build files
clean:
$(GOCLEAN)
rm -rf $(BUILD_DIR)
# Run tests
test:
$(GOCLEAN) -testcache
$(GOTEST) -v ./...
# Cross-compile for all specified platforms and zip each binary
build-all: clean
@mkdir -p $(BUILD_DIR)
@for platform in $(PLATFORMS); do \
GOOS=$$(echo $$platform | cut -d '/' -f 1); \
GOARCH=$$(echo $$platform | cut -d '/' -f 2); \
OUTPUT=$(BUILD_DIR)/$(BINARY_NAME)-$$GOOS-$$GOARCH; \
CGO_ENABLED=0 GOOS=$$GOOS GOARCH=$$GOARCH $(GOBUILD) -ldflags "-s -w" -o $$OUTPUT cmd/main.go || exit 1; \
echo "Built: $$OUTPUT"; \
zip -j $$OUTPUT.zip $$OUTPUT || exit 1; \
echo "Zipped: $$OUTPUT.zip"; \
done
# Generate Swagger documentation
swagger:
$(SWAG) init -g cmd/main.go --output ./docs
# Default target
default: build
.PHONY: build clean test build-all swagger