-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMakefile
More file actions
75 lines (60 loc) · 1.88 KB
/
Copy pathMakefile
File metadata and controls
75 lines (60 loc) · 1.88 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
GO ?= $(shell command -v go 2>/dev/null)
ifeq ($(GO),)
$(error go not found in PATH)
endif
APP_NAME ?= bedrock
# detected Go environment
GO_VERSION := $(shell $(GO) version | awk '{print $$3}')
GOOS := $(shell $(GO) env GOOS)
GOARCH := $(shell $(GO) env GOARCH)
GOHOSTOS := $(shell $(GO) env GOHOSTOS)
GOHOSTARCH := $(shell $(GO) env GOHOSTARCH)
CGO_ENABLED ?= $(shell $(GO) env CGO_ENABLED)
# build/compile flags (override from CLI as needed)
GOFLAGS ?= -trimpath
GCFLAGS ?= all=-trimpath=$(CURDIR)
ASMFLAGS ?= all=-trimpath=$(CURDIR)
LDFLAGS ?= -s -w
BUILD_FLAGS ?=
RUN_FLAGS ?=
.PHONY: help env compile build run test clean lint fmt vet e2e
help:
@echo "Available targets:"
@echo " env - Print detected Go environment"
@echo " compile - Compile the Go application"
@echo " build - Build the Go application"
@echo " run - Run the Go application"
@echo " test - Run tests"
@echo " clean - Remove build artifacts"
@echo " lint - Run linter"
@echo " fmt - Format code"
@echo " vet - Run go vet"
@echo " e2e - Run end-to-end tests (requires 'e2e' build tag)"
env:
@echo "Go binary: $(GO)"
@echo "Go version: $(GO_VERSION)"
@echo "Target: $(GOOS)/$(GOARCH)"
@echo "Host: $(GOHOSTOS)/$(GOHOSTARCH)"
@echo "CGO_ENABLED: $(CGO_ENABLED)"
compile:
CGO_ENABLED=$(CGO_ENABLED) GOOS=$(GOOS) GOARCH=$(GOARCH) \
$(GO) build $(GOFLAGS) -gcflags "$(GCFLAGS)" -asmflags "$(ASMFLAGS)" -ldflags "$(LDFLAGS)" $(BUILD_FLAGS) -o $(APP_NAME) .
build:
$(MAKE) compile
run:
CGO_ENABLED=$(CGO_ENABLED) GOOS=$(GOOS) GOARCH=$(GOARCH) \
$(GO) run $(GOFLAGS) $(RUN_FLAGS) .
test:
CGO_ENABLED=$(CGO_ENABLED) GOOS=$(GOOS) GOARCH=$(GOARCH) \
$(GO) test -v ./...
e2e:
CGO_ENABLED=$(CGO_ENABLED) GOOS=$(GOOS) GOARCH=$(GOARCH) \
$(GO) test -tags=e2e ./tests/e2e/
clean:
rm -f $(APP_NAME)
lint:
golangci-lint run ./...
fmt:
$(GO) fmt ./...
vet:
$(GO) vet ./...