-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
361 lines (303 loc) · 13.4 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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
#!/usr/bin/env make -f
# Multicast Python Module
# ..................................
# Copyright (c) 2017-2025, Mr. Walls
# ..................................
# Licensed under MIT (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# ..........................................
# http://www.github.com/reactive-firewall/multicast/LICENSE.md
# ..........................................
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
ifeq "$(LC_CTYPE)" ""
LC_CTYPE="en_US.UTF-8"
endif
ifndef SHELL
SHELL:=command -pv bash
endif
ifeq "$(ERROR_LOG_PATH)" ""
ERROR_LOG_PATH="/dev/null"
endif
ifeq "$(COMMAND)" ""
COMMAND_CMD!=`command -v xcrun || command which which || command -v which || command -v command`
ifeq "$(COMMAND_CMD)" "*xcrun"
COMMAND_ARGS=--find
endif
ifeq "$(COMMAND_CMD)" "*command"
COMMAND_ARGS=-pv
endif
COMMAND=$(COMMAND_CMD) $(COMMAND_ARGS)
endif
ifeq "$(MAKE)" ""
# just no cmake please
MAKEFLAGS=$(MAKEFLAGS) -s
MAKE!=`$(COMMAND) make 2>$(ERROR_LOG_PATH) || $(COMMAND) gnumake 2>$(ERROR_LOG_PATH)`
endif
ifeq "$(ECHO)" ""
ECHO=printf "%s\n"
endif
ifdef "$(ACTION)"
SET_FILE_ATTR=$(COMMAND) xattr
endif
ifdef "$(SET_FILE_ATTR)"
CREATEDBYBUILDSYSTEM=-w com.apple.xcode.CreatedByBuildSystem true
BSMARK=$(SET_FILE_ATTR) $(CREATEDBYBUILDSYSTEM)
else
BSMARK=$(COMMAND) touch -a
endif
ifeq "$(LINK)" ""
LINK=ln -sf
endif
ifeq "$(PYTHON)" ""
PY_CMD=$(COMMAND) python3
ifneq "$(PY_CMD)" ""
PY_ARGS=-B
else
PY_CMD=$(COMMAND) python
endif
PYTHON=$(PY_CMD) $(PY_ARGS)
ifeq "$(COVERAGE)" ""
COVERAGE=$(PYTHON) -m coverage
#COV_CORE_SOURCE = $(dir $(abspath $(lastword $(MAKEFILE_LIST))))/
COV_CORE_CONFIG = $(dir $(abspath $(lastword $(MAKEFILE_LIST))))/.coveragerc
COV_CORE_DATAFILE = .coverage
endif
ifeq "$(COVERAGE)" ""
COVERAGE!=$(COMMAND) coverage
endif
else
ifeq "$(COVERAGE)" ""
COVERAGE!=$(COMMAND) coverage
#COV_CORE_SOURCE = $(dir $(abspath $(lastword $(MAKEFILE_LIST))))/
COV_CORE_CONFIG = $(dir $(abspath $(lastword $(MAKEFILE_LIST))))/.coveragerc
COV_CORE_DATAFILE = .coverage
endif
endif
ifndef PIP_COMMON_FLAGS
# Define common pip install flags
PIP_COMMON_FLAGS := --use-pep517 --exists-action s --upgrade --upgrade-strategy eager
endif
# Define environment-specific pip install flags
ifeq ($(shell uname),Darwin)
PIP_ENV_FLAGS := --break-system-packages
else
PIP_ENV_FLAGS :=
endif
ifeq "$(WAIT)" ""
WAIT=wait
endif
ifeq "$(INSTALL)" ""
INSTALL=install
ifeq "$(INST_OWN)" ""
INST_OWN=-o root -g staff
endif
ifeq "$(INST_OPTS)" ""
INST_OPTS=-m 755
endif
endif
ifeq "$(LOG)" ""
LOG=no
endif
ifeq "$(LOG)" "no"
QUIET=@
ifeq "$(DO_FAIL)" ""
DO_FAIL=$(ECHO) "ok"
endif
endif
ifeq "$(DO_FAIL)" ""
DO_FAIL=$(COMMAND) :
endif
ifeq "$(RM)" ""
RM=$(COMMAND) rm -f
endif
ifeq "$(RMDIR)" ""
RMDIR=$(RM)Rd
endif
.PHONY: all clean test cleanup init help clean-docs must_be_root must_have_flake must_have_pytest uninstall cleanup-dev-backups
help:
$(QUIET)printf "HELP\nHouse-keeping:\n\tmake help - this help text\n\tmake build - packages the module\n\tmake clean - cleans up a bit\n\tmake init - sets up requirements for first time\nInstall/Remove:\n\tmake install - installs the module properly\n\tmake user-install - tries an unprivileged install (may not work for some users)\n\tmake uninstall - uninstalls the module\n\tmake purge - uninstalls the module, and resets most related things\n\t\t(the big exception is init)\nMisc:\n\tmake build-docs - generate documentation (using sphinx)\n\tmake test - run minimal acceptance testing\n\tmake test-style - run some code-style testing\n\tmake test-pytest - run extensive testing (with pytest)\n\n";
MANIFEST.in: init
$(QUIET)$(ECHO) "include requirements.txt" >"$@" ;
$(QUIET)$(BSMARK) "$@" 2>$(ERROR_LOG_PATH) >$(ERROR_LOG_PATH) || true ;
$(QUIET)$(ECHO) "include README.md" >>"$@" ;
$(QUIET)$(ECHO) "include LICENSE.md" >>"$@" ;
$(QUIET)$(ECHO) "include CHANGES.md" >>"$@" ;
$(QUIET)$(ECHO) "include HISTORY.md" >>"$@" ;
$(QUIET)$(ECHO) "recursive-include . *.txt" >>"$@" ;
$(QUIET)$(ECHO) "exclude .gitignore" >>"$@" ;
$(QUIET)$(ECHO) "exclude .deepsource.toml" >>"$@" ;
$(QUIET)$(ECHO) "exclude .*.ini" >>"$@" ;
$(QUIET)$(ECHO) "exclude .*.yml" >>"$@" ;
$(QUIET)$(ECHO) "exclude .*.yaml" >>"$@" ;
$(QUIET)$(ECHO) "exclude package.json" >>"$@" ;
$(QUIET)$(ECHO) "global-exclude .git" >>"$@" ;
$(QUIET)$(ECHO) "global-exclude codecov_env" >>"$@" ;
$(QUIET)$(ECHO) "global-exclude .DS_Store" >>"$@" ;
$(QUIET)$(ECHO) "prune .gitattributes" >>"$@" ;
$(QUIET)$(ECHO) "prune test-reports" >>"$@" ;
$(QUIET)$(ECHO) "prune .github" >>"$@" ;
$(QUIET)$(ECHO) "prune .circleci" >>"$@" ;
build: init ./setup.py MANIFEST.in
$(QUIET)$(PYTHON) -W ignore -m build --sdist --wheel --no-isolation ./ || $(QUIET)$(PYTHON) -W ignore -m build ./ ;
$(QUITE)$(WAIT)
$(QUIET)$(ECHO) "build DONE."
init:
$(QUIET)$(PYTHON) -m pip install $(PIP_COMMON_FLAGS) $(PIP_ENV_FLAGS) "pip>=24.3.1" "setuptools>=75.0" "wheel>=0.44" "build>=1.1.1" 2>$(ERROR_LOG_PATH) || :
$(QUIET)$(PYTHON) -m pip install $(PIP_COMMON_FLAGS) $(PIP_ENV_FLAGS) -r requirements.txt 2>$(ERROR_LOG_PATH) || :
$(QUIET)$(ECHO) "$@: Done."
install: init build must_be_root
$(QUIET)$(PYTHON) -m pip install $(PIP_COMMON_FLAGS) $(PIP_ENV_FLAGS) -e "git+https://github.com/reactive-firewall/multicast.git#egg=multicast"
$(QUITE)$(WAIT)
$(QUIET)$(ECHO) "$@: Done."
uninstall:
$(QUIET)$(PYTHON) -m pip uninstall --use-pep517 $(PIP_ENV_FLAGS) --no-input -y multicast 2>$(ERROR_LOG_PATH) || :
$(QUITE)$(WAIT)
$(QUIET)$(ECHO) "$@: Done."
legacy-purge: clean uninstall
$(QUIET)$(PYTHON) -W ignore ./setup.py uninstall 2>$(ERROR_LOG_PATH) || :
$(QUIET)$(PYTHON) -W ignore ./setup.py clean 2>$(ERROR_LOG_PATH) || :
$(QUIET)$(RMDIR) ./build/ 2>$(ERROR_LOG_PATH) || :
$(QUIET)$(RMDIR) ./dist/ 2>$(ERROR_LOG_PATH) || :
$(QUIET)$(RMDIR) ./.eggs/ 2>$(ERROR_LOG_PATH) || :
purge: legacy-purge
$(QUIET)$(RM) ./test-reports/*.xml 2>$(ERROR_LOG_PATH) || :
$(QUIET)$(RMDIR) ./test-reports/ 2>$(ERROR_LOG_PATH) || :
$(QUIET)$(ECHO) "$@: Done."
just-test: cleanup MANIFEST.in
$(QUIET)$(COVERAGE) run -p --source=multicast -m unittest discover --verbose --buffer -s ./tests -t $(dir $(abspath $(lastword $(MAKEFILE_LIST)))) || $(PYTHON) -m unittest discover --verbose --buffer -s ./tests -t ./ || DO_FAIL="exit 2" ;
$(QUITE)$(WAIT) ;
$(QUIET)$(DO_FAIL) ;
test: just-test
$(QUIET)$(DO_FAIL) ;
$(QUIET)$(COVERAGE) combine 2>$(ERROR_LOG_PATH) || : ;
$(QUIET)$(COVERAGE) report -m --include=* 2>$(ERROR_LOG_PATH) || : ;
$(QUIET)$(ECHO) "$@: Done."
test-tox: build
$(QUIET)tox -v -- || tail -n 500 .tox/py*/log/py*.log 2>$(ERROR_LOG_PATH)
$(QUIET)$(COVERAGE) combine 2>$(ERROR_LOG_PATH) || : ;
$(QUIET)$(COVERAGE) report -m --include=* 2>$(ERROR_LOG_PATH) || : ;
$(QUIET)$(ECHO) "$@: Done."
test-reports:
$(QUIET)mkdir $(INST_OPTS) ./test-reports 2>$(ERROR_LOG_PATH) >$(ERROR_LOG_PATH) || true ;
$(QUIET)$(BSMARK) ./test-reports 2>$(ERROR_LOG_PATH) >$(ERROR_LOG_PATH) || true ;
$(QUIET)$(ECHO) "$@: Done."
test-reqs: test-reports init
$(QUIET)$(PYTHON) -m pip install $(PIP_COMMON_FLAGS) $(PIP_ENV_FLAGS) -r tests/requirements.txt 2>$(ERROR_LOG_PATH) || true
docs-reqs: ./docs/ ./docs/requirements.txt init
$(QUIET)$(PYTHON) -m pip install $(PIP_COMMON_FLAGS) $(PIP_ENV_FLAGS) -r docs/requirements.txt 2>$(ERROR_LOG_PATH) || : ;
$(QUIET)$(WAIT) ;
test-pytest: cleanup MANIFEST.in must_have_pytest test-reports
$(QUIET)$(PYTHON) -m pytest --cache-clear --doctest-glob=multicast/*.py,tests/*.py --doctest-modules --cov=. --cov-append --cov-report=xml --junitxml=test-reports/junit.xml -v --rootdir=. || DO_FAIL="exit 2" ;
$(QUITE)$(WAIT) ;
$(QUIET)$(DO_FAIL) ;
$(QUIET)$(ECHO) "$@: Done."
test-style: cleanup must_have_flake
$(QUIET)$(PYTHON) -m flake8 --ignore=W191,W391 --max-line-length=100 --verbose --count --config=.flake8.ini --show-source || DO_FAIL="exit 2" ;
$(QUITE)$(WAIT) ;
$(QUIET)$(DO_FAIL) ;
$(QUIET)tests/check_spelling || true
$(QUIET)tests/check_cc_lines || true
$(QUIET)$(ECHO) "$@: Done."
must_have_flake:
$(QUIET)runner=`$(PYTHON) -m pip freeze --all | grep --count -oF flake` ; \
if test $$runner -le 0 ; then $(ECHO) "No Linter found for test." ; exit 126 ; fi
must_have_pytest: init
$(QUIET)runner=`$(PYTHON) -m pip freeze --all | grep --count -oF pytest` ; \
if test $$runner -le 0 ; then $(ECHO) "No python framework (pytest) found for test." ; exit 126 ; fi
cleanup-dev-backups::
$(QUIET)$(RM) ./*/*~ 2>$(ERROR_LOG_PATH) || :
$(QUIET)$(RM) ./.*/*~ 2>$(ERROR_LOG_PATH) || :
$(QUIET)$(RM) ./**/*~ 2>$(ERROR_LOG_PATH) || :
$(QUIET)$(RM) ./*~ 2>$(ERROR_LOG_PATH) || :
$(QUIET)$(RM) ./.*~ 2>$(ERROR_LOG_PATH) || :
cleanup-mac-dir-store::
$(QUIET)$(RM) ./.DS_Store 2>$(ERROR_LOG_PATH) || :
$(QUIET)$(RM) ./*/.DS_Store 2>$(ERROR_LOG_PATH) || :
$(QUIET)$(RM) ./*/.DS_Store 2>$(ERROR_LOG_PATH) || :
$(QUIET)$(RM) ./*/**/.DS_Store 2>$(ERROR_LOG_PATH) || :
cleanup-py-caches: cleanup-dev-backups cleanup-mac-dir-store
$(QUIET)$(RM) ./*.pyc 2>$(ERROR_LOG_PATH) || :
$(QUIET)$(RM) ./*/*.pyc 2>$(ERROR_LOG_PATH) || :
$(QUIET)$(RM) ./*/__pycache__/* 2>$(ERROR_LOG_PATH) || :
$(QUIET)$(RM) ./*/*/*.pyc 2>$(ERROR_LOG_PATH) || :
cleanup-py-cache-dirs: cleanup-py-caches
$(QUIET)$(RMDIR) ./tests/__pycache__ 2>$(ERROR_LOG_PATH) || :
$(QUIET)$(RMDIR) ./*/__pycache__ 2>$(ERROR_LOG_PATH) || :
$(QUIET)$(RMDIR) ./*/*/__pycache__ 2>$(ERROR_LOG_PATH) || :
$(QUIET)$(RMDIR) ./__pycache__ 2>$(ERROR_LOG_PATH) || :
cleanup-hypothesis::
$(QUIET)$(RM) ./.hypothesis/**/* 2>$(ERROR_LOG_PATH) || true
$(QUIET)$(RM) ./.hypothesis/* 2>$(ERROR_LOG_PATH) || true
$(QUIET)$(RMDIR) ./.hypothesis/ 2>$(ERROR_LOG_PATH) || true
cleanup-tests: cleanup-hypothesis cleanup-py-cache-dirs cleanup-py-caches
$(QUIET)$(RM) ./test_env/**/* 2>$(ERROR_LOG_PATH) || true
$(QUIET)$(RM) ./test_env/* 2>$(ERROR_LOG_PATH) || true
$(QUIET)$(RMDIR) ./test_env/ 2>$(ERROR_LOG_PATH) || true
$(QUIET)$(RMDIR) .pytest_cache/ 2>$(ERROR_LOG_PATH) || true
$(QUIET)$(RMDIR) ./.tox/ 2>$(ERROR_LOG_PATH) || true
cleanup-multicast: cleanup-py-cache-dirs cleanup-py-caches
$(QUIET)$(RM) multicast/*.pyc 2>$(ERROR_LOG_PATH) || true
$(QUIET)$(RM) multicast/*~ 2>$(ERROR_LOG_PATH) || true
$(QUIET)$(RM) multicast/__pycache__/* 2>$(ERROR_LOG_PATH) || true
$(QUIET)$(RM) multicast/*/*.pyc 2>$(ERROR_LOG_PATH) || true
cleanup-multicast-eggs: cleanup-dev-backups cleanup-mac-dir-store
$(QUIET)$(RM) multicast.egg-info/* 2>$(ERROR_LOG_PATH) || true
$(QUIET)$(RMDIR) multicast.egg-info 2>$(ERROR_LOG_PATH) || true
$(QUIET)$(RMDIR) .eggs 2>$(ERROR_LOG_PATH) || true
$(QUIET)$(RMDIR) ./.eggs/ 2>$(ERROR_LOG_PATH) || true
cleanup-src-dir: cleanup-dev-backups cleanup-mac-dir-store
$(QUIET)$(RM) ./src/**/* 2>$(ERROR_LOG_PATH) || true
$(QUIET)$(RM) ./src/* 2>$(ERROR_LOG_PATH) || true
$(QUIET)$(RMDIR) ./src/ 2>$(ERROR_LOG_PATH) || true
cleanup: cleanup-tests cleanup-multicast cleanup-multicast-eggs cleanup-src-dir
$(QUIET)$(RM) ./.coverage 2>$(ERROR_LOG_PATH) || true
$(QUIET)$(RM) ./coverage*.xml 2>$(ERROR_LOG_PATH) || true
$(QUIET)$(RM) ./sitecustomize.py 2>$(ERROR_LOG_PATH) || true
$(QUIET)$(RMDIR) ./test-reports/ 2>$(ERROR_LOG_PATH) || true
$(QUIET)$(WAIT) ;
build-docs: ./docs/ ./docs/Makefile docs-reqs
$(QUIET)$(MAKE) -s -C ./docs/ -f Makefile html 2>$(ERROR_LOG_PATH) || DO_FAIL="exit 2" ;
$(QUIET)$(WAIT) ;
$(QUIET)mkdir $(INST_OPTS) ./docs/www 2>$(ERROR_LOG_PATH) >$(ERROR_LOG_PATH) || : ;
$(QUIET)$(BSMARK) ./docs/www 2>$(ERROR_LOG_PATH) >$(ERROR_LOG_PATH) || : ;
$(QUIET)$(WAIT) ;
$(QUIET)cp -fRp ./docs/_build/ ./docs/www/ 2>$(ERROR_LOG_PATH) || DO_FAIL="exit 35" ;
$(QUIET)$(WAIT) ;
$(QUIET)$(MAKE) -s -C ./docs/ -f Makefile clean 2>$(ERROR_LOG_PATH) || : ;
$(QUIET)$(WAIT) ;
$(QUIET)$(ECHO) "Documentation should be in docs/www/html/"
$(QUIET)$(DO_FAIL) ;
clean-docs: ./docs/ ./docs/Makefile
$(QUIET)$(RM) ./docs/www/* 2>$(ERROR_LOG_PATH) || : ;
$(QUIET)$(RMDIR) ./docs/www/ 2>$(ERROR_LOG_PATH) || : ;
$(QUIET)$(MAKE) -s -C ./docs/ -f Makefile clean 2>$(ERROR_LOG_PATH) || : ;
$(QUIET)$(WAIT) ;
./docs/:
$(QUIET)test -d "$@" || DO_FAIL="exit 77" ; # set fail if can't verify directory
$(QUIET)test -e "$@" || DO_FAIL="exit 69" ; # overwrite exitcode if does not exsist.
$(QUIET)$(DO_FAIL) ;
./docs/Makefile: ./docs/
$(QUIET)$(WAIT) ;
clean: clean-docs cleanup
$(QUIET)$(ECHO) "Cleaning Up."
$(QUIET)$(COVERAGE) erase 2>$(ERROR_LOG_PATH) || true
$(QUIET)$(RM) ./test-results/junit.xml 2>$(ERROR_LOG_PATH) || true
$(QUIET)$(RM) ./MANIFEST.in 2>$(ERROR_LOG_PATH) || true
$(QUIET)$(ECHO) "All clean."
must_be_root:
$(QUIET)runner=`whoami` ; \
if test $$runner != "root" ; then $(ECHO) "You are not root." ; exit 1 ; fi
user-install: build
$(QUIET)$(PYTHON) -m pip install $(PIP_COMMON_FLAGS) $(PIP_ENV_FLAGS) --user "pip>=24.3.1" "setuptools>=75.0" "wheel>=0.44" "build>=1.1.1" 2>$(ERROR_LOG_PATH) || true
$(QUIET)$(PYTHON) -m pip install $(PIP_COMMON_FLAGS) $(PIP_ENV_FLAGS) --user -r "https://raw.githubusercontent.com/reactive-firewall/multicast/stable/requirements.txt" 2>$(ERROR_LOG_PATH) || true
$(QUIET)$(PYTHON) -m pip install $(PIP_COMMON_FLAGS) $(PIP_ENV_FLAGS) --user -e "git+https://github.com/reactive-firewall/multicast.git#egg=multicast"
$(QUITE)$(WAIT)
$(QUIET)$(ECHO) "$@: Done."
%:
$(QUIET)$(ECHO) "No Rule Found For $@" 1>&2 ;
$(QUIET)$(WAIT) ;