# libgks Makefile
# Phil Farrell, Stanford Earth Sciences
# 13 April 1989
#
# Default action is to make the complete libgks.a library, with both
# C and Fortran binding routines, all optimized.  You can specify
# CFLAGS on the make command line to override.  For example, to make
# a version with no optimization and symbol information for the 
# debugger, use
#	% make clean
#	% make "CFLAGS=-g"
#
CFLAGS = -O
#
# SFLAGS defines special compiler flags unique to your system.
# -DBSD = use the Berkeley signal catching mechanism; otherwise use
#	a simpler one.
# -DFOURTHREEBSD = this is a 4.3BSD or derivative.  Needed to use a 
#	proper low-level routine name from the F77 library.  If not defined,
#	uses the 4.2BSD routine name.
# -f68881 = use 68881 floating point chip on a Sun workstation
# Other system-specific compiler flags can be included in this macro.
SFLAGS= -DBSD -DFOURTHREEBSD
#
# Does not make or clean the "samples" subdirectory.
#
# Compiler directives to specify include file locations, in addition 
# to the default system locations.
# INC defines the include directories with the proper pathnames for 
# compilations that take place at the next directory level; INCINC
# defines the same directories with the proper pathnames for compilations
# that take place two directory levels down.
# Following two definitions are used when vplot exists in a parallel
# directory, but has not been installed
#INC = -I../include -I../../vplot/filters/include
#INCINC = -I../../include -I../../../vplot/filters/include
# Following two definitions are used when vplot has been installed
# (/usr/local/include may be needed instead of /usr/include)
INC = -I../include -I/usr/include
INCINC = -I../../include -I/usr/include

# Parameters for installation
OWNER=root
GROUP=graphics
# Locations where gks.h include files and library will be installed
INCFILES = gks.h gksdevice.h
INCLUDE = /usr/local/include
LIB = /usr/local/lib
# Flag to decide whether to link include files into /usr/include.
# Define as "y" to make the link; anything else to not make it
INCLINK = y

# MARGS can be used to pass arguments (such as -n) to lower level 
# make commands
MARGS =

CFILES = control/*.c error/*.c output/*.c attrib/*.c xform/*.c \
		segment/*.c input/*.c inquiry/*.c utility/*.c \
		devices/vplot/*.c devices/generic/*.c \
		devices/tek401x/*.c devices/tek410x/*.c 

LIBGKS = libgks.a

all: $(LIBGKS)

install: all
	cd include; list="$(INCFILES)"; for i in $$list; do \
		install -c -o $(OWNER) -g $(GROUP) -m 0644 $$i $(INCLUDE); done
	-if test "$(INCLINK)" = "y"; then list="$(INCFILES)";\
		for i in $$list; do \
		ln -s $(INCLUDE)/$$i /usr/include; done; fi
	install -c -o $(OWNER) -g $(GROUP) -m 0644 $(LIBGKS) $(LIB)
#	addlocalman gks.3 libgks.3

# Before making the library, we first de-archive any existing library.
# That way, we only re-compile changed .c files.  If you want to 
# re-compile everything, do "make clean" first.
$(LIBGKS): $(CFILES)
	-test -f $(LIBGKS) && (cd .objects; ar xo ../$(LIBGKS))
	rm -f .objects/__*
	cd attrib; make LIBGKS="$(LIBGKS)" $(MARGS) \
		CFLAGS="$(CFLAGS) $(SFLAGS) $(INC)" $(LIBGKS)
	cd control; make LIBGKS="$(LIBGKS)" $(MARGS) \
		CFLAGS="$(CFLAGS) $(SFLAGS) $(INC)" $(LIBGKS)
	cd devices; make LIBGKS="$(LIBGKS)" $(MARGS) \
		CFLAGS="$(CFLAGS) $(SFLAGS) $(INCINC)" $(LIBGKS)
	cd error; make LIBGKS="$(LIBGKS)" $(MARGS) \
		CFLAGS="$(CFLAGS) $(SFLAGS) $(INC)" $(LIBGKS)
	cd input; make LIBGKS="$(LIBGKS)" $(MARGS) \
		CFLAGS="$(CFLAGS) $(SFLAGS) $(INC)" $(LIBGKS)
	cd inquiry; make LIBGKS="$(LIBGKS)" $(MARGS) \
		CFLAGS="$(CFLAGS) $(SFLAGS) $(INC)" $(LIBGKS)
	cd output; make LIBGKS="$(LIBGKS)" $(MARGS) \
		CFLAGS="$(CFLAGS) $(SFLAGS) $(INC)" $(LIBGKS)
	cd segment; make LIBGKS="$(LIBGKS)" $(MARGS) \
		CFLAGS="$(CFLAGS) $(SFLAGS) $(INC)" $(LIBGKS)
	cd utility; make LIBGKS="$(LIBGKS)" $(MARGS) \
		CFLAGS="$(CFLAGS) $(SFLAGS) $(INC)" $(LIBGKS)
	cd xform; make LIBGKS="$(LIBGKS)" $(MARGS) \
		CFLAGS="$(CFLAGS) $(SFLAGS) $(INC)" $(LIBGKS)
	ar crv $(LIBGKS) .objects/*.o
	ranlib $(LIBGKS)
	rm -f .objects/*.o core

clean:
	rm -f $(LIBGKS) *.o .objects/*.o core
	cd attrib; make $(MARGS) clean
	cd control; make $(MARGS) clean
	cd devices; make $(MARGS) clean
	cd error; make $(MARGS) clean
	cd input; make $(MARGS) clean
	cd inquiry; make $(MARGS) clean
	cd output; make $(MARGS) clean
	cd segment; make $(MARGS) clean
	cd utility; make $(MARGS) clean
	cd xform; make $(MARGS) clean
	
