# FILE: Makefile	VI.IV's MAKEFILE
#==============================================================
# EDIT HISTORY:
#
# 23/06/94	HAIM ROMAN, COMPUTER SCIENCE DEPARTMENT, TECHNION
# Changed to install in /usr/local/bin (instead of /usr/local)
#
# 05/05/91	HAIM ROMAN, COMPUTER SCIENCE DEPARTMENT, TECHNION
# (1) Now installing the debug version of vi_iv, because I expect to 
# see & try to fix several bugs in the immeidate future.
#
# 25/04/90	HAIM ROMAN, COMPUTER SCIENCE DEPARTMENT, TECHNION
# (1) Took stripping out from the install command & put it as a
# separate command in the "all:" target (search for string "STRIP").
# (2) Added vi_iv to list of files deleted in "clean:" target.
#
# 05/03/90	HAIM ROMAN, COMPUTER SCIENCE DEPARTMENT, TECHNION
# (1) In the 'insman' target, 'chgrp' was misspelled as 'chgroup'.
# Corrected that.
#
# 01/01/90	HAIM ROMAN, COMPUTER SCIENCE DEPARTMENT, TECHNION
# (1) Re-added the -DVMUNIX option to compiling.  This was in Uri's
# version, I don't know why it was ever taken out.  This option is
# necessary if you "xstr".
# (2) Put in SCCS identification keywords (look for pattern %[A-Z]%).
# 
# 11/1989	HAIM ROMAN, COMPUTER SCIENCE DEPARTMENT, TECHNION
# Version CST-1.1: Installed on the CS Department's Sun-4 (Host Name: CS)
# (1) commented out the backup target.
# (2) changed name of executable file from vi.iv to vi_iv & installing
# it to a different place.  This is because the user will access a
# shellscript called vi.iv which will set up the enviornment & then run
# the actual program.
# (3) Commented out the original 'install' & 'ninstall' targets,
# because they were designed for the original ex editor & for making
# vi.iv a complete replacement for ex.
# (4) I commented out definitions that were no longer used.  I tended
# not to change them, but to add new definitions that I needed.  This
# makes the file long & messy looking, but it's safer for now.
# (5) added the 'insman' target to install the manual.
#
# ??/198?	URI HABUSHA, COMPUTER SCIENCE DEPARTMENT, TECHNION
# Modified from ex's Makefile for vi.iv
#================================================================
# Copyright (c) 1980 Regents of the University of California.
# All rights reserved.  The Berkeley software License Agreement
# specifies the terms and conditions for redistribution.
#===============================================================
# ORIGINAL COMMENTS FOR EX:
#
#	@(#)Makefile	5.3
#
#VERSION=3.7
VERSION= 5.3
#
# Ex skeletal makefile for VAX VM/Unix 4.2BSD
#
# NB: This makefile doesn't indicate any dependencies on header files.
#
# Ex is very large - this version will not fit on PDP-11's without overlay
# software.  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.)  VMUNIX makes ex considerably larger, raising many limits
# and improving speed and simplicity of maintenance.  It is suitable only
# for a VAX or other large machine, and then probably only in a paged system.
#
# Don't define VFORK unless your system has the VFORK system call,
# which is like fork but the two processes have only one data space 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
#=====================================================================
# NOTES ADDED BY HAIM ROMAN (11/1989)
#
# (1) PRINT -- The print: target has NOT been commented out, but I
# have not tried it.  I did comment out the reference to cxref,
# because it is not currently available on our system.
#
# (2) EXRECOVER & EXPRESERVE -- I don't know what the state of these
# programs are currently.  Have they been changed for vi.iv?
#
# (3) MAIN TARGETS -- below is a list of the main targets, the
# targets one needs to reference when invoking 'make'.
#
#	all:		compile programs
#	install:	install software
#	insman:		install manual
#	clean:		remove files
#	tags:		create tags file for source code
#	lint:		run source code through lint
#	print:		format & print files
#	vgrind:		format source code via vgrind & troff
#
# (4) INSTALLING FOR SUN4 -- the source code will sit on a Sun-3, but
# it will have to be compiled on a sun-4 (name: CS).  Normally, a user
# on CS is treated as the same user on the Sun-3s, & thus user ABCDE on
# CS is treated as the owner of files on the Sun-3 owned by a user named
# ABCDE.  But this is NOT true if the user is ROOT.  So here is the
# procedure:
#
#	(A) Make the owner of the source files & their directory
#	someone other than ROOT.
#
#	(B) That user can execute all of the above targets from CS.
#	He should be super-user for the 'install' & 'insman' targets, 
#	but should be under his regular user name for the other steps.
#	
#=====================================================================
# DEFINTIONS:
#
#RMTDIR	= cs:/usr/haim/visrc	>>> SEE NOTES ON THE backup: TARGET <<<
#BCUPDIR =/staff/023/urih/bcup	>>>not referenced anywhere <<<
#
#	For normal vi, BINDIR is both the directory where vi is
#	installed & the directory where other needed utilities are
#	installed.  However, at TCSF, these directories are not the
#	same.  Thus, BINDIR remains the directory of the utilities.
#	CSBINDIR (defined at the end of the make variables) is the
#	directory where vi.iv is installed.
#		(HR-TCSF 05.05.1991)
BINDIR=	/usr/ucb
#NBINDIR=/usr/new
#LIBDIR=	/usr/lib
FOLD=	${BINDIR}/fold
CTAGS=	${BINDIR}/ctags
XSTR=	${BINDIR}/xstr
DEBUGFLAGS=	-DTRACE -g
NONDEBUGFLAGS=	-O
DEB=	${DEBUGFLAGS}	# or ${NONDEBUGFLAGS} for no debug
# DEB=	${NONDEBUGFLAGS}	# or ${DEBUGFLAGS} to debug
#	((( stripping was taken from the install command & executed as
#	    a separate command so that it could be put in the "all:"
#	    target.  This is to handle the case where "all:" is
#	    executed on one type of machine, but "install:" is
#	    executed on another.	-- HR-TCSF 25/04/90 )))
# STRIP= strip vi_iv	# for no debug
STRIP= 			# for debug

