# Makefile $Revision: 6.12 $
#
# 1) Select the proper EXDIR (path), MANDIR, MANEXT, LIBDIR, SIGVOID,
#	and DFLT_PAGER. Most of the other things aren't normally changed
#	(see the comments with each)
# 2) Select the proper machine/compiler/OS section of code
# 3) make install
# 4) If you have the command 'file' that uses /etc/magic add the line:
#	38	string		Spreadsheet	sc file


# Specify the name of the program.
# All documentation and installation keys on this value.
# 
name=sc
NAME=SC

# This is where the install step puts it.
#EXDIR=/site/bin
EXDIR=/usr/local/bin

# This is where the man page goes.
#MANDIR=/site/man/man1
#MANEXT=1
MANDIR=/usr/man/manl
MANEXT=l

# This is where the library file (tutorial) goes.
#LIBDIR=/site/lib/$(name)
LIBDIR=/usr/local/lib/$(name)

# Set SIMPLE for lex.c if you don't want arrow keys or lex.c blows up
SIMPLE=
#SIMPLE=-DSIMPLE

# Set BROKENCURSES if your curses has the nl/nonl bug
# if it does and you don't set BROKENCURSES, the display will
# be staggered across the screen
BROKENCURSES=
#BROKENCURSES=-DBROKENCURSES

# Set DOBACKUPS if you would like a backup copy of a source file on a save
#DOBACKUPS=
DOBACKUPS=-DDOBACKUPS

# Set INTERNATIONAL if you need 8 bit characters.  You should
# not set this if you are running 5.3.0.  I think it is OK in 5.3.1.
#INTERNATIONAL=-DINTERNATIONAL
INTERNATIONAL=

# Set SIGVOID if signal routines are type void.  System 5.3, VMS and ANSI C
# Compliant systems use this.  Most BSD systems and the UNIXPC 'cc' do not.
#SIGVOID=-DSIGVOID
SIGVOID=

# Set IEEE_MATH if you need setsticky() calls in your signal handlers
#
#IEEE_MATH=-DIEEE_MATH
IEEE_MATH=

# Set RINT if you do not have rint() in math.h
# So far I know you what to undefine this on/with:
#	SunOS 4.0.3c compiler
#RINT=
RINT=-DRINT

# This is the name of a pager like "more".
# "pg" may be appropriate for SYSV.
DFLT_PAGER=-DDFLT_PAGER=\"less\"
#DFLT_PAGER=-DDFLT_PAGER=\"more\"

# this is the name to save back ups in
SAVE=-DSAVENAME=\"$(NAME).SAVE\"

# flags for lint
LINTFLAGS=-abchxv

# For ULTRIX: define the BSD4.2 section and SIGVOID above
#	tdw@cl.cam.ac.uk tested on Ultrix 3.1C-0

# Use this for system AIX V3.1
#CFLAGS= -O -DSYSV2 -DCHTYPE=int -DNLS
#LDFLAGS=
#LIB=-lm -lPW -lcurses

# Use this for system V.2
#CFLAGS= -O -DSYSV2 
#LDFLAGS=
#LIB=-lm -lPW -lcurses

# Use this for system V.3
#CFLAGS= -O -DSYSV3
#LDFLAGS=
#LIB=-lm -lcurses -lPW

# Microport
#CFLAGS= -DSYSV2 -O -DUPORT -Ml
#LDFLAGS=-Ml
#LIB=-lm -lcurses -lPW

# Use this for BSD 4.2
#CFLAGS= -O -DBSD42
#LDFLAGS=
#LIB=-lm -lcurses -ltermcap

# Use this for Sequent boxes
CC=atscc
CFLAGS=-O -DBSD42
CFLAGS=-O -DBSD42
#LDFLAGS= -s
LIB=-lm -lcurses -ltermcap
PSCLIB=-lseq

# Use this for BSD 4.3
#CFLAGS= -O -DBSD43
#LDFLAGS=
#LIB=-lm -lcurses -ltermcap

# Let's try this for sunos4.1 with a sysv flavor
# (to get good sysv curses). This may also speed screen updates.
#CC=/usr/5bin/cc
#FLAGS= -O -DSYSV3 -DSIGVOID -DSUNOS41SYSV
#LDFLAGS=
#LIB=-lm -lcurses 

# Use this for system III (XENIX)
#CFLAGS= -O -DSYSIII
#LDFLAGS= -i
#LIB=-lm -lcurses -ltermcap

# Use this for VENIX
#CFLAGS= -DVENIX -DBSD42 -DV7
#LDFLAGS= -z -i 
#LIB=-lm -lcurses -ltermcap

# For SCO Unix V rel. 3.2.0
#       -compile using rcc, cc does not cope with gram.c
#       -edit /usr/include/curses.h, rcc does not understand #error
#       -link: make CC=cc, rcc's loader gets unresolved __cclass, __range
#               (rather strange,?)
#CC=rcc
#SIGVOID=-DSIGVOID
#CFLAGS= -O -DSYSV3
#LDFLAGS=
#LIB=-lm -lcurses -ltinfo -lPW

# All of the source files
SRC=sc.h sc.c lex.c gram.y interp.c crypt.c xmalloc.c cmds.c range.c help.c \
	vi.c eres.sed sres.sed Makefile psc.c vmtbl.c format.c version.c

# The objects
OBJS=sc.o interp.o cmds.o gram.o lex.o crypt.o xmalloc.o range.o help.o vi.o \
	vmtbl.o format.o version.o 

# The documents in the Archive
DOCS=README CHANGES sc.doc psc.doc tutorial.sc VMS_NOTES

