#############################################################################
# Makefile $Revision: 1.2 $
#
# How to build the 'ss' package:
# 1) Read this Makefile, keeping an eye out for anything that appears to
#    have a bearing on your situation.
#
# 2) Customize these variables, to match the situation at your site:
#    EXDIR (path), MANDIR, MANEXT, LIBDIR, SIGVOID, RE_COMP/REGCMP, 
#    DFLT_PAGER, and FMOD. 
#
#    There are lost of other variables, but most shouldn't need to be
#    changed.  (If you followed #1, you probably already know that, and
#    have probably already changed any you think should be changed.)
#
# 3) Underneath the heading "SYSTEM DEFINES", below, there are sections
#    of code for many different machine/compiler/OS setups.  Select
#    the section that corresponds to your site, and:
#      (a) Uncomment it.
#      (b) Customize it, if needed.
#      (c) Ensure that all other System Defines are commented out.
#
# 4) "make"
#    This will build everything, but will not install it.  If you want
#    you can install the pieces yourself, or issue the "make install"
#    command.  ( "make man" will build the ss man page )
#
# 5) If you have the command 'file' that uses /etc/magic you can
#    add the line to /etc/magic:
#	38	string		Spreadsheet	sc/ss file
#############################################################################

#
#       Commonly Changed Variables.  Modify as necessary for your site
#---------------------------------------------------------------------------

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

# This is where the man page goes.
# MANDIR	= /usr/local/src/man/man1	# reno
# MANEXT	= 1				# reno
  MANDIR	= /usr/man/manl
  MANEXT	= l
  MANMODE	= 644

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

# Set SIGVOID if signal routines are type void.
# use: SIGVOID=-DSIGVOID for:
#	System 5.3, SunOS 4.X, VMS, BSD4.4 (reno), and ANSI C Compliant systems
# use: SIGVOID=		 for:
#  BSD systems (excluding reno, BSD4.4), and the UNIXPC 'cc'
  SIGVOID	=-DSIGVOID
# SIGVOID	=

# Set RE_COMP if you have the re_comp/re_exec regular expression routines
# (most BSD based systems do).
#  RE_COMP	=-DRE_COMP
RE_COMP	=

# Set REGCMP if you have the regcmp/regex regular expression routines
# (most System V based systems do)
##REGCMP	=-DREGCMP
  REGCMP	=

# Set if you have regex(3) (e.g., 4.4BSD)
#REGEX =
REGEX 		=-DREGEX

# 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\"	# generic && reno

# If you get errors about fmod being undefined when you try to
# compile, then define NO_FMOD (most likely BSD4.3 and Mt Xinu).
# FMOD		=-DNO_FMOD
  FMOD		=

#
#       Variables which are NOT commonly changed.  
#---------------------------------------------------------------------------

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

# Set NOUNGETCH for lex.c if you don't have ungetch() in your
# curses library.
NOUNGETCH = -DNOUNGETCH
#  NOUNGETCH = 

# 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. Also try IDLOKBAD below.
  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 IEEE_MATH if you need setsticky() calls in your signal handlers
# IEEE_MATH	=-DIEEE_MATH
  IEEE_MATH	=

# Set RINT=-DRINT if you do not have rint() in math.h
# Set RINT=	on/with (they have rint):
#	SunOS 4.0.3c, 4.1.1 compiler
#	BSD4.4 (reno)
RINT	=
# RINT	=-DRINT

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

# Path to crypt, do NOT define if you don't have crypt.
# most systems:
##CRYPT		=-DCRYPT_PATH=\"/bin/crypt\"
# BSD:
# CRYPT		=-DCRYPT_PATH=\"/usr/bin/crypt\"
# other people?:
# CRYPT		=-DCRYPT_PATH=\"/usr/local/bin/crypt\"
# For 4.4BSD
BDES		=-DCRYPT_PATH=\"/usr/bin/bdes\"

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

# flags for lint
  LINTFLAGS	=-abchxv

## # Format of quick reference guide generated by $(name)qref
## # Leave undefined for normal text output.
## # QREF_FMT=
##   QREF_FMT=-DTROFF


