#!/usr/bin/make -f

NAME=confont
COOLNAME=ConFont
FONTS=Regular
WHERE=${DESTDIR}/usr/share/fonts
SRCDIR=.
BLDDIR=build

default: all
all: otf ttf webfonts
#all: $COOLNAME.sfd
OTF=$(FONTS:%=$(BLDDIR)/$(COOLNAME)-%.otf)
TTF=$(FONTS:%=$(BLDDIR)/$(COOLNAME)-%.ttf)
WOFF2=$(FONTS:%=$(BLDDIR)/$(COOLNAME)-%.woff2)

# if one of these conversions fails, it'll look funny, but it'll say why.
# that fontforge header is a little noisy - cut it down slightly

$(BLDDIR)/${COOLNAME}-%.otf: ${COOLNAME}.sfd ${BLDDIR}
	@echo -n "  BUILD    $@:	"
	fontforge -c 'open("$<").generate("$@");print("otf: OK\n")' 2>&1 | tail -n +6

$(BLDDIR)/${COOLNAME}-%.ttf: ${COOLNAME}.sfd ${BLDDIR}
	@echo -n "  BUILD    $@:	"
	fontforge -c 'open("$<").generate("$@");print("ttf: OK\n")' 2>&1 | tail -n +6

$(BLDDIR)/${COOLNAME}-%.woff2: ${COOLNAME}.sfd ${BLDDIR}
	@echo -n "  WEBFONT    $@:	"
	fontforge -c 'open("$<").generate("$@");print("woff OK\n")' 2>&1 | tail -n +6

${BLDDIR}:
	@mkdir -p build

ttf: $(TTF)
otf: $(OTF)
webfonts: $(WOFF2)

install: ttf otf webfonts
	mkdir -p ${WHERE}/opentype/${NAME} ${WHERE}/truetype/${NAME} ${WHERE}/woff/${NAME}
	install -D -m 0644 $(BLDDIR)/*.otf ${WHERE}/opentype/${NAME}
	install -D -m 0644 $(BLDDIR)/*.ttf ${WHERE}/truetype/${NAME}
	install -D -m 0644 $(BLDDIR)/*.woff2 ${WHERE}/woff/${NAME}

clean:
	# the "build" literal is a special case so that we do not delete "."
	rm -r build $(BLDDIR)/*.ttf $(BLDDIR)/*.otf $(BLDDIR)/*.woff2 || echo 'Nothing to clean at this moment...'
