-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMakefile.old
152 lines (113 loc) · 4.36 KB
/
Makefile.old
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
UNAME_S = $(shell uname -s)
SOURCE_DIR = src
TIKZ_LIBS = $(wildcard $(SOURCE_DIR)/*.code.tex)
TEX_FILES_ALL_ = $(wildcard $(SOURCE_DIR)/*.tex)
TIKZ_FILES_ALL = $(filter-out $(TIKZ_LIBS), $(TEX_FILES_ALL_))
TIKZ_LUALATEX = $(filter %.lualatex.tex, $(TIKZ_FILES_ALL))
TIKZ_LATEX = $(filter-out $(TIKZ_LUALATEX), $(TIKZ_FILES_ALL))
PDF_LATEX = $(addprefix out/, $(addsuffix .pdf, $(basename $(notdir $(TIKZ_LATEX) ))))
OUTPUT_DIR = out
# Detect operating system. Sort of tricky for Windows because of MSYS, cygwin, MGWIN
OSFLAG :=
ifeq ($(OS), Windows_NT)
OSFLAG = WINDOWS
else
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S), Linux)
OSFLAG = LINUX
endif
ifeq ($(UNAME_S), Darwin)
OSFLAG = OSX
endif
endif
.PHONY: all
all: $(PDF_LATEX)
# rules for .tex files to be compiled with pdflatex
out/%.pdf:: src/%.tex msg_pdf_files
cd $(SOURCE_DIR) && \
pdflatex --interaction=batchmode -halt-on-error -output-directory ../$(OUTPUT_DIR) $(<F) > /dev/null 2>&1; \
printf "`du -sh $@` <- \n"
# one-time mesage
.INTERMEDIATE: msg_pdf_files
msg_pdf_files:
$(info generating pdf files)
# remove PNG and PDF files
.PHONY: clean
clean: tidy cleanlualatex cleansourcedir
find $(OUTPUT_DIR) -maxdepth 1 -name \*.png -delete
find $(OUTPUT_DIR) -maxdepth 1 -name \*.pdf -delete
# remove byproducts
.PHONY: tidy
tidy:
find $(OUTPUT_DIR) -maxdepth 1 -name \*.log -delete
find $(OUTPUT_DIR) -maxdepth 1 -name \*.aux -delete
find $(OUTPUT_DIR) -maxdepth 1 -name \*.out -delete
find $(OUTPUT_DIR) -maxdepth 1 -name \*.gz -delete
find $(OUTPUT_DIR) -maxdepth 1 -name \*.snm -delete
find $(OUTPUT_DIR) -maxdepth 1 -name \*.toc -delete
find $(OUTPUT_DIR) -maxdepth 1 -name \*.nav -delete
find $(OUTPUT_DIR) -maxdepth 1 -name \*.fls -delete
find $(OUTPUT_DIR) -maxdepth 1 -name \*.fdb_latexmk -delete
.PHONY: cleanlualatex
cleanlualatex: tidylualatex
find $(OUTPUT_DIR) -maxdepth 1 -name \*.lualatex.png -delete
find $(OUTPUT_DIR) -maxdepth 1 -name \*.lualatex.pdf -delete
.PHONY: tidylualatex
tidylualatex:
find $(OUTPUT_DIR) -maxdepth 1 -name \*.lualatex.log -delete
find $(OUTPUT_DIR) -maxdepth 1 -name \*.lualatex.aux -delete
find $(OUTPUT_DIR) -maxdepth 1 -name \*.lualatex.out -delete
find $(OUTPUT_DIR) -maxdepth 1 -name \*.lualatex.synctex.gz -delete
.PHONY: cleansourcedir
cleansource:
find $(SOURCE_DIR) -maxdepth 1 -name \*.png -delete
find $(SOURCE_DIR) -maxdepth 1 -name \*.pdf -delete
find $(SOURCE_DIR) -maxdepth 1 -name \*.log -delete
find $(SOURCE_DIR) -maxdepth 1 -name \*.aux -delete
find $(SOURCE_DIR) -maxdepth 1 -name \*.out -delete
find $(SOURCE_DIR) -maxdepth 1 -name \*.gz -delete
find $(SOURCE_DIR) -maxdepth 1 -name \*.snm -delete
find $(SOURCE_DIR) -maxdepth 1 -name \*.toc -delete
find $(SOURCE_DIR) -maxdepth 1 -name \*.nav -delete
find $(SOURCE_DIR) -maxdepth 1 -name \*.fls -delete
find $(SOURCE_DIR) -maxdepth 1 -name \*.fdb_latexmk -delete
# .PHONY: info
# info:
# @echo $(words $(TIKZ_LIBS))
# @echo $(words $(TEX_FILES_ALL_))
# @echo $(words $(TIKZ_FILES_ALL))
# @echo $(words $(TIKZ_LATEX))
# @echo $(words $(TIKZ_LATEX))
# @echo $(words $(TIKZ_LUALATEX))
# @echo $(TIKZ_LIBS)
# @echo $(words $(PDF_LATEX))
.PHONY: info
info:
@echo $(words $(TIKZ_LIBS))
@echo $(words $(TIKZ_FILES_ALL_))
@echo $(words $(TIKZ_FILES_ALL))
@echo $(words $(TIKZ_LATEX))
@echo $(words $(TIKZ_LUALATEX))
@echo $(TIKZ_LIBS)
.PHONY: getos
getos:
@# Testing different ways of detecting the OS
@echo "OS is:" $(OSFLAG)
@# these two are equivalent
@echo "Number of words in OS env var:" $(words $(OS))
@echo count words in findstring $(words $(findstring $(OS),))
@if [ $(words $(OS)) -gt 0 ]; then echo "OS env word count it is greater than zero, means it is WINDOWS"; fi
@# Using if
@if [ "$(findstring $(OS), Windows_NT)" != "" ]; then echo "OS returns Windows_NT, not an empty string"; fi
@# using test
@if test $(findstring $(OS), Windows_NT) ; then echo "WINDOWS passed the test"; fi;
@if test $(findstring $(OSFLAG), WINDOWS); then echo "findstring of OSFLAG found WINDOWS"; fi
@if test $(OSFLAG) = WINDOWS; then echo "OSFLAG is WINDOWS"; fi
@if test $(findstring $(OSFLAG), OSX); then echo "it is a Mac"; fi
$(eval NUMWORDS = $(words $(findstring $(OS), Windows_NT)))
@echo NUMWORDS $(NUMWORDS)
ifeq ($(strip $(findstring $(OS), Windows_NT) ),)
@echo "findstring found OS empty. No WINDOWS here"
else
@echo "findstring found OS filled, so it is WINDOWS"
endif