# Copyright (C) 1994-95 Cronyx Ltd.
# Author: Serge Vakulenko, <vak@cronyx.ru>
# Changes Copyright (C) 1996-1999 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.3.0

#
# Default installation directories, fix for your sistem
#
R6DIR=/usr/X11R6/lib/X11/fonts/cyrillic
R5DIR=/usr/X386/lib/X11/fonts/cyrillic
NCDDIR=/usr/lib/X11/ncd/fonts/LOCAL.new
OWNDIR=/usr/local/lib/openwin/fonts

DIRS =  75dpi 100dpi misc

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

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

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

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

install:
	@echo Choose a platform:
	@echo make instX11R6 [USERDIR=xxx]
	@echo make instX11R5 [USERDIR=xxx]
	@echo make instncdfs [USERDIR=xxx]
	@echo make instopenwin [USERDIR=xxx] - for SunOS 4.1.x, Solaris 2.x


X11R6: allbdf mk_pcf_gz

instX11R6: X11R6
	@if [ "x$(USERDIR)" != "x" ]; then \
		echo $(USERDIR) > .destdir; \
	else \
		echo $(R6DIR) > .destdir; \
	fi
	make install_pcf DESTDIR=`cat .destdir`

X11R5: allbdf mk_pcf_Z

instX11R5: X11R5
	@if [ "x$(USERDIR)" != "x" ]; then \
		echo $(USERDIR) > .destdir; \
	else \
		echo $(R5DIR) > .destdir; \
	fi
	make install_pcf DESTDIR=`cat .destdir`

ncdfs: allbdf mk_pcf_Z

instncdfs: ncdfs
	@if [ "x$(USERDIR)" != "x" ]; then \
		echo $(USERDIR) > .destdir; \
	else \
		echo $(NCDDIR) > .destdir; \
	fi
	make install_pcf DESTDIR=`cat .destdir` \
		MKFONTDIR=ncdmkfontdir

openwin: allbdf mk_openwin

instopenwin: openwin
	@if [ "x$(USERDIR)" != "x" ]; then \
		echo $(USERDIR) > .destdir; \
	else \
		echo $(R6DIR) > .destdir; \
	fi
	make install_openwin DESTDIR=`cat .destdir`

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

clean cleanall:
	rm -fr .destdir mk_pcf_* mk_openwin /tmp/test?dir/cyrillic
	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 -f mk_openwin .destdir

install_pcf:
	-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 -f mk_pcf_* .destdir

#
# 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

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


/tmp/test6dir/cyrillic:
	make instX11R6 USERDIR=$@

bin6-dist: /tmp/test6dir/cyrillic
	(cd /tmp/test6dir; tar cf - cyrillic) | \
	gzip > ../x6rus-$(VERSION)-bin.tgz



/tmp/test5dir/cyrillic:
	make instX11R5 USERDIR=$@

bin5-dist:  /tmp/test5dir/cyrillic
	(cd /tmp/test5dir; tar cf - cyrillic) | \
	gzip > ../x5rus-$(VERSION)-bin.tgz
