.PHONY: all clean ttf web pack

VERSION=0.015

TOOLS=tools
SRC=sources
WEB=web
DOC=documentation
FONTS=amiri-regular

BUILD=$(TOOLS)/build.py
FF=python $(BUILD)
MKEOT=ttf2eot

SFDS=$(FONTS:%=$(SRC)/%.sfd)
DTTF=$(FONTS:%=%.ttf)
WTTF=$(FONTS:%=$(WEB)/%.ttf)
WOFF=$(FONTS:%=$(WEB)/%.woff)
EOTS=$(FONTS:%=$(WEB)/%.eot)
PDFS=$(FONTS:%=$(DOC)/%-table.pdf)
CSSS=$(WEB)/amiri.css
FEAT=$(SRC)/classes.fea $(SRC)/gsub.fea $(SRC)/locl.fea $(SRC)/tnum.fea $(SRC)/lellah.fea $(SRC)/calt.fea $(SRC)/kern.fea

docfiles=$(DOC)/README.txt $(DOC)/README-Arabic.txt $(DOC)/NEWS.txt $(DOC)/NEWS-Arabic.txt
license=OFL.txt OFL-FAQ.txt

all: ttf web

ttf: $(DTTF)
web: $(WTTF) $(WOFF) $(EOTS) $(CSSS)
table: $(PDFS)

%.ttf: $(SRC)/%.sfd $(FEAT) $(BUILD)
	@echo "   FF\t$@"
	@$(FF) --input $< --output $@ --feature-files "$(FEAT)" --version $(VERSION) --no-localised-name

$(WEB)/%.ttf: $(SRC)/%.sfd $(FEAT) $(BUILD)
	@echo "   FF\t$@"
	@mkdir -p $(WEB)
	@$(FF) --web --input $< --output $@ --feature-files "$(FEAT)" --version $(VERSION)

$(WEB)/%.woff: $(SRC)/%.sfd $(FEAT) $(BUILD)
	@echo "   FF\t$@"
	@mkdir -p $(WEB)
	@$(FF) --web --input $< --output $@ --feature-files "$(FEAT)" --version $(VERSION)

$(WEB)/%.eot: $(WEB)/%.ttf
	@echo "   FF\t$@"
	@mkdir -p $(WEB)
	@$(MKEOT) $< > $@

$(WEB)/%.css: $(SFDS) $(BUILD)
	@echo "   GEN\t$@"
	@mkdir -p $(WEB)
	@$(FF) --css --input $^ --output $@ --version $(VERSION)

$(DOC)/%-table.pdf: %.ttf
	@echo "   GEN\t$@"
	@mkdir -p $(DOC)
	@fntsample --font-file $< --output-file $@.tmp --print-outline > $@.txt
	@pdfoutline $@.tmp $@.txt $@

clean:
	@rm -rf $(DTTF) $(WTTF) $(WOFF) $(EOTS) $(CSSS)

