prefix         = @prefix@
exec_prefix    = @exec_prefix@
bindir         = $(DESTDIR)@bindir@
datarootdir    = @datarootdir@
OPTIONAL_PROGS = @OPTIONAL_PROGS@

# Something like /usr/lib/kbd or /usr/share/kbd
DATA_DIR = @datadir@

OLDPROGS= mapscrn loadunimap
PROGS   = dumpkeys loadkeys showkey setfont showconsolefont \
	  setleds setmetamode kbd_mode chvt deallocvt \
	  psfxtable kbdrate fgconsole openvt

# probably also getkeycodes and setkeycodes are arch-specific;
# they will work on an alpha, though, and perhaps be dummy on a sun
ifeq ($(KEYCODES_PROGS),yes)
PROGS += getkeycodes setkeycodes
endif

ifeq ($(RESIZECONS_PROGS),yes)
PROGS += resizecons
endif

# Not installed by default
ifeq ($(OPTIONAL_PROGS),yes)
PROGS += screendump setlogcons setvesablank spawn_console spawn_login \
	 getunimap clrunimap outpsfheader setpalette
endif

# Installed by default
SHCMDS  = unicode_start unicode_stop

WARN	= -Wall -Wmissing-prototypes -Wstrict-prototypes -Wunused-function \
	-Wunused-label -Wunused-variable -Wunused-value
DEFS	= -DDATADIR=\"$(DATA_DIR)\"

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

all:	$(PROGS) $(OLDPROGS) $(MISC)

progs:	$(PROGS)

old:	$(OLDPROGS)

# don't change 4711 to 0711 - this is the setuid target
setuid:
	chmod 4711 $(bindir)/openvt

install: all
	install -d -m 0755 $(bindir)
	install -s -m 0755 $(PROGS) $(OLDPROGS) $(bindir)
	install -m 0755 $(SHCMDS) $(bindir)
	for i in psfaddtable psfgettable psfstriptable; do \
		rm -f $(bindir)/$$i; ln -s psfxtable $(bindir)/$$i; \
	done
	@echo "You may also want to add psf.magic to /usr/lib/magic"

# loadkeys.o: separate rule since the flex output does not permit -Wall
loadkeys.o: loadkeys.c analyze.c
	$(CC) -c $(CFLAGS) $(DEFS) $<

# mapscrn and loadunimap are now part of setfont
# but can be compiled separately, if desired
main_mapscrn.o: mapscrn.c paths.h
	$(CC) $(CFLAGS) $(WARN) $(DEFS) -DMAIN -c $< -o $@

main_loadunimap.o: loadunimap.c paths.h
	$(CC) $(CFLAGS) $(WARN) $(DEFS) -DMAIN -c $< -o $@

$(OLDPROGS): %: main_%.o findfile.o psffontop.o utf8.o
	$(CC) $(LDFLAGS) $^ -o $@

clean reallyclean spotless:
	rm -f core *.o analyze.c loadkeys.c
	rm -f $(PROGS) $(OLDPROGS) $(MISC) *~

distclean: clean
	rm -f Makefile

$(PROGS): %: %.o

#
# dependencies
#

ksyms.o: koi8.syms.h ethiopic.syms.h

findfile.o loadkeys.o loadunimap.o mapscrn.o resizecons.o setfont.o: findfile.h

catwithfont.o chvt.o clrunimap.o deallocvt.o dumpkeys.o fgconsole.o: getfd.h
getfd.o getkeycodes.o getunimap.o kbd_mode.o loadkeys.o loadunimap.o: getfd.h
mapscrn.o resizecons.o setfont.o setkeycodes.o setlogcons.o: getfd.h
setpalette.o setvesablank.o showconsolefont.o showkey.o: getfd.h

kdfontop.o setfont.o showconsolefont.o: kdfontop.h

clrunimap.o kdmapop.o loadunimap.o mapscrn.o: kdmapop.h

dumpkeys.o ksyms.o loadkeys.o: ksyms.h

dumpkeys.o loadkeys.o: modifiers.h

catwithfont.o chvt.o clrunimap.o deallocvt.o dumpkeys.o fgconsole.o: nls.h
findfile.o getfd.o getkeycodes.o getunimap.o kbd_mode.o kbdrate.o: nls.h
kdfontop.o ksyms.o loadkeys.o loadunimap.o mapscrn.o psffontop.o: nls.h
psfxtable.o resizecons.o screendump.o setfont.o setkeycodes.o setleds.o: nls.h
setmetamode.o setvesablank.o showconsolefont.o showkey.o xmalloc.o: nls.h

loadkeys.o loadunimap.o mapscrn.o resizecons.o setfont.o: paths.h

loadunimap.o psffontop.o psfxtable.o setfont.o: psf.h

psffontop.o psfxtable.o setfont.o: psffontop.h

loadunimap.o psffontop.o utf8.o: utf8.h

openvt.o: openvt.h
chvt.o deallocvt.o dumpkeys.o getkeycodes.o getunimap.o kbd_mode.o: version.h
kbdrate.o loadkeys.o loadunimap.o mapscrn.o psfxtable.o resizecons.o: version.h
screendump.o setfont.o setkeycodes.o setleds.o setmetamode.o: version.h
showconsolefont.o showkey.o totextmode.o: version.h

findfile.o kdfontop.o loadunimap.o psffontop.o psfxtable.o: xmalloc.h
setfont.o xmalloc.o: xmalloc.h

#
# constituent object files
#

dumpkeys loadkeys: ksyms.o xmalloc.o

getunimap screendump showconsolefont: xmalloc.o

psfxtable: psffontop.o xmalloc.o utf8.o

loadkeys mapscrn setfont resizecons loadunimap: findfile.o xmalloc.o

chvt clrunimap deallocvt dumpkeys fgconsole getkeycodes getunimap: getfd.o
kbd_mode loadkeys loadunimap mapscrn resizecons setkeycodes setfont: getfd.o
setpalette showconsolefont setlogcons setvesablank showkey openvt: getfd.o

setfont: mapscrn.o loadunimap.o kdmapop.o kdfontop.o psffontop.o utf8.o

loadunimap: utf8.o

getunimap mapscrn clrunimap loadunimap showconsolefont: kdmapop.o

catwithfont showconsolefont: kdfontop.o

openvt: openvt.o
