Loading

Paste #pbyx4naaq

  1. # Various needed programs
  2. HG= hg
  3. PYTHON3 = python3
  4. SED = sed
  5. ZIP = zip
  6.  
  7. NMLC = nmlc
  8. GRFID = grfid
  9.  
  10. HG_INFO = bin/hg-info
  11. FILL_TEMPLATE = bin/fill-template
  12. FIND_FILES = bin/find-files
  13. MK_ARCHIVE = bin/mk-archive
  14.  
  15.  
  16. # Project details
  17. PROJECT_NAME = firs
  18. SOURCES=$(shell $(FIND_FILES) --ext=.py --ext=.pynml src)
  19.  
  20. DOCS_DIR = docs
  21. # graphics is not copied to generated currently in FIRS, unlike RH, IH etc - could be changed
  22. GRAPHICS_DIR = src/graphics
  23. # lang is not copied to generated currently in FIRS, unlike RH, IH etc - could be changed
  24. LANG_DIR = src/lang
  25. NML_FILE = generated/firs.nml
  26. NML_FLAGS =-c -l $(LANG_DIR)
  27.  
  28. EXPORTED = no
  29. ifeq ($(strip $(EXPORTED)),no)
  30.   # Not exported source, therefore regular checkout
  31.   REPO_INFO = $(shell $(HG_INFO) --num-id --version)
  32.   REPO_REVISION = $(word 1,$(REPO_INFO))
  33.   REPO_VERSION = $(word 2,$(REPO_INFO))
  34. else
  35.   # Exported version, lines below should get modified in 'bundle_src' target
  36.   REPO_REVISION = ${exported_revision}
  37.   REPO_VERSION = ${exported_version}
  38. endif
  39.  
  40. REPO_TITLE = "$(PROJECT_NAME) $(REPO_VERSION)"
  41. PROJECT_VERSIONED_NAME = $(PROJECT_NAME)-$(REPO_VERSION)
  42. ARGS = '${REPO_TITLE}' '${REPO_REVISION}' '${TEST_INDUSTRY}' '${NO_MP}'
  43.  
  44. GRF_FILE = $(PROJECT_NAME).grf
  45. TAR_FILE = $(PROJECT_NAME).tar
  46. ZIP_FILE = $(PROJECT_NAME).zip
  47. MD5_FILE = $(PROJECT_NAME).check.md5
  48.  
  49. DOC_FILES = docs/license.txt docs/changelog.txt
  50. HTML_DOCS = docs
  51.  
  52. SOURCE_NAME = $(PROJECT_VERSIONED_NAME)-source
  53. BUNDLE_DIR = bundle_dir
  54.  
  55. # graphviz tools
  56. GVPR ?= $(shell which gvpr)
  57. DOT  ?= $(shell which dot)
  58.  
  59. # Build rules
  60. .PHONY: default graphics lang nml grf tar bundle_tar bundle_zip bundle_src clean
  61. default: html_docs grf
  62. bundle_tar: tar
  63. bundle_zip: $(ZIP_FILE)
  64. graphics: $(GRAPHICS_DIR)
  65. lang: $(LANG_DIR)
  66. nml: $(NML_FILE)
  67. grf: $(GRF_FILE)
  68. tar: $(TAR_FILE)
  69. html_docs: $(HTML_DOCS)
  70.  
  71. custom_tags.txt: custom_tags.template
  72.     $(FILL_TEMPLATE) --template=custom_tags.template --output=custom_tags.txt \
  73.         version=$(VERSION)
  74.  
  75. # determining deps reliably for graphics generation is hard, as graphics processor depends on many things so always rebuild all
  76. $(GRAPHICS_DIR):
  77.     $(PYTHON3) src/render_graphics.py $(ARGS)
  78.  
  79. $(LANG_DIR):
  80.     $(PYTHON3) src/render_lang.py $(ARGS)
  81.  
  82. $(NML_FILE): $(SOURCES)
  83.     $(PYTHON3) src/render_nml.py $(ARGS)
  84.  
  85. $(GRF_FILE): $(GRAPHICS_DIR) $(LANG_DIR) $(NML_FILE) custom_tags.txt $(HTML_DOCS)
  86.     $(NMLC) $(NML_FLAGS) --grf=$(GRF_FILE) $(NML_FILE)
  87.  
  88. $(HTML_DOCS):
  89.     $(PYTHON3) src/render_docs.py $(ARGS)
  90.  
  91. # Insane trick to check whether both DOT and GVPR are not empty.
  92. ifeq ($(DOT)$(GVPR),$(GVPR)$(DOT))
  93.     echo "[HTML DOCS] graphviz not found, skipping cargo flow graphs"
  94. else
  95.     mkdir docs/html/static/img/cargoflow
  96.     $(GVPR) 'BEG_G { fname = sprintf("docs/html/%s.dot", $$G.name); writeG($$G, fname) }' docs/cargoflow.dotall
  97.     cd docs/html; $(DOT) -Tsvg -O *.dot
  98. endif
  99.  
  100. $(TAR_FILE): $(GRF_FILE)
  101.     $(MK_ARCHIVE) --tar --output=$(TAR_FILE) --base=$(PROJECT_VERSIONED_NAME) docs $(GRF_FILE)
  102.  
  103. $(ZIP_FILE): $(TAR_FILE)
  104.     $(ZIP) -9rq $(ZIP_FILE) $(TAR_FILE) >/dev/null
  105.  
  106. $(MD5_FILE): $(GRF_FILE)
  107.     $(GRFID) -m $(GRF_FILE) > $(MD5_FILE)
  108.  
  109. bundle_src: $(MD5_FILE)
  110.     if test -d $(BUNDLE_DIR); then rm -r $(BUNDLE_DIR); fi
  111.     mkdir $(BUNDLE_DIR)
  112.     $(HG) archive -t files $(BUNDLE_DIR)/src
  113.     $(FILL_TEMPLATE) --template=Makefile \
  114.         --output=$(BUNDLE_DIR)/src/Makefile \
  115.         "exported_revision=$(REPO_REVISION)" \
  116.         "exported_version=$(REPO_VERSION)"
  117.     $(SED) -i -e 's/^EXPORTED = no/EXPORTED = yes/' $(BUNDLE_DIR)/src/Makefile
  118.     $(MK_ARCHIVE) --tar --output=$(SOURCE_NAME).tar --base=$(SOURCE_NAME) \
  119.         `$(FIND_FILES) $(BUNDLE_DIR)/src` $(MD5_FILE)
  120.  
  121. # this is a macOS-specifc install location; the pre-2017 Makefile handled multiple platforms, that could be restored if needed
  122. install: firs.grf
  123.     cp firs.grf ~/Documents/OpenTTD/newgrf/
  124.  
  125. clean:
  126.     for f in .chameleon_cache .nmlcache src/__pycache__ src/*/__pycache__ docs generated \
  127.     $(GRF_FILE) $(TAR_FILE) $(ZIP_FILE) $(MD5_FILE) $(BUNDLE_DIR) $(SOURCE_NAME).tar custom_tags.txt;\
  128.     do if test -e $$f;\
  129.        then rm -r $$f;\
  130.        fi;\
  131.     done

Comments