summaryrefslogtreecommitdiff
path: root/pandoc.mk
blob: c3f511714fe7cedd0962fd87047611abb865dcf8 (plain)
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
# -*- make -*-
# (C) 2013 by Eugeniy Mikhailov, <evgmik@gmail.com>
# Processing of pandoc files 

CLEAN_TARGETS      += clean_md
REAL_CLEAN_TARGETS += real_clean_md

md_files  = $(wildcard *.md)
tex_from_md  = $(md_files:%.md=%.tex)
pdf_from_md  = $(md_files:%.md=%.pdf)	
html_from_md = $(md_files:%.md=%.html)

# to disable preprocessor use
#PANDOC_PREPROCESSOR_CMD ?= cat 
#PANDOC_PREPROCESSOR_OPTIONS ?= 

# preprocessor on
PANDOC_PREPROCESSOR_CMD ?= gpp
PANDOC_PREPROCESSOR_OPTIONS ?= -U "" "" "(" "," ")" "(" ")" "\#" "\\" -M "<\#" "\n" " " " " "\n" "(" ")"
PANDOC_PREPROCESSOR ?= $(PANDOC_PREPROCESSOR_CMD) $(PANDOC_PREPROCESSOR_OPTIONS)

PANDOC_HTML_METADATA ?= cat -
PANDOC_TEX_METADATA ?= cat - $(CONFIG_DIR)/tex_metadata.yaml
PANDOC_PDF_METADATA ?= $(PANDOC_TEX_METADATA)

PANDOC_COMMON_OPTIONS ?= --standalone --smart
PANDOC_HTML_OPTIONS ?= -s --css=$(TOPDIR)/css_styles/evmik_pandoc.css --section-divs  --toc 
PANDOC_TEX_OPTIONS ?= --latex-engine=pdflatex
PANDOC_PDF_OPTIONS ?= --latex-engine=pdflatex

PANDOC_CMD := pandoc
PANDOC := $(PANDOC_CMD) $(PANDOC_COMMON_OPTIONS)

html_md: $(html_from_md)

pdf_tex:  $(pdf_from_independent_tex)

pdf_md:  $(pdf_from_md)

tex_md: $(tex_from_md)



$(html_from_md): %.html : %.md $(md_fig_files) $(md_configs)
	$(PANDOC_PREPROCESSOR) $< | $(PANDOC_HTML_METADATA) | $(PANDOC) -t html $(PANDOC_HTML_OPTIONS) -o $@
	
$(tex_from_md): %.tex : %.md $(md_fig_files) $(md_configs)
	$(PANDOC_PREPROCESSOR) $< | $(PANDOC_TEX_METADATA) | $(PANDOC) -t latex $(PANDOC_TEX_OPTIONS) -o $@

$(pdf_from_md): %.pdf : %.md $(md_fig_files) $(md_configs)
	$(PANDOC_PREPROCESSOR) $< | $(PANDOC_PDF_METADATA) | $(PANDOC) $(PANDOC_PDF_OPTIONS) -o $@


dest_dir_md: 
	$(INSTALL) -d -m 0755 $(dest_dir)

install_md_src: dest_dir_md install_md_fig_files
ifneq ($(strip $(md_files)),)
	$(INSTALL) -m 0644 $(html_from_md) $(dest_dir)/
endif

install_md_fig_files: 
ifneq ($(strip $(md_fig_files)),)
	$(INSTALL) -m 0644 $(md_fig_files) $(dest_dir)/
endif

install_html_md: dest_dir_md $(html_from_md) install_md_fig_files
ifneq ($(strip $(html_from_md)),)
	$(INSTALL) -m 0644 $(html_from_md) $(dest_dir)/
endif

install_pdf_md: dest_dir_md $(pdf_from_md)
ifneq ($(strip $(pdf_from_md)),)
	$(INSTALL) -m 0644 $(pdf_from_md) $(dest_dir)/
endif

clean_md: clean_md_aux
	
real_clean_md: clean_md_tex clean_md_aux
ifneq ($(strip $(pdf_from_md)),)
	rm -f $(pdf_from_md)
endif
ifneq ($(strip $(html_from_md)),)
	rm -f $(html_from_md)
endif

clean_md_tex:
ifneq ($(strip $(tex_from_md)),)
	rm -f $(tex_from_md)
endif

clean_md_aux: 
ifneq ($(strip $(tex_from_md)),)
	rm -f $(tex_from_md:%.tex=%.dvi)
	rm -f $(tex_from_md:%.tex=%.log)
	rm -f $(tex_from_md:%.tex=%.aux)
	rm -f $(tex_from_md:%.tex=%.nav)
	rm -f $(tex_from_md:%.tex=%.out)
	rm -f $(tex_from_md:%.tex=%.snm)
	rm -f $(tex_from_md:%.tex=%.toc)
	rm -f $(tex_from_md:%.tex=%.vrb)
	rm -f $(tex_from_md:%.tex=%.blg)
	rm -f $(tex_from_md:%.tex=%.bbl)
	rm -f missfont.log
	rm -f *Notes.bib
endif