# combined Makefile for ELVIS - a clone of `vi`
#
# After editing this Makefile as described below, you should...
#
# Use `make` to compile all programs
# Use `make install` to copy the programs to the BIN directory
# Use `make clean` to remove all object files
# Use `make clobber` to remove everything except source & documentation
# Use `make tags` to build new "tags" and "refs" files
# Use `make uue` to produce uuencoded compressed tar archives of the source
# Use `make sh` to produce shar archives of the source
# Use `make print` to print the Elvis documentation
#
# Several groups of Makefile settings are included below.  Choose *ONE* group
# of settings for your particular system, and leave the others commented out.
# The meanings of these settings are:
#	O	the filename extension for unlinked object files -- usually .o
#	E	the filename extension for executable files -- usually null
#	EXTRA	version-specific object files used in elvis
#	EXTRA2	version-specific object files used in elvis, virec, & refont
#	LIBS	any special libraries, such as "-ltermcap"
#	BIN	directory where executables should be installed
#	CC	the C compiler command, possibly with "memory model" flags
#	CFLAGS	compiler flags used to select compile-time options
#	OF	link flag to control the output file's name -- usually -o<space>
#	RF	flag used to denote "compile but don't link" -- usually -c
#	DATE	a "cc" flag that defines "DATE".  e.g. DATE=-DDATE=\"7/4/76\"
#	EVAL	the word "eval", if DATE requires it
#	PROGS	the list of all programs
#	CHMEM	any extra commands to be run after ELVIS is linked
#	SORT	if the "tags" file must be sorted, then SORT=-DSORT
#	INST	installation method: inst.dos, inst.os9, or inst.unix
#	RM	the name of a program that deletes files
#	PR1	used to print documentation -- typically "refont -c"
#	PR2	used to send text to printer -- typically "| lpr"
#	DUMMY	usually nothing, but OS9 needs "dummy"
#	DOC	name of "doc" directory, with a trailing slash


#---- These settings are recommended for Coherent ----
O=.o
E=
EXTRA=
EXTRA2=
LIBS=	-lterm
BIN=	/usr/bin
CC=	cc 
CFLAGS=	-O -DCOHERENT -DCRUNCH -DNO_CHARATTR -DNO_CURSORSHAPE \
	-DNO_DIGRAPH -DNO_MKEXRC
OF=	-o 
RF=	-c
DATE=	-DDATE=\'\"`date`\"\'
EVAL=	eval
PROGS=	elvis$E ctags$E ref$E virec$E refont$E
CHMEM=	fixstack 2000 $(DESTDIR)elvis$E
SORT=
INST=	inst.unix
RM=	rm -f
PR1=	refont -b
PR2=	>Elvis.doc
DUMMY=
DOC=	doc/
DESTDIR= /interim/usr/bin/


###########################################################################
###########################################################################
###                                                                     ###
###     The rest of this Makefile contains no user-servicable parts     ###
###                                                                     ###
###########################################################################
###########################################################################

OBJS=	blk$O cmd1$O cmd2$O curses$O cut$O ex$O input$O main$O misc$O \
	modify$O move1$O move2$O move3$O move4$O move5$O opts$O recycle$O \
	redraw$O regexp$O regsub$O system$O tio$O tmp$O vars$O vcmd$O \
	vi$O

ALIAS=	alias$O

DOCS=	$(DOC)index.doc $(DOC)intro.doc $(DOC)visual.doc $(DOC)ex.doc \
	$(DOC)regexp.doc $(DOC)options.doc $(DOC)cutbufs.doc $(DOC)differ.doc \
	$(DOC)internal.doc $(DOC)cflags.doc $(DOC)termcap.doc \
	$(DOC)environ.doc $(DOC)versions.doc

SRC1=	README $(DOC)intro.doc $(DOC)visual.doc $(DOC)ex.doc \
	$(DOC)versions.doc $(DOC)cflags.doc $(DOC)differ.doc
SRC2=	$(DOC)cutbufs.doc $(DOC)options.doc $(DOC)environ.doc $(DOC)regexp.doc \
	$(DOC)internal.doc $(DOC)termcap.doc $(DOC)index.doc $(DOC)ctags.man \
	$(DOC)elvis.man $(DOC)ref.man $(DOC)refont.man $(DOC)virec.man
SRC3=	Elvis.lnk Elvis.mak Elvis.prj Makefile.mix alias.c atari.c \
	ctags.c pc.c ref.c shell.c sysdos.c virec.c wildcard.c \
	profile.sh osk.c osk.h date.c
