-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
94 lines (87 loc) · 4.08 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
# This Makefile assumes you have `latexmk` installed correctly, as well as XeLaTeX.
#
# The beamertheme-metropolis package uses special fonts so we must use XeLaTeX instead
# of pdflatex. Compiling with xelatex also allows you use utf-8 characters directly in
# your source code, allowing you to directly type things like chinese characters or
# accents. Most of the time, though, you can get away with using pdflatex.
#
# This Makefile assumes there is a directory structure:
#
# ./
# - Makefile (this one)
# <directory01>/
# - <single source>.xetex
# <directory02>/
# - <single source>.xetex
# ...
#
# In words, that there are some number of directories with exactly one .xetex file n each
# directory. The goal is to compile each <directory>/<single source>.xetex into
# <directory>/<single source>.pdf.
#
# This directory structure is not necesssary, and a single .xetex file in the current directory
# will also be compiled without issue. Search for
#
# $(COMPILED_PDFS): %.pdf: %.xetex
#
# to see how to modify this file to use with your tex project, if you want.
SINGLE_SOURCE := $(shell find . -name "*.xetex") # find all .xetex files
NO_EXTENSIONS := $(basename $(SINGLE_SOURCE)) # make basename gives the path without the extension
COMPILED_PDFS := $(SINGLE_SOURCE:.xetex=.pdf) # change <single source>.xetex to <single source>.pdf
# Defining the `all` rule enables you to just type `make` in the same directory as the
# Makefile. If it is not defined, the first rule defined will be executed when you
# only type `make`. We make `all` depend on the expansion of COMPILED_PDFS so that
# `all` will not be finished until every one of the rules in COMPILED_PDFS (below) is
# also finished.
all: $(COMPILED_PDFS)
# This defines a rule for each file in the list COMPILED_PDFS. So if COMPILED_PDFS was
# the list
#
# lecture01/lecture01.pdf lecture02/lecture02.pdf
#
# then this would create the targets
#
# lecture01/lecture01.pdf: lecture01/lecture01.xetex
# lecture02/lecture02.pdf: lecture02/lecture02.xetex
#
# Since we want to compile the results in the respective folders (as opposed to the
# folder where this Makefile is), the jobname needs to be specified as such. Refer to
# the following for what the automatic variables are:
#
# https://www.gnu.org/software/make/manual/html_node/Automatic-Variables.html
#
# To enable relative portability of this Makefile, it has been written such that you
# could easily place it in the same directory as your .xetex source file and type make.
#
# Note that you can easily invoke `latexmk` without the -xelatex flag to use `pdflatex`,
# and if you do so you should have `.tex` extensions, rather than `.xetex`.
#
# Then just uncomment these two lines and comment out the following copy.
# $(COMPILED_PDFS): %.pdf: %.xetex
# latexmk -xelatex --shell-escape --jobname=$(basename $@) $<
$(COMPILED_PDFS): %.pdf: %.xetex
cd $(shell dirname $@) && \
latexmk -xelatex --shell-escape --jobname=$(basename $(shell basename $@)) $(shell basename $<)
# Defining clean targets is a common practice, allowing the user to cleanup the files
# generated during compilation with ease. The `clean` target will get rid of the
# intermediate compilation files, and the `realclean` target will do this as well as
# remove the PDF files.
#
# The EXTENSIONS list is a list of the intermediate files that will be produced. The
# CLEANABLES list is generated by looping over all of the elements in NO_EXTENSIONS
# defined above, and for each one of those will add to the list each one of the
# extensions listed in EXTENSIONS.
EXTENSIONS := .aux .blg .out .bbl .log .nav .snm .toc .vrb .pyg .fdb_latexmk .fls
CLEANABLES := $(foreach file, $(NO_EXTENSIONS), \
$(foreach ext, $(EXTENSIONS), \
$(file)$(ext)))
# Some extra items need to be cleaned for minted on OSX.
MINTED := $(foreach partial, $(NO_EXTENSIONS), \
$(shell dirname $(partial))/_minted-$(shell basename $(partial)))
TYPE := $(shell uname -s)
.PHONY: clean realclean
clean:
rm -f $(CLEANABLES)
rm -rf $(MINTED)
realclean: clean
rm -f $(COMPILED_PDFS)