forked from papis/papis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
460 lines (350 loc) · 9.86 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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
# File: common-makefile/src/version.m4
MAKEFILE_VERSION = v0.0.1-21-g392d792
MAKEFILE_DATE = 31-07-2017 15:47
MAKEFILE_AUTHOR = Alejandro Gallo
MAKEFILE_URL = https://github.com/alejandrogallo/python-makefile
MAKEFILE_LICENSE = GPLv3
## <<HELP
#
# Python Makefile
#
## HELP
# Local configuration
-include config.mk
CLEAN_FILES += \
$(shell find . -name *.pyc) \
$(shell find . -name *.pyo) \
$(shell find . -name __pycache__) \
$(wildcard test_* ) \
# File: common-makefile/src/os.m4
# Recognise OS
ifeq ($(shell uname),Linux)
LINUX := 1
OSX :=
else
LINUX :=
OSX := 1
endif
# File: common-makefile/src/shell-utils.m4
# Shell used
SH ?= bash
# Alias for `SHELL'
SHELL ?= $(SH)
# Python interpreter
PY ?= python
# Alias for `PY'
PYTHON ?= $(PY)
# Perl command
PERL ?= perl
# Grep program version
GREP ?= grep
# Find utility
FIND ?= find
# `sed` program version
SED ?= $(if $(OSX),gsed,sed)
# `awk` program to use
AWK ?= $(if $(OSX),gawk,awk)
# For creating tags
CTAGS ?= ctags
# To get complete paths
READLINK ?= $(if $(OSX),greadlink,readlink)
# `xargs` program to use
XARGS ?= xargs
# `tr` program to use
TR ?= tr
# `git` version to use
GIT ?= git
# `which` program to use
WHICH ?= which
# `sort` program to use
SORT ?= sort
# `uniq` program to use
UNIQ ?= uniq
# `Makefile` binary
MAKE ?= $(or $(MAKE),make)
# `rm` command
RM ?= rm
# C++ compiler
CXX ?= g++
# C compiler
CC ?= gcc
# Fortran compiler
FC ?= gfortran
# File: common-makefile/src/log.m4
# If secondary programs output is shown
QUIET ?= 0
# If the log messages should be also muted
QQUIET ?=
# If the commands issued should be printed write `DEBUG=1` if you want to see
# all commands.
DEBUG ?=
# For coloring
TPUT ?= $(shell $(WHICH) tput 2> /dev/null)
# If messages should have color
WITH_COLOR ?= 1
ifneq ($(strip $(QUIET)),0)
FD_OUTPUT = 2>&1 > /dev/null
else
FD_OUTPUT =
endif
ifdef DEBUG
DBG_FLAG =
DBG_FILE ?= .makefile-dbg
$(shell date | $(SED) "p; s/./=/g" > $(DBG_FILE))
else
DBG_FLAG = @
DBG_FILE =
endif
define log-debug
>> $(or $(DBG_FILE),/dev/null) echo
endef
# Print commands like [CMD]
define print-cmd-name
"[$(COLOR_LB) \
$(shell \
if test "$(1)" = g++; then \
echo -n GXX; \
elif test "$(1)" = gcc; then \
echo -n GCC; \
elif test "$(1)" = icc; then \
echo -n ICC; \
elif test "$(1)" = cc; then \
echo -n CC; \
elif test "$(1)" = povray; then \
echo -n POV; \
elif test "$(1)" = perl; then \
echo -n PL; \
elif test "$(1)" = perl5; then \
echo -n PL5; \
elif test "$(1)" = ruby; then \
echo -n RB; \
elif test "$(1)" = ruby2; then \
echo -n RB2; \
elif test "$(1)" = python; then \
echo -n PY; \
elif test "$(1)" = python2; then \
echo -n PY2; \
elif test "$(1)" = python3; then \
echo -n PY3; \
elif test "$(1)" = pdflatex; then \
echo -n pdfTeX; \
elif test "$(1)" = bash; then \
echo -n BASH; \
elif test "$(1)" = gnuplot; then \
echo -n GPT; \
elif test "$(1)" = mupdf; then \
echo -n muPDF; \
else \
echo -n "$(1)" | tr a-z A-Z ; \
fi
)\
$(COLOR_E)]"
endef
ifndef QQUIET
ifeq ($(strip $(WITH_COLOR)),1)
# Red
COLOR_R ?= $(if $(TPUT),$(shell $(TPUT) setaf 1),"\033[0;31m")
# Green
COLOR_G ?= $(if $(TPUT),$(shell $(TPUT) setaf 2),"\033[0;32m")
# Yellow
COLOR_Y ?= $(if $(TPUT),$(shell $(TPUT) setaf 3),"\033[0;33m")
# Dark blue
COLOR_DB ?= $(if $(TPUT),$(shell $(TPUT) setaf 4),"\033[0;34m")
# Lila
COLOR_L ?= $(if $(TPUT),$(shell $(TPUT) setaf 5),"\033[0;35m")
# Light blue
COLOR_LB ?= $(if $(TPUT),$(shell $(TPUT) setaf 6),"\033[0;36m")
# Empty color
COLOR_E ?= $(if $(TPUT),$(shell $(TPUT) sgr0),"\033[0m")
ARROW ?= @echo "$(COLOR_L)===>$(COLOR_E)"
else
ARROW ?= @echo "===>"
endif #WITH_COLOR
ECHO ?= @echo
else
ARROW := @ > /dev/null echo
ECHO := @ > /dev/null echo
endif #QQUIET
# File: ctags.m4
# ====================================
# Ctags generation for latex documents
# ====================================
#
# Generate a tags file so that you can navigate through the tags using
# compatible editors such as emacs or (n)vi(m).
#
tags: ## Create python exhuberant ctags
$(CTAGS) --language-force=python -R *
# File: install.m4
# Old-style requirements file
REQUIREMENTS ?= requirements.txt
# Command to be run when make `install` is run
INSTALL_COMMAND ?= $(PYTHON) setup.py install
# Command to be run when make `install-local` is run
INSTALL_LOCAL_COMMAND ?= $(PYTHON) setup.py install --user
# Command to be run when make `install-dev` is run
INSTALL_DEV_COMMAND ?= $(PYTHON) setup.py develop
# Command to be run when make `install-dev-local` is run
INSTALL_DEV_LOCAL_COMMAND ?= $(PYTHON) setup.py develop --user
# Command to be run when make `uninstall` is run
UNINSTALL_COMMAND ?= $(PIP) uninstall $(shell $(PYTHON) setup.py --name)
# Command to be run when make `install-deps` is run
INSTALL_DEPS_COMMAND ?= $(PIP) install -r requirements.txt
# Command to be run when make `install-deps-local` is run
INSTALL_DEPS_LOCAL_COMMAND ?= $(PIP) install --user -r requirements.txt
install-dev-local: ## Install developement version locally
$(ARROW) Installing development version locally
$(DBG_FLAG)$(INSTALL_DEV_LOCAL_COMMAND)
install-dev: ## Install developement version
$(ARROW) Installing development version
$(DBG_FLAG)$(INSTALL_DEV_COMMAND)
install-local: ## Install the package locally
$(ARROW) Installing locally
$(DBG_FLAG)$(INSTALL_LOCAL_COMMAND)
install: ## Install the package
$(ARROW) Installing...
$(DBG_FLAG)$(INSTALL_COMMAND)
uninstall: ## Uninstall the package
$(ARROW) Uninstalling...
$(DBG_FLAG)$(UNINSTALL_COMMAND)
install-deps-local: ## Install python requirements locally
$(ARROW) Installing dependencies...
$(DBG_FLAG)$(INSTALL_DEPS_LOCAL_COMMAND)
install-deps: ## Install python requirements
$(ARROW) Installing dependencies...
$(DBG_FLAG)$(INSTALL_DEPS_COMMAND)
# File: lint.m4
# Linter program
PY_LINTER ?= flake8
# ============
# Check syntax
# ============
#
# It checks the syntax (lints) of all the tex sources using the program in the
# TEX_LINTER variable.
#
lint: ## Check syntax of sources
$(PY_LINTER)
# File: doc.m4
doc: ## Create documentation
make -C doc/ html
doc-%:
make -C doc/ $*
update-gh-pages: ## Update github pages
@echo "Warning: Black magic in action"
git push origin $$(git subtree split --prefix doc/build/html/ master):gh-pages --force
# File: test.m4
# Command to run for `make test`
TEST_COMMAND ?= $(PYTHON) setup.py test
test: ## Run the tests
$(DBG_FLAG)$(TEST_COMMAND)
# File: virtualenv.m4
ENV ?=
ENV_FOLDER ?= env
ENV_PIP ?= $(ENV_FOLDER)/bin/pip
ENV_PYTHON ?= $(ENV_FOLDER)/bin/python
VIRTUALENV ?= virtualenv
ifdef ENV
PYTHON = $(ENV_PYTHON)
PIP = $(ENV_PIP)
DEPENDENCIES += virtualenv
DIST_DEPENDENCIES += virtualenv
endif
virtualenv: $(ENV_FOLDER) ## Create the python virtual environment
$(ENV_FOLDER):
$(ARROW) "Creating virtual environment in '$(ENV_FOLDER)' \
with python executable '$(PYTHON)'"
$(DBG_FLAG)$(VIRTUALENV) -p $(PYTHON) $(ENV_FOLDER)
# File: common-makefile/src/update.m4
MAKEFILE_UPDATE_URL ?= https://raw.githubusercontent.com/alejandrogallo/python-makefile/master/dist/Makefile
# ===============================
# Update the makefile from source
# ===============================
#
# You can always get the latest `Makefile` version using this target. You may
# override the `MAKEFILE_UPDATE_URL` to any path where you save your own
# personal makefile
#
update: ## Update the makefile from the repository
$(ARROW) "Getting makefile from $(MAKEFILE_UPDATE_URL)"
$(DBG_FLAG)wget $(MAKEFILE_UPDATE_URL) -O Makefile
# File: common-makefile/src/clean.m4
# Remove command flags
RM_FLAGS ?= -rf
# Default clean file to be cleaned
DEFAULT_CLEAN_FILES ?=
# Files to be cleaned
CLEAN_FILES ?= $(DEFAULT_CLEAN_FILES)
# =============
# Main cleaning
# =============
#
# This does a main cleaning of the produced auxiliary files. Before using it
# check which files are going to be cleaned up.
#
clean: ## Remove build and temporary files
$(ARROW) Cleaning up...
$(DBG_FLAG) {\
for file in $(CLEAN_FILES); do \
test -e $$file && { \
$(RM) $(RM_FLAGS) $$file && \
echo $(call print-cmd-name,RM) "$$file";\
} || : ; \
done \
}
# File: common-makefile/src/print-variable.m4
# This is used for printing defined variables from Some other scripts. For
# instance if you want to know the value of the `PDF_VIEWER` defined in the
# Makefile, then you would do
# ```
# make print-PDF_VIEWER
# ```
# and this would output `PDF_VIEWER=mupdf` for instance.
FORCE:
print-%:
$(DBG_FLAG)echo '$*=$($*)'
# =====================================
# Print a variable used by the Makefile
# =====================================
#
# For debugging purposes it is useful to print out some variables that the
# makefile is using, for that just type `make print` and you will be prompted
# to insert the name of the variable that you want to know.
#
FORCE:
print: ## Print a variable
$(DBG_FLAG)read -p "Variable to print: " variable && \
$(MAKE) --no-print-directory print-$$variable
# File: common-makefile/src/help.m4
# ================
# Print quick help
# ================
#
# It prints a quick help in the terminal
help: ## Prints help for targets with comments
$(DBG_FLAG)$(or $(AWK),awk) ' \
BEGIN {FS = ":.*?## "}; \
/^## *<<HELP/,/^## *HELP/ { \
help=$$1; \
gsub("#","",help); \
if (! match(help, "HELP")) \
print help ; \
}; \
/^[a-zA-Z0-9_\-.]+:.*?## .*$$/{ \
printf "\033[36m%-30s\033[0m %s\n", $$1, $$2 ; \
};' \
$(MAKEFILE_LIST)
@echo ""
@echo " $(MAKEFILE_VERSION)"
@echo " $(MAKEFILE_URL)"
@echo " Copyright $(MAKEFILE_AUTHOR) $(MAKEFILE_LICENSE) $(MAKEFILE_DATE)"
@echo ""
# File: common-makefile/src/help-target.m4
FORCE:
help-%:
$(DBG_FLAG)$(SED) -n "/[#] [=]\+/,/^$*: / { /"$*":/{q}; p; } " $(MAKEFILE_LIST) \
| tac \
| sed -n "1,/===/ {/===/n; s/^# //p}" \
| tac \
| sed -n "p; 1s/./=/gp; 1a\ "
# vim: cc=80