# $Id: Makefile,v 1.7 89/09/21 11:28:28 mbp Exp $

# Master makefile for viewwld

# Note: Viewwld uses two libraries called GR and LGD.  This makefile
# builds these libraries and then compiles/installs viewwld. If you
# are installing LGD and GR separately from viewwld, do not use this
# makefile.  Use the individual makefiles for LGD, GR, and viewwld.
# Specifically, you should follow the installation instructions in the
# README files in the gr, lgd, and viewwld subdirectories.

### Instructions:
###
### A. For quick and dirty compilation:
###      Just type 'make'.  This will create the executable file
###      'viewwld' and the manual page 'viewwld.1' in the viewwld
###	 subdirectory.
###
###      This should be sufficent on most systems.  Note, however,
###      that the resulting program will break if you delete the
###      source code.  To eliminate this problem, or if you get an
###      error, use method B.
###
###	 Note: after the 'make', the pathname of the executable file
###	 relative to this dir will be viewwld/viewwld.  If you
###	 named the top viewwld directory 'viewwld', then the complete
###	 pathname of the executable will be something like
###	 /u/yourlogin/viewwld/viewwld/viewwld. (Sorry!)
###
### B. For 'official' compilation:
###      Make the changes indicated in this makefile below, and then
###      type 'make'.  This will create the executable file 'viewwld'
###      and the manual page viewwld.x (where you specify the
###      extension x) in this directory.
###
### C. To install:
###      Make the changes indicated in this makefile below, and then
###      type 'make install'.  This will do the following things
###      (unless you prevent some of them as described below):
###
### 	1. Compile viewwld as in B above
### 	2. Copy the file viewwld/viewwld.hlp to a permanent directory,
###	     creating this directory if it doesn't exist
### 	3. Copy the files gr/gr_{header,trailer}.ps to a permanent
### 	     directory, creating this directory if it doesn't exist
### 	3. Strip the executable file and move it to a permanent bin
### 	     directory
### 	4. Move the manual page to a permanent manual directory
### 	5. Copy the SunView defaults file lgd/sunview/LGD.d to a
### 	     directory that is searched by defaultsedit(1)
###
### D. To clean up the viewwld dir:
###      Type 'make clean'; this deletes all intermediate files but
###      leaves the final product files (executables, libraries, etc).
###      To delete the final product files too, essentially returning
###      the viewwld directory to its original state, type 'make
###      veryclean'.

##############################################
#        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 (the C-shell), remove the comment char from this line
# and change the path to the complete path of the main viewwld dir
# (the one containing this makefile):
#PWD=/u/yourlogin/viewwld

# 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

# HELPDIR should be the pathname of directory containing the file
# 'viewwld.help'.  Viewwld needs this file at run-time, so you should
# probably install it in some permanent location (rather than with the
# source code), such as /usr/local/lib/viewwld.
#
# When doing 'make install', HELPDIR is created if it does not exist,
# and if the file 'viewwld.help' does not exist in HELPDIR, it will be
# copied into it.  You should be sure that you have write permission
# in HELPDIR, or in its parent if it does not yet exist.
#
# The current (uninstalled) location of viewwld.help is the 'viewwld'
# subdirectory; if you want to leave it there, specify
# HELPDIR=$(PWD)/viewwld
HELPDIR=$(PWD)/viewwld

# PSDIR should be the pathname of directory containing the GR
# PostScript files gr_header.ps and gr_trailer.ps.  Viewwld needs
# these file at run-time, so you should probably install them in some
# permanent location (rather than with the source code), such as
# /usr/local/lib/viewwld.
#
# When doing 'make install', PSDIR will be created if it does not
# exist, and if either gr_header.ps or gr_trailer.ps does not exist in
# PSDIR, it will be copied into it.  You should be sure that you have
# write permission in PSDIR, or in its parent if it does not yet
# exist.
#
# The current (uninstalled) location of gr_header.ps and gr_trailer.ps
# is the 'gr' subdirectory; if you want to leave them there, specify
# PSDIR=$(PWD)/gr
PSDIR=$(PWD)/gr

# DEFAULT_SPOOL_COMMAND should be a shell command for printing
# PostScript files.  It may consists of one or more words separated by
# whitespace, and it should take a single argument, which is the name
# of a PostScript file to be printed.  Likely values are "lpr", "lpr
# -plw2", etc.  If your system has no way to print PostScript files,
# you should set DEFAULT_SPOOL_COMMAND to nothing; in this case the
# '=' sign should be the last thing on this line; no trailing space!
DEFAULT_SPOOL_COMMAND=lpr

#########################################################################
### The remaining macros are only used by 'make install'.  If you are
### just going to compile viewwld without installing it, you can
### ingore everything below this point.
###
### Most of the following macros specify the names of directories into
### which viewwld and its supporting files should be installed.  For
### each of these macros, the makefile will install the corresponding
### file only if the macro has a value.  Hence, if you want to prevent
### the makefile from installing a particular file or files, just comment
### out the corresponding macro definition.
###
### Each of the directories you specify here should exist and should
### be writable by you before you do 'make install'.
#########################################################################

# BINDIR should be the directory in which you want to install the
# executable file (used only by 'make install').  Should probably be
# /usr/local/bin.
BINDIR=/usr/local/bin

