.utils 5.94 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
pr           = $(shell echo "\e[38;5;36m")
sc           = $(shell echo "\e[38;5;231m")
ac           = $(shell echo "\e[38;5;197m")
rst          = $(shell echo "\e[0m")
dollar       = `echo '\$$'`

out_length   = 80
header       = -------------------------------------------------------------------------------
print_banner = $1$(header)\n==$(rst) $2$1\n$(header)$(rst)\n

ERRS         = error
LOG          = @echo "$(call print_banner,$(ac),Error Log:$(sc)$1$(rst))\e[1A"                               && \
               grep $(ERRS) $1 -nR -A4 -B8 | fold -sw $(out_length)                                           | \
               sed --expression='s/--/$(ac)$(header)\n$(header)$(rst)/g'                                      | \
               grep --color -E -e '' -e '$(ERRS)' && echo "$(ac)$(header)\n$(header)$(rst)\n"

INSTRUCTIONS = "$(call print_banner,$(pr),$(sc)Help Instructions $(rst))\n"                                     \
               "Provided targets:\n\n   build, view, preview, log, clean, distclean, help\n\n"                  \
               "Three environment variables are used to configure the behavior of those targets:\n"             \
               "\n"                                                                                             \
               "$(pr)$(dollar)TARGET$(rst) is used to specify the $(sc)tex$(rst) file to compile"               \
               "(default: $(pr)$(dollar)BASENAME$(rst)).\n"                                                     \
               "$(pr)$(dollar)VARIANTS$(rst) is used to specify none, one, or multiple variants"                \
               "(default: $(pr)$(dollar)BASEVARIANTS$(rst)).\n"                                                 \
25
               "$(pr)$(dollar)OPTS$(rst) is used to pass additional options to $(sc)latexmk$(rst).\n"           \
26
27
28
               "\n"                                                                                             \
               "Examples:\n\n"                                                                                  \
               " $(dollar) make $(pr)OPTS$(rst)=$(sc)-gg$(rst)\n"                                               \
29
               " $(dollar) make $(pr)TARGET$(rst)=$(sc)resources/tex/intro$(rst) view\n"                        \
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
               " $(dollar) make $(pr)VARIANTS$(rst)=$(sc)handout,presentation$(rst) build\n"                    \
               " $(dollar) make $(pr)VARIANTS$(rst)=, view\n"                                                   \
               "\n"                                                                                             \
               "Export variables to set them permanently.\n\n"                                                  \
               " $(dollar) export $(pr)TARGET$(rst)=$(sc)resources/tex/intro.tex$(rst)\n"                       \
               " $(dollar) export $(pr)VARIANTS$(rst)=$(sc)notes$(rst)\n"                                       \
               " $(dollar) make\n"                                                                              \
               " $(dollar) make preview\n"                                                                      \
               " $(dollar) make clean\n"                                                                        \
               "\n$(pr)$(header)$(rst)"                                                                         \
               "\n$(pr)$(header)$(rst)"

LATEXMK_ERRS = $(if $(strip $(TARGET)),,$(eval TARGET=$(BASENAME)))                                             \
               $(if $(strip $(VARIANTS)),,$(eval VARIANTS=$(BASEVARIANTS)))                                     \
               $(eval SOURCE=$(notdir $(basename $(TARGET))))                                                   \
               $(if $(strip $(VARIANTSLIST)),                                                                   \
                 $(foreach v, $(VARIANTSLIST),                                                                  \
                   $(call LOG, $(BUILDDIR)/$(SOURCE)-$(v).log)                                                  \
                  );,                                                                                           \
                 $(call LOG, $(BUILDDIR)/$(SOURCE).log)                                                         \
                )

LATEXMK_SELECT = $(if $(strip $(TARGET)),,$(eval TARGET=$(BASENAME)))                                           \
                 $(if $(strip $(VARIANTS)),,$(eval VARIANTS=$(BASEVARIANTS)))                                   \
                 $(eval SOURCE=$(basename $(TARGET)))                                                           \
                 $(if $(strip $(VARIANTSLIST)),                                                                 \
                   $(foreach v, $(VARIANTSLIST),                                                                \
                     export JOBNAME=$(notdir $(SOURCE))-$(v)                                                    \
                            TYPE=$(v) &&                                                                        \
                     $(call LATEXMK,$(SOURCE),$1);                                                              \
                    ),                                                                                          \
                   export JOBNAME=$(notdir $(SOURCE))                                                           \
                          TYPE=presentation &&                                                                  \
                   $(call LATEXMK, $(SOURCE), $1);                                                              \
                  )

LATEXMK_PREVIEW = $(if $(strip $(VARIANTS)),,$(eval VARIANTS=$(BASEVARIANTS)))                                  \
                  $(if $(strip $(VARIANTSLIST)),$(eval VARIANTSLIST=$(firstword $(VARIANTSLIST))),)             \
                  $(call LATEXMK_SELECT, -pvc)