SRC4=	blk.c cmd1.c cmd2.c config.h curses.c
SRC5=	curses.h cut.c ex.c input.c main.c misc.c
SRC6=	modify.c move1.c move2.c move3.c move4.c move5.c opts.c recycle.c \
	redraw.c 
SRC7=	regexp.c regexp.h regsub.c system.c tinytcap.c tio.c tmp.c 
SRC8=	vars.c vcmd.c vi.c vi.h refont.c

###########################################################################

all: $(PROGS)
	@echo done.

elvis$E: $(OBJS) $(EXTRA) $(EXTRA2)
	$(CC) $(CFLAGS) $(OF) $(DESTDIR)elvis$E $(OBJS) $(EXTRA) $(EXTRA2) $(LIBS)
	-$(CHMEM)
	su root chown bin $(DESTDIR)elvis
	su root chgrp bin $(DESTDIR)elvis
	su root chmod 755 $(DESTDIR)elvis
	su root ln -f $(DESTDIR)elvis $(DESTDIR)vi
	su root ln -f $(DESTDIR)elvis $(DESTDIR)ex
	su root ln -f $(DESTDIR)elvis $(DESTDIR)view
	su root ln -f $(DESTDIR)elvis $(DESTDIR)input

ctags$E: ctags.c
	$(CC) $(CFLAGS) $(SORT) $(OF) $(DESTDIR)ctags$E ctags.c
	su root chown bin $(DESTDIR)ctags
	su root chgrp bin $(DESTDIR)ctags
	su root chmod 511 $(DESTDIR)ctags

ref$E: ref.c
	$(CC) $(CFLAGS) $(OF) $(DESTDIR)ref$E ref.c
	su root chown bin $(DESTDIR)ref
	su root chgrp bin $(DESTDIR)ref
	su root chmod 511 $(DESTDIR)ref

virec$E: virec.c
	$(CC) $(CFLAGS) $(OF) $(DESTDIR)virec$E virec.c $(EXTRA2)
	su root chown bin $(DESTDIR)virec
	su root chgrp bin $(DESTDIR)virec
	su root chmod 511 $(DESTDIR)virec

view$E: $(ALIAS)
	$(CC) $(CFLAGS) $(OF) view$E $(ALIAS)

ex$E: $(ALIAS)
	$(CC) $(CFLAGS) $(OF) ex$E $(ALIAS)

vi$E: $(ALIAS)
	$(CC) $(CFLAGS) $(OF) vi$E $(ALIAS)

input$E: $(ALIAS)
	$(CC) $(CFLAGS) $(OF) input$E $(ALIAS)

wildcard$E: wildcard.c
	$(CC) $(CFLAGS) $(OF) wildcard$E wildcard.c

refont$E: refont.c
	$(CC) $(CFLAGS) $(OF) refont$E refont.c $(EXTRA2)

##############################################################################

# The file cmd1.c is compiled with the extra flag -DDATE="today's date".
cmd1$O: cmd1.c vi.h config.h
	$(EVAL) $(CC) $(CFLAGS) $(RF) $(DATE) cmd1.c

# "It all depends..."
$(OBJS): vi.h curses.h config.h

# OS9 must create a custom date.c file, and compile it.
date$O: $(OBJS)
	@echo '/* compilation date of elvis */' >-date.c
	@echo -r 'char date[] = "' >+date.c
	@echo -r 'echo -r ' >-/dd/tmp/date.c
	@date >+/dd/tmp/date.c
	@shell /dd/tmp/date.c >+date.c
	@echo '";' >+date.c
	@del /dd/tmp/date.c
	$(CC) $(CFLAGS) $(RF) date.c

##############################################################################
install: $(INST)
	@echo Installation complete.

inst.unix: $(DUMMY)
	su root chown bin $(DESTDIR)elvis
	su root chgrp bin $(DESTDIR)elvis
	su root chmod 755 $(DESTDIR)elvis
	su root ln $(DESTDIR)elvis $(DESTDIR)vi
	su root ln $(DESTDIR)elvis $(DESTDIR)ex
	su root ln $(DESTDIR)elvis $(DESTDIR)view
	su root ln $(DESTDIR)elvis $(DESTDIR)input

inst.dos: $(DUMMY)
	copy $(PROGS) $(BIN)
	copy $(BIN)/ex$E $(BIN)/vi$E
	copy $(BIN)/ex$E $(BIN)/view$E
	copy $(BIN)/ex$E $(BIN)/input$E

