-
Notifications
You must be signed in to change notification settings - Fork 15
/
Makefile
163 lines (127 loc) · 3.54 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
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
.DEFAULT_GOAL := build
VERSION ?= $(shell git rev-parse HEAD)
BIN ?= go-mud-server
DOCKER_COMPOSE := docker-compose -f provisioning/docker-compose.yml
export GOFLAGS := -mod=mod
export GOSUMDB := off
## Build Targets
.PHONY: docker_build
docker_build:
TAG=$(VERSION) $(DOCKER_COMPOSE) build server
DOCKER_CMD ?= bash
.PHONY: console
console:
@docker run --rm -it --init \
-v "$(PWD)":/src \
-w /src \
golang:1.21.3-alpine3.18 \
$(DOCKER_CMD)
docker-%:
@$(MAKE) console DOCKER_CMD="make $(patsubst docker-%,%,$@)"
# Clean both development and production containers
.PHONY: clean
clean:
$(DOCKER_COMPOSE) down --volumes --remove-orphans
docker system prune -a
## Run Targets
.PHONY: run
run: ### Build and run server.
$(DOCKER_COMPOSE) up --build --remove-orphans server
.PHONY: client
client: ### Build and run client terminal client
$(DOCKER_COMPOSE) run --rm terminal telnet go-mud-server 33333
.PHONY: image_tag
image_tag:
@echo $(VERSION)
.PHONY: port
port:
@$(eval PORT := $(shell $(DOCKER_COMPOSE) port server 8080))
@echo $(PORT)
.PHONY: shell
shell:
@$(eval CONTAINER_NAME := $(shell docker ps --filter="name=mud" --format '{{.Names}}' ))
docker exec -it $(CONTAINER_NAME) /bin/sh
#
#
# Local code run/test
#
#
.PHONY: validate
validate: fmtcheck vet
.PHONY: test
test:
@go test ./...
.PHONY: coverage
coverage:
@mkdir -p bin/covdatafiles && \
go test ./... -coverprofile=bin/covdatafiles/cover.out && \
go tool cover -html=bin/covdatafiles/cover.out && \
rm -rf bin
#
#
# For a complete list of GOOS/GOARCH combinations:
# Run: go tool dist list
#
#
.PHONY: build_rpi
build_rpi: ### Build a binary for a raspberry pi
env GOOS=linux GOARCH=arm GOARM=5 go build -o $(BIN)-rpi
.PHONY: build_win64
build_win64: ### Build a binary for 64bit windows
env GOOS=windows GOARCH=amd64 go build -o $(BIN)-win64.exe
.PHONY: build_linux64
build_linux64: ### Build a binary for linux
env GOOS=linux GOARCH=amd64 go build -o $(BIN)-linux64
.PHONY: build
build: validate build_local ### Validate the code and build the binary.
.PHONY: build_local
build_local:
CGO_ENABLED=0 go build -trimpath -a -o $(BIN)
# Go targets
.PHONY: fmt
fmt:
@go fmt ./...
.PHONY: fmtcheck
fmtcheck:
@set -e; \
unformatted=$$(go fmt ./...); \
if [ ! -z "$$unformatted" ]; then \
echo Fixed inconsistent format in some files.; \
echo $$unformatted; \
exit 1; \
fi
.PHONY: mod
mod:
@go mod vendor
@go mod tidy
@go mod verify
.PHONY: vet
vet:
@go vet
.PHONY: set_gopath
set_gopath:
ifeq ($(OS),Windows_NT)
setx PATH "$(PATH);mytest" -m
else
export GOPATH=$GOPATH:$(pwd)
endif
.PHONY: view_pprof_mem
view_pprof_mem:
go tool pprof -http=:8989 source/_datafiles/profiles/mem.pprof
#
# Help target - greps and formats special comments to form a "help" command for makefiles
#
## Help
.PHONY: help
help: ### List makefile targets.
# 1. grep for any lines starting with "##" or containing "\s###\s"
# 2. Align targets/comments with string padding
# 3. Wrap lines starting with "##" in ANSI escape codes (color) as headers
# 4. Wrap lines containing "\s###\s" in ANSI escape codes (color) as commands
# 5. Add new lines before any that aren't prefixed with space (Headers)
@grep -hE "^##\s|\s###\s" $(MAKEFILE_LIST) \
| awk -F'[[:space:]]###[[:space:]]' '{printf "%-36s### %s\n", substr($$1,1,35), $$2}' \
| sed -E "s/^## ([^#]*)#*/`printf "\033[90;3m"`\1`printf "\033[0m"`/" \
| sed "s/\(.*\):\(.*\)###\(.*\)$$/ `printf "\033[93m"`\1:`printf "\033[36m"`\2`printf "\033[97m"`-\3`printf "\033[0m"`/" \
| sed "/^[^[:blank:]]/{x;p;x;}"
@printf "\n"