# $Id: Makefile,v 2.3 89/09/20 17:53:41 mbp Exp $

# Makefile for GR

# Make the changes indicated below, and type 'make' to compile,
# or 'make install' to install (and compile).

# When you are finished installing, type 'make clean' to erase .o and
# temporary files, or 'make veryclean' to erase everything that can be
# regenerated (this essentially returns the GR directory to its
# original state).

##############################################
#        BEGIN CONFIGUATION SECTION	     #
#					     #
# Change the macros below to suit your needs #
##############################################

# The following line must be hard-coded if not using csh.  If you are
# not using csh, remove the comment char from the beginning of this
# line and replace the pathname here with the pathname of the
# directory that GR is in (the one containing this Makefile):
#PWD=/u/yourlogin/src/gr

# Additional compiler options (such as -O, -g, etc):
OPTIONS=-O

# DEFAULT_SPOOL_COMMAND should be the command for sending a PostScript
# file to your printer.  It may consist of a single word, such as
# 'lpr', or of several words separated by whitespace, such as 'lpr
# -Plw2'.  If your system cannot print PostScript files, give the
# empty string (in this case the '=' should be the last thing on this
# line --- no trailing spaces!).
DEFAULT_SPOOL_COMMAND=lpr

# AUXDIR should be the (complete) pathname of the directory where you
# want to install the files that GR programs need at run-time. You
# should probably install these files in some permanent location
# (rather than with the source code), such as /usr/local/lib/gr, so
# that GR programs will not be dependent on the location of the GR
# source code.
#
# When doing 'make install', AUXDIR is created if it does not exist,
# and the auxiliary files are copied into it.  You should be sure that
# you have write permission in AUXDIR, or in its parent if it does not
# yet exist.
#
# The path you give for AUXDIR should be one which is recognized by
# all workstations for which this installation is being done.
#
# To leave the auxiliary files in their current location (with the
# source code), specify AUXDIR=$(PWD).
AUXDIR=$(HOME)/lib/gr

# SAMPLEDIR should be the complete pathname of the directory where you
# want install the example gr program grdemo.c
#
# When doing 'make install', SAMPLEDIR is created if it does not
# exist, and grdemo.c is copied into it.  You should be sure that you
# have write permission in SAMPLEDIR, or in its parent if it does not
# yet exist.
#
# Specify SAMPLEDIR=$(PWD) to keep grdemo.c with the rest of the gr
# source code.
SAMPLEDIR=$(HOME)/lib/gr

# LIBDIR should be the directory in which you want to install the GR
# library files libgr.a and libgr3d.a (used only by 'make install').
# LIBDIR should probably be /usr/local/lib.  LIBDIR must exist and
# must be writeable by you before you do 'make install'.
#
# To prevent 'make install' from trying to install the library files,
# comment out the LIBDIR def.
LIBDIR=$(HOME)/lib/$(CPUTYPE)

# The next line should either be 'LIBFLAG=$(LIBDIR)' or should be
# commented out.  If the directory you specify for LIBDIR above is one
# of the directories normally searched by ld(1) (such as /usr/lib or
# /usr/local/lib), comment this line out.  If LIBDIR is not normally
# searched by ld(1), leave this definition in.
LIBFLAG=-L$(LIBDIR)

# INCLDIR should be the directory in which you want to install the GR
# header file gr.h.  All gr application programs must '#include' this
# file.  Should probably be something like /usr/local/include or
# /usr/local/lib/gr.  INCLDIR must exist and be writeable by you
# before you do 'make install'.
#
# To prevent 'make install' from trying to install gr.h, comment
# out the INCLDIR def.
INCLDIR=$(HOME)/lib/gr

# MANEXT should be the extension which you want to use for the
# manual page.  Should probably be 3.
MANEXT=3

# MANPATH should be the directory in which you want to install the GR
# manual pages (used only by 'make install').  Should probably be
# /usr/local/man.  (Note: the manual pages will be installed in the
# directory $(MANPATH)/man$(MANEXT); for example, if MANEXT=3 and
# MANPATH=/usr/local/man, the manual pages will be installed in the dir
# /usr/local/man/man3.)  $(MANPATH)/man$(MANEXT) must exist and be
# writeable by you before you do 'make install'.
#
MANPATH=$(HOME)/man

# MANDIR should be the complete pathname of the dir where you want
# to install the manual pages.
#
# To prevent 'make install' from trying to install the manual pages,
# comment out the MANDIR def.
MANDIR=$(MANPATH)/man$(MANEXT)

# CP = copy command to use when installing files
CP=ln

##############################################
#         END CONFIGUATION SECTION	     #
#					     #
#     Don't change anything below here       #
##############################################

SHELL=/bin/sh

INSTALL_BIN = instl

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

MAKEFILE = Makefile

HEADER_FILE=$(AUXDIR)/gr_header.ps
TRAILER_FILE=$(AUXDIR)/gr_trailer.ps
HELP_FILE=$(AUXDIR)/gr.help
AUXFILES =	gr_header.ps gr_trailer.ps gr.help
LIBFILES =	libgr.a libgr3d.a
MANPAGES =	grintro.$(MANEXT) gr.$(MANEXT)

CFLAGS = $(OPTIONS)

CFILES =	gr.c window.c help.c confirmer.c print.c postscript.c

