Last active
January 10, 2018 06:53
-
-
Save tekknolagi/19b17431843c05109c833cc925d460fe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Pandoc with my options | |
PANDOCBIN=stack exec pandoc -- --smart --standalone --from=markdown+footnotes \ | |
--filter pandoc-include-code | |
# Special options for ether PDF or HTML | |
PANDOCPDF=$(PANDOCBIN) --include-in-header header.tex | |
PANDOCWEB=$(PANDOCBIN) --self-contained --include-in-header header.html | |
# Where the output should go | |
OBJDIR=_gen | |
# Find all the lecture files -- should be laid out flat in lectures/ | |
LECTURE_SOURCES=$(wildcard lectures/*.md) | |
LECTURES_PDF=$(addprefix $(OBJDIR)/, $(LECTURE_SOURCES:.md=.pdf)) | |
LECTURES_WEB=$(addprefix $(OBJDIR)/, $(LECTURE_SOURCES:.md=.html)) | |
GREP=grep --files-with-matches --recursive --perl-regexp | |
LECTURES_WITH_IMAGES=$(shell $(GREP) '.*\!\[.*\]\((.*\.dot\.png)\).*' lectures) | |
LECTURES_WITH_INCLUDES=$(shell $(GREP) '```\{\.\w+\s+include=(.+)\s*.*}' lectures) | |
SHARDS= | |
SHARDS+=$(LECTURES_WITH_IMAGES) | |
SHARDS+=$(LECTURES_WITH_INCLUDES) | |
# Compile a list of dependency Makefiles so that make will update the generated | |
# documents whenever a sub-document (diagram, code listing) changes. | |
LECTURES_DEP=$(addprefix $(OBJDIR)/, $(SHARDS:.md=.md.d)) | |
all: $(LECTURES_DEP) syllabus lectures | |
clean: | |
rm -rf $(OBJDIR) | |
syllabus: $(OBJDIR)/syllabus.pdf $(OBJDIR)/syllabus.html | |
lectures: $(LECTURES_PDF) $(LECTURES_WEB) | |
# The process for generating a dependency Makefile involves finding the | |
# sub-documents within the markdown and then ejecting them as dependencies for | |
# the PDFs and HTML files. | |
$(OBJDIR)/%.md.d: %.md | |
@mkdir -p $(@D) # Make the directory required for the target | |
@echo Building $@ ... | |
$(eval PDF := $(OBJDIR)/$(<:.md=.pdf)) | |
$(eval HTML := $(OBJDIR)/$(<:.md=.html)) | |
@# Find the dot-made diagrams in files | |
@perl -ne 'print "$(PDF) $(HTML): $$1"."\n" if s/.*!\[.*\]\((.*\.dot\.png)\).*/\1/p' $< > $@ | |
@# Find the included code in files | |
@perl -ne 'print "$(PDF) $(HTML): $$1"."\n" if s/```\{\.\w+\s+include=(.+)\s*.*}/\1/g' $< >> $@ | |
$(OBJDIR)/%.dot.png: %.dot | |
@mkdir -p $(@D) # Make the directory required for the target | |
dot -Tpng $< -o $@ | |
$(OBJDIR)/%.pdf: %.md header.tex | |
@mkdir -p $(@D) | |
@echo Building $@ ... | |
@$(PANDOCPDF) -s $< -o $@ | |
$(OBJDIR)/%.html: %.md header.html | |
@mkdir -p $(@D) | |
@echo Building $@ ... | |
@$(PANDOCWEB) -s $< -o $@ | |
# The minus sign suppresses errors, which happen on a clean make | |
-include $(LECTURES_DEP) | |
# Use POSIX versions of make features | |
.POSIX: | |
# These targets do not produce object files of those names, so they must be | |
# phony targets. | |
.PHONY: all clean syllabus lectures |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment