.utils 7.97 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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"                                     \
18
19
               "Provided targets:\n\n   build, view, preview, clean, distclean, log, open, help\n"              \
               "\n"                                                                                             \
20
21
22
23
24
25
               "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"                                                 \
26
               "$(pr)$(dollar)OPTS$(rst) is used to pass additional options to $(sc)latexmk$(rst).\n"           \
27
28
29
               "\n"                                                                                             \
               "Examples:\n\n"                                                                                  \
               " $(dollar) make $(pr)OPTS$(rst)=$(sc)-gg$(rst)\n"                                               \
30
               " $(dollar) make $(pr)TARGET$(rst)=$(sc)resources/tex/intro$(rst) view\n"                        \
31
32
33
34
35
36
37
               " $(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"                                                                              \
38
               " $(dollar) make open\n"                                                                         \
39
40
41
42
43
44
45
               " $(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)))                                     \
46
47
48
49
50
51
52
53
               $(foreach file,$(TARGET),                                                                        \
                 $(eval SOURCE=$(notdir $(basename $(file))))                                                   \
                 $(if $(strip $(VARIANTSLIST)),                                                                 \
                   $(foreach variant, $(VARIANTSLIST),                                                          \
                     $(call LOG, $(BUILDDIR)/$(SOURCE)-$(variant).log)                                          \
                    );,                                                                                         \
                   $(call LOG, $(BUILDDIR)/$(SOURCE).log)                                                       \
                  )                                                                                             \
54
55
56
57
                )

LATEXMK_SELECT = $(if $(strip $(TARGET)),,$(eval TARGET=$(BASENAME)))                                           \
                 $(if $(strip $(VARIANTS)),,$(eval VARIANTS=$(BASEVARIANTS)))                                   \
58
59
60
61
62
63
64
65
66
67
68
69
                 $(foreach file,$(TARGET),                                                                      \
                   $(eval SOURCE=$(basename $(file)))                                                           \
                   $(if $(strip $(VARIANTSLIST)),                                                               \
                     $(foreach variant, $(VARIANTSLIST),                                                        \
                       export JOBNAME=$(notdir $(SOURCE))-$(variant)                                            \
                              TYPE=$(variant) &&                                                                \
                       $(call LATEXMK,$(SOURCE),$1);                                                            \
                      ),                                                                                        \
                     export JOBNAME=$(notdir $(SOURCE))                                                         \
                            TYPE=presentation &&                                                                \
                     $(call LATEXMK, $(SOURCE), $1);                                                            \
                    )                                                                                           \
70
71
72
73
                  )

LATEXMK_PREVIEW = $(if $(strip $(VARIANTS)),,$(eval VARIANTS=$(BASEVARIANTS)))                                  \
                  $(if $(strip $(VARIANTSLIST)),$(eval VARIANTSLIST=$(firstword $(VARIANTSLIST))),)             \
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
                  $(call LATEXMK_SELECT, -pvc)

LATEXMK_OPEN    = $(if $(strip $(TARGET)),,$(eval TARGET=$(BASENAME)))                                          \
                  $(if $(strip $(VARIANTS)),,$(eval VARIANTS=$(BASEVARIANTS)))                                  \
                  $(foreach file,$(TARGET),                                                                     \
                    $(eval SOURCE=$(basename $(file)))                                                          \
                    $(if $(strip $(VARIANTSLIST)),                                                              \
                      $(foreach variant, $(VARIANTSLIST),                                                       \
                        $(eval JOBNAME=$(notdir $(SOURCE))-$(variant).pdf)                                      \
                        $(VIEWER) $(BUILDDIR)/$(JOBNAME);                                                       \
                       ),                                                                                       \
                      $(eval JOBNAME=$(notdir $(SOURCE)).pdf)                                                   \
                      $(VIEWER) $(BUILDDIR)/$(JOBNAME);                                                         \
                     )                                                                                          \
                   )