forked from cs2043-sp16/lecture-slides
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
84 lines (79 loc) · 3.66 KB
/
Makefile
File metadata and controls
84 lines (79 loc) · 3.66 KB
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
# 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 .tex file, 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>.tex
# <directory02>/
# - <single source>.tex
# ...
#
# In words, that there are some number of directories with exactly one .tex file n each
# directory. The goal is to compile each <directory>/<single source>.tex into
# <directory>/<single source>.pdf.
#
# This directory structure is not necesssary, and a single .tex file in the current directory
# will also be compiled without issue. Search for
#
# $(COMPILED_PDFS): %.pdf: %.tex
#
# to see how to modify this file to use with your tex project, if you want.
SINGLE_SOURCE := $(shell find . -name "*.tex") # find all .tex files
NO_EXTENSIONS := $(basename $(SINGLE_SOURCE)) # make basename gives the path without the extension
COMPILED_PDFS := $(SINGLE_SOURCE:.tex=.pdf) # change <single source>.tex 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.tex
# lecture02/lecture02.pdf: lecture02/lecture02.tex
#
# 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 .tex source file and type make.
#
# Then just uncomment these two lines and comment out the following copy.
# $(COMPILED_PDFS): %.pdf: %.tex
# latexmk -xelatex --shell-escape --jobname=$(basename $@) $<
$(COMPILED_PDFS): %.pdf: %.tex
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)))
.PHONY: clean realclean
clean:
rm -f $(CLEANABLES)
realclean: clean
rm -f $(COMPILED_PDFS)