-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
83 lines (70 loc) · 2.22 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
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
BINARY_NAME=secm
VERSION?=0.1.0
BUILD_DIR=build
MAIN_PACKAGE=.
# Go build flags
LDFLAGS=-ldflags "-X main.Version=${VERSION}"
GOFLAGS=-trimpath
# Supported platforms
PLATFORMS=linux darwin windows
ARCHITECTURES=amd64 arm64
# Development tools
GOFMT=gofmt
GOTEST=go test
.PHONY: all build clean test fmt build-all
# Default target
all: clean build
# Build for current platform
build:
@echo "Building ${BINARY_NAME}..."
@go build ${GOFLAGS} ${LDFLAGS} -o ${BUILD_DIR}/${BINARY_NAME} ${MAIN_PACKAGE}
# Build for all platforms
build-all: clean
@echo "Building for all platforms..."
@$(foreach PLATFORM,$(PLATFORMS),\
$(foreach ARCH,$(ARCHITECTURES),\
echo "Building for ${PLATFORM}/${ARCH}..." && \
GOOS=${PLATFORM} GOARCH=${ARCH} go build ${GOFLAGS} ${LDFLAGS} \
-o ${BUILD_DIR}/${BINARY_NAME}-${VERSION}-${PLATFORM}-${ARCH}$(if $(findstring windows,${PLATFORM}),.exe,) \
${MAIN_PACKAGE} ; \
)\
)
# Build for specific platform (usage: make build-platform PLATFORM=darwin ARCH=arm64)
build-platform:
@echo "Building for ${PLATFORM}/${ARCH}..."
@GOOS=${PLATFORM} GOARCH=${ARCH} go build ${GOFLAGS} ${LDFLAGS} \
-o ${BUILD_DIR}/${BINARY_NAME}-${VERSION}-${PLATFORM}-${ARCH}$(if $(findstring windows,${PLATFORM}),.exe,) \
${MAIN_PACKAGE}
# Clean build directory
clean:
@echo "Cleaning build directory..."
@rm -rf ${BUILD_DIR}/*
@mkdir -p ${BUILD_DIR}
# Run tests
test:
@echo "Running tests..."
@${GOTEST} -v ./...
# Format code
fmt:
@echo "Formatting code..."
@${GOFMT} -w .
# Install locally for development
install: build
@echo "Installing ${BINARY_NAME}..."
@cp ${BUILD_DIR}/${BINARY_NAME} ${GOPATH}/bin/
# Show help
help:
@echo "Available targets:"
@echo " make - Build for current platform"
@echo " make build-all - Build for all platforms"
@echo " make build-platform PLATFORM=darwin ARCH=arm64 - Build for specific platform"
@echo " make clean - Clean build directory"
@echo " make test - Run tests"
@echo " make fmt - Format code"
@echo " make install - Install locally"
@echo ""
@echo "Supported platforms: ${PLATFORMS}"
@echo "Supported architectures: ${ARCHITECTURES}"
@echo ""
@echo "Example:"
@echo " make build-platform PLATFORM=darwin ARCH=arm64"