|
| 1 | + |
| 2 | +OUT_DIR := build/ |
| 3 | +TOPTARGETS := clean all |
| 4 | +FILES := $(wildcard git-days/*.tex sheet/*.tex) |
| 5 | + |
| 6 | +define compile_latex_with_jobname_and_env |
| 7 | + cd $(4) && $(3) latexmk --shell-escape -synctex=1 -interaction=nonstopmode -file-line-error -lualatex -jobname=$(2) "$(1)" |
| 8 | +endef |
| 9 | + |
| 10 | +define build_latex_with_jobname_and_env |
| 11 | + $(eval DIR := $(dir $(1))) |
| 12 | + $(eval FILE := $(notdir $(1))) |
| 13 | + @echo -e "\e[1;32mCompiling \"$(FILE)\" in \"$(DIR)\" with jobname \"$(2)\"$<\e[0m" |
| 14 | + @$(call compile_latex_with_jobname_and_env,$(FILE),$(2),$(3),$(DIR)) |
| 15 | + @echo -e "\e[1;32mSuccessfully compiled \"$(FILE)\" in \"$(DIR)\" with jobname \"$(2)\"$<\e[0m" |
| 16 | + @mkdir -p $(OUT_DIR) |
| 17 | + @cp $(DIR)/$(2).pdf $(OUT_DIR)/ |
| 18 | +endef |
| 19 | + |
| 20 | +all: |
| 21 | + $(MAKE) compile |
| 22 | + |
| 23 | +$(FILES:.tex=.tex.regular): |
| 24 | + $(eval FILE := $(patsubst %.tex.regular,%.tex,$@)) |
| 25 | + $(call build_latex_with_jobname_and_env,$(FILE),$(notdir $(patsubst %.tex,%,$(FILE))),) |
| 26 | + |
| 27 | +$(FILES:.tex=.tex.darkmode): |
| 28 | + $(eval FILE := $(patsubst %.tex.darkmode,%.tex,$@)) |
| 29 | + $(call build_latex_with_jobname_and_env,$(FILE),$(notdir $(patsubst %.tex,%-darkmode,$(FILE))),DARK_MODE=1) |
| 30 | + |
| 31 | +compile: $(FILES:.tex=.tex.regular) $(FILES:.tex=.tex.darkmode) |
| 32 | + @echo -e "\e[1;42mAll Done. PDFs can be found in $(OUT_DIR)\e[0m" |
| 33 | + |
| 34 | +clean: |
| 35 | + @echo -e "\e[1;34mCleaning up leftover build files...$<\e[0m" |
| 36 | + @latexmk -C -f git-days |
| 37 | + @find . -ignore_readdir_race -not \( -path "*/.git/*" -prune \) -wholename '**/options.cfg' -exec rm -rf {} \; |
| 38 | + @find . -ignore_readdir_race -maxdepth 1 -not \( -path "*/.git/*" -prune \) -wholename '**/*.pdf' -exec rm -rf {} \; |
| 39 | + @find . -ignore_readdir_race -not \( -path "*/.git/*" -prune \) -wholename '**/*.aux' -exec rm -rf {} \; |
| 40 | + @find . -ignore_readdir_race -not \( -path "*/.git/*" -prune \) -wholename '**/*.fdb_latexmk' -exec rm -rf {} \; |
| 41 | + @find . -ignore_readdir_race -not \( -path "*/.git/*" -prune \) -wholename '**/*.fls' -exec rm -rf {} \; |
| 42 | + @find . -ignore_readdir_race -not \( -path "*/.git/*" -prune \) -wholename '**/*.len' -exec rm -rf {} \; |
| 43 | + @find . -ignore_readdir_race -not \( -path "*/.git/*" -prune \) -wholename '**/*.listing' -exec rm -rf {} \; |
| 44 | + @find . -ignore_readdir_race -not \( -path "*/.git/*" -prune \) -wholename '**/*.log' -exec rm -rf {} \; |
| 45 | + @find . -ignore_readdir_race -not \( -path "*/.git/*" -prune \) -wholename '**/*.out' -exec rm -rf {} \; |
| 46 | + @find . -ignore_readdir_race -not \( -path "*/.git/*" -prune \) -wholename '**/*.synctex.gz' -exec rm -rf {} \; |
| 47 | + @find . -ignore_readdir_race -not \( -path "*/.git/*" -prune \) -wholename '**/*.toc' -exec rm -rf {} \; |
| 48 | + @find . -ignore_readdir_race -not \( -path "*/.git/*" -prune \) -wholename '**/*.nav' -exec rm -rf {} \; |
| 49 | + @find . -ignore_readdir_race -not \( -path "*/.git/*" -prune \) -wholename '**/*.snm' -exec rm -rf {} \; |
| 50 | + @find . -ignore_readdir_race -not \( -path "*/.git/*" -prune \) -wholename '**/*.vrb' -exec rm -rf {} \; |
| 51 | + @find . -ignore_readdir_race -not \( -path "*/.git/*" -prune \) -wholename '**/*.bbl' -exec rm -rf {} \; |
| 52 | + @find . -ignore_readdir_race -not \( -path "*/.git/*" -prune \) -wholename '**/*.blg' -exec rm -rf {} \; |
| 53 | + @find . -ignore_readdir_race -not \( -path "*/.git/*" -prune \) -wholename '**/*.idx' -exec rm -rf {} \; |
| 54 | + @find . -ignore_readdir_race -not \( -path "*/.git/*" -prune \) -wholename '**/*.ilg' -exec rm -rf {} \; |
| 55 | + @find . -ignore_readdir_race -not \( -path "*/.git/*" -prune \) -wholename '**/*.ind' -exec rm -rf {} \; |
| 56 | + @find . -ignore_readdir_race -not \( -path "*/.git/*" -prune \) -wholename '**/*.pyg' -exec rm -rf {} \; |
| 57 | + @find . -ignore_readdir_race -not \( -path "*/.git/*" -prune \) -wholename '**/*.bak[0-9]*' -exec rm -rf {} \; |
| 58 | + @find . -ignore_readdir_race -not \( -path "*/.git/*" -prune \) -wholename '**/_minted-*' -exec rm -rf {} \; |
| 59 | + @find . -ignore_readdir_race -not \( -path "*/.git/*" -prune \) -wholename '**/svg-inkscape' -exec rm -rf {} \; |
| 60 | + @echo -e "\e[1;44mDone cleaning up leftover build files.$<\e[0m" |
| 61 | + |
| 62 | +cleanBuild: |
| 63 | + @echo -e "\e[1;34mCleaning up build directory...$<\e[0m" |
| 64 | + @rm -rf $(OUT_DIR) |
| 65 | + @echo -e "\e[1;44mDone cleaning up build directory.$<\e[0m" |
| 66 | + |
| 67 | +cleanAll: clean cleanBuild |
0 commit comments