# SAMPLEDIR should be the directory in which you want to install the
# example vector (intput) files which come with viewwld.  To leave them
# where they are now (with the source code in the viewwld subdirectory),
# specify SAMPLEDIR=$(PWD)/viewwld.
SAMPLEDIR=$(PWD)/viewwld

# MANEXT should be the extension which you want to use for the manual
# page.  Should probably be l or 1.  Do not comment out this
# definition!
MANEXT=1

# MANDIR should be the directory in which you want to install the
# viewwld manual page (used only by 'make install').  Should probably be
# /usr/local/man.  (Note: the extension subdirectory will be appended to
# the value of MANDIR; for example if MANEXT=1 and
# MANDIR=/usr/local/man, the manual page will be installed in the dir
# /usr/local/man/man1.)
MANDIR=/usr/local/man

# DEFAULTSDIR should be the directory in which you want to install the
# viewwld defaults file (which is named 'LGD.d').  This file must be
# installed in a directory (probably /usr/lib/defaults) that is searched
# by the program defaultsedit(1) if you want users to be able to use
# defaultsedit to set customized values for viewwld parameters.  If you
# do not install this file, users can still set customized viewwld
# parameter values by editing the file '.defaults' in their home
# directories manually.  (See the viewwld manual page for more details.)
DEFAULTSDIR=/usr/lib/defaults

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

PSFILES = gr/gr_header.ps gr/gr_trailer.ps
DEFAULTSFILE = lgd/sunview/LGD.d

all:	all_quietly
	@echo ''
	@echo Viewwld compilation is complete.
	@echo ''
	@echo The executable file is:
	@echo '  ' $(PWD)/viewwld/viewwld.
	@echo The manual page file is:
	@echo '  ' $(PWD)/viewwld/viewwld.$(MANEXT)
	@echo ''

all_quietly:
	cd gr ; make libgr3d.a \
			PWD=$(PWD)/gr \
			FOPTION=$(FOPTION) \
			OPTIONS="$(OPTIONS)" \
			AUXDIR=$(PSDIR) \
			DEFAULT_SPOOL_COMMAND="$(DEFAULT_SPOOL_COMMAND)"
	cd lgd ; make liblgd.a \
			PWD=$(PWD)/gr \
			FOPTION=$(FOPTION) \
			OPTIONS="$(OPTIONS)" \
			GR_HEADER=$(PWD)/gr/gr.h \
			DEFAULTSDIR=$(DEFAULTSDIR)
	cd viewwld ; make			\
			PWD=$(PWD)/gr		\
			FOPTION=$(FOPTION)	\
			OPTIONS="$(OPTIONS)"	\
			HELPDIR=$(HELPDIR)	\
			SAMPLEDIR=$(SAMPLEDIR)	\
			PSDIR=$(PSDIR)		\
			LGDLIB=../lgd/liblgd.a	\
			GRLIB=../gr/libgr3d.a	\
			GR_HEADER=../gr/gr.h	\
			LGD_HEADER=../lgd/lgd.h \
			MANEXT=$(MANEXT)	\
			all

install:	all_quietly install_viewwld install_ps install_defaults
	@echo ''
	@echo viewwld installation complete
	@echo ''

install_viewwld:
	cd viewwld ; make			\
			PWD=$(PWD)/gr		\
			FOPTION=$(FOPTION)	\
			OPTIONS="$(OPTIONS)"	\
			HELPDIR=$(HELPDIR)	\
			LGDLIB=../lgd/liblgd.a	\
			GRLIB=../gr/libgr3d.a	\
			GR_HEADER=../gr/gr.h	\
			LGD_HEADER=../lgd/lgd.h	\
			BINDIR=$(BINDIR)	\
			MANEXT=$(MANEXT)	\
			MANDIR=$(MANDIR)	\
			SAMPLEDIR=$(SAMPLEDIR)	\
			install_quietly

install_ps:
	@if test "$(PSDIR)" != "$(PWD)/gr" ; then		\
	  if test -f $(PSDIR) ; then				\
	    echo ERROR: PSDIR \($(PSDIR)\) is not a directory ;	\
	    exit 1 ;						\
	  fi ;							\
	  if test ! -d $(PSDIR) ; then				\
	    echo mkdir $(PSDIR) ;				\
	    mkdir $(PSDIR) ;					\
	  fi ;							\
	  echo cp $(PSFILES) $(PSDIR) ;				\
	  cp $(PSFILES) $(PSDIR) ;				\
	fi

install_defaults:
	@if test "$(DEFAULTSDIR)" != "" ; then				\
	  if test ! \( -d $(DEFAULTSDIR) -a -w $(DEFAULTSDIR) \) ; then	\
	    echo '' ;							\
	    echo DEFAULTSDIR = $(DEFAULTSDIR) ;				\
	    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 DEFAULTSDIR in the ;	\
	    echo Makefile exists and that you can write in it. ;	\
	    echo '' ;							\
	    exit 1 ;							\
	  fi ;								\
	  echo cp $(DEFAULTSFILE) $(DEFAULTSDIR) ;			\
	  cp $(DEFAULTSFILE) $(DEFAULTSDIR) ;				\
	fi

clean:
	/bin/rm -f *~  *% *.man #*#
	cd gr ; make clean
	cd lgd ; make clean
	cd viewwld ; make clean

veryclean:
	/bin/rm -f *~  *% *.man #*#
	cd gr ; make veryclean
	cd lgd ; make veryclean
	cd viewwld ; make veryclean
