#/*
# * This file is a product of Sun Microsystems, Inc. and is provided for
# * unrestricted use provided that this legend is included on all tape
# * media and as a part of the software program in whole or part.  Users
# * may copy or modify this file without charge, but are not authorized to
# * license or distribute it to anyone else except as part of a product
# * or program developed by the user.
# * 
# * THIS FILE IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
# * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
# * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
# * 
# * This file is provided with no support and without any obligation on the
# * part of Sun Microsystems, Inc. to assist in its use, correction,
# * modification or enhancement.
# * 
# * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
# * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY THIS FILE
# * OR ANY PART THEREOF.
# * 
# * In no event will Sun Microsystems, Inc. be liable for any lost revenue
# * or profits or other special, indirect and consequential damages, even
# * if Sun has been advised of the possibility of such damages.
# * 
# * Sun Microsystems, Inc.
# * 2550 Garcia Avenue
# * Mountain View, California  94043
# */

# --- Installation and Build Directories ---
INSDIR=/usr/NeWS
BINDIR=${INSDIR}/bin
DEMODIR=${INSDIR}/demo
LIBDIR=${INSDIR}/lib
INCLUDEDIR=${INSDIR}/include
INCLUDE=../../include
LIBNEWS=../../lib/NeWS

# Global macro definitions
OPT=-O
TARGET_ARCH=
SYSV_NETLIB=
OSI=SUN
VER=SUNREF
SYSV_NETWORK=
BYTES=

COPTS=${BYTES}

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

SRC1=sc.h sc.c lex.c gram.y interp.c
SRC2=cmds.c eres.sed sres.sed Makefile cvt.sed scdisp.cps tax-form expense-acct
DOCS=README $(name).man $(name).doc

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

#Use this for system V.2
#CFLAGS= -O -DSYSV -I${INCLUDE}
#LIB=-lm -lcurses

#Use this for BSD 4.2
#CFLAGS= -O -DBSD42 -I${INCLUDE}
#LIB=-lm -lcurses -ltermcap

#Use this for BSD 4.3
#CFLAGS= -O -DBSD43 -I${INCLUDE}
#CFLAGS= -g -f68881 -DBSD43 -I${INCLUDE}
#LIB=${LIBCPS} -lm

#Use this for system III (XENIX)
#CFLAGS= -O -DSYSIII -I${INCLUDE}
#LIB=-lm -lcurses -ltermcap

#Use this for running with NeWS
CFLAGS=-O -I${INCLUDE} -D${VER}
LIBCPS= ${LIBNEWS}/libcps.a
CPS=${LIBNEWS}/cps
LIB=${LIBCPS} -lm ${SYSV_NETLIB}


$(name):	sc.o lex.o gram.o interp.o cmds.o
	cc ${CFLAGS} ${TARGET_ARCH} sc.o lex.o gram.o interp.o cmds.o ${LIB} -o $(name)

diff_to_sc:	diff_to_sc.c
	cc ${CFLAGS} ${TARGET_ARCH} -o dtv diff_to_sc.c

lex.o:	sc.h y.tab.h gram.o
	cc ${CFLAGS} ${TARGET_ARCH} ${SIMPLE} -c lex.c

interp.o:	sc.h

sc.o:	sc.h

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

cmds.o: cmds.c sc.h

y.tab.h:	gram.y

gram.o:	sc.h y.tab.h gram.c eres.sed sres.sed
	cc ${CFLAGS} ${TARGET_ARCH} -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 -f y.tab.c gram.c

clean:
	rm -f *.o *res.h y.tab.h $(name) debug core gram.c 

shar: ${SRC1} ${SRC2} ${DOCS}
	shar -v -c ${DOCS} ${SRC2} > sc.shar.1
	shar -v -c ${SRC1} > sc.shar.2

lint: sc.h sc.c lex.c gram.c interp.c cmds.c
	lint ${CFLAGS} ${SIMPLE } sc.c lex.c gram.c interp.c cmds.c ${LIB}

$(name).1:	sc.doc
	sed -e s/pname/$(name)/g sc.doc >  $(name).1

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

${LIBDIR}/sc:
	-mkdir ${LIBDIR} ${LIBDIR}/sc
install: $(name) $(name).1 tax-form expense-acct ${LIBDIR}/sc
	rm -f ${BINDIR}/${name}; cp ${name} ${BINDIR}
	-mkdir ${INSDIR}/man
	rm -f ${INSDIR}/man/${name}.1; cp ${name}.1 ${INSDIR}/man
	rm -f ${LIBDIR}/sc/tax-form ${LIBDIR}/sc/expense-acct
	cp tax-form expense-acct ${LIBDIR}/sc

inst-man: $(MANDIR)/$(name).1

$(EXDIR)/$(name): $(name)
	mv -f $(EXDIR)/$(name) $(EXDIR)/$(name).old
	strip $(name)
	cp $(name) $(EXDIR)

$(MANDIR)/$(name).1: $(name).1
	cp $(name).1 $(MANDIR)
lex.o sc.o: scdisp.h
scdisp.h: scdisp.cps ${CPS}
	${CPS} scdisp.cps

${CPS}: FRC
	-cd ${LIBNEWS}; make -k OPT='${OPT}' COPTS='${COPTS}' OSI='${OSI}' \
		VER='${VER}' TARGET_ARCH='${TARGET_ARCH}' TERMLIB='${TERMLIB}' \
		DESTDIR='${DESTDIR}' INSDIR='${INSDIR}' \
		SYSV_NETWORK='${SYSV_NETWORK}' SYSV_NETLIB='${SYSV_NETLIB}' cps

${LIBCPS}: FRC
	-cd ${LIBNEWS}; make -k OPT='${OPT}' COPTS='${COPTS}' OSI='${OSI}' \
		VER='${VER}' TARGET_ARCH='${TARGET_ARCH}' TERMLIB='${TERMLIB}' \
		DESTDIR='${DESTDIR}' INSDIR='${INSDIR}' \
		SYSV_NETWORK='${SYSV_NETWORK}' SYSV_NETLIB='${SYSV_NETLIB}' \
		libcps.a 

FRC:
