# Copyright (C) 1994-95 Cronyx Ltd.
# Author: Serge Vakulenko, <vak@cronyx.ru>
# Changes Copyright (C) 1996-1997 by Andrey A. Chernov, Moscow, Russia.
# Changes Copyright (C) 1996 by Sergey Vovk - vsv
#
# This software may be used, modified, copied, distributed, and sold,
# in both source and binary form provided that the above copyright
# and these terms are retained. Under no circumstances is the author
# responsible for the proper functioning of this software, nor does
# the author assume any responsibility for damages incurred with its use.

# ATTENTION: perl, gzip, compress, bdftopcf, mkfontdir
# required to build this set

SHELL = /bin/sh

VERSION = 2.2.0

DIRS =  75dpi 100dpi misc

X11BASE?=/usr/X11R6
MV?=/bin/mv
R6DIR=/usr/X11R6/lib/X11/fonts/cyrillic
R5DIR=/usr/X386/lib/X11/fonts/cyrillic
NCDDIR=/usr/lib/X11/ncd/fonts/LOCAL.new

# see below destinations install_pcf, install_openwin...
DESTDIR = /dev/null

#MKFONTDIR = /usr/bin/X11/mkfontdir
MKFONTDIR = mkfontdir

#BLDFAMILY = /usr/openwin/bin/bldfamily
BLDFAMILY = bldfamily

usage:
	@echo Choose a platform:
	@echo make X11R6
	@echo make X11R5
	@echo make openwin - for SunOS 4.1.x, Solaris 2.x

X11R6: allbdf mk_pcf_gz

X11R6_install: X11R6
	make install_pcf DESTDIR=$(X11BASE)/lib/X11/fonts/cyrillic

X11R5: allbdf mk_pcf_Z
	make install_pcf DESTDIR=$(R5DIR)

ncdfs: allbdf mk_pcf_Z
	make install_pcf DESTDIR=$(NCDDIR) \
		MKFONTDIR=ncdmkfontdir

openwin: allbdf mk_openwin
	make install_openwin DESTDIR=/usr/local/lib/openwin/fonts

$(R6DIR): X11R6

$(R5DIR): X11R5

allbdf clean cleanall:
	for dir in ${DIRS}; do \
		cd ./$$dir; \
		if [ -f Makefile ]; then \
		  make -f Makefile $@; \
		fi; \
		cd ..; \
	done

mk_openwin:
	for dir in ${DIRS}; do \
		cd ./$$dir; ../BDF2openwin; \
		cd ..; \
	done
	touch mk_openwin

mk_pcf_Z:
	for dir in ${DIRS}; do \
		cd ./$$dir; ../BDF2pcf Z; \
		cd ..; \
	done
	touch $@

mk_pcf_gz:
	for dir in ${DIRS}; do \
		cd ./$$dir; ../BDF2pcf gz; \
		cd ..; \
	done
	touch $@

install_openwin:
	-mkdir -p $(DESTDIR)
	cp xrus.info $(DESTDIR)
	chmod 644 $(DESTDIR)/xrus.info
	@set -x; \
	for dir in ${DIRS}; do \
		if [ ! -d $(DESTDIR)/$$dir ]; then mkdir $(DESTDIR)/$$dir; fi; \
		cd ./$$dir; \
		if [ -f fonts.alias ]; then \
		    ../ALIAS2Compat \
			< fonts.alias > $(DESTDIR)/$$dir/Compat.list; \
		fi; \
		mv Synonyms.list *.f? $(DESTDIR)/$$dir; \
		$(BLDFAMILY) -d $(DESTDIR)/$$dir; \
		cd ..; \
	done
	rm mk_openwin

install_pcf:
	@if [ -d $(DESTDIR) ]; then ${MV} $(DESTDIR) $(DESTDIR).old; fi
	-mkdir -p $(DESTDIR)
	cp xrus.info $(DESTDIR)
	chmod 644 $(DESTDIR)/xrus.info
	@set -x; \
	for dir in ${DIRS}; do \
		if [ ! -d $(DESTDIR)/$$dir ]; then mkdir $(DESTDIR)/$$dir; fi; \
		cd ./$$dir; \
		if [ -f fonts.alias ]; then \
		    cp fonts.alias $(DESTDIR)/$$dir; \
		fi; \
		mv *.pcf.* $(DESTDIR)/$$dir; \
		$(MKFONTDIR) $(DESTDIR)/$$dir; \
		cd ..; \
	done
	rm mk_pcf_*

#
# make once only, don't prepare src-dist after this hack!!!
#
koi8hack:
	for dir in ${DIRS}; do \
		cd ./$$dir; ../KOI8-R2KOI8R-1 *.bdf fonts.alias; \
		make clean; \
		cd ..; \
	done
	echo XFLD hacked to koi8r-1 >koi8hack
	date >>koi8hack

# obsolete
#install:
#        -mkdir -p $(DESTDIR)
#        cp xrus.info $(DESTDIR)
#        chmod 644 $(DESTDIR)/xrus.info
#        for dir in ${DIRS}; do \
#                cd ./$$dir; make DESTDIR=${DESTDIR}/$$dir install; cd ..; \
#        done

src-dist: cleanall ../xrus-$(VERSION)-src.tgz

../xrus-$(VERSION)-src.tgz:
	(cd ..; tar cf - xrus-$(VERSION)-src) | gzip > $@

bin6-dist: ../x6rus-$(VERSION)-bin.tgz

../x6rus-$(VERSION)-bin.tgz: $(R6DIR)
	(cd $(R6DIR)/..; tar cf - cyrillic) | gzip > $@


bin5-dist: ../x5rus-$(VERSION)-bin.tgz

../x5rus-$(VERSION)-bin.tgz: $(R5DIR)
	(cd $(R5DIR)/..; tar cf - cyrillic) | gzip > $@