#	((( added -DVMUNIX -- HR-TCSF 01/01/90 )))
OPTIONS= -DCHDIR -DVFORK -DVMUNIX
CFLAGS=	${OPTIONS} ${DEB}
LDFLAGS=	-z		# or -i or -n
TERMLIB=	-ltermcap
MKSTR=	${BINDIR}/mkstr
CXREF=	${BINDIR}/cxref	>>> currently not available at CS <<<
INCLUDE=/usr/include
PR=	pr
#  strings.o MUST BE THE LAST FILE IN THE "OBJS" DEFINITION!
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_tagio.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 ex_RL.o ex_tputs.o ex_vgetline.o \
	strings.o
#	printf.o bcopy.o strings.o ex_RL.o ex_tputs.o \
#	ex_vgetline.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 ex_RL.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_tagio.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
SRC7=   ex_RL.c ex_tputs.c ex_vgetline.c
MISC=	makefile READ_ME rofix
VGRIND=	csh /usr/ucb/vgrind
#VHDR=	"Ex Version ${VERSION}"
VHDR=	"vi.iv Version ${VERSION}"
#
# Added for installing for Technion CS Department (Haim Roman 11/1989)
#CSINSFILES= vi.iv vi_iv termcap
CSBINDIR= /usr/local/bin
CSLIBDIR= /usr/local/lib/vi.iv
CSMANFILE= vi.iv.l
CSMANDIR= /usr/man/manl
CSCATFILE= /usr/man/catl/${CSMANFILE}
CSGROUP= wheel
CSOWNER= root

#====================================================================
# TARGETS:

.c.o:
# if you are compiling with -DVMUNIX, uncomment the following line:
	${CC} -E ${CFLAGS} $*.c | ${XSTR} -c -

# else uncomment the following lines:
#	${MKSTR} - ex${VERSION}strings x $*.c
#	${CC} -E ${CFLAGS} x$*.c | ${XSTR} -c -
#	rm -f x$*.c
#
# either way, leave the following lines uncommented:
	${CC} ${CFLAGS} -c x.c 
	mv x.o $*.o

#-----------------------------------------------------------
all:	 a.out exrecover expreserve
	${STRIP}

a.out: ${OBJS}
	@echo loading a.out
	@${CC} ${LDFLAGS} ${OBJS} ${TERMLIB}
	mv a.out vi_iv
	chmod a+rx vi_iv

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

#-----------------------------------------------------------
${OBJS}: ${HDRS}

ex_vars.h:
	csh makeoptions ${CFLAGS}

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

# xstr: hands off!
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} ${CFLAGS} exrecover.o ex_extern.o -o exrecover

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

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

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

#-----------------------------------------------------------
# INSTALLATION TARGET FOR VI.IV ON THE COMPUTER SCIENCE DEPARTMENT
# (created by Haim Roman 11/1989)
#install:  ${CSINSFILES}
install:  
	-rm -f ${CSBINDIR}/vi.iv ${CSLIBDIR}/vi_iv ${CSLIBDIR}/termcap
	install -g ${CSGROUP} -o ${CSOWNER} -m 1755 ${STRIP}  vi_iv ${CSLIBDIR}
	install -g ${CSGROUP} -o ${CSOWNER} -m 1755     vi.iv ${CSBINDIR}
	install -g ${CSGROUP} -o ${CSOWNER} -m 0744     termcap ${CSLIBDIR}

#-----------------------------------------------------------
# INSTALL THE MANUAL
#
insman: ${CSMANFILE}
	rm -f ${CSMANDIR}/${CSMANFILE} ${CSCATFILE}
	install -g ${CSGROUP} -o ${CSOWNER} -m 0744     ${CSMANFILE} ${CSMANDIR}
