-
Notifications
You must be signed in to change notification settings - Fork 54
/
Makefile
139 lines (114 loc) · 4.54 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
# Various needed programs
GIT = git
PYTHON3 = python3
SED = sed
ZIP = zip
NMLC = nmlc
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 = firs
# lang is not copied to generated currently in FIRS, unlike RH, IH etc - could be changed
LANG_DIR = generated/lang
NML_FILE = generated/firs.nml
NML_FLAGS =-c -l $(LANG_DIR) --verbosity=4 --no-optimisation-warning
-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
PROJECT_VERSIONED_NAME = $(PROJECT_NAME)-$(REPO_VERSION)
ARGS = '${TEST_INDUSTRY}' '${NO_MP}'
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
# graphviz tools
GVPR ?= $(shell which gvpr)
DOT ?= $(shell which dot)
# 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
lang: $(LANG_DIR)
nml: $(NML_FILE)
grf: $(GRF_FILE)
tar: $(TAR_FILE)
html_docs: $(HTML_DOCS)
# remove the @ for more verbose output (@ suppresses command output)
_V ?= @
$(LANG_DIR): $(shell $(FIND_FILES) --ext=.py --ext=.pynml --ext=.lng src)
$(_V) $(PYTHON3) src/render_lang.py $(ARGS)
$(HTML_DOCS): $(shell $(FIND_FILES) --ext=.py --ext=.pynml --ext=.pt --ext=.lng src)
$(_V) $(PYTHON3) src/render_docs.py $(ARGS)
# Insane trick to check whether both DOT and GVPR are not empty.
ifeq ($(DOT)$(GVPR),$(GVPR)$(DOT))
echo "[HTML DOCS] graphviz not found, skipping cargo flow graphs"
else
mkdir docs/html/static/img/cargoflow
$(GVPR) 'BEG_G { fname = sprintf("docs/html/%s.dot", $$G.name); writeG($$G, fname) }' docs/cargoflow.dotall
cd docs/html; $(DOT) -Tsvg -O *.dot
endif
$(NML_FILE): $(shell $(FIND_FILES) --ext=.py --ext=.pynml src)
$(_V) $(PYTHON3) src/render_nml.py $(ARGS)
$(GRF_FILE): $(shell $(FIND_FILES) --ext=.py --ext=.png src) $(LANG_DIR) $(NML_FILE) $(HTML_DOCS)
$(NMLC) $(NML_FLAGS) --grf=$(GRF_FILE) $(NML_FILE)
$(TAR_FILE): $(GRF_FILE) $(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_FILE) $(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_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)
$(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
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]"