#  Makefile for Mona fonts
#  by 1@2ch, 2002, public domain

VERSION = 2.11

## Machine dependent

SED_CMD		= sed
PERL_CMD	= perl

# for XFree86
GZIP_CMD	= gzip
GZIP_SUFFIX	= gz

# for traditional Xserver (SunOS, HP-UX, Tru64 etc.)
#GZIP_CMD	= compress
#GZIP_SUFFIX	= Z

X11BINDIR	= /usr/X11R6/bin
X11FONTDIR	= /usr/X11R6/lib/X11/fonts/local
BDFTOPCF	= $(X11BINDIR)/bdftopcf
MKDIRHIER	= $(X11BINDIR)/mkdirhier	# 'mkdir -p' may also work.
MKFONTDIR	= $(X11BINDIR)/mkfontdir

## Other macros

BIT2BDF	= $(PERL_CMD) tools/bit2bdf
BDFMERGE= $(PERL_CMD) tools/bdfmerge
MKBOLD	= $(PERL_CMD) tools/mkbold -V
MKITALIC= $(PERL_CMD) tools/mkitalic -V
ADJUST	= $(PERL_CMD) tools/adjust
MKISO8859= $(SED_CMD) 's/@@REGISTRY@@/ISO8859/g;s/@@ENCODING@@/1/g;s/@@CHARS@@/191/g;'
MKJISX0201= $(SED_CMD) 's/@@REGISTRY@@/JISX0201.1976/g;s/@@ENCODING@@/0/g;s/@@CHARS@@/159/g;'

BDF =	mona6x12a mona6x12aB mona6x12aI mona6x12aBI \
	mona6x12r mona6x12rB mona6x12rI mona6x12rBI \
	mona7x14a mona7x14aB mona7x14aI mona7x14aBI \
	mona7x14r mona7x14rB mona7x14rI mona7x14rBI \
	mona8x16a mona8x16aB mona8x16aI mona8x16aBI \
	mona8x16r mona8x16rB mona8x16rI mona8x16rBI \
	monak12 monak12B monak12I monak12BI \
	monak14 monak14B monak14I monak14BI \
	monak16 monak16B monak16I monak16BI

## Dependencies

bdf:	bdf-normal bdf-bold bdf-italic bdf-bold-italic

bdf-normal:	dist/mona6x12a.bdf dist/mona6x12r.bdf \
		dist/mona7x14a.bdf dist/mona7x14r.bdf \
		dist/mona8x16a.bdf dist/mona8x16r.bdf \
		dist/monak12.bdf \
		dist/monak14.bdf \
		dist/monak16.bdf
bdf-bold:	dist/mona6x12aB.bdf dist/mona6x12rB.bdf \
		dist/mona7x14aB.bdf dist/mona7x14rB.bdf \
		dist/mona8x16aB.bdf dist/mona8x16rB.bdf \
		dist/monak12B.bdf \
		dist/monak14B.bdf \
		dist/monak16B.bdf
bdf-italic:	dist/mona6x12aI.bdf dist/mona6x12rI.bdf \
		dist/mona7x14aI.bdf dist/mona7x14rI.bdf \
		dist/mona8x16aI.bdf dist/mona8x16rI.bdf \
		dist/monak12I.bdf \
		dist/monak14I.bdf \
		dist/monak16I.bdf
bdf-bold-italic:dist/mona6x12aBI.bdf dist/mona6x12rBI.bdf \
		dist/mona7x14aBI.bdf dist/mona7x14rBI.bdf \
		dist/mona8x16aBI.bdf dist/mona8x16rBI.bdf \
		dist/monak12BI.bdf \
		dist/monak14BI.bdf \
		dist/monak16BI.bdf

# primary bitmaps

dist/mona6x12a.bdf: src/mona6x12.bit0 src/mona6x12a.bit1
	$(MKISO8859) src/mona6x12.bit0 src/mona6x12a.bit1 | \
		$(BIT2BDF) > dist/mona6x12a.bdf
