# Makefile for Xrus
#/*
#  xrus - keyboard switcher/indicator
#  Copyright (c) 1996 Alexander V. Lukyanov
#  This is free software with no warranty.
#  See COPYING for details.
#*/

VERSION=@VERSION@

SHELL=/bin/sh
CC=@CC@
AWK=@AWK@

prefix=@prefix@
exec_prefix=@exec_prefix@
bindir=@bindir@

#DEBUGFLAGS=-g -DDEBUG
CFLAGS=-O $(DEBUGFLAGS)
LDFLAGS=$(DEBUGFLAGS)

DISTFILES=\
 xrus.c props.c menu.c menu.h xrus.h props.h Xrus.ad xrus.doc*\
 keycomb.c keycomb.h altmap.c altmap.h xalloca.h alloca.c\
 kbdstate.c kbdstate.h\
 Makefile.in configure configure.in aclocal.m4 acconfig.h config.h.in\
 *xrus.xmm mkdefres.awk mkdefres.sh koi8x16.bdf README\
 COPYING INSTALL* ANNOUNCE-* TODO NEWS mkinstalldirs install-sh

.c.o:
	$(CC) -c -I. $(CFLAGS) @CFLAGS@ @DEFS@ $<

all:  xrus
	touch .made

.made: all

xrus_OBJS=xrus.o props.o menu.o defres.o keycomb.o altmap.o kbdstate.o @ALLOCA@
xrus: $(xrus_OBJS)
	rm -f $@
	$(CC) $(LDFLAGS) @LDFLAGS@ -o $@ $(xrus_OBJS) @LIBS@

alloca.o: alloca.c
altmap.o: altmap.c altmap.h xrus.h keycomb.h xalloca.h
kbdstate.o: kbdstate.c xrus.h kbdstate.h
keycomb.o: keycomb.c keycomb.h xrus.h xalloca.h
menu.o: menu.c xrus.h menu.h props.h altmap.h
props.o: props.c keycomb.h xrus.h xalloca.h
xrus.o: xrus.c xalloca.h keycomb.h xrus.h props.h menu.h kbdstate.h

defres.c:   Xrus.ad mkdefres.awk mkdefres.sh
	AWK=$(AWK) $(SHELL) mkdefres.sh

DISTDIR=xruskb-$(VERSION)
dist:
	-mkdir $(DISTDIR)
	-ln -f $(DISTFILES) $(DISTDIR)
	tar cfz $(DISTDIR).tar.gz $(DISTDIR)
	rm -rf $(DISTDIR)

install: .made
	./mkinstalldirs $(bindir)
	-if [ -f $(bindir)/xrus ]; then \
		rm -f $(bindir)/xrus.old; \
		mv $(bindir)/xrus $(bindir)/xrus.old; \
	fi
	./install-sh -c xrus $(bindir)/xrus

clean:
	rm -f *.o xrus core defres.c .made

distclean:  clean
	rm -f Makefile config.h config.log config.status config.cache

realclean:  distclean
	rm -f configure config.h.in
