SHELL=/bin/bash

.PHONY: all clean upload

.SECONDARY:

main_sources = $(wildcard *.mdwn)
pdfs = $(patsubst %.mdwn,%.pdf,$(main_sources))
deps = $(patsubst %,tex_out/%.d,$(main_sources))

all: $(pdfs)

tex_out/%.mdwn.d: %.mdwn ../../mdwn_inline.py
	@mkdir -p $(dir $@)
	@../../mdwn_inline.py --deps $< tex_out/$*.mdwn

tex_out/%.mdwn: %.mdwn ../../mdwn_inline.py
	mkdir -p $(dir $@)
	../../mdwn_inline.py $< tex_out/$*.mdwn

%.pdf: tex_out/%.mdwn ../../pandoc_img.py
	pandoc \
		--filter ../../pandoc_img.py \
		-V margin-top=0.9in \
		-V margin-bottom=0.9in \
		-V margin-left=0.4in \
		-V margin-right=0.4in \
		-V fontsize=9pt \
		-V papersize=legal \
		-V linkcolor=blue \
		-f markdown $< \
		-s --self-contained \
		--mathjax \
		-o $@

upload: all
	sftp sftp://ftp@ftp.libre-soc.org:922 <<<$$'cd biginteger\nprogress\nput *.pdf'

clean:
	rm -fr *.pdf tex_out

-include $(deps)