dist/mona6x12r.bdf: src/mona6x12.bit0 src/mona6x12r.bit1
	$(MKJISX0201) src/mona6x12.bit0 src/mona6x12r.bit1 | \
		$(BIT2BDF) > dist/mona6x12r.bdf
dist/mona7x14a.bdf: src/mona7x14.bit0 src/mona7x14a.bit1
	$(MKISO8859) src/mona7x14.bit0 src/mona7x14a.bit1 | \
		$(BIT2BDF) > dist/mona7x14a.bdf
dist/mona7x14r.bdf: src/mona7x14.bit0 src/mona7x14r.bit1
	$(MKJISX0201) src/mona7x14.bit0 src/mona7x14r.bit1 | \
		$(BIT2BDF) > dist/mona7x14r.bdf
dist/mona8x16a.bdf: src/mona8x16.bit0 src/mona8x16a.bit1
	$(MKISO8859) src/mona8x16.bit0 src/mona8x16a.bit1 | \
		$(BIT2BDF) > dist/mona8x16a.bdf
dist/mona8x16r.bdf: src/mona8x16.bit0 src/mona8x16r.bit1
	$(MKJISX0201) src/mona8x16.bit0 src/mona8x16r.bit1 | \
		$(BIT2BDF) > dist/mona8x16r.bdf
dist/monak12.bdf: src/monak12-base.bit src/monak12-ext.bit
	$(BDFMERGE) src/monak12-base.bit src/monak12-ext.bit | \
		$(BIT2BDF) > dist/monak12.bdf
dist/monak14.bdf: src/monak14-base.bit src/monak14-ext.bit
	$(BDFMERGE) src/monak14-base.bit src/monak14-ext.bit | \
		$(BIT2BDF) > dist/monak14.bdf
dist/monak16.bdf: src/monak16-base.bit src/monak16-ext.bit
	$(BDFMERGE) src/monak16-base.bit src/monak16-ext.bit | \
		$(BIT2BDF) > dist/monak16.bdf

# modified bitmaps

dist/mona6x12aB.bdf: dist/mona6x12a.bdf
	$(MKBOLD) dist/mona6x12a.bdf > dist/mona6x12aB.bdf
dist/mona6x12rB.bdf: dist/mona6x12r.bdf
	$(MKBOLD) dist/mona6x12r.bdf > dist/mona6x12rB.bdf
dist/mona6x12aI.bdf: dist/mona6x12a.bdf
	$(MKITALIC) dist/mona6x12a.bdf > dist/mona6x12aI.bdf
dist/mona6x12rI.bdf: dist/mona6x12r.bdf
	$(MKITALIC) dist/mona6x12r.bdf > dist/mona6x12rI.bdf
dist/mona6x12aBI.bdf: dist/mona6x12aI.bdf
	$(MKBOLD) dist/mona6x12aI.bdf > dist/mona6x12aBI.bdf
dist/mona6x12rBI.bdf: dist/mona6x12rI.bdf
	$(MKBOLD) dist/mona6x12rI.bdf > dist/mona6x12rBI.bdf

dist/mona7x14aB.bdf: dist/mona7x14a.bdf
	$(MKBOLD) dist/mona7x14a.bdf > dist/mona7x14aB.bdf
dist/mona7x14rB.bdf: dist/mona7x14r.bdf
	$(MKBOLD) dist/mona7x14r.bdf > dist/mona7x14rB.bdf
dist/mona7x14aI.bdf: dist/mona7x14a.bdf
	$(MKITALIC) dist/mona7x14a.bdf > dist/mona7x14aI.bdf
dist/mona7x14rI.bdf: dist/mona7x14r.bdf
	$(MKITALIC) dist/mona7x14r.bdf > dist/mona7x14rI.bdf
dist/mona7x14aBI.bdf: dist/mona7x14aI.bdf
	$(MKBOLD) dist/mona7x14aI.bdf > dist/mona7x14aBI.bdf
