#sccs	"@(#)vi/mc68k:Makefile	1.5"
#

include $(MAKEINC)/Makepre.h

VERSION=3.7
BINDIR=../misc
XSTR=${BINDIR}/xstr
CTAGS=ctags
DEBUGFLAGS=-DTRACE -g
NONDEBUGFLAGS=-O
DEB=${NONDEBUGFLAGS}	# or ${DEBUGFLAGS} to to debug
OPTIONS=-DLISPCODE -DCHDIR -DUCVISUAL -DUSG3TTY -DSTDIO -DVMUNIX
CFLAGS=-DTABS=8 ${OPTIONS} ${DEB} ${CRYPT}
LDFLAGS=-z	# or -i or -n
TERMLIB=-ltermcap
CXREF=cxref
INCLUDE=/usr/include
PR=pr
OBJS=	ex.o ex_addr.o ex_cmds.o ex_cmds2.o ex_cmdsub.o \
	ex_data.o ex_extern.o ex_get.o ex_io.o ex_put.o ex_re.o \
	ex_set.o ex_subr.o ex_temp.o ex_tty.o ex_unix.o \
	ex_v.o ex_vadj.o ex_vget.o ex_vmain.o ex_voper.o \
	ex_vops.o ex_vops2.o ex_vops3.o ex_vput.o ex_vwind.o \
	printf.o bcopy.o strings.o
HDRS=	ex.h ex_argv.h ex_re.h ex_temp.h ex_tty.h ex_tune.h ex_vars.h ex_vis.h
SRC1=	ex.c ex_addr.c ex_cmds.c ex_cmds2.c ex_cmdsub.c
SRC2=	ex_data.c ex_get.c ex_io.c ex_put.c ex_re.c
SRC3=	ex_set.c ex_subr.c ex_temp.c ex_tty.c ex_unix.c
SRC4=	ex_v.c ex_vadj.c ex_vget.c ex_vmain.c ex_voper.c
SRC5=	ex_vops.c ex_vops2.c ex_vops3.c ex_vput.c ex_vwind.c
SRC6=	printf.c bcopy.c expreserve.c exrecover.c
DEPENDLIST= $(SRC1) $(SRC2) $(SRC3) $(SRC4) $(SRC5) $(SRC6)
MISC=	makefile READ_ME rofix
VGRIND=	csh /usr/ucb/vgrind
VHDR=	"Ex Version ${VERSION}"
ID = id.o

all:	Makeincludes ex exrecover expreserve
	rm -f ex${VERSION}strings
	ln strings ex${VERSION}strings

Makeincludes: $(DEPENDLIST)
	$(INCCMD) $(DEPENDLIST) | $(SORT) | $(FILTER) > Makeincludes
	$(MAKE)

includes: $(DEPENDLIST)
	$(INCCMD) $(DEPENDLIST) | $(SORT) | $(FILTER) > Makeincludes


ex: 	${OBJS} ${HDRS} $(ID)
	${CC} ${LDFLAGS} -o ex ${OBJS} ${TERMLIB} $(ID)
	size ex
	strip ex

exrecover: exrecover.o $(ID)
	${CC} ${CFLAGS} -s exrecover.o ex_extern.o $(ID) -o exrecover
	rm -f ex${VERSION}recover
	ln exrecover ex${VERSION}recover

exrecover.o: exrecover.c
	${CC} ${CFLAGS} -c -O exrecover.c

expreserve: expreserve.o $(ID)
	${CC} expreserve.o $(ID) -s -o expreserve
	rm -f ex${VERSION}preserve
	ln expreserve ex${VERSION}preserve

expreserve.o:
	${CC} ${CFLAGS} -c -O expreserve.c

clean:
	rm -f *.o 

clobber: clean
	rm -f ex vi view edit *recover *preserve *strings\
		 core errs trace x*.[s]

install:
	rm -f vi; ln ex vi
	$(INSTALL) -i$(EXITFLAG) vi $(INSDIR) $(PROTOFILE)
	$(INSTALL) -i$(EXITFLAG) ex${VERSION}strings $(INSDIR) $(PROTOFILE)
	$(INSTALL) -i$(EXITFLAG) ex${VERSION}recover $(INSDIR) $(PROTOFILE)
	$(INSTALL) -i$(EXITFLAG) ex${VERSION}preserve $(INSDIR) $(PROTOFILE)

lint:
	lint ${CFLAGS} ex.c ex_?*.c
	lint ${CFLAGS} -u exrecover.c
	lint ${CFLAGS} expreserve.c

print:
	@${PR} READ* BUGS
	@${PR} makefile*
	@${PR} /etc/termcap
	@(size -l a.out ; size *.o) | ${PR} -h sizes
	@${PR} -h errno.h ${INCLUDE}/errno.h
	@${PR} -h setjmp.h ${INCLUDE}/setjmp.h
	@${PR} -h sgtty.h ${INCLUDE}/sgtty.h
	@${PR} -h signal.h ${INCLUDE}/signal.h
	@${PR} -h sys/stat.h ${INCLUDE}/sys/stat.h
	@${PR} -h sys/types.h ${INCLUDE}/sys/types.h
	@ls -ls | ${PR}
	@${CXREF} *.c | ${PR} -h XREF
	@${PR} *.h *.c

bcopy.o:	bcopy.c
	${CC} -c ${CFLAGS} bcopy.c

# xstr: hands off!
# strings is built by ../misc/xstr
strings.o: strings rofix
	rm -f xs.c; ${XSTR}
	${CC} -c -S xs.c
	ed - <rofix xs.s
	${AS} -o strings.o xs.s
	rm xs.s

tags:	/tmp
	${CTAGS} -w ex.[hc] ex_*.[hc]

id.c: ../vi.sl
	mkslid >id.c

id.o: id.c
	$(CC) -c id.c

populate:
	getunit

# This is the way ex_vars.h used to be generated.
# ex_vars.h:
# 	csh makeoptions ${CFLAGS}

.c.o:
# ifdef VMUNIX
	${CC} -E ${CFLAGS} $*.c | ${XSTR} -c -
# endif
	${CC} ${CFLAGS} -c x.c 
	mv x.o $*.o

include Makeincludes
include $(MAKEINC)/Makepost.h