# *** SPECIAL NOTES ***
# HP-UX 7.0: Do NOT use -O
#	(known broken, try sc's boolean operators if you wish)
#
# **** SYSV curses bugs... ****
# Try setting IDLOKBAD to fix (with an empty spreadsheet):
#	a) Redrawing the bottom half of the screen when you
#	 	move between row 9 <-> 10
#	b) the highlighted row labels being trash when you
#		move between row 9 <-> 10
#	c) On an xterm on Esix Rev. D+ from eating lines
#		 -goto (or move) a few lines (or more) past the bottom
#		 of the screen, goto (or move) to the top line on the
#		 screen, move upward and the current line is deleted, the
#		 others move up even when they should not, check by
#		 noticing the rows become 2, 3, 40, 41, 42... (etc).
#	Known systems/terminfos w/ curses problems:
#	{Esix Rev. D+, AT&T SysV3.2.1}:at386-m,xterm, HP-UX7.0:(not sure)
#  IDLOKISBAD	=-DIDLOKBAD
IDLOKISBAD	=

# If you don't have idlok() in your curses define NOIDLOK
#  NO_IDLOK=
NO_IDLOK=-DNOIDLOK

# If moving right off the screen causes the screen to not redraw
# properly, define RIGHT_CBUG to get around a curses problem on some
# boxes, this forces screen redraws when going right off the screen
  RIGHTBUG	=
# RIGHTBUG	=-DRIGHT_CBUG

# IF you have problems w/ your yacc try bison, Berkeley yacc, or
# some other yacc. Some systems don't allow you to
# increase the number of terminals (mostly AT&T), SCO's does though.
# NOTE: Do not use with bison 1.16! Get a new version...
YACC		=yacc
#  YACC		=bison -y

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

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

#	SYSTEM DEFINES
#---------------------------------------------------------------------------
# Locate your System in the following ALPHABETICAL list of systems, and
# uncomment the defintions relating to it.  See the comments accompanying
# each system for further information.  
#
# **> Make sure that all other systems are commented out! <**

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

# BSD 4.2
#- - - - - - - - - - - - - - - - - - - -
#CFLAGS		= -O -DBSD42
#LDFLAGS	=
#LIB		=-lm -lcurses -ltermcap
# with gcc also use:
#CC		=gcc

# BSD 4.3
#- - - - - - - - - - - - - - - - - - - -
CFLAGS		= -O -DBSD43 -I.
LDFLAGS	=
LIB		=-lgnuregex -lm -lcurses -ltermcap
CC=	gcc

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

# Mips (preliminary, based on System V.3 entry)
#- - - - - - - - - - - - - - - - - - - -
# On Mips use: "/usr/bsd43/bin/make"
# CC            = gcc
# CFLAGS        = -DSYSV3 -O -I/usr/include -I/usr/include/posix
# LDFLAGS       = -s
# YACC          = bison -y
# LIB           = -lm -lcurses -lPW

# MS-DOS, Microsoft C 5.1 and NDMAKE
#- - - - - - - - - - - - - - - - - - - -
#CC		=cl
#CFLAGS		= -AL -O -Fo$*.o
#LDFLAGS	=/noi /st:0x4000
#LIB		=lcurses
#YACC		=bison -y
#
#.SUFFIXES : .o .c
#.c.o:
#	$(CC) $(CFLAGS) -c $*.c

# 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
#CC		=cc
#CC		=gcc -fstrength-reduce
#SIGVOID	=-DSIGVOID
#CFLAGS		= -O -DSYSV3
#LDFLAGS	=
#LIB		=-lm -lcurses -ltinfo -lPW
#YACC		=yacc -Sm10000

# SCO Unix 3.2.2 and ODT 1.1
#- - - - - - - - - - - - - - - - - - - -
#CC		=cc
#CFLAGS		= -O -DSYSV3
#LDFLAGS	=
#LIB		=-lm -lcurses -lPW -lmalloc -lc_s
#YACC		=yacc -Sm10000