dist/mona7x14rBI.bdf: dist/mona7x14rI.bdf
	$(MKBOLD) dist/mona7x14rI.bdf > dist/mona7x14rBI.bdf

dist/mona8x16aB.bdf: dist/mona8x16a.bdf
	$(MKBOLD) dist/mona8x16a.bdf > dist/mona8x16aB.bdf
dist/mona8x16rB.bdf: dist/mona8x16r.bdf
	$(MKBOLD) dist/mona8x16r.bdf > dist/mona8x16rB.bdf
dist/mona8x16aI.bdf: dist/mona8x16a.bdf
	$(MKITALIC) dist/mona8x16a.bdf > dist/mona8x16aI.bdf
dist/mona8x16rI.bdf: dist/mona8x16r.bdf
	$(MKITALIC) dist/mona8x16r.bdf > dist/mona8x16rI.bdf
dist/mona8x16aBI.bdf: dist/mona8x16aI.bdf
	$(MKBOLD) dist/mona8x16aI.bdf > dist/mona8x16aBI.bdf
dist/mona8x16rBI.bdf: dist/mona8x16rI.bdf
	$(MKBOLD) dist/mona8x16rI.bdf > dist/mona8x16rBI.bdf

dist/monak12B.bdf: dist/monak12.bdf
	$(MKBOLD) dist/monak12.bdf > dist/monak12B.bdf
dist/monak12I.bdf: dist/monak12.bdf
	$(MKITALIC) dist/monak12.bdf > dist/monak12I.bdf
dist/monak12BI.bdf: dist/monak12I.bdf
	$(MKBOLD) dist/monak12I.bdf > dist/monak12BI.bdf

dist/monak14B.bdf: dist/monak14.bdf
	$(MKBOLD) dist/monak14.bdf > dist/monak14B.bdf
dist/monak14I.bdf: dist/monak14.bdf
	$(MKITALIC) dist/monak14.bdf > dist/monak14I.bdf
dist/monak14BI.bdf: dist/monak14I.bdf
	$(MKBOLD) dist/monak14I.bdf > dist/monak14BI.bdf

dist/monak16B.bdf: dist/monak16.bdf
	$(MKBOLD) dist/monak16.bdf > dist/monak16B.bdf
dist/monak16I.bdf: dist/monak16.bdf
	$(MKITALIC) dist/monak16.bdf > dist/monak16I.bdf
dist/monak16BI.bdf: dist/monak16I.bdf
	$(MKBOLD) dist/monak16I.bdf > dist/monak16BI.bdf


##  Utilities

# clean
clean:
	-rm dist/*.bdf dist/fonts.dir
ttfclean:
	cd ttfsrc; make clean

# packing
pack: clean ttfclean
	cd ..; tar c --numeric-owner --bzip2 -f monafonts-$(VERSION).tar.bz2.bin monafonts-$(VERSION)

# test
test12:	dist/mona6x12r.bdf dist/mona6x12a.bdf dist/monak12.bdf testrun
test14:	dist/mona7x14r.bdf dist/mona7x14a.bdf dist/monak14.bdf testrun
test16:	dist/mona8x16r.bdf dist/mona8x16a.bdf dist/monak16.bdf testrun
testrun:
	$(MKFONTDIR) `pwd`/dist
	xset -fp `pwd`/dist; xset +fp `pwd`/dist; xset fp rehash
	#xedit -xrm '*font:-mona*12*jisx0201.1976-0' test.html
	#xfontsel -pattern '-mona*'
	netscape tools/test.html

# install
install: bdf
	if [ ! -d $(X11FONTDIR) ]; then \
		$(MKDIRHIER) $(X11FONTDIR); \
	fi
	for i in $(BDF); do \
		$(BDFTOPCF) dist/$$i.bdf | \
		$(GZIP_CMD) -c > $(X11FONTDIR)/$$i.pcf.$(GZIP_SUFFIX); \
	done
	$(MKFONTDIR) $(X11FONTDIR)

# append fonts.alias
install-alias:
	cat fonts.alias.mona >> $(X11FONTDIR)/fonts.alias
