forked from wowsims/sod
-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
267 lines (230 loc) · 9.76 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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
BASE_DIR := sod
OUT_DIR := dist/$(BASE_DIR)
TS_CORE_SRC := $(shell find ui/core -name '*.ts' -type f)
ASSETS_INPUT := $(shell find assets/ -type f)
ASSETS := $(patsubst assets/%,$(OUT_DIR)/assets/%,$(ASSETS_INPUT))
# Recursive wildcard function. Needs to be '=' instead of ':=' because of recursion.
rwildcard = $(foreach d,$(wildcard $(1:=/*)),$(call rwildcard,$d,$2) $(filter $(subst *,%,$2),$d))
GOROOT := $(shell go env GOROOT)
UI_SRC := $(shell find ui -name '*.ts' -o -name '*.tsx' -o -name '*.scss' -o -name '*.html')
HTML_INDECIES := ui/balance_druid/index.html \
ui/feral_druid/index.html \
ui/feral_tank_druid/index.html \
ui/restoration_druid/index.html \
ui/elemental_shaman/index.html \
ui/enhancement_shaman/index.html \
ui/restoration_shaman/index.html \
ui/warden_shaman/index.html \
ui/hunter/index.html \
ui/mage/index.html \
ui/rogue/index.html \
ui/tank_rogue/index.html \
ui/holy_paladin/index.html \
ui/protection_paladin/index.html \
ui/retribution_paladin/index.html \
ui/healing_priest/index.html \
ui/shadow_priest/index.html \
ui/warlock/index.html \
ui/tank_warlock/index.html \
ui/warrior/index.html \
ui/tank_warrior/index.html \
ui/raid/index.html \
ui/detailed_results/index.html
$(OUT_DIR)/.dirstamp: \
$(OUT_DIR)/lib.wasm \
ui/core/proto/api.ts \
$(ASSETS) \
$(OUT_DIR)/bundle/.dirstamp
touch $@
$(OUT_DIR)/bundle/.dirstamp: \
$(UI_SRC) \
$(HTML_INDECIES) \
vite.config.mts \
vite.build-workers.ts \
node_modules \
tsconfig.json \
ui/core/index.ts \
ui/core/proto/api.ts
npx tsc --noEmit
npx tsx vite.build-workers.ts
npx vite build
touch $@
ui/core/index.ts: $(TS_CORE_SRC)
find ui/core -name '*.ts' | \
awk -F 'ui/core/' '{ print "import \x22./" $$2 "\x22;" }' | \
sed 's/\.ts";$$/";/' | \
grep -v 'import "./index";' > $@
.PHONY: clean
clean:
rm -rf ui/core/proto/*.ts \
sim/core/proto/*.pb.go \
wowsimsod \
wowsimsod-windows.exe \
wowsimsod-amd64-darwin \
wowsimsod-arm64-darwin \
wowsimsod-amd64-linux \
dist \
binary_dist \
ui/core/index.ts \
ui/core/proto/*.ts \
node_modules \
$(HTML_INDECIES)
find . -name "*.results.tmp" -type f -delete
.PHONY: copydb
copydb:
mkdir -p $(OUT_DIR)/assets/database
cp -r assets/database/* $(OUT_DIR)/assets/database/
ui/core/proto/api.ts: proto/*.proto node_modules
npx protoc --ts_opt generate_dependencies --ts_out ui/core/proto --proto_path proto proto/api.proto
npx protoc --ts_out ui/core/proto --proto_path proto proto/test.proto
npx protoc --ts_out ui/core/proto --proto_path proto proto/ui.proto
ui/%/index.html: ui/index_template.html
$(eval title := $(shell echo $(shell basename $(@D)) | sed -r 's/(^|_)([a-z])/\U \2/g' | cut -c 2-))
cat ui/index_template.html | sed -e 's/@@TITLE@@/Season of Discovery $(title) Simulator/g' -e 's/@@SPEC@@/$(shell basename $(@D))/g' > $@
package-lock.json:
npm install
node_modules: package-lock.json
npm ci
# Generic rule for hosting any class directory
.PHONY: host_%
host_%: $(OUT_DIR) node_modules
npx http-server $(OUT_DIR)/..
# Generic rule for building index.html for any class directory
$(OUT_DIR)/%/index.html: ui/index_template.html $(OUT_DIR)/assets
$(eval title := $(shell echo $(shell basename $(@D)) | sed -r 's/(^|_)([a-z])/\U \2/g' | cut -c 2-))
echo $(title)
mkdir -p $(@D)
cat ui/index_template.html | sed -e 's/@@TITLE@@/CLASSIC $(title) Simulator/g' -e 's/@@SPEC@@/$(shell basename $(@D))/g' > $@
.PHONY: wasm
wasm: $(OUT_DIR)/lib.wasm
# Builds the generic .wasm, with all items included.
$(OUT_DIR)/lib.wasm: sim/wasm/* sim/core/proto/api.pb.go $(filter-out sim/core/items/all_items.go, $(call rwildcard,sim,*.go))
@echo "Starting webassembly compile now..."
@if GOOS=js GOARCH=wasm go build -o ./$(OUT_DIR)/lib.wasm ./sim/wasm/; then \
printf "\033[1;32mWASM compile successful.\033[0m\n"; \
else \
printf "\033[1;31mWASM COMPILE FAILED\033[0m\n"; \
exit 1; \
fi
$(OUT_DIR)/assets/%: assets/%
mkdir -p $(@D)
cp $< $@
binary_dist/dist.go: sim/web/dist.go.tmpl
mkdir -p binary_dist/$(BASE_DIR)
touch binary_dist/$(BASE_DIR)/embedded
cp sim/web/dist.go.tmpl binary_dist/dist.go
binary_dist: $(OUT_DIR)/.dirstamp
rm -rf binary_dist
mkdir -p binary_dist
cp -r $(OUT_DIR)/ binary_dist/
rm -f binary_dist/$(BASE_DIR)/lib.wasm
rm -rf binary_dist/$(BASE_DIR)/assets/db_inputs
rm -f binary_dist/$(BASE_DIR)/assets/database/db.bin
rm -f binary_dist/$(BASE_DIR)/assets/database/leftover_db.bin
# Rebuild the protobuf generated code.
.PHONY: proto
proto: sim/core/proto/api.pb.go ui/core/proto/api.ts
# Builds the web server with the compiled client.
.PHONY: wowsimsod
wowsimsod: binary_dist devserver
.PHONY: devserver
devserver: sim/core/proto/api.pb.go sim/web/main.go binary_dist/dist.go
@echo "Starting server compile now..."
@if go build -o wowsimsod ./sim/web/main.go; then \
printf "\033[1;32mBuild Completed Successfully\033[0m\n"; \
else \
printf "\033[1;31mBUILD FAILED\033[0m\n"; \
exit 1; \
fi
.PHONY: air
air:
ifeq ($(WATCH), 1)
@if ! command -v air; then \
echo "Missing air dependency. Please run \`make setup\`"; \
exit 1; \
fi
endif
rundevserver: air devserver
ifeq ($(WATCH), 1)
npx vite build -m development --watch &
ulimit -n 10240 && air -tmp_dir "/tmp" -build.include_ext "go,proto" -build.args_bin "--usefs=true --launch=false" -build.bin "./wowsimsod" -build.cmd "make devserver" -build.exclude_dir "assets,dist,node_modules,ui,tools"
else
./wowsimsod --usefs=true --launch=false --host=":3333"
endif
wowsimsod-windows.exe: wowsimsod
# go build only considers syso files when invoked without specifying .go files: https://github.com/golang/go/issues/16090
cp ./assets/favicon_io/icon-windows_amd64.syso ./sim/web/icon-windows_amd64.syso
cd ./sim/web/ && GOOS=windows GOARCH=amd64 GOAMD64=v2 go build -o wowsimsod-windows.exe -ldflags="-X 'main.Version=$(VERSION)' -s -w"
cd ./cmd/wowsimcli && GOOS=windows GOARCH=amd64 GOAMD64=v2 go build -o wowsimcli-windows.exe --tags=with_db -ldflags="-X 'main.Version=$(VERSION)' -s -w"
rm ./sim/web/icon-windows_amd64.syso
mv ./sim/web/wowsimsod-windows.exe ./wowsimsod-windows.exe
mv ./cmd/wowsimcli/wowsimcli-windows.exe ./wowsimcli-windows.exe
release: wowsimsod wowsimsod-windows.exe
GOOS=darwin GOARCH=amd64 GOAMD64=v2 go build -o wowsimsod-amd64-darwin -ldflags="-X 'main.Version=$(VERSION)' -s -w" ./sim/web/main.go
GOOS=darwin GOARCH=arm64 go build -o wowsimsod-arm64-darwin -ldflags="-X 'main.Version=$(VERSION)' -s -w" ./sim/web/main.go
GOOS=linux GOARCH=amd64 GOAMD64=v2 go build -o wowsimsod-amd64-linux -ldflags="-X 'main.Version=$(VERSION)' -s -w" ./sim/web/main.go
GOOS=linux GOARCH=amd64 GOAMD64=v2 go build -o wowsimcli-amd64-linux --tags=with_db -ldflags="-X 'main.Version=$(VERSION)' -s -w" ./cmd/wowsimcli/cli_main.go
# Now compress into a zip because the files are getting large.
zip wowsimsod-windows.exe.zip wowsimsod-windows.exe
zip wowsimsod-amd64-darwin.zip wowsimsod-amd64-darwin
zip wowsimsod-arm64-darwin.zip wowsimsod-arm64-darwin
zip wowsimsod-amd64-linux.zip wowsimsod-amd64-linux
zip wowsimcli-amd64-linux.zip wowsimcli-amd64-linux
zip wowsimcli-windows.exe.zip wowsimcli-windows.exe
sim/core/proto/api.pb.go: proto/*.proto
protoc -I=./proto --go_out=./sim/core ./proto/*.proto
# Only useful for building the lib on a host platform that matches the target platform
.PHONY: locallib
locallib: sim/core/proto/api.pb.go
go build -buildmode=c-shared -o wowsimsod.so --tags=with_db ./sim/lib/library.go
.PHONY: nixlib
nixlib: sim/core/proto/api.pb.go
GOOS=linux GOARCH=amd64 GOAMD64=v2 go build -buildmode=c-shared -o wowsimsod-linux.so --tags=with_db ./sim/lib/library.go
.PHONY: winlib
winlib: sim/core/proto/api.pb.go
GOOS=windows GOARCH=amd64 GOAMD64=v2 CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc go build -buildmode=c-shared -o wowsimsod-windows.dll --tags=with_db ./sim/lib/library.go
.PHONY: items
items: sim/core/items/all_items.go sim/core/proto/api.pb.go
sim/core/items/all_items.go: $(call rwildcard,tools/database,*.go) $(call rwildcard,sim/core/proto,*.go)
go run tools/database/gen_db/*.go -outDir=./assets -gen=db
.PHONY: test
test: $(OUT_DIR)/lib.wasm binary_dist/dist.go
go test --tags=with_db ./sim/...
.PHONY: update-tests
update-tests:
find . -name "*.results" -type f -delete
find . -name "*.results.tmp" -exec bash -c 'cp "$$1" "$${1%.results.tmp}".results' _ {} \;
.PHONY: fmt
fmt: tsfmt
gofmt -w ./sim
gofmt -w ./tools
.PHONY: tsfmt
tsfmt:
for dir in $$(find ./ui -maxdepth 1 -type d -not -path "./ui" -not -path "./ui/worker"); do \
echo $$dir; \
npx tsfmt -r --useTsfmt ./tsfmt.json --baseDir $$dir; \
done
# one time setup to install pre-commit hook for gofmt and npm install needed packages
setup:
cp pre-commit .git/hooks
chmod +x .git/hooks/pre-commit
! command -v air && curl -sSfL https://raw.githubusercontent.com/cosmtrek/air/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin || true
# Host a local server, for dev testing
.PHONY: host
host: air $(OUT_DIR)/.dirstamp node_modules
ifeq ($(WATCH), 1)
ulimit -n 10240 && air -tmp_dir "/tmp" -build.include_ext "go,ts,js,html" -build.bin "npx" -build.args_bin "http-server $(OUT_DIR)/.." -build.cmd "make" -build.exclude_dir "dist,node_modules,tools"
else
# Intentionally serve one level up, so the local site has 'wotlk' as the first
# directory just like github pages.
npx http-server $(OUT_DIR)/..
endif
devmode: air devserver
ifeq ($(WATCH), 1)
npx tsx vite.build-workers.ts & npx vite serve --host &
air -tmp_dir "/tmp" -build.include_ext "go,proto" -build.args_bin "--usefs=true --launch=false --wasm=false" -build.bin "./wowsimsod" -build.cmd "make devserver" -build.exclude_dir "assets,dist,node_modules,ui,tools"
else
./wowsimsod --usefs=true --launch=false --host=":3333"
endif
webworkers:
npx tsx vite.build-workers.ts --watch=$(if $(WATCH),true,false)