Makefile 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # dependencies
  2. GORENDER := ./gopath/bin/gorender --palette "vox/ttd_palette.json" -s 4 -overwrite
  3. NMLC := nml/nmlc
  4. GCC := gcc
  5. MANIFEST := manifest.json
  6. TIME := $(shell date -u +%Y/%m/%d\ %H:%M:%S\ UTC)
  7. # utilities
  8. GIT_NUMBER := $(shell git rev-list --count HEAD)
  9. .PHONY: all sprites code clean clean_grf clean_png copy
  10. # default rule
  11. all: sprites code
  12. # voxel paths
  13. VOX_DIR = vox
  14. VOX_FILES = $(wildcard $(VOX_DIR)/*/*.vox)
  15. VOX_8BPP_FILES = $(addsuffix _8bpp.png, $(basename $(VOX_FILES)))
  16. VOX_32BPP_FILES = $(addsuffix _32bpp.png, $(basename $(VOX_FILES)))
  17. VOX_MASK_FILES = $(addsuffix _mask.png, $(basename $(VOX_FILES)))
  18. VOX_GENREATED_FILES = $(VOX_8BPP_FILES) $(VOX_32BPP_FILES) $(VOX_MASK_FILES)
  19. %_8bpp.png %_32bpp.png %_mask.png: %.vox
  20. @echo "Rendering, manifest = $(dir $<)/$(MANIFEST), $<"
  21. @$(GORENDER) -m "$(dir $<)/$(MANIFEST)" $<
  22. # sprites
  23. sprites: $(VOX_GENREATED_FILES)
  24. # code
  25. NML_FILE = cns.nml
  26. CODE_FILES = $(shell find . \( -name '*.pnml' -o -name '*.lng' \)) $(INDEX_FILE)
  27. INDEX_FILE = indexes.pnml
  28. GRF_FILE = cns.grf
  29. TAGS = tags.txt
  30. CUSTOM_TAGS = custom_tags.txt
  31. # Rule to run nmlc when the NML file changes
  32. # The GRF file is rebuilt every time the PNML files or the graphics files are changed
  33. $(CUSTOM_TAGS): $(TAGS)
  34. $(GCC) -E -x c -D 'GIT_NUMBER=$(GIT_NUMBER)' -D 'CURRENT_TIME=$(TIME)' -o $@ $<
  35. $(NML_FILE): $(CODE_FILES) $(VOX_GENREATED_FILES) $(CUSTOM_TAGS)
  36. $(GCC) -E -x c -D 'GIT_NUMBER=$(GIT_NUMBER)' -o $@ $(INDEX_FILE)
  37. $(GRF_FILE): $(NML_FILE)
  38. $(NMLC) $<
  39. # Rule to run nmlc when the NML file changes
  40. code: $(GRF_FILE)
  41. # clean
  42. clean: clean_grf clean_png
  43. clean_grf:
  44. @echo "Cleaning GRF and NML files"
  45. @rm -f *.grf
  46. @rm -f *.nml
  47. @rm -f $(CUSTOM_TAGS)
  48. clean_png:
  49. @echo "Cleaning PNG files"
  50. @find $(VOX_DIR) -name '*.png' -type f -delete
  51. # this is only for debug purpose, you could modify it to copy the GRF to the OpenTTD data directory
  52. # it should be something like /mnt/c/users/<username>/documents/openttd/newgrf on wsl
  53. copy:
  54. @echo "Copying GRF files to OpenTTD data directory"
  55. @cp $(GRF_FILE) ~/.local/share/openttd/newgrf/$(GRF_FILE)