PREFIX = motions
TEX = $(addsuffix _.tex, $(basename $(wildcard *.mdwn)))
PDF = $(addprefix $(PREFIX)-, $(subst .main.tex,.pdf,$(wildcard *.main.tex)))
ALL = $(TEX) $(PDF)

PREAMBLE = preamble_.tex acronyms_.tex attendants_.tex

all: $(ALL)

%_.tex: %.mdwn
	cat < $< | sed -e 's/^$$/\\mypar\n/' \
	| sed -f ../../preamble/acronyms.sed \
	      -f ../../preamble/attendants.sed \
	      -f ../../preamble/snippets.sed \
	      -f headings.sed \
	| pandoc -f markdown -t latex > $@

motions-%.pdf: %.main.tex $(TEX) $(PREAMBLE)
	pdflatex -jobname=$(basename $@) $<
	! grep -q  "Rerun.*right" $(basename $@).log ||\
	 pdflatex -jobname=$(basename $@) $<

clean:
	rm -f $(ALL)

$(PREAMBLE): %_.tex: ../../preamble/%.tex
	sed 's/..\/preamble\/\([a-z]*\)/\1_/g' < $< > $@

SEND_FILES = \
  $(wildcard *.pdf)

send:
	rsync -ruvp --chmod=Dugo+rx,Fugo+r $(SEND_FILES) www.fripost.org:/var/www/fripost.org/minutes
	@echo; echo Now avialable as; for f in $(SEND_FILES); do echo " - https://fripost.org/minutes/$$f"; done