SHELL=/bin/bash


# this is to make tex2svg from mathjax-node-cli show up in the PATH
# for the svgjax.py script
export PATH := $(HOME)/node_modules/.bin:$(PATH)


# convention to identify which SVGs need rendering
SVGMATHSOURCE=$(wildcard *_math.svg)
SVGMATHRENDER=$(SVGMATHSOURCE:_math.svg=.svg)

# render all IPE files to svg
IPESOURCE=$(wildcard *.ipe)
IPERENDER=$(IPESOURCE:.ipe=.svg)

# render all EMF files to png and svg
EMFSOURCE=$(wildcard *.emf)
EMFPNG=$(EMFSOURCE:.emf=.png)
EMFSVG=$(EMFSOURCE:.emf=.svg)


default: all

all: emf ipe svgmath


emf: emfpng emfsvg

emfpng: $(EMFPNG)

emfsvg: $(EMFSVG)

ipe: $(IPERENDER)

svgmath: $(SVGMATHRENDER)

%.png: %.emf
	emf2png $<

%.svg: %.pdf
	pdf2svg $< $@

%.pdf: %.emf
	emf2pdf $<

%.svg: %_math.svg
	./svgjax.py $< $@

%.svg: %.ipe
	iperender -svg $< $@
