# $Id: Makefile,v 1.7 89/09/20 18:27:46 mbp Exp $

# Makefile for viewwld

# Use this makefile directly only if you are installing LGD and GR
# independently of viewwld.  In this case, make the changes indicated
# below and then type 'make' to compile, or 'make install' to install
# (and compile).

##############################################
#        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 the file 'viewwld.help' 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 path you give for HELPDIR should be one which is recognized by
# all workstations for which this installation is being done.
#
# To leave 'viewwld.help' in its current location (in the viewwld
# source code directory), specify HELPDIR=$(PWD).
HELPDIR=$(PWD)

# SAMPLEDIR should be the complete pathname of the directory where you
# want to keep the example vector (input) files. Viewwld does not use
# these files directly, but they are mentioned in the manual page, and
# the pathname you specify here will be used when creating the manual
# page.
#
# When doing 'make install', SAMPLEDIR is created if it does not
# exist, and the example files will be 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 them with the viewwld source code.
SAMPLEDIR=$(PWD)

# PSDIR should be the complete pathname of the directory containing
# the files gr_header.ps and gr_trailer.ps; these files are part of
# the GR graphics library that viewwld uses and are mentioned in the
# viewwld manual page; the pathname you specify here will be used when
# creating the manual page.  You should specify the same value for
# PSDIR here that you did in the GR makefile when you installed GR;
# (probably something like /usr/local/lib/gr).
PSDIR=/usr/local/lib/gr

# LGDLIB should be the pathname of the LGD library file liblgd.a
LGDLIB=/usr/local/lib/liblgd.a

# GRLIB should be the pathname of the GR library file grlib3d.a
GRLIB=/usr/local/lib/libgr3d.a

# GR_HEADER should be the pathname of the GR header file "gr.h"
GR_HEADER=../gr/gr.h

# LGD_HEADER should be the pathname of the LGD header file "lgd.h"
LGD_HEADER=../lgd/lgd.h

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

#########################################################################
### The remaining macros are only used by 'make install'.  If you are
### just going to compile viewwld without installing it, you can
### ignore 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, 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

# 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

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

HELPFILE=$(HELPDIR)/viewwld.help
SAMPLEFILES= house.vec lorenz.vec
OTHERFLAGS = -DDEVICE_SUNVIEW
CFLAGS=$(OPTIONS) $(FOPTION) $(OTHERFLAGS)

all:	viewwld viewwld.$(MANEXT)

viewwld:	viewwld.o
	cc $(CFLAGS) -o viewwld viewwld.o	\
	  $(LGDLIB)				\
	  $(GRLIB)				\
	  -lm -lsuntool -lsunwindow -lpixrect

viewwld.o: 	viewwld.c
	cc $(CFLAGS) 			 \
	  -DHELPFILE='"$(HELPFILE)"' 	 \
	  -DGR_HEADER='"$(GR_HEADER)"'	 \
	  -DLGD_HEADER='"$(LGD_HEADER)"' \
	  -c -o viewwld.o viewwld.c

viewwld.$(MANEXT):	viewwld.tpl
	rm -f viewwld.$(MANEXT)
	sed						\
	  -e "/BBBBBBBBBB/,/EEEEEEEEEE/d"		\
	  -e "s*MANSECTION_VALUE*$(MANEXT)*g"		\
	  -e "s*SAMPLEDIR_VALUE*$(SAMPLEDIR)/*g"	\
	  -e "s*HELPDIR_VALUE*$(HELPDIR)/*g"		\
	  -e "s*PSDIR_VALUE*$(PSDIR)/*g"		\
	  viewwld.tpl > viewwld.$(MANEXT)

viewwld.man:	viewwld.$(MANEXT)
	rm -f viewwld.man
	nroff -man viewwld.$(MANEXT) | col -b > viewwld.man

install:	install_quietly
	@echo ''
	@echo viewwld installation complete
	@echo ''

install_quietly:	install_help install_bin install_man install_samples

install_help:	viewwld.help
	@if test "$(HELPDIR)" != "$(PWD)" ; then			\
	  if test -f $(HELPDIR) ; then					\
	    echo ERROR: HELPDIR \($(HELPDIR)\) is not a directory ;	\
	    exit 1 ;							\
	  fi ;								\
	  if test ! -d $(HELPDIR) ; then				\
	    echo mkdir $(HELPDIR) ;					\
	    mkdir $(HELPDIR) ;						\
	  fi ;								\
	    echo cp viewwld.help $(HELPDIR) ;				\
	    cp viewwld.help $(HELPDIR) ;				\
	fi

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

install_man:	viewwld.$(MANEXT)
	@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 viewwld.$(MANEXT) $(MANDIR)/man$(MANEXT) ;		 \
	  cp viewwld.$(MANEXT) $(MANDIR)/man$(MANEXT) ;			 \
	fi

install_samples:
	@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 $(SAMPLEFILES) $(SAMPLEDIR) ;			\
	    cp $(SAMPLEFILES) $(SAMPLEDIR) ;				\
	fi

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

veryclean:	clean
	/bin/rm -f viewwld *.man *.$(MANEXT)

lint:
	lint $(OTHERFLAGS) \
	  -DHELPFILE='"$(HELPFILE)"' \
	  -DGR_HEADER='"$(GR_HEADER)"' \
	  -DLGD_HEADER='"$(LGD_HEADER)"' \
	  viewwld.c \
	  $(HOME)/lib/llib-llgd.ln \
	  $(HOME)/lib/llib-llgdsunview.ln \
	  $(HOME)/lib/llib-lgr.ln
