#   Makefile
#
#   Copyright (c) 2012, Nikita Volchenkov <nikitavolchenkov@gmail.com>
#   All rights reserved.
#
#   Redistribution and use in source and binary forms, with or without
#   modification, are permitted provided that the following conditions are met:
#
#   1. Redistributions of source code must retain the above copyright notice,
#      this list of conditions and the following disclaimer.
#   2. Redistributions in binary form must reproduce the above copyright
#      notice, this list of conditions and the following disclaimer in the
#      documentation and/or other materials provided with the distribution.
#
#   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
#   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
#   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
#   ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
#   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
#   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
#   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
#   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
#   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
#   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
#   POSSIBILITY OF SUCH DAMAGE.

VERSION = 0.3
DISTPREFIX = opengostfont
GENFONTS = ./genfonts.py

SFDFILES := OpenGostTypeA-Regular.sfd OpenGostTypeB-Regular.sfd OpenGostTypeA-UpsideDown.sfd OpenGostTypeB-UpsideDown.sfd

OTFDIR := ./$(DISTPREFIX)-otf-$(VERSION)
OTFFILES := $(SFDFILES:.sfd=.otf)
OTFFILES := $(addprefix $(OTFDIR), $(OTFFILES))

TTFDIR := ./$(DISTPREFIX)-ttf-$(VERSION)
TTFFILES := $(SFDFILES:.sfd=.ttf)
TTFFILES := $(addprefix $(TTFDIR), $(TTFFILES))

SRCDIR := ./$(DISTPREFIX)-src-$(VERSION)
SCRIPTS = $(GENFONTS) Makefile
DOCUMENTS = LICENSE

all: otf ttf
.PHONY: otf ttf all dist-otf dist-ttf dist-src dist clean
.PHONY: dist-otf-zip dist-ttf-zip dist-zip dist-all

$(OTFDIR):
	mkdir -p $(OTFDIR)

$(TTFDIR):
	mkdir -p $(TTFDIR)

$(SRCDIR):
	mkdir -p $(SRCDIR)

$(OTFFILES): $(OTFDIR) $(SFDFILES)
	$(GENFONTS) --output-dir $(OTFDIR) --opentype $(SFDFILES)

$(TTFFILES): $(TTFDIR) $(SFDFILES)
	$(GENFONTS) --output-dir $(TTFDIR) --truetype $(SFDFILES)

otf: $(OTFFILES)

ttf: $(TTFFILES)

copy-doc-otf: otf
	cp $(DOCUMENTS) $(OTFDIR)

copy-doc-ttf: ttf
	cp $(DOCUMENTS) $(TTFDIR)

dist-otf: otf copy-doc-otf
	tar --xz -cf $(DISTPREFIX)-otf-$(VERSION).tar.xz $(OTFDIR)

dist-ttf: ttf copy-doc-ttf
	tar --xz -cf $(DISTPREFIX)-ttf-$(VERSION).tar.xz $(TTFDIR)

dist-otf-zip: otf copy-doc-otf
	zip -9 -r -X $(DISTPREFIX)-otf-$(VERSION).zip $(OTFDIR)

dist-ttf-zip: ttf copy-doc-ttf
	zip -9 -r -X $(DISTPREFIX)-ttf-$(VERSION).zip $(TTFDIR)

dist-src: $(SRCDIR)
	cp $(SFDFILES) $(SCRIPTS) $(DOCUMENTS) $(SRCDIR)
	tar --xz -cf $(DISTPREFIX)-src-$(VERSION).tar.xz $(SRCDIR)

dist: dist-otf dist-ttf

dist-zip: dist-otf-zip dist-ttf-zip

dist-all: dist dist-zip dist-src

clean:
	rm -rf $(OTFDIR) $(TTFDIR) $(SRCDIR) *.tar.xz *.zip

