width = 133
height = `perl -e 'print int($(width) * 0.51)'`
threshold1 = 0.5
threshold2 = 0.9

target = ubel.txt

all: $(target)

$(target): layer1.txt layer2.txt merge_layers.rb trim_space.pl freq.pl
	ruby merge_layers.rb layer1.txt layer2.txt | perl trim_space.pl > $@
	perl freq.pl $@

layer1.txt: ubel.png Makefile pgmtotxt.pl
	pngtopnm $< | pamscale -xsize=$(width) -ysize=$(height) | pamthreshold -simple -threshold=$(threshold1) | pamtopnm | ppmtopgm | perl pgmtotxt.pl > $@

layer2.txt: ubel.png Makefile pgmtotxt.pl
	pngtopnm $< | pamscale -xsize=$(width) -ysize=$(height) | pamthreshold -simple -threshold=$(threshold2) | pamtopnm | ppmtopgm | perl pgmtotxt.pl |sed -e 's/X/./g' > $@

clean:
	-rm -f $(target) layer{1,2}.txt
