forked from clemsonacm/hackpack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
84 lines (66 loc) · 2.45 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
# Where to put auxiliary files and the hack pack PDF.
OUTDIR = build
# Filetypes that the preprocessor script runs over. Separated with pipes, e.g. a|b
PREPTYPES = cpp|py|tex
# `find` regex to match the preprocessable files. Substitutes to escape pipes.
PREPREGEX = ".*\.\($(subst |,\|,$(PREPTYPES))\)"
# Auxiliary files to move to the OUTDIR.
AUXFILES = *.aux *.blg *.fdb_latexmk *.fls *.idx *.ilg *.ind *.log *.out *.pdf *.toc
# 1 if your version of `latexmk` supports the `-outdir` option, 0 otherwise.
HAS_OUTDIR = $(shell latexmk --help | grep -- "-output-directory" | wc -l)
# Location of the preprocessing script.
PREPSCRIPT = ./formatting/preprocessor.awk
# -pdf to generate a pdf, -g to force recompilation.
LATEXMKOPTS = -pdf -g -pdflatex='pdflatex --shell-escape'
# Exclude directory from find commands
EXCLUDEDIR=-not -path './util/*'
# Extension for backups of preprocessable files.
BACKUPEXT = tmpbackup
# Extension for temporary location for preprocessed files.
TMPEXT = tmp
GNUFIND= $(shell uname -a| grep -- "Linux" | wc -l)
ifeq ($(GNUFIND), 1)
FIND = find
else
FIND = gfind
endif
# Build the Hackpack++ by default.
default: hackpackpp
include LICENSES/Makefile
# Use `make hackpack` or `make hackpackpp` to build the hackpack or hackpack++.
hackpack hackpackpp: license
# Back up and preprocess preprocessable files.
$(FIND) . -regex $(PREPREGEX) $(EXCLUDEDIR) -exec cp "{}" "{}.$(BACKUPEXT)" \; \
-exec sh -c 'awk -v V=$@ -f $(PREPSCRIPT) "{}" > "{}.$(TMPEXT)"' \; \
-exec mv "{}.$(TMPEXT)" "{}" \;
# Build the PDF and auxiliary files into the OUTDIR.
ifeq ($(HAS_OUTDIR), 1)
-latexmk $(LATEXMKOPTS) -auxdir=$(OUTDIR) -outdir=$(OUTDIR)
else
-rm -rf $(OUTDIR)
-mkdir $(OUTDIR)
-latexmk $(LATEXMKOPTS)
-mv $(AUXFILES) $(OUTDIR)
endif
# Delete preprocessed files.
-$(FIND) . -regex $(PREPREGEX) $(EXCLUDEDIR) -delete
# Restore backups of preprocessed files.
-$(FIND) . -iname "*.$(BACKUPEXT)" $(EXCLUDEDIR) -exec ./util/rename 's/\.$(BACKUPEXT)$$//' "{}" \;
.PHONY: clean show test
# Display the hack pack, if it exists.
show:
evince $(OUTDIR)/hackpack.pdf
# Delete temporary files that might exist and clean the OUTDIR.
clean:
-$(FIND) . -iname "*.$(BACKUPEXT)" $(EXCLUDEDIR) -delete
-$(FIND) . -iname "*.$(TMPEXT)" $(EXCLUDEDIR) -delete
-$(FIND) . -name "*.pdf" $(EXCLUDEDIR) -delete
-./modules.sh clean
ifeq ($(HAS_OUTDIR), 1)
-latexmk -c -outdir=$(OUTDIR) -auxdir=$(OUTDIR)
else
-rm -rf $(OUTDIR)
-mkdir $(OUTDIR)
endif
test:
./modules.sh test