# Sequent boxes
#- - - - - - - - - - - - - - - - - - - -
#CC		=atscc
#CFLAGS		=-O -DBSD42
#LDFLAGS	= 
#LIB		=-lm -lcurses  -ltermcap
#PSCLIB		=-lseq
# with gcc also use:
#CC		=gcc
#CFLAGS		= -O -DBSD42 -pipe

# Sun Systems
#- - - - - - - - - - - - - - - - - - - -
# Use this for SunOS 4.X if you have the System V package installed.
# This will link with the System V curses which is preferable to the
# BSD curses (especially helps scrolling on slow (9600bps or less)
# serial lines).
#
# Be sure to define SIGVOID and RE_COMP above.
# 
# CC		= /usr/5bin/cc
# CFLAGS	= -O -DSYSV3 
# LDFLAGS	=
#  LIB		= -lm -lcurses 

### Try gcc 2.0
#  CC		= /usr/gnu/bin/gcc
#  CFLAGS	= -O -DSYSV3  -I/usr/5include
#  LDFLAGS	= -L/usr/5lib

# Ultrix Systems (preliminary - Ultrix V4.2a, Rev. 47)
#- - - - - - - - - - - - - - - - - - - -
# The following comments came with `sc'.
#       # For ULTRIX: define the BSD4.2 section and SIGVOID above
#       #   tdw@cl.cam.ac.uk tested on Ultrix 3.1C-0
# I'm not _quite_ listening to them.  Specifically: I use gcc and am
# using the System V curses -- cursesX -- in Ultrix.  Art Mulder
# CC            = /usr/gnu/bin/gcc
# CFLAGS        = -O -DULTRIX
# LIB           = -lm -lcursesX
# LDFLAGS       =

# system V.2 (includes: HP-UX 7.05, UNIXPC)
#- - - - - - - - - - - - - - - - - - - -
#CFLAGS		= -O -DSYSV2 
#LDFLAGS	=
#LIB		=-lm -lPW -lcurses
# with gcc on a Sequent also use:
#CC		=att gcc
#CFLAGS		=  -DSYSV2 -g -pipe -traditional

# system V.3
#- - - - - - - - - - - - - - - - - - - -
##CFLAGS	=  -DSYSV3 -O
##LDFLAGS	= -s
##CFLAGS	=  -DSYSV3 -g
##LDFLAGS	= -g
##LIB		=-lm -lcurses -lPW

# with gcc also use:
#CC		=gcc
#CFLAGS		= -DSYSV3 -O -pipe -traditional
#YACC		=bison -y
# debugging bison (bison 1.16 is broken)
#CFLAGS=  -DSYSV3 -g -pipe -traditional
#YACC=bison -y -v -t -l


# system V.4
#- - - - - - - - - - - - - - - - - - - -
#CFLAGS		=  -DSYSV4 -DSYSV3 -O
#LDFLAGS	= -s
#LIB		=-lm -lcurses -lgen
# with gcc also use:
#CC		=gcc
#CFLAGS		=  -DSYSV3 -O -pipe

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

# XENIX Version 2.3
#- - - - - - - - - - - - - - - - - - - -
#CFLAGS		= -O -DSYSIII -DXENIX2_3
#LDFLAGS	= -i
#LIB		=-lm -lcurses -ltermcap

# XENIX system III 
#- - - - - - - - - - - - - - - - - - - -
#CFLAGS		= -O -DSYSIII
#LDFLAGS	= -i
#LIB		=-lm -lcurses -ltermcap

#
#       Some Definitions used in compiling/installing
#---------------------------------------------------------------------------

# All of the source files
SRC=Makefile cmds.c crypt.c eres.sed format.c gram.y interp.c \
	lex.c pss.c range.c ss.c ss.h screen.c sres.sed version.c \
	vmtbl.c xmalloc.c ctrl.c disprange.c getinput.c \
    	menu.c menu_file.c menu_edit.c menu_cell.c menu_rowcol.c \
    	menu_name.c menu_misc.c menu_macro.c help.c

