-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathMakefile
142 lines (115 loc) · 4 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
# COPYRIGHT
#
# Copyright 2016, 2017 Keith Miyake <keith.miyake@gmail.com>
# Copyright 2011-2016 David Caplan
#
# LICENSE
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Default Configs
#
THISPATH=$(shell pwd)
BASEPATH=$(THISPATH)/source
SECTIONSFILE=_SECTIONS.txt
BUILDNAME=dissertation
# TIMESTAMP=$(shell date "+%Y%m%d-%H%M%S")
# BUILDNAME=example-$(TIMESTAMP)
OUTPUT_FOLDER=output
CSL=chicago-author-date
PANDOC_OPTIONS=--dpi=600 --latex-engine=xelatex --filter pandoc-tablenos --filter pandoc-fignos --filter pandoc-citeproc
# Optionally pass a different config file location on the command line
# e.g., $ CFGFILE=myspecialconfig.txt make
# _CONFIG.txt is the default configuration file
CFGFILE?=_CONFIG.txt
# Include the config file
include $(CFGFILE)
OUTPUTPATH=$(THISPATH)/$(OUTPUT_FOLDER)/$(BUILDNAME)
TEMPLATEPATH=$(THISPATH)/templates
TEMPLATEFILE=$(TEMPLATEPATH)/$(TEMPLATE).tex
# Load the sections from the SECTIONSFILE if they're not defined in the config file
ifndef SECTIONS
# This combines all the filepaths in SECTIONSFILE file
SECTIONS := $(shell cat $(SECTIONSFILE) | tr '\n\r' ' ' | tr '\n' ' ' )
SECTIONS := $(addprefix $(BASEPATH)/, $(SECTIONS))
endif
ifdef DOCX_TEMPLATE
DOCX_TEMPLATE := --reference-docx $(TEMPLATEPATH)/$(DOCX_TEMPLATE).docx
endif
ifdef ODT_TEMPLATE
ODT_TEMPLATE := --reference-odt $(TEMPLATEPATH)/$(ODT_TEMPLATE).odt
endif
ifdef REFS
PANDOC_OPTIONS := --bibliography=$(BASEPATH)/$(REFS) $(PANDOC_OPTIONS)
endif
ifdef CSL
PANDOC_OPTIONS := --csl=$(THISPATH)/csl/$(CSL).csl $(PANDOC_OPTIONS)
endif
.DEFAULT_GOAL := pdf
.PHONY: all clean html pdf epub embed viewpdf viewhtml
.PHONY: pre
pre:
@echo Using config: $(MDCFG)
@mkdir -p $(OUTPUT_FOLDER)
.PHONY: post
post:
@echo "Finished compiling all targets"
.PHONY: clean
clean:
@rm -rf $(OUTPUT_FOLDER)
.PHONY: all
all: clean pdf latex html docx odt embed epub post viewpdf viewhtml
.PHONY: pdf
pdf: pre
cd $(BASEPATH) && \
pandoc -o $(OUTPUTPATH).pdf --template=$(TEMPLATEFILE) $(PANDOC_OPTIONS) $(SECTIONS)
.PHONY: pdfsafemode
pdfsafemode: pre
cd $(BASEPATH) && \
pandoc -o $(OUTPUTPATH).pdf $(PANDOC_OPTIONS) $(SECTIONS)
.PHONY: docx
docx: pre
cd $(BASEPATH) && \
pandoc -o $(OUTPUTPATH).docx $(DOCX_TEMPLATE) $(PANDOC_OPTIONS) $(SECTIONS)
.PHONY: odt
odt: pre
cd $(BASEPATH) && \
pandoc -o $(OUTPUTPATH).odt $(ODT_TEMPLATE) $(SECTIONS)
.PHONY: latex
cd $(BASEPATH) && \
pandoc -o $(OUTPUTPATH).pdf --csl=./csl/$(CSL).csl $(SECTIONS)
latex: pre
[ -d "$(BASEPATH)/images" ] || ln -s $(BASEPATH)/images $(OUTPUT_FOLDER)/
cd $(BASEPATH) && \
pandoc -s -o $(OUTPUTPATH).tex --template=$(TEMPLATEFILE) $(PANDOC_OPTIONS) $(SECTIONS)
.PHONY: html
html: pre
cd $(BASEPATH) && \
pandoc -s --mathjax="http://cdn.mathjax.org/mathjax/latest/MathJax.js" --section-divs -o $(OUTPUTPATH).html -t html5 $(PANDOC_OPTIONS) $(SECTIONS)
.PHONY: embed
embed: pre
cd $(BASEPATH) && \
pandoc --reference-links --mathjax="http://cdn.mathjax.org/mathjax/latest/MathJax.js" --section-divs -o $(OUTPUT_FOLDER)/embed.html -t html5 --normalize $(PANDOC_OPTIONS) $(SECTIONS)
.PHONY: epub
epub: pre
cd $(BASEPATH) && \
pandoc -s --biblatex -o $(OUTPUTPATH).epub -t epub $(PANDOC_OPTIONS) $(SECTIONS)
# open files that were rendered
.PHONY: viewpdf
viewpdf:
type xdg-open >/dev/null 2>&1 && xdg-open $(OUTPUTPATH).pdf || open $(OUTPUTPATH).pdf
.PHONY: viewhtml
viewhtml:
type xdg-open >/dev/null 2>&1 && xdg-open $(OUTPUTPATH).html || open $(OUTPUTPATH).html
# vim: set ft=make: