forked from ATLAS-Titan/CSW-BigScience
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
84 lines (64 loc) · 2.69 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
#- GNU Makefile
#- Makefile ~~
#
# This contains live instructions to typeset a PDF.
#
# This isn't as fancy as my "usual" Makefiles, which are full of macros and
# happiness, but there is a much greater level of urgency here than usual.
#
# ~~ last updated 25 Sep 2018
SHELL := sh
ECHO := echo
define alert
printf '\033[1;31mError: %s\n\033[1;0m' $(strip $(1)) >&2
endef
define contingent
$(shell \
contingent() { \
for each in $$@; do \
command -v $${each} >/dev/null 2>&1 ; \
if [ $$? -eq 0 ]; then \
command -v $${each} ; \
return $$? ; \
fi ; \
done ; \
printf 'echo "\033[1;31m(%s)\033[1;0m"' '$(firstword $(1))' ; \
return 1 ; \
} ; \
contingent $(1) \
)
endef
PROJ_ROOT := $(realpath $(dir $(firstword $(MAKEFILE_LIST))))
PROJECT := draft
SUBMISSION := $(PROJ_ROOT)/$(PROJECT).pdf
BIBTEX := $(call contingent, bibtex)
GREP := $(call contingent, grep)
LATEX := $(call contingent, pdflatex latex) -no-shell-escape
OPEN := $(call contingent, acroread gnome-open open)
RM := $(call contingent, rm) -rf
greplog = ( $(GREP) -c $(1) "$(PROJ_ROOT)/$(PROJECT).log" > /dev/null )
.PHONY: all clean clobber distclean reset run
all: run
clean: reset
clobber: clean
@ $(RM) $(wildcard *.aux *.bbl *.blg *.dvi *.log *.out)
distclean: clobber
@ $(RM) $(SUBMISSION)
open: $(SUBMISSION)
@ $(OPEN) $^
reset:
@ $(call contingent, clear)
run: $(SUBMISSION)
@ $(OPEN) $(SUBMISSION)
###
$(SUBMISSION): $(wildcard $(PROJ_ROOT)/*.tex)
@ cd $(PROJ_ROOT) ; \
$(LATEX) -jobname $(PROJECT) main ; \
while $(call greplog, "Rerun to"); do \
$(BIBTEX) $(PROJECT) ; \
$(LATEX) -jobname $(PROJECT) main ; \
done
###
%:
@ $(call alert, "No target '$@' is available.")
#- vim:set syntax=make: