-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
133 lines (109 loc) · 4.38 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
# Various needed programs
HG= hg
PYTHON3 = python3
SED = sed
ZIP = zip
NMLC = nmlc
GRFID = grfid
HG_INFO = bin/hg-info
FILL_TEMPLATE = bin/fill-template
FIND_FILES = bin/find-files
MK_ARCHIVE = bin/mk-archive
# Project details
PROJECT_NAME = road-hog
GRAPHICS_DIR = generated/graphics
LANG_DIR = generated/lang
NML_FILE = generated/road-hog.nml
NML_FLAGS =-c -l $(LANG_DIR)
EXPORTED = no
ifeq ($(strip $(EXPORTED)),no)
# Not exported source, therefore regular checkout
REPO_INFO = $(shell $(HG_INFO) --num-id --version)
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 = '$(REPO_REVISION)' '$(REPO_VERSION)' '$(PW)' '$(ROSTER)'
GRF_FILE = generated/$(PROJECT_NAME).grf
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_tar: tar
bundle_zip: $(ZIP_FILE)
release: bundle_tar copy_docs_to_grf_farm
graphics: $(GRAPHICS_DIR)
lang: $(LANG_DIR)
nml: $(NML_FILE)
grf: $(GRF_FILE)
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
ROSTER = *
# remove the @ for more verbose output (@ suppresses command output)
_V ?= @
$(GRAPHICS_DIR): $(shell $(FIND_FILES) --ext=.py --ext=.png src)
$(_V) $(PYTHON3) src/render_graphics.py $(ARGS)
$(LANG_DIR): $(shell $(FIND_FILES) --ext=.py --ext=.pynml --ext=.lng src)
$(_V) $(PYTHON3) src/render_lang.py $(ARGS)
$(HTML_DOCS): $(GRAPHICS_DIR) $(shell $(FIND_FILES) --ext=.py --ext=.pynml --ext=.pt --ext=.lng src)
$(_V) $(PYTHON3) src/render_docs.py $(ARGS)
$(NML_FILE): $(shell $(FIND_FILES) --ext=.py --ext=.pynml src)
$(_V) $(PYTHON3) src/render_nml.py $(ARGS)
$(GRF_FILE): $(GRAPHICS_DIR) $(LANG_DIR) $(NML_FILE) $(HTML_DOCS)
$(NMLC) $(NML_FLAGS) --grf=$(GRF_FILE) $(NML_FILE)
$(TAR_FILE): $(GRF_FILE)
# the goal here is a sparse tar that bananas will accept; bananas can't accept html docs etc, hence they're not included
# create an intermediate dir, and copy in what we need for bananas
mkdir $(PROJECT_VERSIONED_NAME)
cp docs/readme.txt $(PROJECT_VERSIONED_NAME)
cp docs/license.txt $(PROJECT_VERSIONED_NAME)
cp docs/changelog.txt $(PROJECT_VERSIONED_NAME)
cp $(GRF_FILE) $(PROJECT_VERSIONED_NAME)
$(MK_ARCHIVE) --tar --output=$(TAR_FILE) --base=$(PROJECT_VERSIONED_NAME) $(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_FILE)
$(GRFID) -m $(GRF_FILE) > $(MD5_FILE)
bundle_src: $(MD5_FILE)
if test -d $(BUNDLE_DIR); then rm -r $(BUNDLE_DIR); fi
mkdir $(BUNDLE_DIR)
$(HG) 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
install: $(GRF_FILE)
# 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
rm ~/Documents/OpenTTD/newgrf/$(PROJECT_NAME).grf
cp $(GRF_FILE) ~/Documents/OpenTTD/newgrf/
clean:
$(_V) echo "[CLEANING]"
$(_V) for f in .chameleon_cache .nmlcache src/__pycache__ src/*/__pycache__ docs generated \
$(GRF_FILE) $(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]"