O	= .o
X	=
L	=
CC	= gcc
MV	= mv
RM	= rm -f
DEBUG_FLAGS = -ggdb
AR	= ar
AR1	= cr
AR2	=
AR3	=
RANLIB  = ar -s

DEFINES = -DTN3270 -Dlinux -Dunix -DUSE_TERMIO -DTERMCAP -DKLUDGELINEMODE \
	-DNO_URGENT -DDIAGNOSTICS  -DPRINTSCREEN 
INCLUDES = -I. -I.. -I/usr/include/bsd/bsd.h -I/usr/include/bsd
OPTIMIZE = -O
OPTIMIZE = ${DEBUG_FLAGS}
CFLAGS	= $(OPTIMIZE) $(INCLUDES) $(DEFINES)

# Which keyboard are we emulating.
#KBD	= 3180.kbd
#KBD	= 3270pc.kbd
KBD	= unix.kbd

# The source files...
ALLH =	api.h declare.h externs.h function.h hostctlr.h oia.h \
	options.h screen.h scrnctlr.h printscreen.h 

ALLC =	api.c function.c inbound.c oia.c options.c outbound.c printscreen.c 

# Note: NO function.o!
ALLO =	api$O inbound$O oia$O options$O outbound$O printscreen$O

ALLHC=	${ALLH} ${ALLC}
ALLPRINT =	3180.kbd 3270pc.kbd unix.kbd ${ALLHC}

ALLSOURCE =	${ALLPRINT} makefile makefile.mak

.s.o:
	/lib/cpp -E $< | as -o $@

.c.obj:
	${CC} ${CFLAGS} -c $<

all: kbd.out ctlrlib.a

ctlrlib.a:	${ALLO}
	${RM} $@
	for i in ${ALLO}; do (${AR} ${AR1} $@ ${AR2} $$i${AR3}); done
	${RANLIB} $@

clean:
	@echo "Cleaning tn3270/ctlr..."
	@for i in $(ALLO) mset tn3270 prt3270 m4.out errs \
		makefile.bak ctlrlib.a kbd.out TMPfunc.out; \
			do (${RM} $$i); done

kbd.out:	$(KBD) hostctlr.h
	(cd ../tools; make mkhits$X )
	${RM} $@ TMPfunc.out
	$(CC) $(CFLAGS) -E function.c > TMPfunc.out
	../tools/mkhits - ../ctlr/TMPfunc.out < $(KBD) > $@
	${RM} TMPfunc.out
