.SUFFIXES:	.src .bdf .snf .fb .pcf

SHELL		= /bin/sh
ECHO		= echo $(TAB)
BDFTOSNF	= bdftosnf
BDFTOPCF	= bdftopcf
CVFONT		= convertfont
FONTINCDIR	= ../../include
FONTINC		= -I$(FONTINCDIR)

MADEFLAG	= fontsmade

F1              = vn-r14
F2              = vn9x15
F3              = vn10x20
F4              = vnlutRS18
F5              = Rom14-VN
F6              = etl24-viscii
F7              = vn6x13
F8              = vn16x30
F9              = etl16-viscii1
BDF		= $(F1).bdf $(F2).bdf $(F3).bdf $(F4).bdf $(F5).bdf $(F6).bdf\
   		  $(F7).bdf $(F8).bdf
SNF		= $(F1).snf $(F2).snf $(F3).snf $(F4).snf $(F5).snf $(F6).snf\
   		  $(F7).snf $(F8).snf
PCF		= $(F1).pcf $(F2).pcf $(F3).pcf $(F4).pcf $(F5).pcf $(F6).pcf\
   		  $(F7).pcf $(F8).pcf
FB		= $(F1).fb $(F2).fb $(F3).fb $(F4).fb $(F5).fb $(F6).fb\
   		  $(F7).fb $(F8).fb

.src.bdf:
		@echo -n "Generating $@ from $*.src... "
		@cc $(FONTINC) -E $*.src | egrep "^%" | sed 's/^%//' > $@
		@echo Done.
.bdf.pcf:
		$(BDFTOPCF) $*.bdf > $*.pcf

.bdf.snf:
		$(BDFTOSNF) $*.bdf > $*.snf

.bdf.fb:
		convertfont -b $*.bdf


all:		$(BDF)
		@echo ""
		@echo $(TAB)We\'re going to do some font conversion.
		@echo $(TAB)Depending on your system set-up, some of
		@echo $(TAB)the conversion programs may not exist.
		@echo $(TAB)Don't worry about this; it means that
		@echo $(TAB)your font format is one of the others.
		@echo $(TAB)We try to cover PCF, SNF, and FB formats.
		@echo $(TAB)You're out of luck if NONE of these work.
		@echo $(TAB)In that case talk with your system manager,
		@echo $(TAB)because the BDF files we supply has all
		@echo $(TAB)the font data you need.
		@echo ""

		@echo -n "Checking to see if you use PCF fonts... "
		@if [ "`which $(BDFTOPCF) | grep $(BDFTOPCF) | sed 's/^.*\///g'`" = $(BDFTOPCF) ] ; then \
			echo "" ;\
			echo $(TAB)Making PCF fonts for standard X11... ;\
			echo "" ;\
			make allpcf ;\
		else echo "I guess you don't." ;\
		fi

		@echo -n "Checking to see if you use SNF fonts... "
		@-if [ "`which $(BDFTOSNF) | grep $(BDFTOSNF) | sed 's/^.*\///g'`" = $(BDFTOSNF) ] ; then \
			echo "" ;\
			echo $(TAB)Making SNF fonts for standard X11... ;\
			echo "" ;\
			make allsnf ;\
		else echo "I guess you don't." ;\
		fi

		@echo -n "Checking to see if you use FB fonts... "
		@-if [ "`which $(CVFONT) | grep $(CVFONT) | sed 's/^.*\///g'`" = $(CVFONT) ] ; then \
			echo "" ;\
			echo $(TAB)Making FB fonts for OpenWin/News... ;\
			echo "" ;\
			make allfb ;\
		else echo "I guess you don't." ;\
		fi

		mkfontdir >/dev/null 2>&1
		@chmod go+r fonts.*
		@touch $(MADEFLAG)
		@echo Done! Run \"xset +fp `pwd`\" to install X fonts

allpcf:		$(PCF)
# The BDF files are generated anyway, and if they stick around
# MKFONTDIR will generate some confusing error messages for PCF systems.
# Well, we have to keep .bdf around for executable users
		@chmod go+r *.pcf

allsnf:		$(SNF)
		chmod go+r *.snf

allfb:		$(FB)
		chmod go+r *.fb
		bldfamily

clean:
		/bin/rm -f $(PCF) $(SNF) $(FB) $(MADEFLAG) fonts.dir fonts.alias

veryclean:
		/bin/rm -f $(PCF) $(SNF) $(FB) $(MADEFLAG) fonts.dir fonts.alias
