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, clean, distclean, log, open, 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" \ "$(pr)$(dollar)OPTS$(rst) is used to pass additional options to $(sc)latexmk$(rst).\n" \ "\n" \ "Examples:\n\n" \ " $(dollar) make $(pr)OPTS$(rst)=$(sc)-gg$(rst)\n" \ " $(dollar) make $(pr)TARGET$(rst)=$(sc)resources/tex/intro$(rst) view\n" \ " $(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 open\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))) \ $(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) \ ) \ ) LATEXMK_SELECT = $(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), \ export JOBNAME=$(notdir $(SOURCE))-$(variant) \ TYPE=$(variant) && \ $(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) 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); \ ) \ )