$(name):$(PAR) 	$(OBJS)
	$(CC) ${CFLAGS} ${LDFLAGS} ${OBJS} ${LIB} -o $(name)

all:	$(name) p$(name) $(name)qref

p$(name):	psc.c pvmtbl.o
	$(CC) ${CFLAGS} -o p$(name) psc.c pvmtbl.o ${PSCLIB}
	cp p$(name) $(EXDIR)/p$(name)

$(name)qref:	help.c
	$(CC) ${CFLAGS} -DQREF -DSCNAME=\"$(name)\" -o $(name)qref help.c
	cp $(name)qref $(EXDIR)/$(name)qref

pvmtbl.o: sc.h vmtbl.c
	$(CC) ${CFLAGS} -c -DPSC vmtbl.c
	mv vmtbl.o pvmtbl.o

lex.o:	sc.h y.tab.h gram.o lex.c
	$(CC) ${CFLAGS} ${SIMPLE} ${IEEE_MATH} ${INTERNATIONAL} ${SIGVOID} -c lex.c

sc.o:	sc.h sc.c
	$(CC) ${CFLAGS} ${BROKENCURSES} ${INTERNATIONAL} ${DFLT_PAGER} ${SIGVOID} ${SAVE} -c sc.c

interp.o:	interp.c sc.h
	$(CC) ${CFLAGS} ${IEEE_MATH} ${SIGVOID} ${RINT} -c interp.c

gram.o:	sc.h y.tab.h

cmds.o: cmds.c sc.h
	$(CC) ${CFLAGS} ${DOBACKUPS} -c cmds.c

crypt.o: crypt.c sc.h
	$(CC) ${CFLAGS} ${DOBACKUPS} -c crypt.c

range.o: range.c sc.h

help.o: help.c sc.h

format.o: format.c

vi.o: vi.c sc.h

y.tab.h:	gram.y

gram.o:	sc.h y.tab.h gram.c
	$(CC) ${CFLAGS} -c gram.c
	sed<gram.y >experres.h -f eres.sed;sed < gram.y > statres.h -f sres.sed

gram.c:	gram.y
	$(YACC) -d gram.y; mv y.tab.c gram.c

clean:
	rm -f *.o *res.h y.tab.h $(name) p$(name) debug core gram.c $(name).1 \
	$(name).man p$(name).man p$(name).1 y.output $(name)qref

shar: ${SRC} ${DOCS}
	shar -c -m 64000 -f shar ${DOCS} ${SRC}

sshar: ${SRC}
	shar -c -m 1000000 -f shar ${SRC}

lint: sc.h sc.c lex.c gram.c interp.c cmds.c crypt.c range.c help.c \
 	vi.c version.c xmalloc.c format.c vmtbl.c
	lint ${LINTFLAGS} ${CFLAGS} ${SIMPLE} sc.c lex.c gram.c interp.c \
 	cmds.c crypt.c range.c help.c vi.c version.c xmalloc.c format.c \
 	vmtbl.c -lcurses -lm 
	make lintqref

lintqref: help.c
	lint ${LINTFLAGS} ${CFLAGS} ${SIMPLE} -DQREF help.c

lintpsc: psc.c vmtbl.c
	lint ${LINTFLAGS} ${CFLAGS} ${SIMPLE} -DPSC psc.c vmtbl.c

inspect: sc.h sc.c lex.c gram.c interp.c cmds.c crypt.c
	/bruces/ianj/bin/i386/inspect -abv -t 8 sc.c lex.c gram.c interp.c \
	cmds.c crypt.c range.c xmalloc.c help.c vi.c

print: sc.h gram.y sc.c lex.c interp.c cmds.c crypt.c 
	prc sc.h gram.y sc.c lex.c interp.c cmds.c crypt.c | lpr

$(name).1:	sc.doc
	sed -e s/pname/$(name)/g -e s/PNAME/$(NAME)/g \
	   -e s%#LIBDIR#%$(LIBDIR)%g sc.doc >  $(name).1

$(name).man:	$(name).1
	nroff -man $(name).1 > $(name).man

laser:	$(name).1
	itpf -x -Pim2 -man $(name).1

p$(name).1:	psc.doc
	sed -e s/pname/$(name)/g -e s/PNAME/$(NAME)/g psc.doc >  p$(name).1

p$(name).man:	p$(name).1
	nroff -man p$(name).1 > p$(name).man

install: $(EXDIR)/$(name) $(LIBDIR)/tutorial $(MANDIR)/$(name).$(MANEXT)

$(EXDIR)/$(name): $(name)
	cp $(name) $(EXDIR)
	strip $(EXDIR)/$(name)

$(LIBDIR)/tutorial: tutorial.sc $(LIBDIR)
	cp tutorial.sc $(LIBDIR)/tutorial.$(name)

$(LIBDIR):
	mkdir $(LIBDIR)

$(MANDIR)/$(name).$(MANEXT): $(name).1
	cp $(name).1 $(MANDIR)/$(name).$(MANEXT)

diffs: ${SRC}
	for i in ${SRC} ${DOCS} ;\
		do \
		rcsdiff -c -r6.11 $$i ;\
		done

# THA 10/14/90  Added code to make a patchfile
patchfile: ${SRC}
	rm -f patchfile
	for i in ${SRC} ${DOCS} format.c ;\
		do \
		diffc $$i /users/toma/sc6.8me/$$i >> patchfile ;\
		done

test: test.o vmtbl.o
	$(CC) ${CFLAGS} ${LDFLAGS} test.o vmtbl.o ${LIB} -o test
