# $Id: Makefile-orig,v 2.5.4.1 1993/03/10 19:43:09 steve Exp $
#
# Copyright (C) 1990 UCAR/Unidata
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for any purpose without fee is hereby granted, provided
# that the above copyright notice appear in all copies, that both that
# copyright notice and this permission notice appear in supporting
# documentation, and that the name of UCAR/Unidata not be used in
# advertising or publicity pertaining to distribution of the software
# without specific, written prior permission.  UCAR makes no
# representations about the suitability of this software for any purpose.
# It is provided "as is" without express or implied warranty.  It is
# provided with no support and without obligation on the part of UCAR or
# Unidata, to assist in its use, correction, modification, or enhancement.

#
# Makefile for the "demonstration programs" subdirectory of the XGKS package.

# Anticipated, changeable macros (others might not work):
#CC	= cc#			C compiler.  Unset => make(1) default.
COPTS	= -g#			cc(1) options (e.g. "-g", "-O")
BINMODE	= 775
DESTDIR	= /usr/local/ldm#	assumed to contain "bin", "include",
#				"lib", and "man" subdirectories
#FC	= f77#			Fortran compiler. Unset => make(1) default.
#				Set to empty string => platform doesn't have
#				Fortran compiler.
FOPTS	= -g#			f77(1) options
OS	= sunos_4.1.1
X11_INCDIR	= `case $(OS) in \
		    hp*) echo /usr/include/X11R4;; \
		    *) echo $${OPENWINHOME-/usr}/include;; \
		  esac`
X11_LIBDIR	= `case $(OS) in \
		    hp*) echo /usr/lib/X11R4;; \
		    *) echo $${OPENWINHOME-/usr/lib/X11}$${OPENWINHOME+/lib};; \
		  esac`
#
# udposix(3) header-file and library references:
#
UDPOSIX_CPP	= -I$(DESTDIR)/include/udposix/$(CC)
UDPOSIX_LD	= -L$(DESTDIR)/lib -ludposix_$(CC)

# End of anticipated macros

MY_MFLAGS	= \
		CC="$(CC)" \
		COPTS="$(COPTS)" \
		BINMODE="$(BINMODE)" \
		DESTDIR="$(DESTDIR)" \
		FC="$(FC)" \
		FOPTS="$(FOPTS)" \
		OS="$(OS)" \
		UDPOSIX_CPP="$(UDPOSIX_CPP)"	\
		UDPOSIX_LD="$(UDPOSIX_LD)"	\
		X11_INCDIR="$(X11_INCDIR)" \
		X11_LIBDIR="$(X11_LIBDIR)"

CSRCS		= defcolors.c font.c hanoi.c mi.c pline.c pmark.c
FSRCS		= gksdemo.f star.f

BINDIR		= $(DESTDIR)/bin
INCDIR		= $(DESTDIR)/include
NAME		= demo
VERSIONID	= $(NAME)vers
INCPATH		= ../lib/src
UNICOS_INC      = `case $(OS) in unicos_5*) echo -I/usr/include/stdc;; esac`
INCLUDES	= -I$(INCPATH) $(UDPOSIX_CPP) -I$(X11_INCDIR) $(UNICOS_INC)
DEFINES		=
CPPOPTS		= $(INCLUDES) $(DEFINES)
CFLAGS		= $(CPPOPTS) $(COPTS)
FFLAGS		= $(FOPTS)
SHELL		= /bin/sh
LIBDIR		= $(DESTDIR)/lib

#
# The following macro defines the $(FC) option for adding a directory
# to the library search-path.  In most systems, this is "-L"; HPUX,
# however, uses "-Wl,-L,".
#
FC-L		= `case $(OS) in hpux*) echo -Wl,-L,;; *) echo -L;; esac`

#
# NB: The sequence of `-L's and `-l's in the following is necessary due to a
# bug in the UNICOS cc(1) utility.
#
LIBXGKS		= -L../lib/src -lxgks -L$(LIBDIR) -lxgks
LIBFXGKS	= $(FC-L)../lib/fortran -lfxgks $(FC-L)../lib/src -lxgks \
		      $(FC-L)$(LIBDIR) -lfxgks -lxgks

SYSLIBS		= -lX11 -lm \
			`case $(OS) in \
			    sunos*)	echo -L/usr/5lib;; \
			    unicos_5*)	echo -lnet -lsc;; \
			    unicos_6*)	echo -lnet;; \
			esac`

LIBS		= $(LIBXGKS)  -L$(LIBDIR) $(UDPOSIX_LD) -L$(X11_LIBDIR) \
			$(SYSLIBS)
LIBS_F77	= $(LIBFXGKS) $(FC-L)$(LIBDIR) $(UDPOSIX_LD) \
			$(FC-L)$(X11_LIBDIR) $(SYSLIBS)
LIBC		= `case $(OS) in nextos*) ;; *) echo -lc;; esac`

#
#	The following list is a subset of the XGKS programs contained
#	in the original X11R4 distribution.  IMHO, it contains the 
#	useful ones.
#
CPROGS		= defcolors font hanoi mi pline pmark 

#
#	The following list contains the Fortran programs.  They're cute
#	(especially "gksdemo") but not particularly useful.
#
FPROGS		= star gksdemo

all:		$(CPROGS)
	@-if [ -n "$(FC)" ]; then \
	    $(MAKE) $(MFLAGS) $(MY_MFLAGS) $(FPROGS); \
	fi