OFILES_2D =	gr.o window.o help.o confirmer.o print.o postscript.o

OFILES_3D =	gr_3D.o window_3D.o help.o confirmer.o print.o \
		postscript.o animate.o

IMAGES =	images/clear.image images/mmouse.image \
		images/rmouse.image images/msmouse.image \
		images/rsmouse.image images/esc.image \
		images/perspective.image images/save.image \
		images/horizontal_pan.image images/play.image \
		images/tilt.image images/horizontal_sweep.image \
		images/print.image images/vertical_pan.image \
		images/lmouse.image images/redraw.image \
		images/vertical_sweep.image images/lsmouse.image \
		images/reset.image images/zoom.image images/anim.image

all:		$(LIBFILES) $(MANPAGES) grdemo.c

libgr.a:	$(OFILES_2D)
	ar rc libgr.a $(OFILES_2D)
	ranlib libgr.a

libgr3d.a:	$(OFILES_3D)
	ar rc libgr3d.a $(OFILES_3D)
	ranlib libgr3d.a

gr.o:		gr.c gr.h internal.h
	cc $(CFLAGS)  -c -o gr.o gr.c

gr_3D.o:	gr.c gr.h internal.h
	cc -DTHREE_D $(CFLAGS)  -c -o gr_3D.o gr.c

window.o:	window.c window2.c images.h internal.h
	cc $(CFLAGS)  -c -o window.o window.c

window_3D.o:	window.c window2.c images.h internal.h
	cc -DTHREE_D $(CFLAGS)  -c -o window_3D.o window.c

help.o:		help.c internal.h Makefile
	cc -DDEFAULT_HELP_FILE='"$(HELP_FILE)"' \
	   $(CFLAGS)  -c -o help.o help.c

images.h:	$(IMAGES)
	touch images.h

confirmer.o:	confirmer.c internal.h images/confirmer.image
	cc $(CFLAGS)  -c -o confirmer.o confirmer.c

print.o:	print.c internal.h Makefile
	cc -DDEFAULT_SPOOL_COMMAND='"$(DEFAULT_SPOOL_COMMAND)"' \
	   $(CFLAGS)  -c -o print.o print.c

animate.o:	animate.c $(IMAGES) Makefile
	cc -DTHREE_D $(CFLAGS) -c -o animate.o animate.c

postscript.o:	postscript.c internal.h Makefile
	cc -DHEADER_FILE='"$(HEADER_FILE)"' \
	   -DTRAILER_FILE='"$(TRAILER_FILE)"' \
	   $(CFLAGS)  -c -o postscript.o postscript.c

install:	install_aux install_sample \
		install_lib install_header install_man
	@echo ''
	@echo gr installation complete
	@echo ''

install_aux:	$(AUXFILES)
	$(INSTALL) -mkdir '$(AUXDIR)' $(AUXFILES)

install_lib:	$(LIBFILES)
	$(INSTALL) '$(LIBDIR)' $(LIBFILES)
	@if test "$(LIBDIR)" != "" ; then				\
	  echo cd $(LIBDIR) \; ranlib $(LIBFILES) ;			\
	  cd $(LIBDIR) ; ranlib $(LIBFILES) ;				\
	fi

install_man:	$(MANPAGES)
	$(INSTALL) '$(MANDIR)' $(MANPAGES)

install_header:	gr.h
	$(INSTALL) '$(INCLDIR)' gr.h

install_sample:	grdemo.c
	$(INSTALL) '$(SAMPLEDIR)' grdemo.c

grintro.$(MANEXT):	grintro.tpl Makefile
	rm -f grintro.$(MANEXT)
	sed					\
	  -e "/BBBBBBBBBB/,/EEEEEEEEEE/d"	\
	  -e "s*MANSECTION_VALUE*$(MANEXT)*g"	\
	  grintro.tpl > grintro.$(MANEXT)

gr.$(MANEXT):	gr.tpl Makefile
	rm -f gr.$(MANEXT)
	sed					\
	  -e "/BBBBBBBBBB/,/EEEEEEEEEE/d"	\
	  -e "s*MANSECTION_VALUE*$(MANEXT)*g"	\
	  -e "s*INCLDIR_VALUE*$(INCLDIR)*g"	\
	  -e "s*LIBDIR_VALUE*$(LIBDIR)*g"	\
	  -e "s*LIBFLAG_VALUE*$(LIBFLAG)*g"	\
	  -e "s*AUXDIR_VALUE*$(AUXDIR)*g"	\
	  -e "s*SAMPLEDIR_VALUE*$(SAMPLEDIR)*g"	\
	  gr.tpl > gr.$(MANEXT)

grdemo.c:	grdemo.tpl Makefile
	rm -f grdemo.c
	sed					\
	  -e "/BBBBBBBBBB/,/EEEEEEEEEE/d"	\
	  -e "s*INCLDIR_VALUE*$(INCLDIR)*g"	\
	  -e "s*LIBDIR_VALUE*$(LIBDIR)*g"	\
	  -e "s*LIBFLAG_VALUE*$(LIBFLAG)*g"	\
	  grdemo.tpl > grdemo.c

clean:
	/bin/rm -f *.o *~ *%

veryclean:
	/bin/rm -f *.o *~ *% *.a *.cat grdemo.c *.$(MANEXT)

distclean:	veryclean
