VERSION=2.13
# @(#)makefile.v7	13.4 9/24/80
#
# Ex skeletal makefile for version 7, with overlays for nonseparate I/D PDP11's
#
# NB: This makefile doesn't indicate any dependencies on header files.
#
# Ex is very large - it may not fit on PDP-11's depending on the operating
# system and the cflags you turn on. Things that can be turned off to save
# space include LISPCODE (-l flag, showmatch and lisp options), UCVISUAL
# (visual \ nonsense on upper case only terminals), CHDIR (the undocumented
# chdir command,)  RDONLY (-R flag, view), SOFTTABS (^T tabs), ZCMD (the
# various strange options after z plus ^F/^B), ZZCMD (ZZ from visual), WRAPMGN
# (wrapmargin), TAGSCODE (the tags feature), OPENCODE (open without visual),
# CRNL (code to support terminals with cr, nl, or ns attributes),
# BEEHIVE (superbee: f1=esc, f2=^c)
# Rule of thumb: OPENCODE will buy you about 2.5K, LISPCODE and TAGSCODE
# are worth perhaps 1.5K, and the others are worth fairly small amounts
# (mostly about 50-100 bytes).  UCVISUAL is worth a bit more (256?) and
# you should take it out unless you have such a terminal.
# Also make sure you are running the doprnt printf and not the portable
# one unless you have to run the portable one.
#
# Don't define VFORK unless your system has the VFORK system call,
# which is like fork but the two processes share memory until the
# child execs. This speeds up ex by saving the memory copy.
#
# If your system expands tabs to 4 spaces you should -DTABS=4 below
#
CC=     cc -V
AS=	as -V
BINDIR=	/usr/ucb
INSDIR=	/usr/ucb
LIBDIR=	/usr/lib
FOLD=	${BINDIR}/fold
CTAGS=	${BINDIR}/ctags
XSTR=	${BINDIR}/xstr
MKSTR=	${BINDIR}/mkstr
CXREF=	${BINDIR}/cxref
INCLUDE=/usr/include
TERMLIB=-lovtermcap
PR=	pr
# Debugging must be done on a vax, otherwise it just won't fit.
DEB=	${NONDEBUGFLAGS}	# or ${DEBUGFLAGS} if mdd
DEBUGFLAGS=	-DTRACE -g
NONDEBUGFLAGS=	-O
CFLAGS=	${OPTIONS} ${DEB} 
# See also CFLAGS in the termcap makefile.
OPTIONS=	-DLISPCODE -DCHDIR -DSOFTTABS -DZCMD -DZZCMD -DRDONLY -DWRAPMGN -DTAGSCODE -DOPENCODE -DCRNL
# everything:	-DLISPCODE -DCHDIR -DUCVISUAL -DSOFTTABS -DZCMD -DZZCMD -DRDONLY -DWRAPMGN -DTAGSCODE -DOPENCODE -DCRNL -DBEEHIVE
# PRINTF can be "pprintf.o" for the portable version or "printf.o ovdoprnt.o"
# for the nonportable version, which uses ovdoprnt (written in pdp-11 assembly
# language) and is quite a bit smaller than pprintf.o (about 900 bytes)
PRINTF=	printf.o ovdoprnt.o
OBJS=	ex.o ex_addr.o ex_cmds.o ex_cmds2.o ex_cmdsub.o ex_data.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} strings.o

.c.o:
	${MKSTR} - ex${VERSION}strings x $*.c
	${CC} -E ${CFLAGS} x$*.c | ${XSTR} -c -
	rm -f x$*.c
	${CC} ${CFLAGS} -c x.c 
	mv x.o $*.o

a.out: ${OBJS}
	ld -X /lib/crt0.o -n\
	    -Z ex_addr.o ex_cmds.o ex_cmds2.o ex_cmdsub.o ex_re.o ex_set.o\
	    -Z ex_vadj.o ex_vmain.o ex_voper.o ex_vwind.o ex_vops3.o\
	    -Z ex_v.o ex_vget.o ex_vops.o ex_vops2.o ex_vput.o\
	    -Z ex_get.o ex_io.o ex_temp.o ex_tty.o ex_unix.o ex.o\
	    -L ex_put.o ex_subr.o printf.o strings.o ovdoprnt.o\
	       ex_data.o ${TERMLIB} -lovc 

all:	a.out exrecover expreserve tags

ex.o:	ex.c ex.h ex_argv.h ex_re.h ex_temp.h ex_tty.h ex_tune.h ex_vars.h ex_vis.h

tags:
	${CTAGS} -w *.h *.c

${OBJS}: ex_vars.h

# ex_vars.h:
# 	csh makeoptions ${CFLAGS}

strings.o: strings
	${XSTR}
	${CC} -c -S xs.c
#	ed - <:rofix xs.s
	${AS} -o strings.o xs.s
	rm xs.s
	
exrecover: exrecover.o
	${CC} -o exrecover exrecover.o

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

expreserve: expreserve.o
	${CC} -o expreserve expreserve.o

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

clean:
#	If we dont have ex we cant make it so dont rm ex_vars.h
#	-rm -f expreserve exrecover
	-rm -f a.out ex${VERSION}strings strings core trace
	-rm -f *.o x*.[cs]

ninstall: a.out
	-mv ${NBINDIR}/ex ${NBINDIR}/oldex
	-rm -f ${NBINDIR}/vi ${NBINDIR}/view ${NBINDIR}/oldex
	cp a.out ${NBINDIR}/ex
	-cp ex${VERSION}strings ${LIBDIR}/ex${VERSION}strings
	ln ${NBINDIR}/ex ${NBINDIR}/vi
#	ln ${NBINDIR}/ex ${NBINDIR}/view
	chmod 1755 ${NBINDIR}/ex

install: a.out
	-ln ${BINDIR}/ex ${BINDIR}/oldex
	-rm -f ${BINDIR}/ex ${BINDIR}/e /usr/bin/ex ${BINDIR}/edit ${BINDIR}/vi ${BINDIR}/view ${BINDIR}/oldex
	cp a.out ${BINDIR}/ex
	-cp ex${VERSION}strings ${LIBDIR}/ex${VERSION}strings
	ln ${BINDIR}/ex ${BINDIR}/edit
	ln ${BINDIR}/ex ${BINDIR}/e
	ln ${BINDIR}/ex ${BINDIR}/vi
#	ln ${BINDIR}/ex ${BINDIR}/view
#	ln ${BINDIR}/ex /usr/bin/ex
	chmod 1755 ${BINDIR}/ex

installutil: exrecover expreserve
	cp exrecover ${LIBDIR}/ex${VERSION}recover
	cp expreserve ${LIBDIR}/ex${VERSION}preserve
	chmod 4755 ${LIBDIR}/ex${VERSION}recover ${LIBDIR}/ex${VERSION}preserve
#	cd ../termcap ; make install
	mkdir /usr/preserve

lint:
	lint ex.c ex_?*.c
	lint -u exrecover.c
	lint 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 stat.h ${INCLUDE}/stat.h
	@${PR} -h types.h ${INCLUDE}/types.h
	@ls -ls | ${PR}
	@${CXREF} *.c | ${PR} -h XREF
	@${PR} *.h *.c