# The objects
OBJS=cmds.o crypt.o format.o gram.o interp.o lex.o range.o ss.o \
	screen.o version.o vmtbl.o xmalloc.o ctrl.o \
        disprange.o getinput.o \
	menu.o menu_file.o menu_edit.o menu_cell.o menu_rowcol.o \
	menu_name.o menu_misc.o menu_macro.o help.o

# The documents in the Archive
DOCS=README ss.man pss.doc VMS_NOTES torev build.com


#   	MAIN MAKE TARGETS
#---------------------------------------------------------------------------

# Default Make Target:  Make ``ss'' and ``pss''.
# Nothing is installed.
#- - - - - - - - - - - - - - - - - - - -

all:	$(name) p$(name) 


# Make ``ss''
#- - - - - - - - - - - - - - - - - - - -

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

# Alternative link for MS-DOS
# $(name): 	$(OBJS)
#	link ${LDFLAGS} ${OBJS},$(name),,${LIB};


# Make ``pss''
#- - - - - - - - - - - - - - - - - - - -

p$(name):	pss.c pvmtbl.o pxmalloc.o
	$(CC) $(CFLAGS) ${LDFLAGS} -o p$(name) pss.c pvmtbl.o pxmalloc.o ${PSCLIB}

# Alternative link for MS-DOS (NB: MSC 5.1 has no getopt.c)
# p$(name):    pss.o pvmtbl.o pxmalloc.o getopt.o
#     link ${LDFLAGS} pss.o pvmtbl.o pxmalloc.o getopt.o,p$(name);

# Documentation
#- - - - - - - - - - - - - - - - - - - -

# 1) convert ``ss.man'' to ``ss.l''
#	- replace all occurances of ``pname'' with ``ss'' (or whatever
#	  the NAME is above)
#	- insert the proper revision number

man:	ss.man
	name=$(name) NAME=$(NAME) LIBDIR=$(LIBDIR) sh torev ss.man > $(name).$(MANEXT)

# - Do the same for ``pss.doc''
pman:	pss.doc
	name=$(name) NAME=$(NAME) LIBDIR=$(LIBDIR) sh torev pss.doc > p$(name).$(MANEXT)

#  	Make Install
#---------------------------------------------------------------------------

install: $(EXDIR)/$(name) $(EXDIR)/p$(name) \
	 $(MANDIR)/$(name).$(MANEXT) $(MANDIR)/p$(name).$(MANEXT)

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

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

$(MANDIR)/$(name).$(MANEXT): man
	cp $(name).$(MANEXT) $(MANDIR)/$(name).$(MANEXT)
	chmod $(MANMODE) $(MANDIR)/$(name).$(MANEXT)

$(MANDIR)/p$(name).$(MANEXT): pman
	cp p$(name).$(MANEXT) $(MANDIR)/p$(name).$(MANEXT)
	chmod $(MANMODE) $(MANDIR)/p$(name).$(MANEXT)


# 	SUPPLEMENTARY MAKE TARGETS
#---------------------------------------------------------------------------
# (These are usually not made directly themselves)


# ``ss'' supplementary objects
#- - - - - - - - - - - - - - - - - - - -

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

$(YTAB).h:	gram.y

cmds.o: cmds.c ss.h
	$(CC) ${CFLAGS} ${DOBACKUPS} ${CRYPT} ${BDES} -c cmds.c

crypt.o: crypt.c ss.h
	$(CC) ${CFLAGS} ${CRYPT} ${BDES} ${DOBACKUPS} -c crypt.c

format.o: format.c

interp.o:	interp.c ss.h
	$(CC) ${CFLAGS} ${IEEE_MATH} ${SIGVOID} ${RINT} ${RE_COMP} ${REGCMP} ${REGEX} ${FMOD} -c interp.c

gram.o:	ss.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:	ss.h $(YTAB).h gram.o lex.c
	$(CC) ${CFLAGS} ${NOUNGETCH} ${SIMPLE} ${IEEE_MATH} ${SIGVOID} ${NONOTIMEOUT} -c lex.c