inst.os9: $(DUMMY)
	copy $(PROGS) -rw=$(BIN)
	chd $(BIN); attr -epenprnpw $(PROGS)

##############################################################################
clean: $(DUMMY)
	$(RM) *$O $(DOC)*.1 elvis?.uue elvis?.sh core

clobber: clean
	$(RM) tags refs $(PROGS)

##############################################################################
print: refont$E
	$(PR1) $(DOCS) $(PR2)

tags refs: ctags$E
	./ctags -r *.c *.h

##############################################################################
uue: elvis1.uue elvis2.uue elvis3.uue elvis4.uue elvis5.uue \
	elvis6.uue elvis7.uue elvis8.uue

elvis1.uue: $(SRC1)
	tar cf elvis1.tar $(SRC1)
	compress -b13 elvis1.tar
	cp README elvis1.uue
	uue elvis1.tar.Z - >>elvis1.uue
	$(RM) elvis1.tar*

elvis2.uue: $(SRC2)
	tar cf elvis2.tar $(SRC2)
	compress -b13 elvis2.tar
	uue elvis2.tar.Z
	$(RM) elvis2.tar*

elvis3.uue: $(SRC3)
	tar cf elvis3.tar $(SRC3)
	compress -b13 elvis3.tar
	uuencode elvis3.tar.Z <elvis3.tar.Z >elvis3.uue
	$(RM) elvis3.tar*

elvis4.uue: $(SRC4)
	tar cf elvis4.tar $(SRC4)
	compress -b13 elvis4.tar
	uuencode elvis4.tar.Z <elvis4.tar.Z >elvis4.uue
	$(RM) elvis4.tar*

elvis5.uue: $(SRC5)
	tar cf elvis5.tar $(SRC5)
	compress -b13 elvis5.tar
	uuencode elvis5.tar.Z <elvis5.tar.Z >elvis5.uue
	$(RM) elvis5.tar*

elvis6.uue: $(SRC6)
	tar cf elvis6.tar $(SRC6)
	compress -b13 elvis6.tar
	uuencode elvis6.tar.Z <elvis6.tar.Z >elvis6.uue
	$(RM) elvis6.tar*

elvis7.uue: $(SRC7)
	tar cf elvis7.tar $(SRC7)
	compress -b13 elvis7.tar
	uuencode elvis7.tar.Z <elvis7.tar.Z >elvis7.uue
	$(RM) elvis7.tar*

elvis8.uue: $(SRC8)
	tar cf elvis8.tar $(SRC8)
	compress -b13 elvis8.tar
	uuencode elvis8.tar.Z <elvis8.tar.Z >elvis8.uue
	$(RM) elvis8.tar*

##############################################################################
sh: elvis1.sh elvis2.sh elvis3.sh elvis4.sh elvis5.sh elvis6.sh \
	elvis7.sh elvis8.sh

elvis1.sh: $(SRC1)
	cat   >elvis1.sh README
	echo >>elvis1.sh ': ------------------------ CUT HERE --------------------'
	echo >>elvis1.sh 'test -d doc || mkdir doc || exit 2'
	shar >>elvis1.sh -h $(SRC1)

elvis2.sh: $(SRC2)
	echo  >elvis2.sh ': ------------------------ CUT HERE --------------------'
	echo >>elvis2.sh 'test -d doc || mkdir doc || exit 2'
	shar >>elvis2.sh -h $(SRC2)

elvis3.sh: $(SRC3)
	shar $(SRC3) >elvis3.sh

elvis4.sh: $(SRC4)
	shar $(SRC4) >elvis4.sh

elvis5.sh: $(SRC5)
	shar $(SRC5) >elvis5.sh

elvis6.sh: $(SRC6)
	shar $(SRC6) >elvis6.sh

elvis7.sh: $(SRC7)
	shar $(SRC7) >elvis7.sh

elvis8.sh: $(SRC8)
	shar $(SRC8) >elvis8.sh

##############################################################################

# Under XENIX only!  This stores all sources on a 3.5" 720k floppy disk.
floppy: $(SRC1) $(SRC2) $(SRC3) $(SRC4) $(SRC5) $(SRC6) $(SRC7) $(SRC8)
	tar c5v $(SRC1) $(SRC2) $(SRC3) $(SRC4) $(SRC5) $(SRC6) $(SRC7) $(SRC8)
