# $Id: Makefile,v 1.7 89/09/20 18:15:13 mbp Exp $

# Makefile for LGD

# Before running this Makefile, make the changes in the configuration
# section below.  Then type 'make' to compile, or 'make install' to
# install (and compile).  Do this from this directory only.  You need
# not make any changes to the device driver Makefile (sunview/Makefile
# for the SunView version).

# 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 LGD 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 LGD is in (the one containing this Makefile):
#PWD=/u/yourlogin/src/lgd

# 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

# SAMPLEDIR should be the complete pathname of the directory where you
# want install the example lgd program lgddemo.c
#
# When doing 'make install', SAMPLEDIR is created if it does not
# exist, and lgddemo.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 lgddemo.c with the rest of the lgd
# source code.
SAMPLEDIR=/usr/local/lib/lgd

# LIBDIR should be the directory in which you want to install the LGD
# library file liblgd.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

# LIBFLAGS should give the flags to pass to ld(1) to tell it where to
# find the libraries necessary for LGD programs.  Should include the
# LGD library itself as well as any required -L options and additional
# libraries.  For the SunView version, LIBFLAGS should probably be
# either
#    LIBFLAGS=-llgd -lgr3d -lm -lsuntool -lsunwindow -lpixrect
# if the lgd and gr libraries are installed in a directory (LIBDIR) that
# is searched by ld(1) (such as /usr/local/lib or /usr/lib), or
#    LIBFLAGS=-L$(LIBDIR) -llgd -lgr3d -lm -lsuntool -lsunwindow -lpixrect
# if LIBDIR is not searched by ld(1).
LIBFLAGS=-llgd -lgr3d -lm -lsuntool -lsunwindow -lpixrect

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

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

###
### (The remaining macros have to do with the SunView device driver.)
###

# DEV and DEVDIR specify the graphics device.  Since the only device
# currently supported is SunView, do not change these; they should be
# 'DEV=SUNVIEW' and 'DEVDIR=sunview'.
DEV=SUNVIEW
DEVDIR=sunview

# AUXDIR should be the (complete) pathname of the directory where you
# want to install the files that LGD 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/lgd, so
# that LGD programs will not be dependent on the location of the LGD
# 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/lgd

# DEFAULTSDIR should be the directory in which you want to install the
# lgd SunView defaults file ('LGD.d').  This file should 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 lgd parameters.  If you do
# not install this file, users can still set customized lgd parameter
# values by editing the file '.defaults' in their home directories
# manually.  (See the lgd manual page for more details.)
#
# The value you give for DEFAULTSDIR should be the pathname of an
# existing directory in which you have write permission.
#
# To prevent the Makefile from trying to install the defaults file,
# comment out the defition of DEFAULTSDIR.
DEFAULTSDIR=/usr/lib/defaults

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

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

BITSPERBYTE=8
OBJS = lgd.o mf.o vector.o
CFILES = lgd.c mf.c vector.c
CFLAGS = $(OPTIONS) $(FOPTION)
MANPAGES =	lgdintro.$(MANEXT) lgd.$(MANEXT)

all:	liblgd.a $(MANPAGES) lgddemo.c

liblgd.a:	$(OBJS) $(DEVDIR)/lgddev.o
	ar rc liblgd.a $(OBJS) $(DEVDIR)/lgddev.o
	ranlib liblgd.a

$(DEVDIR)/lgddev.o:
	cd $(DEVDIR) ; \
	$(MAKE) \
	  PWD=$(PWD)/$(DEVDIR) \
	  FOPTION=$(FOPTION) \
	  OPTIONS="$(OPTIONS)" \
	  AUXDIR=$(AUXDIR) \
	  DEFAULTSDIR=$(DEFAULTSDIR) \
	  GR_HEADER=$(GR_HEADER)

lgd.o:		lgd.c lgd.h internal.h mf.h vector.h $(DEVDIR)/dpu.h
	cc $(CFLAGS) -I$(DEVDIR) -D$(DEV) -DBITSPERBYTE=$(BITSPERBYTE) \
	   -c -o lgd.o lgd.c

mf.o: 		mf.c mf.h
	cc $(CFLAGS) -c -o mf.o mf.c

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

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

lgd.$(MANEXT):	lgd.tpl Makefile
	rm -f lgd.$(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*LIBFLAGS_VALUE*$(LIBFLAGS)*g"	\
	  -e "s*AUXDIR_VALUE*$(AUXDIR)*g"	\
	  -e "s*SAMPLEDIR_VALUE*$(SAMPLEDIR)*g"	\
	  lgd.tpl > lgd.$(MANEXT)

lgddemo.c:	lgddemo.tpl Makefile
	rm -f lgddemo.c
	sed					\
	  -e "/BBBBBBBBBB/,/EEEEEEEEEE/d"	\
	  -e "s*INCLDIR_VALUE*$(INCLDIR)*g"	\
	  -e "s*LIBFLAGS_VALUE*$(LIBFLAGS)*g"	\
	  -e "s*FOPTION_VALUE*$(FOPTION)*g"	\
	  lgddemo.tpl > lgddemo.c

install:	install_dev install_sample \
		install_lib install_header install_man
	@echo ''
	@echo lgd installation complete
	@echo ''

install_dev:
	cd $(DEVDIR) ; make install \
	  PWD=$(PWD)/$(DEVDIR) \
	  FOPTION=$(FOPTION) \
	  OPTIONS="$(OPTIONS)" \
	  AUXDIR=$(AUXDIR) \
	  DEFAULTSDIR=$(DEFAULTSDIR) \
	  GR_HEADER=$(GR_HEADER)

install_lib:	liblgd.a
	@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 liblgd.a $(LIBDIR) ;					\
	  cp liblgd.a $(LIBDIR) ;					\
	  echo ranlib $(LIBDIR)/liblgd.a ;				\
	  ranlib $(LIBDIR)/liblgd.a ;					\
	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:	lgd.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 lgd.h $(INCLDIR) ;					 \
	  cp lgd.h $(INCLDIR) ;						 \
	fi

install_sample:	lgddemo.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 lgddemo.c $(SAMPLEDIR) ;				\
	    cp lgddemo.c $(SAMPLEDIR) ;					\
	fi

lintlibs:
	lint -I$(DEVDIR) -D$(DEV) \
	  -DBITSPERBYTE=$(BITSPERBYTE) \
	  -Clgd $(CFILES)
	cd $(DEVDIR) ; \
	$(MAKE) PWD=$(PWD)/$(DEVDIR) \
		lintlib

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

veryclean:
	/bin/rm -f *.o *~ *% *.a *.cat lgddemo.c *.$(MANEXT)
	cd $(DEVDIR) ; $(MAKE) veryclean
