Advertisement
stromback

makefiile

Nov 25th, 2022
15
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.81 KB | None | 0 0
  1. OUT_DIR := dist/wotlk
  2. TS_CORE_SRC := $(shell find ui/core -name '*.ts' -type f)
  3. ASSETS_INPUT := $(shell find assets/ -type f)
  4. ASSETS := $(patsubst assets/%,$(OUT_DIR)/assets/%,$(ASSETS_INPUT))
  5. # Recursive wildcard function. Needs to be '=' instead of ':=' because of recursion.
  6. rwildcard = $(foreach d,$(wildcard $(1:=/*)),$(call rwildcard,$d,$2) $(filter $(subst *,%,$2),$d))
  7. GOROOT := $(shell go env GOROOT)
  8. UI_SRC := $(shell find ui -name '*.ts' -o -name '*.scss' -o -name '*.html')
  9. HTML_INDECIES := ui/balance_druid/index.html \
  10. ui/feral_druid/index.html \
  11. ui/feral_tank_druid/index.html \
  12. ui/elemental_shaman/index.html \
  13. ui/enhancement_shaman/index.html \
  14. ui/hunter/index.html \
  15. ui/mage/index.html \
  16. ui/rogue/index.html \
  17. ui/retribution_paladin/index.html \
  18. ui/protection_paladin/index.html \
  19. ui/healing_priest/index.html \
  20. ui/shadow_priest/index.html \
  21. ui/smite_priest/index.html \
  22. ui/warlock/index.html \
  23. ui/warrior/index.html \
  24. ui/protection_warrior/index.html \
  25. ui/deathknight/index.html \
  26. ui/tank_deathknight/index.html \
  27. ui/raid/index.html \
  28. ui/detailed_results/index.html
  29.  
  30. $(OUT_DIR)/.dirstamp: \
  31. $(OUT_DIR)/lib.wasm \
  32. ui/core/proto/api.ts \
  33. $(ASSETS) \
  34. $(OUT_DIR)/bundle/.dirstamp
  35. touch $@
  36.  
  37. $(OUT_DIR)/bundle/.dirstamp: \
  38. $(UI_SRC) \
  39. $(HTML_INDECIES) \
  40. vite.config.js \
  41. node_modules \
  42. tsconfig.json \
  43. ui/core/index.ts \
  44. ui/core/proto/api.ts \
  45. $(OUT_DIR)/net_worker.js \
  46. $(OUT_DIR)/sim_worker.js
  47. npx tsc --noEmit
  48. npx vite build
  49. touch $@
  50.  
  51. $(OUT_DIR)/sim_worker.js: ui/worker/sim_worker.js
  52. cat '$(GOROOT)/misc/wasm/wasm_exec.js' > $(OUT_DIR)/sim_worker.js
  53. cat ui/worker/sim_worker.js >> $(OUT_DIR)/sim_worker.js
  54.  
  55. $(OUT_DIR)/net_worker.js: ui/worker/net_worker.js
  56. cp ui/worker/net_worker.js $(OUT_DIR)
  57.  
  58. ui/core/index.ts: $(TS_CORE_SRC)
  59. find ui/core -name '*.ts' | \
  60. awk -F 'ui/core/' '{ print "import \x22./" $$2 "\x22;" }' | \
  61. sed 's/\.ts";$$/";/' | \
  62. grep -v 'import "./index";' > $@
  63.  
  64. .PHONY: clean
  65. clean:
  66. rm -rf ui/core/proto/*.ts \
  67. sim/core/proto/*.pb.go \
  68. wowsimwotlk \
  69. wowsimwotlk-windows.exe \
  70. wowsimwotlk-amd64-darwin \
  71. wowsimwotlk-amd64-linux \
  72. dist \
  73. binary_dist \
  74. ui/core/index.ts \
  75. ui/core/proto/*.ts \
  76. node_modules \
  77. $(HTML_INDECIES)
  78. find . -name "*.results.tmp" -type f -delete
  79.  
  80.  
  81. ui/core/proto/api.ts: proto/*.proto node_modules
  82. npx protoc --ts_opt generate_dependencies --ts_out ui/core/proto --proto_path proto proto/api.proto
  83. npx protoc --ts_out ui/core/proto --proto_path proto proto/test.proto
  84. npx protoc --ts_out ui/core/proto --proto_path proto proto/ui.proto
  85.  
  86. ui/%/index.html: ui/index_template.html
  87. $(eval title := $(shell echo $(shell basename $(@D)) | sed -r 's/(^|_)([a-z])/\U \2/g' | cut -c 2-))
  88. cat ui/index_template.html | sed 's/@@TITLE@@/WOTLK $(title) Simulator/g' > $@
  89.  
  90. package-lock.json:
  91. npm install
  92.  
  93. node_modules: package-lock.json
  94. npm ci
  95.  
  96. # Generic rule for hosting any class directory
  97. .PHONY: host_%
  98. host_%: $(OUT_DIR) node_modules
  99. npx http-server $(OUT_DIR)/..
  100.  
  101. # Generic rule for building index.html for any class directory
  102. $(OUT_DIR)/%/index.html: ui/index_template.html $(OUT_DIR)/assets
  103. $(eval title := $(shell echo $(shell basename $(@D)) | sed -r 's/(^|_)([a-z])/\U \2/g' | cut -c 2-))
  104. echo $(title)
  105. mkdir -p $(@D)
  106. cat ui/index_template.html | sed 's/@@TITLE@@/WOTLK $(title) Simulator/g' > $@
  107.  
  108. .PHONY: wasm
  109. wasm: $(OUT_DIR)/lib.wasm
  110.  
  111. # Builds the generic .wasm, with all items included.
  112. $(OUT_DIR)/lib.wasm: sim/wasm/* sim/core/proto/api.pb.go $(filter-out sim/core/items/all_items.go, $(call rwildcard,sim,*.go))
  113. @echo "Starting webassembly compile now..."
  114. @if GOOS=js GOARCH=wasm go build -o ./$(OUT_DIR)/lib.wasm ./sim/wasm/; then \
  115. printf "\033[1;32mWASM compile successful.\033[0m\n"; \
  116. else \
  117. printf "\033[1;31mWASM COMPILE FAILED\033[0m\n"; \
  118. exit 1; \
  119. fi
  120.  
  121. $(OUT_DIR)/assets/%: assets/%
  122. mkdir -p $(@D)
  123. cp $< $@
  124.  
  125. binary_dist/dist.go: sim/web/dist.go.tmpl
  126. mkdir -p binary_dist/wotlk
  127. touch binary_dist/wotlk/embedded
  128. cp sim/web/dist.go.tmpl binary_dist/dist.go
  129.  
  130. binary_dist: $(OUT_DIR)
  131. rm -rf binary_dist
  132. mkdir -p binary_dist
  133. cp -r $(OUT_DIR) binary_dist/
  134. rm binary_dist/wotlk/lib.wasm
  135. rm -rf binary_dist/wotlk/assets/database
  136. mkdir -p binary_dist/wotlk/assets/database
  137. cp $(OUT_DIR)/assets/database/* ./binary_dist/wotlk/assets/database
  138.  
  139. # Builds the web server with the compiled client.
  140. .PHONY: wowsimwotlk
  141. wowsimwotlk: binary_dist devserver
  142.  
  143. .PHONY: devserver
  144. devserver: sim/core/proto/api.pb.go sim/web/main.go binary_dist/dist.go
  145. @echo "Starting server compile now..."
  146. @if go build -o wowsimwotlk ./sim/web/main.go; then \
  147. printf "\033[1;32mBuild Completed Succeessfully\033[0m\n"; \
  148. else \
  149. printf "\033[1;31mBUILD FAILED\033[0m\n"; \
  150. exit 1; \
  151. fi
  152.  
  153. rundevserver: devserver
  154. ./wowsimwotlk --usefs=true --launch=false
  155.  
  156. release: wowsimwotlk
  157. GOOS=windows GOARCH=amd64 GOAMD64=v2 go build -o wowsimwotlk-windows.exe -ldflags="-X 'main.Version=$(VERSION)' -s -w" ./sim/web/main.go
  158. GOOS=darwin GOARCH=amd64 GOAMD64=v2 go build -o wowsimwotlk-amd64-darwin -ldflags="-X 'main.Version=$(VERSION)' -s -w" ./sim/web/main.go
  159. GOOS=linux GOARCH=amd64 GOAMD64=v2 go build -o wowsimwotlk-amd64-linux -ldflags="-X 'main.Version=$(VERSION)' -s -w" ./sim/web/main.go
  160. GOOS=linux GOARCH=amd64 GOAMD64=v2 go build -o wowsimcli-amd64-linux -ldflags="-X 'main.Version=$(VERSION)' -s -w" ./cmd/wowsimcli/cli_main.go
  161. # Now compress into a zip because the files are getting large.
  162. zip wowsimwotlk-windows.exe.zip wowsimwotlk-windows.exe
  163. zip wowsimwotlk-amd64-darwin.zip wowsimwotlk-amd64-darwin
  164. zip wowsimwotlk-amd64-linux.zip wowsimwotlk-amd64-linux
  165. zip wowsimcli-amd64-linux.zip wowsimcli-amd64-linux
  166.  
  167. sim/core/proto/api.pb.go: proto/*.proto
  168. protoc -I=./proto --go_out=./sim/core ./proto/*.proto
  169.  
  170. .PHONY: items
  171. items: sim/core/items/all_items.go sim/core/proto/api.pb.go
  172.  
  173. sim/core/items/all_items.go: $(call rwildcard,tools/database,*.go) $(call rwildcard,sim/core/proto,*.go)
  174. go run tools/database/gen_db/*.go -outDir=./assets
  175.  
  176. .PHONY: test
  177. test: $(OUT_DIR)/lib.wasm binary_dist/dist.go
  178. go test --tags=with_db ./...
  179.  
  180. .PHONY: update-tests
  181. update-tests:
  182. find . -name "*.results" -type f -delete
  183. find . -name "*.results.tmp" -exec bash -c 'cp "$$1" "$${1%.results.tmp}".results' _ {} \;
  184.  
  185. .PHONY: fmt
  186. fmt: tsfmt
  187. gofmt -w ./sim
  188. gofmt -w ./tools
  189.  
  190. .PHONY: tsfmt
  191. tsfmt:
  192. for dir in $$(find ./ui -maxdepth 1 -type d -not -path "./ui" -not -path "./ui/worker"); do \
  193. echo $$dir; \
  194. npx tsfmt -r --useTsfmt ./tsfmt.json --baseDir $$dir; \
  195. done
  196.  
  197. # one time setup to install pre-commit hook for gofmt and npm install needed packages
  198. setup:
  199. cp pre-commit .git/hooks
  200. chmod +x .git/hooks/pre-commit
  201.  
  202. # Host a local server, for dev testing
  203. .PHONY: host
  204. host: $(OUT_DIR)/.dirstamp node_modules
  205. # Intentionally serve one level up, so the local site has 'wotlk' as the first
  206. # directory just like github pages.
  207. npx http-server $(OUT_DIR)/..
  208.  
  209. .PHONY: buildsim
  210. buildsim: $(OUT_DIR)/.dirstamp node_modules
  211.  
  212. .PHONY: exe
  213. exe:
  214. rm -rf wowsimwotlk-amd64-darwin.zip wowsimwotlk-amd64-linux.zip wowsimcli-amd64-linux.zip wowsimwotlk-windows.exe.zip
  215. make clean
  216. sudo apt update -y && sudo apt upgrade -y
  217. sudo apt install -y protobuf-compiler
  218. go get -u -v google.golang.org/protobuf
  219. go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
  220. make setup
  221. make test
  222. make update-tests
  223. make buildsim
  224. make wowsimwotlk
  225. make release
  226. rm -rf wowsimwotlk wowsimwotlk-amd64-darwin wowsimwotlk-amd64-linux wowsimwotlk-windows.exe wowsimcli-amd64-linux
  227. gh release upload release wowsimcli-amd64-linux.zip wowsimwotlk-amd64-darwin.zip wowsimwotlk-amd64-linux.zip wowsimwotlk-windows.exe.zip -R str0mback/wotlk --clobber
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement