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

# Floating point option; should be one of
#	-f68881 for MC68881 coprocessor
#	-ffpa for FBA board
#	-fsoft (or null) for software operations (the default)
FOPTION=

# 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=/usr/local/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=/usr/local/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=/usr/local/lib

# 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=/usr/local/lib/gr

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

# MANDIR 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 $(MANDIR)/man$(MANEXT); for example, if MANEXT=3 and
# MANDIR=/usr/local/man, the manual pages will be installed in the dir
# /usr/local/man/man3.)  $(MANDIR)/man$(MANEXT) must exist and be
# writeable by you before you do 'make install'.
#
# To prevent 'make install' from trying to install the manual pages,
# comment out the MANDIR def.
MANDIR=/usr/local/man

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

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) $(FOPTION)

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)
	@if test "$(AUXDIR)" != "$(PWD)" ; then				\
	  if test -f $(AUXDIR) ; then					\
	    echo ERROR: AUXDIR \($(AUXDIR)\) is not a directory ;	\
	    exit 1 ;							\
	  fi ;								\
	  if test ! -d $(AUXDIR) ; then					\
	    echo mkdir $(AUXDIR) ;					\
	    mkdir $(AUXDIR) ;						\
	  fi ;								\
	    echo cp $(AUXFILES) $(AUXDIR) ;				\
	    cp $(AUXFILES) $(AUXDIR) ;					\
	fi

install_lib:	$(LIBFILES)
	@if test "$(LIBDIR)" != "" ; then				\
	  if test ! \( -d $(LIBDIR) -a -w $(LIBDIR) \) ; then		\
	    echo '' ;							\
	    echo LIBDIR = $(LIBDIR) ;					\
	    echo is not an existing directory in which you have write ; \
	    echo permission.  Try installing again after making sure ;	\
	    echo that the directory you give for LIBDIR in the ;	\
	    echo Makefile exists and that you can write in it. ;	\
	    echo '' ;							\
	    exit 1 ;							\
	  fi ;								\
	  echo cp $(LIBFILES) $(LIBDIR) ;				\
	  cp $(LIBFILES) $(LIBDIR) ;					\
	  echo cd $(LIBDIR) \; ranlib $(LIBFILES) ;			\
	  cd $(LIBDIR) ; ranlib $(LIBFILES) ;				\
	fi

install_man:	$(MANPAGES)
	@if test "$(MANDIR)" != "" ; then				 \
	  if test ! \( -d $(MANDIR)/man$(MANEXT) -a			 \
	               -w $(MANDIR)/man$(MANEXT) \) ; then		 \
	    echo '' ;							 \
	    echo '$$(MANDIR)/man$$(MANEXT) = $(MANDIR)/man$(MANEXT)' ;   \
	    echo is not an existing directory in which you have write ;	 \
	    echo permission.  Try installing again after you make sure ; \
	    echo that the values you give in the Makefile for MANDIR ;	 \
	    echo 'and MANEXT are such that $$(MANDIR)/man$$(MANEXT)' ;   \
	    echo is an existing directory and that you can write in ;	 \
	    echo it. ;							 \
	    echo '' ;							 \
	    exit 1 ;							 \
	  fi ;								 \
	  echo cp $(MANPAGES) $(MANDIR)/man$(MANEXT) ;			 \
	  cp $(MANPAGES) $(MANDIR)/man$(MANEXT) ;			 \
	fi

install_header:	gr.h
	@if test "$(INCLDIR)" != "" ; then				 \
	  if test ! -d $(INCLDIR) ; then				 \
	    echo '' ;							 \
	    echo INCLDIR = $(INCLDIR) ;					 \
	    echo is not an existing directory in which you have write ;	 \
	    echo permission.  Try installing again after you make sure ; \
	    echo that the directory you give for INCLDIR in the ;	 \
	    echo Makefile exists and that you can write in it. ;	 \
	    echo '' ;							 \
	    exit 1 ;							 \
	  fi ;								 \
	  echo cp gr.h $(INCLDIR) ;					 \
	  cp gr.h $(INCLDIR) ;						 \
	fi

install_sample:	grdemo.c
	@if test "$(SAMPLEDIR)" != "$(PWD)" ; then			\
	  if test -f $(SAMPLEDIR) ; then				\
	    echo ERROR: SAMPLEDIR \($(SAMPLEDIR)\) is not a directory ;	\
	    exit 1 ;							\
	  fi ;								\
	  if test ! -d $(SAMPLEDIR) ; then				\
	    echo mkdir $(SAMPLEDIR) ;					\
	    mkdir $(SAMPLEDIR) ;					\
	  fi ;								\
	    echo cp grdemo.c $(SAMPLEDIR) ;				\
	    cp grdemo.c $(SAMPLEDIR) ;					\
	fi

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"	\
	  -e "s*FOPTION_VALUE*$(FOPTION)*g"	\
	  grdemo.tpl > grdemo.c

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

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