-
Notifications
You must be signed in to change notification settings - Fork 7
/
Makefile
176 lines (141 loc) · 4.21 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
# (C) 2022 Yung-Yu Chen. All rights reserved.
# make PSPYTEX=1 to update the pstrick drawing tex files generated by the *.py
# scripts.
SETUP_FILE ?= ./setup.mk
ifneq (,$(wildcard $(SETUP_FILE)))
include $(SETUP_FILE)
endif
PYTHON ?= python3
SHELL = /bin/bash
NUM ?= 3 # For LaTeX to correctly cross-reference. To save time, use 1.
VERBOSE ?= 0
DOEPS ?= 1
PSPYTEX ?= 0
ifeq ($(VERBOSE),0)
CMDLOG_DIR_REDIRECT := > /dev/null
else
CMDLOG_DIR_REDIRECT := >&1
endif
PSTAKE := ./pstake.py
# tool binaries
LATEX := latex -halt-on-error -interaction=nonstopmode -synctex=1
BIBTEX := bibtex
DVIPS := dvips
# -dALLOWPSTRANSPARENCY is needed by fillstyle=solid
PS2PDF := ps2pdf -dALLOWPSTRANSPARENCY
ifeq ($(DOEPS),0)
DO_PSTAKE = mkdir -p $(EPS_DIR) ; touch $@
DO_PSPY = mkdir -p $(EPS_DIR) ; touch $@
else
DO_PSTAKE = mkdir -p $(EPS_DIR) ; $(PYTHON) $(PSTAKE) $< $@
ifeq ($PSPYTEX,0)
DO_PSPY = mkdir -p $(EPS_DIR) ; $(PYTHON) $< $@
else
DO_PSPY = mkdir -p $(EPS_DIR) ; $(PYTHON) $< $@ $(<:.py=.tex)
endif
endif
# tool binaries
# directories
LOG_DIR := log
EPS_DIR := turgon_eps
SCHEMATIC_DIR := schematic
HANDOVER_DIR := handover
NOWDATE := $(shell date +"%Y%m%d")
CURRENTBRANCH := $(shell git rev-parse --abbrev-ref HEAD | sed 's/\//-/g' 2> /dev/null || echo "nobranch")
NOWID := $(shell git rev-parse --short HEAD 2> /dev/null || echo "nogit")
HANDOVER_FN = $(HANDOVER_DIR)/$(basename $<).$(CURRENTBRANCH).$(NOWID).$(NOWDATE).pdf
TRUNK := turgon
MAKEFILES := Makefile
ALL_TEX := $(wildcard $(SCHEMATIC_DIR)/*.tex)
ALL_SCHPY := $(wildcard $(SCHEMATIC_DIR)/*.py)
ALL_EPS := $(patsubst $(SCHEMATIC_DIR)/%.tex,$(EPS_DIR)/%.eps,$(ALL_TEX)) \
$(patsubst $(SCHEMATIC_DIR)/%.py,$(EPS_DIR)/%.eps,$(ALL_SCHPY))
.PHONY: default
default: cese mesh projection
.PHONY: all
all: default
.PHONY: ho
ho: cese_ho mesh_ho projection_ho
.PHONY: eps
eps: $(ALL_EPS)
$(EPS_DIR)/%.eps: $(SCHEMATIC_DIR)/%.tex pstake.py
mkdir -p $(LOG_DIR) ; \
$(DO_PSTAKE) 2>&1 | \
tee $(LOG_DIR)/pstake-$(notdir $<).log $(CMDLOG_DIR_REDIRECT)
$(EPS_DIR)/%.eps: $(SCHEMATIC_DIR)/%.py
mkdir -p $(LOG_DIR) ; \
$(DO_PSPY) 2>&1 | \
tee $(LOG_DIR)/$(notdir $<).log $(CMDLOG_DIR_REDIRECT)
$(EPS_DIR)/%.png: $(SCHEMATIC_DIR)/%.py
mkdir -p $(LOG_DIR) ; \
$(DO_PSPY) 2>&1 | \
tee $(LOG_DIR)/$(notdir $<).log $(CMDLOG_DIR_REDIRECT)
%.dvi: %.tex $(TRUNK)_main.bib $(TRUNK).cls $(ALL_EPS) $(MAKEFILES)
@echo "Having EPS files: $(ALL_EPS)"
mkdir -p $(LOG_DIR) ; num=1 ; while [ $$num -le $(NUM) ] ; do \
latex_logfile=$(LOG_DIR)/[email protected].$$num.log ; \
echo -n "latex $@ #$$num ... " ; \
$(LATEX) $< 2>&1 | \
tee $$latex_logfile $(CMDLOG_DIR_REDIRECT) ; \
if [[ \
( -z "`grep 'LaTeX Error:' $$latex_logfile`" ) \
&& ( -z "`grep 'Runaway argument\?' $$latex_logfile`" ) \
&& ( -z "`grep \! $$latex_logfile | head -c 1 | grep \!`" ) \
]] ; then \
echo "done" ; \
else \
echo "tail $$latex_logfile:" ; \
tail $$latex_logfile ; \
exit -1 ; \
fi ; \
$(BIBTEX) $(basename $<) 2>&1 | \
tee $(LOG_DIR)/[email protected].$$num.log \
$(CMDLOG_DIR_REDIRECT) ; \
(( num = num + 1 )) ; done
%.ps: %.dvi $(MAKEFILES)
mkdir -p $(LOG_DIR) ; \
$(DVIPS) $< 2>&1 | tee $(LOG_DIR)/[email protected] $(CMDLOG_DIR_REDIRECT)
%.pdf: %.ps $(MAKEFILES)
mkdir -p $(LOG_DIR) ; \
$(PS2PDF) $< 2>&1 | tee $(LOG_DIR)/[email protected] $(CMDLOG_DIR_REDIRECT)
.PHONY: cese
cese: cese.pdf
.PHONY: cese_ho
cese_ho: cese.pdf
@echo "Generating today's PDF: $(HANDOVER_FN)"
mkdir -p $(HANDOVER_DIR)
cp -f $< $(HANDOVER_FN)
.PHONY: mesh
mesh: ustmesh.pdf
.PHONY: mesh_ho
mesh_ho: ustmesh.pdf
@echo "Generating today's PDF: $(HANDOVER_FN)"
mkdir -p $(HANDOVER_DIR)
cp -f $< $(HANDOVER_FN)
.PHONY: projection
projection: projection.pdf
.PHONY: projection_ho
projection_ho: projection.pdf
@echo "Generating today's PDF: $(HANDOVER_FN)"
mkdir -p $(HANDOVER_DIR)
cp -f $< $(HANDOVER_FN)
.PHONY: tex
tex:
chktex cese.tex projection.tex ustmesh.tex
.PHONY: lint
lint: tex
.PHONY: clean_tex
clean_tex:
rm -f *.aux *.bbl *.blg *.dvi *.log *.out *.xwm *.toc *.pdf *.ps \
*.fdb_latexmk *.fls *.pdfsync *.synctex.gz
.PHONY: clean_log
clean_log:
rm -rf $(LOG_DIR)
.PHONY: clean_eps
clean_eps:
rm -rf $(EPS_DIR)
.PHONY: clean_pytex
clean_pytex:
rm -f $(ALL_SCHPY:.py=.tex)
.PHONY: clean
clean: clean_tex clean_log clean_eps