/
Makefile
161 lines (135 loc) · 5.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
# Various needed programs
GIT = git
PYTHON3 = python3
SED = sed
ZIP = zip
NMLC = nmlc
GRFCODEC = grfcodec
GRFID = grfid
GIT_INFO = $(PYTHON3) src/polar_fox/git_info.py
FILL_TEMPLATE = bin/fill-template
FIND_FILES = bin/find-files
MK_ARCHIVE = bin/mk-archive
# Project details
PROJECT_NAME = iron-horse
GRAPHICS_TARGET = generated/graphics/make_target
LANG_DIR = generated/lang
LANG_TARGET = $(LANG_DIR)/english.lng
-include Makefile.local
EXPORTED = no
ifeq ($(strip $(EXPORTED)),no)
# Not exported source, therefore regular checkout
REPO_INFO = $(shell $(GIT_INFO))
REPO_REVISION = $(word 1,$(REPO_INFO))
REPO_VERSION = $(word 2,$(REPO_INFO))
else
# Exported version, lines below should get modified in 'bundle_src' target
REPO_REVISION = ${exported_revision}
REPO_VERSION = ${exported_version}
endif
REPO_TITLE = "$(PROJECT_NAME) $(REPO_VERSION)"
PROJECT_VERSIONED_NAME = $(PROJECT_NAME)-$(REPO_VERSION)
# Args for faster compiles: PW=n (num pool workers) SC=bool (suppress cargo sprites) SD=bool (suppress docs)
ARGS = '$(PW)' '$(ROSTER)' '$(SC)' '$(SD)'
ifdef ROSTER
GRF_FILES = generated/iron-$(ROSTER).grf
else
GRF_FILES = generated/iron-moose.grf generated/iron-horse.grf
ROSTER = 'ALL'
endif
NFO_FILES = $(GRF_FILES:.grf=.nfo)
NML_FILES = $(GRF_FILES:.grf=.nml)
TAR_FILE = $(PROJECT_VERSIONED_NAME).tar
ZIP_FILE = $(PROJECT_VERSIONED_NAME).zip
MD5_FILE = $(PROJECT_NAME).check.md5
HTML_DOCS = docs
SOURCE_NAME = $(PROJECT_VERSIONED_NAME)-source
BUNDLE_DIR = bundle_dir
# Build rules
.PHONY: default graphics lang nml grf tar bundle_tar bundle_zip bundle_src clean
default: html_docs grf
# bundle needs to clean first to ensure we don't use outdated/cached version info
bundle_tar: clean tar
bundle_zip: $(ZIP_FILE)
release: bundle_tar copy_docs_to_grf_farm
graphics: $(GRAPHICS_TARGET)
lang: $(LANG_TARGET)
nml: $(NML_FILES)
nfo: $(NFO_FILES)
grf: $(GRF_FILES)
tar: $(TAR_FILE)
html_docs: $(HTML_DOCS)
# default num. pool workers for python compile,
# default is 0 to disable multiprocessing (also avoids multiprocessing pickle failures masking genuine python errors)
PW = 0
# option to suppress cargo sprites, makes minor difference to compile time
SC = 'False'
# remove the @ for more verbose output (@ suppresses command output)
_V ?= @
$(GRAPHICS_TARGET): $(shell $(FIND_FILES) --ext=.py --ext=.png src)
$(_V) $(PYTHON3) src/render_graphics.py $(ARGS)
$(_V) touch $(GRAPHICS_TARGET)
$(LANG_TARGET): $(shell $(FIND_FILES) --ext=.py --ext=.pynml --ext=.lng src)
$(_V) $(PYTHON3) src/render_lang.py $(ARGS)
$(HTML_DOCS): $(GRAPHICS_TARGET) $(LANG_TARGET) $(shell $(FIND_FILES) --ext=.py --ext=.pynml --ext=.pt --ext=.lng --ext=.png src)
$(_V) $(PYTHON3) src/render_docs.py $(ARGS)
$(NML_FILES): $(shell $(FIND_FILES) --ext=.py --ext=.pynml src)
$(_V) $(PYTHON3) src/render_nml.py $(ARGS)
# nmlc is used to compile a nfo file only, which is then used by grfcodec
# this means that the (relatively slow) nmlc stage can be skipped if the nml file is unchanged (only graphics changed)
$(NFO_FILES): %.nfo : %.nml $(LANG_TARGET) | $(GRAPHICS_TARGET)
$(NMLC) -l $(LANG_DIR) --verbosity=4 --palette=DEFAULT --no-optimisation-warning --nfo=$@ $<
# N.B grf codec can't compile into a specific target dir, so after compiling, move the compiled grf to appropriate dir
# grfcodec -n was tried, but was slower and produced a large grf file
$(GRF_FILES): %.grf : %.nfo $(GRAPHICS_TARGET)
# we use notdir and dir to get the correct paths from the list of target filenames (which include generated dir)
# result is e.g. grfcodec -s -e -c -g 2 iron-horse.grf generated/
time $(GRFCODEC) -s -e -c -g 2 $(notdir $@) $(dir $<)
mv $(notdir $@) $@
$(TAR_FILE): $(GRF_FILES) $(HTML_DOCS)
# the goal here is a sparse tar for distribution
# create an intermediate dir, and copy in what we need
mkdir $(PROJECT_VERSIONED_NAME)
cp docs/readme.txt $(PROJECT_VERSIONED_NAME)
cp docs/changelog.txt $(PROJECT_VERSIONED_NAME)
cp docs/license.txt $(PROJECT_VERSIONED_NAME)
cp $(GRF_FILES) $(PROJECT_VERSIONED_NAME)
$(MK_ARCHIVE) --tar --output=$(TAR_FILE) $(PROJECT_VERSIONED_NAME)
# delete the intermediate dir
rm -r $(PROJECT_VERSIONED_NAME)
$(ZIP_FILE): $(TAR_FILE)
$(ZIP) -9rq $(ZIP_FILE) $(TAR_FILE) >/dev/null
$(MD5_FILE): $(GRF_FILES)
$(GRFID) -m $(GRF_FILES) > $(MD5_FILE)
bundle_src: $(MD5_FILE)
if test -d $(BUNDLE_DIR); then rm -r $(BUNDLE_DIR); fi
mkdir $(BUNDLE_DIR)
$(GIT) archive -t files $(BUNDLE_DIR)/src
$(FILL_TEMPLATE) --template=Makefile \
--output=$(BUNDLE_DIR)/src/Makefile \
"exported_revision=$(REPO_REVISION)" \
"exported_version=$(REPO_VERSION)"
$(SED) -i -e 's/^EXPORTED = no/EXPORTED = yes/' $(BUNDLE_DIR)/src/Makefile
$(MK_ARCHIVE) --tar --output=$(SOURCE_NAME).tar --base=$(SOURCE_NAME) \
`$(FIND_FILES) $(BUNDLE_DIR)/src` $(MD5_FILE)
# this expects to find a '../../grf.farm' path relative to the project, and will fail otherwise
copy_docs_to_grf_farm:
$(_V) $(PYTHON3) src/polar_fox/grf_farm.py $(PROJECT_NAME)
# this is a macOS-specifc install location; the pre-2017 Makefile handled multiple platforms, that could be restored if needed
# remove first, OpenTTD does not like having the _contents_ of the current file change under it, but will handle a removed-and-replaced file correctly
install: default
# note the switch to shell syntax for vars in the for loop, rather than make syntax;
# also the bash magic to strip directory from GRF_FILE_PATH
$(_V) for GRF_FILE_PATH in $(GRF_FILES) ; do \
rm ~/Documents/OpenTTD/newgrf/$${GRF_FILE_PATH##*/} ; \
cp $$GRF_FILE_PATH ~/Documents/OpenTTD/newgrf/ ; \
done
clean:
$(_V) echo "[CLEANING]"
$(_V) for f in .chameleon_cache .nmlcache src/__pycache__ src/*/__pycache__ docs generated \
$(GRF_FILES) $(TAR_FILE) $(ZIP_FILE) $(MD5_FILE) $(BUNDLE_DIR) $(SOURCE_NAME).tar;\
do if test -e $$f;\
then rm -r $$f;\
fi;\
done
$(_V) echo "[DONE]"