#========================================================================
#
# Name - %M%
#
# Version:     %I%
#
# ccsid:       %W% - %G% %U%
# from:        %F%
# date:        %H% %T%
#
# %Q%
#
# Description: Makefile for the Reactive Keyboard
#
# Usage:       make [target] where target is one of:
#      all -- build executables and man pages in current directory
#      clean -- Remove detritus from "make all"
#      clobber -- Restore this directory to pristine state, removes all
#              built files
#      install -- Put executables in BINDIR, man pages in
#              $MANDIR/man$MANSECT and $MANDIR/cat$MANSECT.
#      lint -- Run lint on this directory
#      save -- Copy sources to a save directory
#      shar -- Build shar distribution
#
#========================================================================

#
# Following options modified TO TASTE:
#
# Replace $(DEBUG) with following line when debugging...
#DEBUG=-g

#
# For "make save"
#
SAVEDIR=./save2

#
# For "make install"
#
BINDIR=/usr/local/bin
MANDIR=/usr/man
MANSECT=l

#-----------------------------------------------------------------------
#
# Following options modified depending on TARGET ENVIRONMENT:
#
# following options should work on most BSD systems:
LIBS=-ltermcap
LINTFLAGS=-achx
DEBUG=-O

# following options for all SMI (Sun Microsystems) systems:
#LIBS=-ltermcap
#LINTFLAGS=-abchx
## Note: Sun-3 needs -O2 for kbdbind.c (SIGSEGV in iropt)
#DEBUG=-O4

# Following options for Ultrix
#LIBS=-ltermcap
#LINTFLAGS=
#DEBUG=-O2

# Following options for Sony NEWS
#LIBS=-ltermcap
#LINTFLAGS=-abhvx
#DEBUG=-O

# following options for AIX
#LIBS=-lcurses
#LINTFLAGS=
#DEBUG=-O

# following options for HP-UX
#LIBS=-lcurses
#LINTFLAGS=-achx
#DEBUG=-O

#-----------------------------------------------------------------------
#
# Various Definitions
#
.SUFFIXES: .cat1 .1

.c.o:
	cc $(DEBUG) -c $<

# For some strange reason, the following command will generate an error
# under AIX.  Just type it in by hand and then redo the make.  However,
# be forewarned:  nroff will generate a junky file.  You might wish to
# generate the cat1 on a Sun and then ftp the resulting file back to your
# AIX system.
#
.1.cat1:
	nroff -man $< > $@

RKFILES=cmdline.o complete.o display.o functions.o getopt.o kbdbind.o \
	kbdsys.o reactive.o rk.o utl.o

KBDFILES=kbdsys.o kbdcheck.o

TARGETS=rk rk.cat1 rkfreq rkfreq.cat1 kbdcheck kbdcheck.cat1 setup setup.cat1

SOURCES=.rk.keys EMACS.rk.keys INSIDE.RK.doc Makefile RK.MESSAGES.doc \
	cmdline.c complete.c defaults.h display.c display.h \
	functions.c functions.h getopt.c getopt.h kbdbind.c \
	kbdbind.h kbdcheck.1 kbdcheck.c kbdsys.c kbdsys.h reactive.c \
	reactive.h rk.1 rk.c rk.h rkfreq.1 rkfreq.c rkglobal.h \
	setup.1 setup.c system.h utl.c utl.h

#-----------------------------------------------------------------------
#
# Different Makes
#

all: $(TARGETS)

clean:
	rm -f *.o

clobber:
	rm -f *.o $(TARGETS)

 install:
	cp rk rkfreq kbdcheck setup $(BINDIR)
	cp *.1 $(MANDIR)/man$(MANSECT)
	cp kbdcheck.cat1 $(MANDIR)/cat$(MANSECT)/kbdcheck.1
	cp rk.cat1 $(MANDIR)/cat$(MANSECT)/rk.1
	cp rkfreq.cat1 $(MANDIR)/cat$(MANSECT)/rkfreq.1
	cp setup.cat1 $(MANDIR)/cat$(MANSECT)/setup.1

lint:
	lint $(LINTFLAGS) *.c $(LIBS) >rk.lint

save:
	if [ ! -d $(SAVEDIR) ]; then mkdir $(SAVEDIR); fi
	cp $(SOURCES) $(SAVEDIR)

shar:
	makekit -oMANIFEST $(SOURCES)

#-----------------------------------------------------------------------
#
# Various Dependency Rules
#
# Source file rules
cmdline.o: cmdline.c defaults.h display.h getopt.h kbdbind.h rk.h \
  rkglobal.h system.h utl.h
display.o: defaults.h display.c display.h rkglobal.h rk.h system.h utl.h
complete.o: complete.c defaults.h display.h functions.h kbdbind.h reactive.h \
  rk.h rkglobal.h system.h utl.h
functions.o: defaults.h display.h functions.c functions.h kbdbind.h \
  kbdsys.h reactive.h rk.h rkglobal.h system.h utl.h
getopt.o: getopt.h getopt.c
kbdbind.o: defaults.h display.h functions.h kbdbind.c kbdbind.h rk.h \
  rkglobal.h system.h kbdsys.h
kbdcheck.o: kbdcheck.c kbdsys.h rkglobal.h system.h
kbdsys.o: kbdsys.c kbdsys.h rkglobal.h system.h
reactive.o: defaults.h display.h kbdbind.h kbdsys.h reactive.c reactive.h \
  rk.h rkglobal.h system.h utl.h
rk.o: defaults.h display.h functions.h kbdbind.h kbdsys.h reactive.h rk.c \
  rk.h rkglobal.h system.h utl.h
utl.o: display.h kbdbind.h kbdsys.h rk.h rkglobal.h system.h utl.c

# Linker rules

kbdcheck: $(KBDFILES)
	cc -o kbdcheck $(KBDFILES)

rk: $(RKFILES)
	cc -o rk $(RKFILES) $(LIBS)

# for DECstation Ultrix, consider
#rk: $(RKFILES)
#      cc -o rk -O3 cmdline.c complete.c display.c functions.c getopt.c \
#      kbdbind.c reactive.c rk.c utl.c $(LIBS)
# But as of this writing, this causes a crash in umerge1.31...

rkfreq: functions.h rkfreq.c rkglobal.h system.h
	cc $(DEBUG) -o rkfreq rkfreq.c

setup:  defaults.h rkglobal.h rk.h setup.c
	cc $(DEBUG) -o setup setup.c -ltermcap

