#############################################################################
# Makefile $Revision: 6.21 $
#
# -> Read this Makefile, keeping an eye out for anything that appears to
#    have a bearing on your situation.
#
# -> Customize these variables, to match the situation at your site:
#    EXDIR (path), MANDIR, MANEXT, LIBDIR, 
#
# -> 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.
#
# -> "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 )
#
# -> If you have the command 'file' that uses /etc/magic you can
#    add this line to /etc/magic:
#	38	string		Spreadsheet	sc/ss file
#
#############################################################################

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

# The name of the program.
# All documentation and installation keys on this value.
#   (Actually this is not commonly changed, but it must be defined 
#    before LIBDIR, below.)
  name		= ss
  NAME		= SS

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

# This is where the man page goes, also what the extention and permissions are.
  MANDIR	= /usr/local/man/man1
  MANEXT	= 1
  MANMODE	= 644

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

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

# flags for lint
  LINTFLAGS	=-abchxv

# 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 -d
  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

#	COMPILATION FLAGS
#---------------------------------------------------------------------------
# General compilations definitions are here.  Any necessary 'over-riding'
# of the general case is in the next section: "SYSTEM DEFINES"

  CC		= gcc 			# Default compiler
  LIB		= -lm -lcurses 		# Default needed libraries
  CFLAGS	= -O 			# Default cc flags
  LDFLAGS	= 			# Default ld flags

  # *** SPECIAL NOTES ***
  # HP-UX 7.0: Do NOT use -O
  #	(known broken, try sc's boolean operators if you wish)

#	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
#LIB		=-lm -lPW -lcurses

# BSD 4.2
#- - - - - - - - - - - - - - - - - - - -
#CFLAGS		= -O -DBSD42
#LIB		=-lm -lcurses -ltermcap

# BSD 4.3	(also: HP/Apollo, running SR10.3.5)
#- - - - - - - - - - - - - - - - - - - -
#CFLAGS		= -O -DBSD43
#LIB		=-lm -lcurses -ltermcap

# BSDI		(Mike Durian, durian@advtech.uswest.com, Feb/94)
#- - - - - - - - - - - - - - - - - - - -
# CFLAGS          = -O -DBSD43
# LIB             =-lm -lcurses -ltermcap -lcompat
                 # The compat library is for regular expression stuff.

# Convex OS: Convex CC Version V5.0	(D. Quah, dquah@lse.ac.uk, Jul/93)
#- - - - - - - - - - - - - - - - - - - -
#LIB  = -lm -lcurses -ltermcap -lc_p
#CFLAGS       = -ext -O3
#CCOPTIONS    = $(CFLAGS)

# LINUX	i		(Brooks David Smith <brooks@csd4.csd.uwm.edu>)
#- - - - - - - - - - - - - - - - -- - - 
# LIB 		= -lm -lncurses # Must be using ncurses 1.8.1 or later
# CFLAGS 	= -O6 -DSYSV3
# YACC 		= bison -y

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

# Mips 		(RiscOS 5.0)
#- - - - - - - - - - - - - - - - - - - -
# On Mips use: "/usr/bsd43/bin/make"  (?? is this necessary??)
# - Also, gnu sed dies, use /bin/sed
# CC            = /svr3/bin/cc
# CFLAGS        = -DSYSV3 -O -I/usr/include -I/usr/include/posix
# LDFLAGS       = -s
# 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

# MS-DOS, djgpp, dmake			(D. Quah, dquah@lse.ac.uk, Jul/93)
#- - - - - - - - - - - - - - - - - - - -
#INCFLAGS 	= -If:/include -If:/contrib/curses/inc
#CFLAGS 	= -O2 $(INCFLAGS)
#LDFLAGS 	= -Lf:/lib -Lf:/contrib/curses/lib -lc -lcurses
#LIB  		= -lm -lcurses -lpc -lc
#YACC 		= bison -y

# NeXT					(D. Quah, dquah@lse.ac.uk, Jul/93)
#- - - - - - - - - - - - - - - - - - - -
#YFLAGS 	=-d
#LIB 		= -lm -lcurses -ltermcap -lsys_s
#CFLAGS 	= -O -finline-functions -fomit-frame-pointer

# OSF/1 DEC alpha (preliminary - v1.3)   	(Brooks David Smith, Dec/93,
#- - - - - - - - - - - - - - - - - - - - 	brooks@alpha1.csd.uwm.edu)
#  The curses with OSF1 isn't quite compatible with SYSV curses
#  but is much more capable than BSD curses.  Like SYSV curses
#  it uses a terminfo data base instead of termcap. (?)
#
#CC            = cc
#CFLAGS        = -O2 -DOSF1

# 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
#CFLAGS		= -O -DSYSV3
#LIB		=-lm -lcurses -ltinfo -lPW
#YACC		=yacc -Sm10000

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

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

