width = 110
height = `perl -e 'print int($(width) * 0.5)'`

target = violet.txt

all: $(target)
	@perl freq.pl $<
	@sed -e 's/o/ /g' $(target) | perl freq.pl

violet.txt: gray.txt black.txt
	perl merge.pl $^ | perl trim_space.pl > $@

gray.txt: gray.ppm Makefile
	perl anytotxt.pl $< $(width) $(height) > $@

black.txt: black.ppm Makefile
	perl anytotxt.pl $< $(width) $(height) | sed -e 's/X/o/g' > $@

gray.ppm: violet.png
	pngtopnm $< | pamthreshold -simple -threshold=0.4 | pamdepth 255 | pamtopnm > $@

black.ppm: violet.png
	pngtopnm $< | pamthreshold -simple -threshold=0.6 | pamdepth 255 | pamtopnm > $@

clean:
	-rm -f black.txt black.ppm gray.txt gray.ppm $(target)

backup:
	-rm -f backup.tar.xz
	tar cf backup.tar *.keep *.pl *.svg Makefile
	xz -9 backup.tar