#
#	This rule invokes $(MAKE) to enable make(1)-time redefinition of 
#	BINDIR.
#
#	The programs are linked during the "install" target because
#	the XGKS library might be a sharable one.
#
install:
	$(MAKE) $(MFLAGS) $(MY_MFLAGS) \
	    $(BINDIR)/defcolors \
	    $(BINDIR)/font \
	    $(BINDIR)/mi \
	    $(BINDIR)/pline \
	    $(BINDIR)/pmark \
	    $(BINDIR)/hanoi
	-if [ -n "$(FC)" ]; then \
	    $(MAKE) $(MFLAGS) $(MY_MFLAGS) \
		$(BINDIR)/star \
		$(BINDIR)/gksdemo; \
	fi

#	NB: When run, the programs "hanoi" and "font" make "*.gksm" GKS 
#	Metafiles by default.
clean:
	rm -f core $(CPROGS) $(FPROGS) *.o *.log *.ln *.out *.gksm *.cgm

$(BINDIR)/defcolors:	defcolors
	cp defcolors $@
	chmod $(BINMODE) $@
$(BINDIR)/font:		font
	cp font $@
	chmod $(BINMODE) $@
$(BINDIR)/mi:		mi
	cp mi $@
	chmod $(BINMODE) $@
$(BINDIR)/pline:	pline
	cp pline $@
	chmod $(BINMODE) $@
$(BINDIR)/pmark:	pmark
	cp pmark $@
	chmod $(BINMODE) $@
$(BINDIR)/hanoi:	hanoi
	cp hanoi $@
	chmod $(BINMODE) $@
$(BINDIR)/star:		star
	cp star $@
	chmod $(BINMODE) $@
$(BINDIR)/gksdemo:	gksdemo
	cp gksdemo $@
	chmod $(BINMODE) $@

defcolors:		defcolors.o
	$(CC) $(CFLAGS) -o $@ defcolors.o $(OBJS) $(LIBS)
font:			font.o
	$(CC) $(CFLAGS) -o $@ font.o $(OBJS) $(LIBS)
mi:			mi.o
	$(CC) $(CFLAGS) -o $@ mi.o $(OBJS) $(LIBS)
pline:			pline.o
	$(CC) $(CFLAGS) -o $@ pline.o $(OBJS) $(LIBS)
pmark:			pmark.o
	$(CC) $(CFLAGS) -o $@ pmark.o $(OBJS) $(LIBS)
hanoi:			hanoi.o
	$(CC) $(CFLAGS) -o $@ hanoi.o $(OBJS) $(LIBS)
gksdemo:		gksdemo.o
	$(FC) $(FFLAGS) -o $@ gksdemo.o $(OBJS) $(LIBS_F77) $(LIBC)
star:			star.o
	$(FC) $(FFLAGS) -o $@ star.o $(OBJS) $(LIBS_F77) $(LIBC)

.SUFFIXES:	.ln .c

.c.ln:
	lint -nuz $(CPPOPTS) $< -lansic -lposix 2>&1

# The following rule is for debugging using the CodeCenter 
# (formerly Saber-C) code-development system.
#
.SUFFIXES:	.saber .o .c

gksdemo.saber:	gksdemo.o
	#setopt path . ../lib/src ../lib/src/cgm ../lib/src/gksm ../lib/src/x
	#setopt ansi
	#setopt load_flags -C $(CFLAGS) -I/usr/5include -DDEBUG
	#load -C $(CFLAGS) -I/usr/5include -DDEBUG gksdemo.o $(OBJS) \
	    $(LIBS_F77) -L/usr/local/lang/SC0.0 -lF77 -lc
	#ignore IO

.o.saber:
	#setopt path . ../lib/src ../lib/src/cgm ../lib/src/gksm ../lib/src/x
	#setopt ansi
	#setopt load_flags -C $(CFLAGS) -I/usr/5include -DDEBUG
	#load -C $(CFLAGS) -I/usr/5include -DDEBUG $< $(OBJS) $(LIBS) -lc
	#ignore IO

.c.saber:
	#setopt path . ../lib/src ../lib/src/cgm ../lib/src/gksm ../lib/src/x
	#setopt ansi
	#setopt load_flags -C $(CFLAGS) -I/usr/5include -DDEBUG
	#load -C $(CFLAGS) -I/usr/5include -DDEBUG $< $(OBJS) $(LIBS) -lc
	#ignore IO

test:		all
	@echo Testing window Expose and Resize
	@echo Testing inactive backing-store
	@echo "Xgks.backingstore: off" | xrdb -merge
	./pmark
	@echo Testing active backing-store
	@echo "Xgks.backingstore: on" | xrdb -merge
	./pline
	./defcolors
	./hanoi -o hanoi.gksm
	./mi hanoi.gksm
	./hanoi -o hanoi.cgm
	./mi hanoi.cgm
	./font -o font.gksm
	./mi font.gksm
	./font -o font.cgm
	./mi font.cgm
	-test -f star && ./star
	-test -f gksdemo && ./gksdemo

depend:
	$(CC) $(INCLUDES) $(DEFINES) -M $(CSRCS)

gksdemo.o:	gkspar.inc
defcolors.o:	defcolors.c
defcolors.o:	$(INCPATH)/xgks.h
defcolors.o:	./demo.h
font.o:		font.c
font.o:		$(INCPATH)/xgks.h
font.o:		./demo.h
hanoi.o:	hanoi.c
hanoi.o:	$(INCPATH)/xgks.h
hanoi.o:	./demo.h
mi.o:		mi.c
mi.o:		$(INCPATH)/xgks.h
mi.o:		./demo.h
pline.o:	pline.c
pline.o:	$(INCPATH)/xgks.h
pmark.o:	pmark.c
pmark.o:	$(INCPATH)/xgks.h