range.o: range.c ss.h

ss.o:	ss.h ss.c menu.h disprange.h ctrl.h
	$(CC) ${CFLAGS} ${DFLT_PAGER} $(RIGHTBUG) ${SIGVOID} ${SAVE} -c ss.c

disprange.o:	ss.h disprange.c ctrl.h
	$(CC) ${CFLAGS} ${DFLT_PAGER} ${SIGVOID} ${SAVE} -c disprange.c

menu.o:	ss.h menu.c ctrl.h menu_file.h menu_edit.h menu_cell.h\
    menu_rowcol.h menu_name.h menu_misc.h menu_macro.h
	$(CC) ${CFLAGS} ${DFLT_PAGER} ${SIGVOID} ${SAVE} -c menu.c

menu_file.o:	ss.h menu_file.c getinput.h disprange.h
	$(CC) ${CFLAGS} ${DFLT_PAGER} ${SIGVOID} ${SAVE} -c menu_file.c

menu_edit.o:	ss.h menu_edit.c getinput.h disprange.h
	$(CC) ${CFLAGS} ${DFLT_PAGER} ${SIGVOID} ${SAVE} -c menu_edit.c

menu_cell.o:	ss.h menu_cell.c getinput.h 
	$(CC) ${CFLAGS} ${DFLT_PAGER} ${SIGVOID} ${SAVE} -c menu_cell.c

menu_rowcol.o:	ss.h menu_rowcol.c getinput.h 
	$(CC) ${CFLAGS} ${DFLT_PAGER} ${SIGVOID} ${SAVE} -c menu_rowcol.c

menu_misc.o:	ss.h menu_misc.c getinput.h 
	$(CC) ${CFLAGS} ${DFLT_PAGER} ${SIGVOID} ${SAVE} -c menu_misc.c

menu_macro.o:	ss.h menu_macro.c getinput.h 
	$(CC) ${CFLAGS} ${DFLT_PAGER} ${SIGVOID} ${SAVE} -c menu_macro.c

menu_name.o:	ss.h menu_name.c getinput.h 
	$(CC) ${CFLAGS} ${DFLT_PAGER} ${SIGVOID} ${SAVE} -c menu_name.c

getinput.o:	ss.h getinput.h
	$(CC) ${CFLAGS} ${DFLT_PAGER} ${SIGVOID} ${SAVE} -c getinput.c

ctrl.o:	ss.h ctrl.c ctrl.h menu.h disprange.h menu_cell.h menu_misc.h
	$(CC) ${CFLAGS} ${DFLT_PAGER} ${SIGVOID} ${SAVE} -c ctrl.c

screen.o:	ss.h screen.c
	$(CC) ${CFLAGS} ${BROKENCURSES} ${IDLOKISBAD} ${INTERNATIONAL} ${RIGHTBUG} ${SIGVOID} -c screen.c

help.o: ss.h help.c
	$(CC) ${CFLAGS} -c help.c


# ``pss'' supplementary objects
#- - - - - - - - - - - - - - - - - - - -

pvmtbl.c: vmtbl.c
	-rm -f pvmtbl.c
	${LN} vmtbl.c pvmtbl.c

pvmtbl.o: ss.h pvmtbl.c
	$(CC) ${CFLAGS} -c -DPSC pvmtbl.c

pxmalloc.c: xmalloc.c
	-rm -f pxmalloc.c
	${LN} xmalloc.c pxmalloc.c

pxmalloc.o: ss.h pxmalloc.c
	$(CC) ${CFLAGS} -c -DPSC pxmalloc.c


# 	OTHER MAKE TARGETS
#---------------------------------------------------------------------------

clean:
	rm -f *.o *res.h $(YTAB).h debug core gram.c $(name).$(MANEXT) \
	$(name).$(MANEXT) p$(name).man p$(name).$(MANEXT) y.output \
	pxmalloc.c pvmtbl.c qhelp.c y_tab.h

spotless: clean
	rm -f $(name) p$(name) 

#---------------------------------------------------------------------------
#       end
