# Note: BINDIR, DATADIR also occur in src/Makefile.
MANDIR  = $(DESTDIR)/usr/man
BINDIR  = $(DESTDIR)/usr/bin
DATADIR = $(DESTDIR)@datadir@
# If you change the names of any of the following subdirs,
# also change paths.h.
OLDKEYMAPDIR = keytables
KEYMAPDIR = keymaps
FONTDIR   = consolefonts
TRANSDIR  = consoletrans
KEYMAPSUBDIRS = include sun amiga atari mac i386/azerty i386/dvorak i386/fgGIod i386/qwerty i386/qwertz i386/include

# Do not use GZIP - it is interpreted by gzip
MYGZIP = gzip -f -9

DIR	= kbd-0.97

.EXPORT_ALL_VARIABLES:

all:
	cd src && make all
	case `arch` in *86*) \
		cd src && make i386 ;; \
	esac
	cd openvt && make all
	@echo "Done. You can now do  make install"

# compress data files - do not touch the distribution but copy first
$(KEYMAPDIR)_Z:
	cp -r $(KEYMAPDIR) $(KEYMAPDIR)_Z
	cd $(KEYMAPDIR)_Z && $(MYGZIP) */*.map */*/*.map

$(FONTDIR)_Z:
	cp -r $(FONTDIR) $(FONTDIR)_Z
	cd $(FONTDIR)_Z && $(MYGZIP) * && gunzip README*
# (not yet screenmaps - some other time)

install:	$(KEYMAPDIR)_Z $(FONTDIR)_Z
	cd src && make install
	case `arch` in *86*) \
		cd src && make install386 ;; \
	esac
	cd openvt && make install
	for i in man?; do \
		install -d -m 755 $(MANDIR)/$$i; \
		install -m 644 $$i/* $(MANDIR)/$$i; \
	done
	rm -f $(MANDIR)/man5/keytables.5
	install -d -m 755 $(DATADIR)
	install -d -m 755 $(DATADIR)/$(FONTDIR)
	install -m 644 $(FONTDIR)_Z/* $(DATADIR)/$(FONTDIR)
	install -d -m 755 $(DATADIR)/$(TRANSDIR)
	install -m 644 $(TRANSDIR)/* $(DATADIR)/$(TRANSDIR)
	install -d -m 755 $(DATADIR)/$(KEYMAPDIR)
	install -d -m 755 $(DATADIR)/$(KEYMAPDIR)/i386
	for i in $(KEYMAPSUBDIRS); do \
		install -d -m 755 $(DATADIR)/$(KEYMAPDIR)/$$i ;\
		install -m 644 $(KEYMAPDIR)_Z/$$i/* $(DATADIR)/$(KEYMAPDIR)/$$i ;\
	done
	@echo "Done. You may want to remove old keymaps with"
	@echo "  rm -rf $(DATADIR)/$(OLDKEYMAPDIR)"
	@echo "But be careful to preserve your default map if it is"
	@echo "nonstandard, and to adapt any scripts in rc.local or so."

tar: reallyclean # analyze.c loadkeys.c
	cd ..; 	tar cvfz $(DIR).tar.gz ./$(DIR)

clean:
	cd src && make clean
	cd openvt && make clean
	rm -rf $(KEYMAPDIR)_Z $(FONTDIR)_Z

reallyclean distclean spotless: clean
	find . -name "*~" -exec rm {} ";"
	cd src && make distclean
	cd openvt && make distclean
	rm -f Makefile src/Makefile man1/dumpkeys.1 man1/loadkeys.1 man8/setfont.8

