# $Id: Makefile,v 1.7 89/09/20 17:58:07 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

# Compiler options:
OPTIONS=-O -pipe

# 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
SAMPLEDIR=$(HOME)/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=$(HOME)/lib/$(CPUTYPE)

# 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 -lm -lgr3d -lsuntool -lsunwindow -lpixrect
# if LIBDIR is not searched by ld(1).
#LIBFLAGS=-llgd -lgr3d -lsuntool -lsunwindow -lpixrect
LIBFLAGS=-L$(LIBDIR) -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
INCLDIR=$(HOME)/lib/lgd

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

# To prevent 'make install' from trying to install the manual pages,
# comment out the MANDIR def.
MANDIR=$(MANPATH)/man$(MANEXT)

# 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=IRIS4
DEVDIR=iris4

# 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
AUXDIR=$(HOME)/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
DEFAULTSDIR=$(HOME)/defaults

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

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

# GLGLIB should be the complete pathname of the glg library file (libglg.a)
# This is used only on the IRIS
GLGLIB=$(HOME)/lib/iris4/libglg.a

# GLGHEADER should be the complete pathname of glg.h
# This is used only on the IRIS
GLGHEADER=$(HOME)/lib/glg/glg.h

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

MAKEFILE = Makefile

INSTALL_BIN = instl

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

SHELL = /bin/sh

BITSPERBYTE=8
OBJS = lgd.o mf.o vector.o
CFILES = lgd.c mf.c vector.c
CFLAGS = $(OPTIONS)
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)" \
	  OPTIONS="$(OPTIONS)" \
	  AUXDIR="$(AUXDIR)" \
	  DEFAULTSDIR="$(DEFAULTSDIR)" \
	  CP="$(CP)" \
	  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"	\
	  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) \
	  OPTIONS="$(OPTIONS)" \
	  AUXDIR=$(AUXDIR) \
	  DEFAULTSDIR=$(DEFAULTSDIR) \
	  GR_HEADER=$(GR_HEADER)

install_lib:	liblgd.a
	$(INSTALL) '$(LIBDIR)' liblgd.a
	@if test -f $(LIBDIR)/liblgd.a ; then				\
	  echo ranlib $(LIBDIR)/liblgd.a ;				\
	  ranlib $(LIBDIR)/liblgd.a ;					\
	fi

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

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

install_sample:	lgddemo.c
	$(INSTALL) -mkdir '$(SAMPLEDIR)' lgddemo.c

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

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

clean:	localclean
	cd $(DEVDIR) ; $(MAKE) clean

localveryclean:	localclean
	/bin/rm -f *.a *.cat lgddemo.c *.$(MANEXT)

veryclean:	localveryclean 
	cd $(DEVDIR) ; $(MAKE) veryclean

distclean:	localveryclean
	cd $(DEVDIR) ; $(MAKE) distclean

lgddemo.o:	lgddemo.c
	cc -c $(CFLAGS) -o lgddemo.o lgddemo.c

lgddemo:	dev lgddemo_bin

dev:
	cd $(DEVDIR) ; $(MAKE) lgddev.o

lgddemo_bin:	lgddemo.o liblgd.a
	cc $(CFLAGS) -o lgddemo lgddemo.o liblgd.a \
	  -lgl_s -lm
