Makefile 3.88 KB
Newer Older
1
2
BASENAME     = demo
BUILDDIR     = build
3

4
5
6
7
8
9
# environment
TEXDIRS      = resources/tex:resources/latex-sty:resources/listings:resources/latex
TEXDIRS     := $(TEXDIRS):resources/images:resources/tables:resources/latex
TEXDIRS     := $(TEXDIRS):resources/figures
BIBDIRS      = resources/latex/
BSTDIR       = resources/latex-bst/
10
11

# cf. latexmkrc
12
13
LATEXMK      = latexmk $(OPTS)$1
VIEWER       = xdg-open
14

15
16
17
18
19
LATEXMK_COND = @export DEPSFILE=$(notdir $(basename $(TARGET))) &&                                  \
               $(if $(strip $(TARGET)),                                                             \
                 $(call LATEXMK, $(basename $(TARGET))$1),                                          \
                 $(call LATEXMK, $(BASENAME)$1)                                                     \
               && echo '' && echo $(INSTRUCTIONS))
20

21
22
23
24
LATEXMK_ERRS = $(if $(strip $1),                                                                    \
                 $(call LOG, $(BUILDDIR)/$(basename $1).log),                                       \
                 $(call LOG, $(BUILDDIR)/$(basename $(BASENAME)).log)                               \
               )
25

26
all: build
27

28
29
build: setup
	$(call LATEXMK_COND, )
30

31
32
log:
	$(call LATEXMK_ERRS, $(TARGET))
33

34
35
36
37
38
39
40
41
42
43
44
45
46
47
view: setup
	$(call LATEXMK_COND, -pv)

preview: setup
	$(call LATEXMK_COND, -pvc)

clean: setup
	$(call LATEXMK_COND, -c)

distclean: setup
	$(call LATEXMK_COND, -C)

help:
	@echo $(INSTRUCTIONS)
48
49
50
51

%/:
	mkdir -p $@

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
setup: .FORCE | $(BUILDDIR)/

ccpri=$(shell echo "\033[0;36m")
ccacc=$(shell echo "\033[0;33m")
ccend=$(shell echo "\033[0m")
dollar=`echo '\$$'`

DELIM        = $(ccacc)------------\n------------$(ccend)
ERRS         = error
LOG          = @echo "$(DELIM)\n" && grep $(ERRS) $1 -A4 -B4 |                                      \
               sed --expression='s/--/\n$(DELIM)\n/g'        |                                      \
               grep --color -E -e '' -e '$(ERRS)' && echo "\n$(DELIM)"

INSTRUCTIONS = "$(ccpri)------------------------------------------------------"                     \
               "\n=$(ccend) Help Instructions                                  $(ccpri)="           \
               "\n$(ccpri)------------------------------------------------------$(ccend)\n"         \
               "\n Provided targets:\n\n   build, view, preview, log, clean, distclean, help\n"     \
               "\n Set $(ccpri)$(dollar)TARGET$(ccend) to specify the tex file to"                  \
               "compile \n and $(ccpri)$(dollar)OPTS$(ccend) for additional options"                \
               "to pass to latexmk.\n"                                                              \
               "\n Examples:\n"                                                                     \
               "\n  $(dollar) make $(ccacc)TARGET$(ccend)=tex/figures/logo $(ccacc)OPTS$(ccend)=-gg"\
               "\n  $(dollar) make $(ccacc)TARGET$(ccend)=tex/figures/logo clean"                   \
               "\n\n or set permanently\n"                                                          \
               "\n  $(dollar) export $(ccacc)TARGET$(ccend)=tex/chapter.tex"                        \
               "\n  $(dollar) make"                                                                 \
               "\n  $(dollar) make preview"                                                         \
               "\n  $(dollar) make clean"                                                           \
               "\n\n or unset $(ccacc)$(dollar)TARGET$(ccend) to turn off this help instruction."

82
83
.PHONY: all clean distclean .FORCE

84
# export all variables by default
85
86
87
88
89
90
.EXPORT_ALL_VARIABLES:
TEXINPUTS := :.:$(TEXDIRS)
# bibtex invoked from BUILDDIR, thus prepend './../'
BSTINPUTS := ./../$(BSTDIR)
BIBINPUTS := :.:./../$(BIBDIRS)

91
# disable implicit suffix and built-in rules (for performance and profit)
92
93
.SUFFIXES:
MAKEFLAGS += --no-builtin-rules