10
2
Fork 0
has-writeup/Makefile

81 lines
3.0 KiB
Makefile

.PHONY: all clean
# i know this makefile is mega cursed i'm sorry :<
# ~ 🦈
CATS=aaaa comms ground-segment payload satellite-bus space
DOCS_ALL=$(wildcard $(addsuffix /**/README.md,$(CATS)))
WRITEUP_PDF=writeup.pdf
PDF_DIR=build
HTML_DIR=html
HTML_CONTENT_ALL=$(addprefix $(HTML_DIR)/,jork.png blahaj.css $(wildcard $(addsuffix /**/*,$(CATS))))
HTML_DOCS=$(addprefix $(HTML_DIR)/,$(DOCS_ALL:README.md=index.html))
HTML_INDEX=$(HTML_DIR)/index.html
HTML_TEMPLATE=$(abspath default.html5)
all: README.md $(WRITEUP_PDF) $(HTML_INDEX)
clean:
$(RM) -r $(WRITEUP_PDF) $(PDF_DIR) $(HTML_DIR)
README.md: $(DOCS_ALL)
@echo "GEN $@"
@(printf "# BLAHAJ Hack-a-Sat 2020 Writeups\n\n"; for file in $(DOCS_ALL); do \
printf -- "- [%s](%s)\n" "$$(dirname $$file)" "$$(dirname $$file)"; done) > README.md
$(WRITEUP_PDF): $(DOCS_ALL) fonts.tex misc.tex top.md
@echo "GEN writeup.md"
@mkdir $(PDF_DIR) 2>/dev/null || true
@find . -mindepth 3 -iname '*.png' -exec cp {} $(PDF_DIR) \;
@find . -mindepth 3 -iname '*.py' -exec cp {} $(PDF_DIR) \;
@cp fonts.tex misc.tex jork.png $(PDF_DIR)
@for md in top.md $(DOCS_ALL); do cat $$md; printf "\n\n\\\\newpage\n\n"; done > $(PDF_DIR)/writeup.md
@echo "PDF $@"
@cd $(PDF_DIR) && \
pandoc --filter pandoc-include-code --toc --toc-depth 1 -f markdown-implicit_figures \
-i writeup.md --pdf-engine=lualatex -o writeup.pdf
@cp $(PDF_DIR)/writeup.pdf $@
$(HTML_INDEX): $(HTML_DIR)/index.md $(HTML_DIR)/jork.png $(HTML_DIR)/blahaj.css \
$(HTML_DIR)/favicon.ico $(HTML_DIR)/writeup.pdf
@echo "HTML $@"
@cp -r mathjax/ $(HTML_DIR)/mathjax/
@pandoc -i $< -o $@ -t html5 -s --template $(HTML_TEMPLATE) --metadata lang=en \
--metadata title="BLAHAJ Hack-a-Sat 2020 Writeups" \
--metadata css="blahaj.css"
$(HTML_DIR)/favicon.ico: jork.png
@echo "ICO $@"
@convert $< -resize 128x128 $@
$(HTML_DIR)/writeup.pdf: $(WRITEUP_PDF)
@cp $< $@
$(HTML_DIR)/index.md: $(HTML_CONTENT_ALL) $(HTML_DOCS)
@echo "GEN $@"
@(printf "![A picture of a jork (jean shork)](jork.png)\n\n"; \
printf "# BLAHAJ Hack-a-Sat 2020 Writeups\n\n"; \
printf "[Writeup in PDF format](writeup.pdf)\n\n"; \
for file in $(DOCS_ALL); do \
printf -- "- [%s](%s/)\n" "$$(grep '^# ' $$file|head -n1 | sed 's/^# //')" "$$(dirname $$file)"; \
done) > $@
$(HTML_CONTENT_ALL): $(HTML_DIR)/%: %
@mkdir -p $(dir $@) || true
@cp $< $@
$(HTML_DOCS): %index.html: %README.md $(HTML_CONTENT_ALL)
@echo "HTML $@"
@cd $(dir $@) && $(RM) tmp.md index.html
@cd $(dir $@) && (cat README.md; \
printf "\n\n\n### Files\n"; \
for file in *; do \
[ "$$file" != "tmp.md" ] && printf -- "- [%s](%s)\n" "$$file" "$$file" || true; \
done) >> tmp.md
@cd $(dir $@) && \
pandoc --filter pandoc-include-code --toc -f markdown \
-i tmp.md -t html5 -o index.html --mathjax="../../mathjax/tex-mml-chtml.js" \
-s --metadata title="$$(grep '^# ' README.md|head -n1|sed 's/^# //')" --template $(HTML_TEMPLATE) \
--metadata lang=en --metadata css="../../blahaj.css"
@cd $(dir $@) && $(RM) tmp.md