-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
224 lines (177 loc) · 6.2 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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# file: Makefile
###################################################################################################
#
#
# Makefile
#
#
# $ nix-shell --show-trace
# (nix-shell) make -B -j4 build && make -j4 copy-data-to-dist
# (nix-shell) tar czf tiptoe.tar.gz --directory=./dist .
#
#
###################################################################################################
# Run this by default, when no targets are passed to `make`
# .PHONY: all build clean summary test
#------------------------------------------------------------------------------------
# Constants
#------------------------------------------------------------------------------------
BINARY = tiptoe
SRCDIR = ./src
DISTDIR = ./dist
PROG = $(SRCDIR)/tiptoe.py
PROG_EDITOR = $(SRCDIR)/editor.py
TESTSRCS = $(SRCDIR)/test_editor.py $(SRCDIR)/test_game.py
DFLAGS=
DVERBOSE=
#------------------------------------------------------------------------------------
# Variables
#------------------------------------------------------------------------------------
LEVEL = 0
#------------------------------------------------------------------------------------
# Targets
#------------------------------------------------------------------------------------
# Ensure pyinstaller is installed or use inside nix-shell
# See also: ~
# - https://stackoverflow.com/questions/28033003/pyinstaller-with-pygame
build: ./src/game.py
@echo "Starting build"
@pyinstaller --onefile $(PROG) && echo "[info] exit code: $$?"
@stat $(DISTDIR)/$(BINARY)
@echo "Finished build"
copy-data-to-dist:
@echo "copy-data-to-dist"
@echo " - Starting: Copying data"
mkdir -p $(DISTDIR)/src/data
@echo "[info] exit code: $$?"
cp -r $(SRCDIR)/data $(DISTDIR)/src/
@echo "[info] exit code: $$?"
cp -r $(SRCDIR)/config $(DISTDIR)/src
@echo "[info] exit code: $$?"
@echo " - Finished: Copied data"
clean:
@echo "clean"
@stat $(DISTDIR)
@echo " - Starting"
trash --verbose $(DISTDIR)
@echo " - Finished"
edit:
@echo "edit"
@echo " - Starting"
@echo " - Start the editor at level 0:"
@echo " (Tip: make edit LEVEL=1)"
python ${PROG_EDITOR} ${LEVEL}
@echo " - Finished"
# black --quiet $(SRCDIR)
format:
black $(SRCDIR)
run:
@echo "run"
@echo " - Starting"
@echo " - Run the game:"
python ${PROG}
@echo " - Finished"
summary:
@echo "summary"
@echo " - Starting"
@echo " - Display information for the current directory:"
dust --reverse
@echo " - Display a report for the code in a directory and all subdirectories:"
tokei --files
@echo " - Show a history of commits:"
git log --oneline | head
@echo " - Finished"
strace-binary:
@echo "strace-binary"
@strace -c ./dist/$(BINARY)
# make -j4 watch DFLAGS=--debug
watch:
@echo "watch"
@echo " - Starting"
@echo " - Send a `SIGTERM` to any previously spawned python subprocesses before executing 'python tiptoe.py':"
@echo " (TIP: reload: <Space>, exit: <q>)"
@find src -name '*.py' -not -name 'test_*.py' | entr -r python ${PROG} $(DFLAGS)
@echo " - Finished"
targzip:
@echo "tarzip" && echo "[info] $$(date +%s) [c]reating a g[z]ipped archive from a directory using relative paths"
@echo " - Starting"
@tar czvf tiptoe.tar.gz --directory=./dist .
@echo " - Finished" && echo "Finished: tar saved many files together into a single tape or disk archive, that can be restored to individual files from the archive"
@stat tiptoe.tar.gz
#@Redundancy
# make build && make copy-data-to-dist && du -ch ./dist && stat ./dist/$(BINARY)
build-copy-data: build copy-data-to-dist
@du -ch ./dist
@stat ./dist/$(BINARY)
#@Redundancy
dump_all:
@echo "dump"
@echo " - Starting"
@fd --extension py . | xargs -I _ cat _ | hexdump -C | cat
@echo " - Finished"
#@Redundancy
od_all:
@echo "dump"
@echo " - Starting"
@fd --extension py . | xargs -I _ cat _ | od | cat
@echo " - Finished"
#------------------------------------------------------------------------------------
# Tests
#------------------------------------------------------------------------------------
# ❯ python -m doctest src/internal/prelude.py -v
# ❯ find . -name 'prelude.py' | entr -cprs 'make -j4 doctest'
doctest:
@echo "doctest"
@echo " - Starting"
# find . -name '*.py' | xargs -I _ python -m doctest _
python -m doctest ./src/internal/prelude.py
@echo " - Finished"
# time parallel -j4 --bar --eta python ::: $(TESTSRCS) && echo "exit code: $$?"
test:
@echo "test" && echo "[info] $$(date +%s) NOTE: Test works only for builtin unittest"
@echo " - Starting"
find src -name "test_*.py" | parallel -j 4 --bar --eta python {}
@echo " - Finished"
# find src -name 'test_*.py' | entr -cprs 'make -j4 pytest'
#
#to raise errors on warnings:
# make pytest DVERBOSE='-W error::UserWarning'
#or ignore warnings:
# make -j4 pytest DVERBOSE='-W ignore::DeprecationWarning'
# time find src -name 'test_*.py' | xargs -I _ pytest $(DVERBOSE) -W ignore::DeprecationWarning _
# time find src -name 'test_*.py' | xargs -I _ pytest $(DVERBOSE) -W ignore::DeprecationWarning _
watch-pytest:
@echo "pytest" && echo "[info] $$(date +%s) Testing via pytest"
@echo " - Starting"
find src -name 'test_*.py' | entr -cprs 'pytest -W ignore::DeprecationWarning $(DVERBOSE) src'
@echo " - Finished"
# fd -e py . | entr -cprs 'make -j4 test-discover'
# -s starting directory
# -p pattern
test-discover:
@echo "test" && echo "[info] $$(date +%s) Testing via python -m unittest discover"
@echo " - Starting"
@python -m unittest discover -s src -p "test*.py"
@echo " - Finished"
#------------------------------------------------------------------------------------
# Notes
#------------------------------------------------------------------------------------
# Override a variable defined in the Makefile:
#
# make target variable=new_value
# Force making of a target, even if source files are unchanged:
#
# make --always-make target
# #
# # $ ls *.cpp | entr -r make memcheck-build-run-credits
# #
# memcheck-build-run-credits:
# @echo "buildruncredits"
# @echo " - Starting"
# @echo " - build"
# clang++ -g -std=c++11 gcredits.cpp -o build/gcredits -DLAB_SLOW=1
# @echo " - run"
# valgrind -s --leak-check=full ./build/gcredits
# @echo " - Finished"
#
#------------------------------------------------------------------------------