name=sc
NAME=SC

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

# Set SIGVOID if signal routines are type void.
SIGVOID=-DSIGVOID

# Set RINT=-DRINT if you do not have rint() in math.h
RINT=-DRINT

# Set REGCMP if you have the regcmp/regex regular expression routines
#REGCMP=-DREGCMP

# This is the name of a pager like "more".
DFLT_PAGER=-DDFLT_PAGER=\"more\"

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

# path to crypt, do not define if you don't have crypt
#CRYPT=-DCRYPT_PATH=\"c:\mks\os2\mksos2\crypt.exe\"

# If your system doesn't have notimeout() in curses define NONOTIMEOUT
NO_NOTIMEOUT=-DNONOTIMEOUT

YACC=yacc

# MS-DOS needs y_tab instead of the normal y.tab
YTAB=ytab

# Command to use to make temporary copies of some source files.
LN=cp

#### SYSTEM DEFINES ####

# Use this for OS/2 2.0, Watcom C/386 9.0 and MKS make, yacc and sed
CFLAGS=-I. -omaxet -zp4 -4r -fpi87
#CFLAGS=-I. -d2
LDFLAGS=$(CFLAGS) -l=os2v2 -\"OPTION STACK=24k\"
#LIB=curses.lib regex.lib c:\\\\watcom\\\\lib386\\\\os2\\\\os2386.lib
#LIB=curses.lib c:\\\\watcom\\\\lib386\\\\os2\\\\os2386.lib
LIB=curses.lib

%.c : %.y
	$(YACC) -d gram.y
	mv $(YTAB).c gram.c

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

# The objects
OBJS=cmds$O crypt$O format$O gram$O help$O interp$O lex$O range$O sc$O \
	screen$O version$O vi$O vmtbl$O xmalloc$O

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

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

$(name)$E: 	$(OBJS)
	$(LD) ${LDFLAGS} ${OBJS} ${LIB} -fe=$(name)$E

$(YTAB).h:	gram.y

p$(name)$E:	psc.c getopt.c pvmtbl$O pxmalloc$O
	$(LD) $(LDFLAGS) -fe=p$(name)$E psc.c getopt.c pvmtbl$O pxmalloc$O

$(name)qref$E:	qhelp.c sc.h
	$(LD) $(LDFLAGS) -DQREF -DSCNAME=\"$(NAME)\" qhelp.c -fe=$(name)qref$E

pvmtbl.c: vmtbl.c
	-rm -f pvmtbl.c
	$(LN) vmtbl.c pvmtbl.c

pvmtbl$O: pvmtbl.c sc.h
	$(CC) ${CFLAGS} -c -DPSC pvmtbl.c

pxmalloc.c: xmalloc.c
	-rm -f pxmalloc.c
	$(LN) xmalloc.c pxmalloc.c

# Objects

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

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

format$O: format.c
	$(CC) ${CFLAGS} -c format.c

help$O: help.c sc.h
	$(CC) ${CFLAGS} ${CRYPT} -c help.c

qhelp.c: help.c
	-cp -f help.c qhelp.c

interp$O:	interp.c sc.h
	$(CC) ${CFLAGS} ${IEEE_MATH} ${SIGVOID} ${RINT} ${RE_COMP} ${REGCMP} ${FMOD} -c interp.c

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

lex$O:	sc.h $(YTAB).h gram$O lex.c
	$(CC) ${CFLAGS} ${SIMPLE} ${IEEE_MATH} ${SIGVOID} ${NO_NOTIMEOUT} -c lex.c

pxmalloc$O: sc.h pxmalloc.c
	$(CC) ${CFLAGS} -c -DPSC pxmalloc.c

range$O: range.c sc.h
	$(CC) ${CFLAGS} -c range.c

sc$O:	sc.h sc.c
	$(CC) ${CFLAGS} ${DFLT_PAGER} ${RIGHTBUG} ${SIGVOID} ${SAVE} -c sc.c

screen$O:	sc.h screen.c
	$(CC) ${CFLAGS} ${BROKENCURSES} ${IDLOKISBAD} ${INTERNATIONAL} ${RIGHTBUG} ${SIGVOID} ${NO_IDLOK} -c screen.c

vi$O: vi.c sc.h
	$(CC) ${CFLAGS} -c vi.c

vmtbl$O: vmtbl.c sc.h
	$(CC) ${CFLAGS} -c vmtbl.c

xmalloc$O: xmalloc.c sc.h
	$(CC) ${CFLAGS} -c xmalloc.c

version$O: xmalloc.c sc.h
	$(CC) ${CFLAGS} -c version.c

# other stuff

clean:
	rm -f *$O *$E *.i *.err *.out
