-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathMakefile
200 lines (156 loc) · 4.32 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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
.DEFAULT_GOAL := build
VERSION ?= $(shell git rev-parse HEAD)
BIN ?= go-mud-server
DOCKER_COMPOSE := docker-compose -f compose.yml
export GOFLAGS := -mod=mod
## 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-%,%,$@)"
#
#
# For a complete list of GOOS/GOARCH combinations:
# Run: go tool dist list
#
#
.PHONY: build_rpi_zero2w
build_rpi_zero2w: generate ### Build a binary for a raspberry pi zero 2w
env GOOS=linux GOARCH=arm64 go build -o $(BIN)-rpi
make ungenerate
.PHONY: build_win64
build_win64: generate ### Build a binary for 64bit windows
env GOOS=windows GOARCH=amd64 go build -o $(BIN)-win64.exe
make ungenerate
.PHONY: build_linux64
build_linux64: generate ### Build a binary for linux
env GOOS=linux GOARCH=amd64 go build -o $(BIN)-linux64
make ungenerate
.PHONY: build
build: validate build_local ### Validate the code and build the binary.
.PHONY: build_local
build_local: generate
CGO_ENABLED=0 go build -trimpath -a -o $(BIN)
make ungenerate
.PHONY: ungenerate
ungenerate: ### Reverts to a clean version of modules/all-modules.go
@cp cmd/generate/_all-modules.go modules/all-modules.go
.PHONY: generate
generate: ### Generates include directives for modules
@go generate
# Clean both development and production containers
.PHONY: clean
clean:
$(DOCKER_COMPOSE) down --volumes --remove-orphans
docker system prune -a
## Run Targets
.PHONY: run
run: generate ### Build and run server.
go build -o tmp-gomud.exe
make ungenerate
./tmp-gomud.exe
.PHONY: run-docker
run-docker: ### Build and run server in docker.
$(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
#
#
# Cert generation for testing
#
#
.PHONY: cert-clean
cert-clean:
rm -f server.crt server.key
.PHONY: cert
cert: server.crt server.key
# This rule generates both files in one go using OpenSSL.
server.crt server.key:
openssl req -x509 -nodes -newkey rsa:4096 \
-keyout server.key -out server.crt \
-days 365 -subj "/CN=localhost"
# 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"