#  $Id$
#
#  hypercad graphics program makefile
#
#  Before running this makefile, make sure the macros below are set the
#  the appropriate pathnames.
#
###############################################################

# PWD = complete pathname of the directory containing this Makefile.
# If you are using csh, this should be be set automatically by the
# shell, and you may leave this line commented out.  Otherwise, remove
# the comment char and fill in the complete pathname of this dir.
# PWD = 

# GDB = pathname of gdb lib file 'libgdb.a':
GDB = ../gdb/libgdb.a

# FSA = pathname of fsa obj file 'fsa.l':
FSA = ../fsa/fsa.o

# STRTOKQ = pathname of strtokq obj file 'strtokq.o':
STRTOKQ = ../strtokq/strtokq.o

# GDB_HEADER = pathname of gdb header file 'gdb.h'
GDB_HEADER = ../gdb/gdb.h

# OPTIONS = compiler options
OPTIONS = -g -pipe

# BINDIR = dir in which to install final executable files.  This
# is used by 'make install'.  To prevent installation of executables,
# comment out the def of BINDIR.
BINDIR = $(HOME)/bin

# HELPDIR = dir in which to install help file.  The help file is
# needed at run-time.  To have the program compiled so that it uses
# the copy of the help file in the source code, set
# HELPDIR=$(PWD)/sunview.  You may change HELPDIR to any existing
# directory name, but DO NOT COMMENT OUT THE DEF OF HELPDIR.  If you
# do, the program will not be able to find the help file.
HELPDIR=$(PWD)/sunview

# Command to use for printing PostScript files.  If you can't
# print PostScript files, comment out this def.
SPOOL_COMMAND=lpr

# Copying command for use in installation. Should be 'ln' or 'cp'.
CP=ln

###############################################################

SHELL = /bin/sh

INSTALL_BIN = instl

INSTALL = $(INSTALL_BIN) -cp '$(CP)'

MKDEP_BIN = mkdep

MKDEP = $(MKDEP_BIN)

MAKEFILE = Makefile

CFLAGS = $(OPTIONS)

COMPILE = cc -c $(CFLAGS) -DGDB_HEADER='"$(GDB_HEADER)"'

LINK = cc $(CFLAGS)

GRAPHICSLIBS = -lsuntool -lsunwindow -lpixrect

LIBS = $(GRAPHICSLIBS) -lm

HGRAPHICS_SRCS= hgraphics.c hgdb.c hconvert.c hutil.c \
	      hviewpt.c hcommand.c hdraw.c postscript.c

WINDOW_SRCS=   sunview/window.c sunview/graphics.c sunview/util.c \
	sunview/zoom.c sunview/recenter.c \
	sunview/help.c sunview/print.c sunview/reset.c

WIN.O = sunview/win.o

OBJS= hgraphics.o hgdb.o hconvert.o hutil.o hviewpt.o \
	hcommand.o hdraw.o postscript.o

SRCS= hgraphics.c hgdb.c hconvert.c hutil.c hviewpt.c \
	hcommand.c hdraw.c postscript.c

SUNVIEW_MAKE_OPTIONS = \
  OPTIONS="$(OPTIONS)" \
  SHELL="$(SHELL)"  \
  HELPDIR="$(HELPDIR)"  \
  SPOOL_COMMAND="$(SPOOL_COMMAND)"  \
  CP="$(CP)"  \
  INSTALL_BIN="$(INSTALL_BIN)"  \
  PWD="$(PWD)/sunview"

###############################################################

all:	hgraphics

hgraphics:	$(OBJS) $(WIN.O)
	$(LINK) -o hgraphics $(OBJS)	\
	  $(WIN.O)				\
	  $(GDB)				\
	  $(FSA)				\
	  $(STRTOKQ)				\
	  $(LIBS)

hgraphics.o:
	$(COMPILE) -c hgraphics.c

hgdb.o:
	$(COMPILE) -c hgdb.c

hconvert.o:
	$(COMPILE) -c hconvert.c

hutil.o:
	$(COMPILE) -c hutil.c

hviewpt.o:
	$(COMPILE) -c hviewpt.c

hcommand.o:
	$(COMPILE) -c hcommand.c

hdraw.o:
	$(COMPILE) -c hdraw.c

postscript.o:
	$(COMPILE) -c postscript.c

# The sed script below creates psheader.h from header.ps by
#	1. substituting \\ for \ throughout
#	2. substituting \" for " throughtout
#	3. Prepending " to the first line
#	4. Appending \n\ to every line
#	5. Appending n" to the last line (which by now ends
#	   in \n\ due to step 4)
psheader.h:	header.ps
	/bin/rm -f psheader.h ;
	sed \
		-e 's/\\/\\\\/g'		\
		-e 's/"/\\"/g'			\
		-e '1s/^\(.*\)$$/"\1/' 		\
		-e 's/^\(.*\)$$/\1\\n\\/'	\
		-e '$$s/^\(.*\)/\1n"/'		\
		< header.ps > psheader.h

$(WIN.O):	window

window:
	cd sunview ; 				\
	$(MAKE)					\
	     $(SUNVIEW_MAKE_OPTIONS)		\
	     win.o

lint: 
	lint $(HGRAPHICS_SRCS) $(WINDOW_SRCS)

clean:
	/bin/rm -f *.o *~ ;
	cd sunview ; $(MAKE) clean

veryclean:
	/bin/rm -f *.o *~ hgraphics psheader.h *.o ;
	cd sunview ; $(MAKE) veryclean

distclean:	veryclean

install:	install_bin install_sunview

install_sunview:
	cd sunview; 				\
	$(MAKE)					\
	     $(SUNVIEW_MAKE_OPTIONS)		\
	     install

install_bin:	hgraphics
	strip hgraphics
	$(INSTALL) '$(BINDIR)' hgraphics

depend:
	mkdep $(MAKEFILE) $(HGRAPHICS_SRCS)

########################################################################

# Do not change or alter the '# BEGIN DEPENDENCY LIST' line below;
# 'make depend' uses it.  Anything you put after this line will go
# away when you do 'make depend'.


# BEGIN DEPENDENCY LIST

hgraphics.c:
hgraphics.o: hgraphics.c
hgraphics.o: ./hcore.h
hgraphics.o: ./hglobals.h
hgraphics.o: ./sunview/window.h
hgdb.c:
hgdb.o: hgdb.c
hgdb.o: ./hcore.h
hgdb.o: ./hglobals.h
hconvert.c:
hconvert.o: hconvert.c
hconvert.o: ./hcore.h
hutil.c:
hutil.o: hutil.c
hutil.o: ./hcore.h
hviewpt.c:
hviewpt.o: hviewpt.c
hviewpt.o: ./hcore.h
hviewpt.o: ./hglobals.h
hviewpt.o: ./sunview/window.h
hcommand.c:
hcommand.o: hcommand.c
hcommand.o: ./hcore.h
hcommand.o: ./hglobals.h
hdraw.c:
hdraw.o: hdraw.c
hdraw.o: ./hcore.h
hdraw.o: ./hglobals.h
hdraw.o: ./drawprocs.c
postscript.c:
postscript.o: postscript.c
postscript.o: ./hcore.h
postscript.o: ./hglobals.h
postscript.o: ./psheader.h
postscript.o: ./drawprocs.c