#
#	INSTALL THE ALREADY nroffED VERSION OF THE MANUAL
	tbl ${CSMANFILE} | nroff -man >${CSCATFILE}
	chown ${CSOWNER} ${CSCATFILE}
	chgrp ${CSGROUP} ${CSCATFILE}
	chmod 0444 ${CSCATFILE}
#-----------------------------------------------------------
clean: 
#	If we dont have ex we cant make it so don't rm ex_vars.h
	-rm -f a.out exrecover expreserve strings core errs trace
	-rm -f *.o x*.[cs] vi_iv

#-----------------------------------------------------------
# DISABLE BACKING UP (Haim Roman, 31/10/89)
#
#backup: $(HDRS) $(SRC1) $(SRC2) $(SRC3) $(SRC4) $(SRC5) $(SRC6) $(SRC7)
#	rcp  -p $(HDRS) $(SRC1) $(SRC2) $(SRC3) $(SRC4) $(SRC5) $(SRC6) $(SRC7) $(RMTDIR)
#	echo backup job has been done


#-----------------------------------------------------------
# APPARENTLY, THIS WAS THE ORIGINAL INSTALLATION TARGET FOR EX
# (commented out by Haim Roman, 11/1989)
## install in standard place (/usr/ucb)
#install: a.out exrecover expreserve
#	-rm -f ${DESTDIR}/${BINDIR}/ex
#	-rm -f ${DESTDIR}/${BINDIR}/vi
#	-rm -f ${DESTDIR}/${BINDIR}/view
#	-rm -f ${DESTDIR}/${BINDIR}/edit
#	-rm -f ${DESTDIR}/${BINDIR}/e
#	-rm -f ${DESTDIR}/usr/bin/ex
#	install -s -m 1755 a.out ${DESTDIR}/${BINDIR}/ex
##	cp ex${VERSION}strings ${DESTDIR}/${LIBDIR}/ex${VERSION}strings
#	ln ${DESTDIR}/${BINDIR}/ex ${DESTDIR}/${BINDIR}/edit
#	ln ${DESTDIR}/${BINDIR}/ex ${DESTDIR}/${BINDIR}/e
#	ln ${DESTDIR}/${BINDIR}/ex ${DESTDIR}/${BINDIR}/vi
#	ln ${DESTDIR}/${BINDIR}/ex ${DESTDIR}/${BINDIR}/view
#	ln ${DESTDIR}/${BINDIR}/ex ${DESTDIR}/usr/bin/ex
#	chmod 1755 ${DESTDIR}/${BINDIR}/ex
#	install -s -o root -m 4755 exrecover ${DESTDIR}/${LIBDIR}/ex${VERSION}recover
#	install -s -o root -m 4755 expreserve ${DESTDIR}/${LIBDIR}/ex${VERSION}preserve
## The following line normally fails.  This is OK.
#	-mkdir ${DESTDIR}/usr/preserve

#-----------------------------------------------------------
# DISABLED BECAUSE INSTALLING TO /usr/new DISABLED  (Haim Roman 11/1989)
## move from /usr/new to /usr/ucb
#newucb: a.out
#	-rm -f ${DESTDIR}/${BINDIR}/ex
#	-rm -f ${DESTDIR}/${BINDIR}/vi
#	-rm -f ${DESTDIR}/${BINDIR}/edit
#	-rm -f ${DESTDIR}/${BINDIR}/e
#	-rm -f ${DESTDIR}/usr/bin/ex
#	mv ${DESTDIR}/${NBINDIR}/ex ${DESTDIR}/${NBINDIR}/ex
#	-rm -f ${DESTDIR}/${NBINDIR}/vi
#	ln ${DESTDIR}/${BINDIR}/ex ${DESTDIR}/${BINDIR}/edit
#	ln ${DESTDIR}/${BINDIR}/ex ${DESTDIR}/${BINDIR}/e
#	ln ${DESTDIR}/${BINDIR}/ex ${DESTDIR}/${BINDIR}/vi
#	ln ${DESTDIR}/${BINDIR}/ex ${DESTDIR}/usr/bin/ex
#	chmod 1755 ${DESTDIR}/${BINDIR}/ex

#-----------------------------------------------------------
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

#-----------------------------------------------------------
vgrind:
	tee index < /dev/null
	${VGRIND} -h ${VHDR} ${HDRS}
	${VGRIND} -h ${VHDR} ${SRC1}
	${VGRIND} -h ${VHDR} ${SRC2}
	${VGRIND} -h ${VHDR} ${SRC3}
	${VGRIND} -h ${VHDR} ${SRC4}
	${VGRIND} -h ${VHDR} ${SRC5}
	${VGRIND} -h ${VHDR} ${SRC6}
	${VGRIND} -n -h ${VHDR} ${MISC}
	${VGRIND} -i -h ${VHDR} index
