# names of programs used and compiler flags

CC=gcc
CFLAGS=-O
LFLAGS=-lcurses -ltermcap
NROFF=nroff
TROFF=lroff
PERL=perl

# directories where the stuff gets installed

BINDIR=/usr/staff/bin
BINMODE=755
PERLLIB=/local/usr/lib/perl
LIBMODE=755

# constants used by edit.c

EDIT_RIGHT=-DEDIT_RIGHT=6
EDIT_LEFT=-DEDIT_LEFT=2
BEEP=-DBEEP=mybeep

# no editing beyond this line

PLS=cterm.pl cdefs.pl curcon.pl
OBJ=cterm.o cursesX.o cdefs.o edit.o

all: cterm curcon.pl
cterm: cterm.o cursesX.o edit.o cdefs.o
	${CC} ${CFLAGS} -o cterm cterm.o cursesX.o edit.o cdefs.o ${LFLAGS}
cterm.o: cterm.c defs.h
	${CC} ${CFLAGS} -c cterm.c
cursesX.o: cursesX.c cursesX.h defs.h
	${CC} ${CFLAGS} -c cursesX.c
cdefs.o: cdefs.c cursesX.h defs.h
	${CC} ${CFLAGS} -c cdefs.c
edit.o: edit.c defs.h
	${CC} ${CFLAGS} ${EDIT_RIGHT} ${EDIT_LEFT} ${BEEP} -c edit.c
cdefs.c: cdefs.in
	${PERL} cdefs.mk
curcon.pl: curcon
	./curcon > curcon.pl
curcon: curcon.c
	${CC} ${CFLAGS} -o curcon curcon.c
curcon.c: curcon.in
	${PERL} curcon.mk
cterm.1.nr: cterm.1
	${NROFF} -man cterm.1 > cterm.1.nr
cterm.1.tr: cterm.1
	${TROFF} -man cterm.1 > cterm.1.tr
install: all
	cp cterm ${BINDIR}
	chmod ${BINMODE} ${BINDIR}/cterm
	cp ${PLS} ${PERLLIB}
	cd ${PERLLIB} ; chmod ${LIBMODE} ${PLS}
	@echo 'install man page by hand'
man: cterm.1.tr cterm.1.nr
clean:
	rm -f ${OBJ} core cdefs.c curcon.c curcon
realclean: clean
	rm -f cterm cdefs.pl curcon.pl cterm.1.nr cterm.1.tr cterm.shar
shar: realclean
	shar -o cterm.shar *
backup: shar
	cp cterm.shar ../back
wc: realclean
	wc *
