Skip to content

Commit

Permalink
change to use makefile building
Browse files Browse the repository at this point in the history
  • Loading branch information
Babel-TTT committed Feb 23, 2025
1 parent 70594ad commit 1e13fea
Show file tree
Hide file tree
Showing 18 changed files with 2,184 additions and 1,735 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ chinasettrains-*
gfx/**/*.png
!gfx/*.png
*.lng
*.zip
*.zip
custom_tags.txt
100 changes: 100 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# general
-include Makefile.config
# tools, sprites, lang, code entries need to be specified in Makefile.config
# though the Makefile itself provides default values that can be used if
# following the build instructions in README.md (using scoop to install the tools)
#
# You can override the default values by specifying them in Makefile.config
# this would be useful if e.g. you manually compiled gorender and it's not in your PATH

# tools
PYTHON ?= python3

# sprites

# this default value assumes you have renderobject in your PATH
GORENDER ?= renderobject --palette "ttd_palette.json" -overwrite
VOX_DIR ?= gfx/*
PALETTE ?= ttd_palette.json
MANIFEST ?= manifest.json

# lang
LANG_SCRIPT ?= ./str-csv.py
LANG_SRC ?= docs/str.csv

# code
NMLC ?= nmlc -c
GCC ?= gcc
PROJECT ?= chinasettrains
DOC_FILES ?= license.txt readme.txt changelog.txt
INDEX_FILE ?= chinaset-mtraddon.pnml
OUTPUT_NML ?= chinaset-mtraddon.nml
OUTPUT_GRF ?= chinaset-mtraddon.grf
CUSTOM_TAG_FILE ?= custom_tags.txt

# version
-include Makefile.dist
REPO_REVISION ?= 1 # specify in Makefile.dist
REPO_VERSION_STRING ?= 0.0.1.1 # specify in Makefile.dist

.PHONY: all sprites custom_tags code clean clean_grf clean_png bundle FORCE

# default rule
all: sprites lang code

# voxel paths
VOX_FILES = $(wildcard $(VOX_DIR)/*.vox wildcard $(VOX_DIR)/*/*.vox)

VOX_8BPP_FILES = $(addsuffix _8bpp.png, $(basename $(VOX_FILES)))
VOX_32BPP_FILES = $(addsuffix _32bpp.png, $(basename $(VOX_FILES)))
VOX_MASK_FILES = $(addsuffix _mask.png, $(basename $(VOX_FILES)))

VOX_GENREATED_FILES = $(VOX_8BPP_FILES) $(VOX_32BPP_FILES) $(VOX_MASK_FILES)

%_8bpp.png %_32bpp.png %_mask.png: %.vox
@echo "Rendering, manifest = $(dir $<)/$(MANIFEST), palette = $(dir $<)/$(PALETTE), $<"
@$(GORENDER) -m $(dir $<)/$(MANIFEST) --palette $(dir $<)/$(PALETTE) $<

# sprites
sprites: $(VOX_GENREATED_FILES)

# lang
lang: FORCE
@echo "Generating lang files"
@$(PYTHON) $(LANG_SCRIPT) $(LANG_SRC)

# code
custom_tags: FORCE
@echo "Generating custom tags"
@echo "VERSION_STRING :$(REPO_VERSION_STRING)" > $(CUSTOM_TAG_FILE)

code: custom_tags lang $(VOX_GENERATED_FILES) FORCE
@echo "Preprocessing"
@$(GCC) -E -x c -D REPO_REVISION=$(REPO_REVISION) -D VERSION_STRING=$(REPO_VERSION_STRING) $(INDEX_FILE) > $(OUTPUT_NML)
@echo "Compiling"
@$(NMLC) $(OUTPUT_NML) -o $(OUTPUT_GRF)

# clean
clean: clean_grf clean_png

clean_grf:
@echo "Cleaning GRF and NML files"
@echo "Warning: clean grf won't work when using powershell, please use bash instead."
@rm -f *.grf
@rm -f *.nml
@rm -f $(CUSTOM_TAG_FILE)

clean_png:
@echo "Cleaning PNG files"
@echo "Warning: clean png won't work when using powershell, please use bash instead."
@find $(VOX_DIR)/ -name '*.png' -type f -delete

bundle: code FORCE
@echo "Bundling"
cd docs
cp $(OUTPUT_GRF) docs/
cd docs; tar -cf ../$(PROJECT)-$(REPO_VERSION_STRING).tar $(DOC_FILES) $(OUTPUT_GRF)
rm docs/$(OUTPUT_GRF)

# dummy rule for force rebuilding
FORCE: ;
2 changes: 2 additions & 0 deletions Makefile.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
REPO_REVISION := 30
REPO_VERSION_STRING := 0.3.0
Loading

0 comments on commit 1e13fea

Please sign in to comment.