# Silicon Graphics
#- - - - - - - - - - - - - - - - - - - -
# CFLAGS	= -O -DSYSV3

# Sun Systems
#- - - - - - - - - - - - - - - - - - - -
# This will link with the System V curses which is preferable.

### Using System V cc
# CC		= /usr/5bin/cc
# CFLAGS	= -O -DSYSV3 

### Using gcc 2.*
  CFLAGS	= -O -DSYSV3  -I/usr/5include
##CFLAGS	= -g -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
# CFLAGS        = -O -DULTRIX
# LIB           = -lm -lcursesX

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

# system V.3 (eg: Interactive SysVr3 Release 2.2.1.)
#- - - - - - - - - - - - - - - - - - - -
##CFLAGS	= -DSYSV3 -O
##LDFLAGS	= -s
##LIB		= -lm -lcurses -lPW

# with gcc also use:
#CFLAGS		= -DSYSV3 -O -pipe -traditional
# 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:
#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 disprng.c getinput.c \
    	menu.c m_file.c m_edit.c m_cell.c m_rowcol.c \
    	m_name.c m_misc.c m_macro.c m_view.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 \
        disprng.o getinput.o \
	menu.o m_file.o m_edit.o m_cell.o m_rowcol.o \
	m_name.o m_misc.o m_macro.o m_view.o help.o

#   	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};

  # Alternative link for __GO32__ djgpp	(D. Quah, dquah@lse.ac.uk, Jul/93)
  # $(name):     $(PAR)  $(OBJS)
  # 	$(CC) @${mktmp ${LDFLAGS} ${OBJS} ${LIB} -o $(name)\n}
  # 	@aout2exe $(name)
  # 	@rm -f $(name)

# 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);

  # Alternative link for __GO32__ djgpp	(D. Quah, dquah@lse.ac.uk, Jul/93)
  # Link for __GO32__ djgpp
  # p$(name):    pss.o pvmtbl.o pxmalloc.o
  #	$(CC) $(CFLAGS) @${mktmp ${LDFLAGS} -o p$(name) pss.o pvmtbl.o \
  # pxmalloc.o ${PSCLIB} \n}
  #	@aout2exe p$(name)
  #	@rm -f p$(name)

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

# 1) Convert ``ss.man'' to ``ss.l''
#    - replace all occurances of ``pname'' with ``$NAME'' (see NAME above)
#    - insert the proper revision number

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

# 2) Do the same for ``pss.man''

pman:	pss.man
	name=$(name) NAME=$(NAME) LIBDIR=$(LIBDIR) sh torev pss.man > p$(name).$(MANEXT)
 
#  	Make Install
#---------------------------------------------------------------------------
# DISCLAIMER:  I usually install by hand.  This installation process simply
#	       overwrites what is currently there, makes NO safety backups.

install: $(name) p$(name) man pman $(name).$(MANEXT) p$(name).$(MANEXT)
	cp $(name) $(EXDIR)
	strip $(EXDIR)/$(name)
	cp p$(name) $(EXDIR)
	strip $(EXDIR)/p$(name)
	cp $(name).$(MANEXT) $(MANDIR)
	chmod $(MANMODE) $(MANDIR)/$(name).$(MANEXT)
	cp p$(name).$(MANEXT) $(MANDIR)
	chmod $(MANMODE) $(MANDIR)/p$(name).$(MANEXT)

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

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

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

$(YTAB).h:	gram.y ss.h curs_sup.h

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

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

format.o: format.c

interp.o:	interp.c ss.h
	$(CC) ${CFLAGS} ${IEEE_MATH} ${RINT} ${RE_COMP} ${REGCMP} ${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} -c lex.c

range.o: range.c ss.h

ss.o:	ss.h ss.c menu.h disprng.h ctrl.h
	$(CC) ${CFLAGS} -c ss.c

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

menu.o:	ss.h menu.c ctrl.h m_file.h m_edit.h m_cell.h\
    m_rowcol.h m_name.h m_misc.h m_macro.h m_view.h
	$(CC) ${CFLAGS} -c menu.c

m_file.o:	ss.h m_file.c getinput.h disprng.h
	$(CC) ${CFLAGS} -c m_file.c

m_edit.o:	ss.h m_edit.c getinput.h disprng.h
	$(CC) ${CFLAGS} -c m_edit.c

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

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

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

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

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

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

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

ctrl.o:	ss.h ctrl.c ctrl.h menu.h disprng.h m_cell.h m_misc.h
	$(CC) ${CFLAGS} -c ctrl.c

screen.o:	ss.h screen.c
	$(CC) ${CFLAGS} -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) \
	$(name).$(MANEXT) p$(name) p$(name).$(MANEXT) y.output \
	pxmalloc.c pvmtbl.c qhelp.c y_tab.h

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

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