Commit bbb657fb authored by Alija Sabic's avatar Alija Sabic
Browse files

Update build process

parent c9685109
# -*- cperl -*-
# latexmkrc
$tex = $ENV{'TEXENGINE'};
$builddir = $ENV{'BUILDDIR'};
$job = $ENV{'JOBNAME'};
$bibdirs = $ENV{'BIBDIRS'};
$target = $ENV{'TARGET'};
$type = $ENV{'TYPE'};
$aratio = $ENV{'ARATIO'};
$viewer = $ENV{'VIEWER'};
$recorder = 1;
......@@ -14,11 +16,16 @@ $dependents_list = 1;
$silence_logfile_warnings = 0;
$use_make_for_missing_files = 1;
$out_dir = $builddir;
$deps_file = "$builddir/$target.deps";
$deps_file = "$out_dir/$job.deps";
$jobname = $job;
@BIBINPUTS = ('.',$bibdirs);
# $bibtex = 'bibtex %O %B';
$pdflatex = join '', 'pdflatex %O -interaction=nonstopmode -synctex=1 -file-line-error "\PassOptionsToClass{', $type, '}{beamer} \input{%S}"';
$pdflatex = join '',
$tex,' %O',
'-interaction=nonstopmode -synctex=1 -file-line-error -shell-escape "',
'\PassOptionsToClass{',$type,',aspectratio=',$aratio,'}{beamer} ',
'\input{%S}"';
$pdf_previewer = $viewer;
push @generated_exts, 'blg', 'cut', 'nav', 'snm', 'vrb', 'synctex.gz';
\ No newline at end of file
push @generated_exts, 'blg', 'cut', 'nav', 'snm', 'sta', 'vrb', 'synctex.gz';
\ No newline at end of file
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" \
"Four 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)ASPECTRATIO$(rst) is used to specify the aspect ratio(s)" \
"(default: $(pr)$(dollar)BASEARATIO$(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)" \
"$(pr)ASPECTRATIO$(rst)=$(sc)43,169$(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) export $(pr)ASPECTRATIO$(rst)=$(sc)43$(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))) \
$(if $(strip $(ASPECTRATIO)),,$(eval ASPECTRATIO=$(BASEARATIO))) \
$(foreach file,$(TARGET), \
$(eval SOURCE=$(notdir $(basename $(file)))) \
$(if $(strip $(VARIANTSLIST)), \
$(foreach variant,$(VARIANTSLIST), \
$(if $(strip $(ASPECTRATIOLIST)), \
$(foreach aratio,$(ASPECTRATIOLIST), \
$(call LOG, $(BUILDDIR)/$(SOURCE)-$(variant)-$(aratio).log) \
) \
, \
$(call LOG, $(BUILDDIR)/$(SOURCE)-$(variant).log) \
) \
) \
, \
$(if $(strip $(ASPECTRATIOLIST)), \
$(foreach aratio,$(ASPECTRATIOLIST), \
$(call LOG, $(BUILDDIR)/$(SOURCE)-$(aratio).log) \
) \
, \
$(call LOG, $(BUILDDIR)/$(SOURCE).log) \
) \
) \
)
LATEXMK_SELECT = $(if $(strip $(TARGET)),,$(eval TARGET=$(BASENAME))) \
$(if $(strip $(VARIANTS)),,$(eval VARIANTS=$(BASEVARIANTS))) \
$(if $(strip $(ASPECTRATIO)),,$(eval ASPECTRATIO=$(BASEARATIO))) \
$(foreach file,$(TARGET), \
$(eval SOURCE=$(basename $(file))) \
$(if $(strip $(VARIANTSLIST)), \
$(foreach variant, $(VARIANTSLIST), \
$(if $(strip $(ASPECTRATIOLIST)), \
$(foreach aratio, $(ASPECTRATIOLIST), \
export JOBNAME=$(notdir $(SOURCE))-$(variant)-$(aratio) \
TYPE=$(variant) \
ARATIO=$(aratio) && \
$(call LATEXMK,$(SOURCE),$1); \
) \
, \
export JOBNAME=$(notdir $(SOURCE))-$(variant) \
TYPE=$(variant) \
ARATIO=43 && \
$(call LATEXMK,$(SOURCE),$1); \
) \
) \
, \
$(if $(strip $(ASPECTRATIOLIST)), \
$(foreach aratio, $(ASPECTRATIOLIST), \
export JOBNAME=$(notdir $(SOURCE))-$(aratio) \
TYPE=presentation \
ARATIO=$(aratio) && \
$(call LATEXMK,$(SOURCE),$1); \
) \
, \
export JOBNAME=$(notdir $(SOURCE)) \
TYPE=presentation \
ARATIO=43 && \
$(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))) \
$(if $(strip $(ASPECTRATIO)),,$(eval ASPECTRATIO=$(BASEARATIO))) \
$(foreach file,$(TARGET), \
$(eval SOURCE=$(basename $(file))) \
$(if $(strip $(VARIANTSLIST)), \
$(foreach variant, $(VARIANTSLIST), \
$(if $(strip $(ASPECTRATIOLIST)), \
$(foreach aratio, $(ASPECTRATIOLIST), \
$(eval JOBNAME=$(notdir $(SOURCE))-$(variant)-$(aratio).pdf) \
$(VIEWER) $(BUILDDIR)/$(JOBNAME); \
) \
, \
$(eval JOBNAME=$(notdir $(SOURCE))-$(variant).pdf) \
$(VIEWER) $(BUILDDIR)/$(JOBNAME); \
) \
) \
, \
$(if $(strip $(ASPECTRATIOLIST)), \
$(foreach aratio, $(ASPECTRATIOLIST), \
$(eval JOBNAME=$(notdir $(SOURCE))-$(aratio).pdf) \
$(VIEWER) $(BUILDDIR)/$(JOBNAME); \
) \
, \
$(eval JOBNAME=$(notdir $(SOURCE)).pdf) \
$(VIEWER) $(BUILDDIR)/$(JOBNAME); \
) \
) \
)
\ No newline at end of file
BASENAME = project-overview
include .utils
TEXENGINE ?= xelatex
BASENAME = project-overview
BUILDDIR = build
BASEVARIANTS = presentation
# BASEVARIANTS = beamer,second,handout,trans,article
BASEARATIO = 169
# BASEARATIO = 1610,169,149,141,54,43,32
BUILDDIR = build
VARIANTS = presentation handout notes
# space separated list of requested variants
VARIANTSLIST = $(eval comma:=,) $(subst $(comma), ,$(VARIANTS))
ASPECTRATIOLIST = $(eval comma:=,) $(subst $(comma), ,$(ASPECTRATIO))
# Environment
TEXDIRS = resources/latex/:resources/latex-sty/:resources/images/:resources/listings/
BIBDIRS = resources/latex/
BSTDIR = resources/latex-bst/
TEXDIRS = resources/latex:resources/latex-sty:resources/images:resources/listings
TEXDIRS := $(TEXDIRS):resources/theme:resources/images
BIBDIRS = resources/latex/
BSTDIR = resources/latex-bst/
# cf. latexmkrc
LATEXMKV = export TYPE=$1 TARGET="$(BASENAME)-$1" && latexmk -jobname="$(BASENAME)-$1" $2
LATEXMK = export TYPE= TARGET="$(basename $(notdir $1))" && latexmk $(basename $1)$2
VIEWER = xdg-open
LATEXMK = latexmk $(OPTS) $2 $1.tex | fold -sw $(out_length)
VIEWER = xdg-open
# main targets
all: $(VARIANTS)
clean:
find $(BUILDDIR) -type f -not -name "*.pdf" -delete
distclean:
rm -rf $(BUILDDIR)
define TEMPLATE =
$(BASENAME)-$(strip $(1)).pdf $(strip $(1)).build $(1): setup
$(call LATEXMKV,$(strip $(1)),)
$(strip $(1)).view: setup
$(call LATEXMKV,$(strip $(1)),-pv)
$(strip $(1)).preview: setup
$(call LATEXMKV,$(strip $(1)),-pvc)
$(strip $(1)).clean: setup
$(call LATEXMKV,$(strip $(1)),-c)
$(strip $(1)).distclean: setup
$(call LATEXMKV,$(strip $(1)),-C)
endef
$(foreach variant, $(VARIANTS), $(eval $(call TEMPLATE, $(variant))))
# dynamic targets
%.build: setup
$(call LATEXMK, $@, )
%.view: setup
$(call LATEXMK, $@, -pv)
%.preview: setup
$(call LATEXMK, $@, -pvc)
%.clean: setup
$(call LATEXMK, $@, -c)
%.distclean: setup
$(call LATEXMK, $@, -C)
all: build
build: setup
$(call LATEXMK_SELECT, )
log: setup
$(call LATEXMK_ERRS, $(TARGET))
view: setup
$(call LATEXMK_SELECT, -pv)
open: setup
$(call LATEXMK_OPEN)
preview: setup
$(call LATEXMK_PREVIEW, -pvc)
clean: setup
$(call LATEXMK_SELECT, -c)
distclean: setup
$(call LATEXMK_SELECT, -C)
help:
@echo $(INSTRUCTIONS)
%/:
mkdir -p $@
setup: .FORCE | $(BUILDDIR)/
.PHONY: all presentation handout notes clean distclean .FORCE
.PHONY: all build log view preview clean distclean .FORCE
.EXPORT_ALL_VARIABLES:
export JOBNAME=$(JOBNAME)
TEXINPUTS := :.:$(TEXDIRS)
# bibtex invoked from BUILDDIR, thus prepend './../'
BSTINPUTS := ./../$(BSTDIR)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment