# Makefile for the Fortran subdirectory of the XGKS package.
#
# $Id: Makefile-orig,v 2.5.4.1 1993/03/10 19:44:09 steve Exp $
# $__Header$
#
# 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.

# Anticipated, changeable macros (others might not work):
#CC		=#		C compiler.  Unset => make(1) default.
COPTS		= -O#		WARNING: my VAX ULTRIX 4.0 native cc(1) had
#				problems with `-g', so did my AIX 3.1 cc(1)
#				--SRE 91/3/28
DESTDIR		= /usr/local/ldm#	assumed to contain "bin", "include",
#					"lib", and "man" subdirectories
#FC		= f77#		Fortran compiler.  Default = native macro def.
FOPTS		= -O
FORTC		= fortc#	UDAPE fortc(1) utility
LIBMODE		= 664
LIBTYPE		= sharable#	"nonsharable" or "sharable"
OS		= sunos_4.1.1
RANLIB		= ranlib
#
# The place to find all the <X11/*.h> header-files.  NB: Since X11 header-
# files are included as "#include <X11/...>", this path should actually refer 
# to the parent directory of the directory that actually contains the 
# header-files.
#
X11_INCDIR	= `case $(OS) in \
		    hp*) echo /usr/include/X11R4;; \
		    *) echo $${OPENWINHOME-/usr}/include;; \
		  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

# The following macro is for passing the above, "anticipated" macros to
# make(1)s invoked by this makefile (i.e. recursive make(1)s).
# 
# There is, however, a problem.  The placement of macro re-definitions on
# a make(1) command-line is significant: when more than one definition
# for a given macro is given, the one that takes effect depends on the
# peculiarities of the particular make(1).  For example, the SunOS 4.1
# make(1) takes the last re-definition, whereas the 4.0.3 make(1) takes
# the first.  Consequently, those actions in this makefile that need to
# redefine certain macros, do not use the macro MY_MFLAGS; instead
# they explicitly reproduce the following list.  Therefore, if you add or
# remove macros from this list, be sure to do the same to those actions
# just mentioned.  Also, don't attempt to redefine any of the following
# macros on a make(1) command-line if you also use the MY_MFLAGS macro on
# the command-line.
#
MY_MFLAGS	= \
		CC="$(CC)" \
		COPTS="$(COPTS)" \
		DESTDIR="$(DESTDIR)" \
		FC="$(FC)" \
		FOPTS="$(FOPTS)" \
		FORTC="$(FORTC)" \
		LIBMODE="$(LIBMODE)" \
		LIBTYPE="$(LIBTYPE)" \
		OS="$(OS)" \
		RANLIB="$(RANLIB)" \
		UDPOSIX_CPP="$(UDPOSIX_CPP)"	\
		UDPOSIX_LD="$(UDPOSIX_LD)"	\
		X11_INCDIR="$(X11_INCDIR)"

# Directories:
BINDIR		= $(DESTDIR)/bin
LIBDIR		= $(DESTDIR)/lib
INCDIR		= $(DESTDIR)/include

NAME		= fxgks
LIB_A		= lib$(NAME).a
LIB_SA		= lib$(NAME).sa
LIB_SO		= lib$(NAME).so
LIB_O		= lib$(NAME).o
INCPATH		= ../src
UNICOS_INC	= `case $(OS) in unicos*) echo -I/usr/include/stdc;; esac`
INCLUDES	= -I$(INCPATH) $(UDPOSIX_CPP) -I$(X11_INCDIR) \
		  $(UNICOS_INC)
DEFINES		=
CPPOPTS		= $(DEFINES) $(INCLUDES)
CFLAGS		= $(CPPOPTS) $(COPTS)
FFLAGS		= $(FOPTS)
SHELL		= /bin/sh
INST		= cp
GET_RELNO	=  `sed -n 's/.*\([0-9][0-9]*\.[0-9][0-9]*\).*/\1/p' \
			fxgksvers.c`

CSRCS		= control.c error.c escapes.c externinit.c gerhnd.c \
		getlunname.c inputevent.c inputinit.c inputmode.c inputreq.c \
		inputsamp.c inqerrlist.c inqgksdesc.c inqgkslist.c \
		inqpixel.c inqseglist.c inqstate.c inqwsdesc.c \
		inqwslist.c meta.c output.c rep.c segattr.c segment.c \
		transform.c utils.c wsioutattr.c fxgksvers.c

LNS		= control.ln error.ln escapes.ln externinit.ln gerhnd.ln \
		getlunname.ln inputevent.ln inputinit.ln inputmode.ln \
		inputreq.ln \
		inputsamp.ln inqerrlist.ln inqgksdesc.ln inqgkslist.ln \
		inqpixel.ln inqseglist.ln inqstate.ln inqwsdesc.ln \
		inqwslist.ln meta.ln output.ln rep.ln segattr.ln segment.ln \
		transform.ln utils.ln wsioutattr.ln fxgksvers.ln

OBJECTS		= control.o error.o escapes.o externinit.o gerhnd.o \
		getlunname.o inputevent.o inputinit.o inputmode.o inputreq.o \
		inputsamp.o inqerrlist.o inqgksdesc.o inqgkslist.o \
		inqlun.o inqpixel.o inqseglist.o inqstate.o inqwsdesc.o \
		inqwslist.o meta.o output.o rep.o segattr.o segment.o \
		transform.o utils.o wsioutattr.o fxgksvers.o

LIBMODS		= $(OBJECTS)

SA_OBJS		= externinit.o

all:		$(LIBTYPE)_lib

install:	installed_$(LIBTYPE)_lib

clean:
	rm -f $(LIB_A) $(LIB_SO)* $(LIB_SA)* $(LIB_O) core *.o *.log *.ln \
	    *.trace
	rm -f `echo *.src | sed 's/\.src/.c/g'`

nonsharable_lib:
	@$(MAKE) $(MFLAGS) $(MY_MFLAGS) $(LIB_A)

#
# NB: The placement of macro re-definitions on a make(1) command-line
# is significant and depends on the peculiarities of the particular
# make(1).  In particular, SunOS 4.1 make(1) uses the last
# re-definition, whereas the 4.0.3 make(1) uses the first.
#

#
# Sharable library.  Note that this target might actually create a non-
# sharable library.  In particular, because the SunOS Fortran compilers 
# prior to SunOS 4.1 apparently don't understand the "-pic" option, we make
# a nonsharable-library in that situation.
#
sharable_lib:			fxgksvers.c
	@case "$(OS)" in \
	    aix*) \
		$(MAKE) $(MFLAGS) $(MY_MFLAGS) LIBMODS=$(LIB_O) $(LIB_A);; \
	    sunos_4.1*) \
		relno=$(GET_RELNO); \
		$(MAKE) $(MFLAGS) \
		    COPTS="$(COPTS) -pic" \
		    DESTDIR="$(DESTDIR)" \
		    FC="$(FC)" \
		    FOPTS="$(FOPTS) -pic" \
		    LIBMODE="$(LIBMODE)" \
		    LIBTYPE=sharable \
		    OS="$(OS)" \
		    RANLIB="$(RANLIB)" \
		    RELEASE_NO=$$relno \
		    $(LIB_SA).$$relno $(LIB_SO).$$relno;; \
	    *)	echo 1>&2 "Don't know how to make a shared-library under" \
		    '"$(OS)"'; \
		echo 1>&2 "Making a non-sharable library instead"; \
		$(MAKE) $(MFLAGS) $(MY_MFLAGS)	nonsharable_lib;; \
	esac

#
# NB: Since a previous, incompatible library might exist from a build on
# another platform, we delete it if at first we don't succeed.
#

$(LIB_A):			$(LIBMODS)
	ar ruv $@ $(LIBMODS) || (rm -f $@ && ar rcv $@ $(LIBMODS))
	$(RANLIB) $@

$(LIB_SA).$(RELEASE_NO):	$(SA_OBJS)
	ar ruv $@ $(SA_OBJS) || (rm -f $@ && ar rcv $@ $(SA_OBJS))
	$(RANLIB) $@

#
# SunOS sharable object:
#
$(LIB_SO).$(RELEASE_NO):	$(OBJECTS)
	ld -assert pure-text -o $@ $(OBJECTS)

#
# AIX sharable object:
#
$(LIB_O):	$(OBJECTS)
	/usr/ucb/nm -g $(OBJECTS) | awk '$$(NF-1) == "D" {print $$NF}' \
	    > shlib.exp
	ld -bE:shlib.exp -T512 -H512 -bM:SRE -o $@ $(OBJECTS) \
	    -L../src -L$(LIBDIR) -lxgks $(UDPOSIX_LD) -lxlf -lc
	rm shlib.exp

installed_nonsharable_lib:	nonsharable_lib
	@$(MAKE) $(MFLAGS) $(MY_MFLAGS) $(LIBDIR)/$(LIB_A)

installed_sharable_lib:		sharable_lib
	@case "$(OS)" in \
	    aix*) \
		$(MAKE) $(MFLAGS) $(MY_MFLAGS) $(LIBDIR)/$(LIB_A);; \
	    sunos_4.1*) \
		relno=$(GET_RELNO); \
		$(MAKE) $(MFLAGS) $(MY_MFLAGS) RELEASE_NO=$$relno \
		    $(LIBDIR)/$(LIB_SA).$$relno \
		    $(LIBDIR)/$(LIB_SO).$$relno;; \
	    *)	echo 1>&2 "Don't know how to make a shared-library under" \
		    '"$(OS)"'; \
		echo 1>&2 "Installing non-sharable library instead"; \
		$(MAKE) $(MFLAGS) $(MY_MFLAGS) installed_nonsharable_lib;; \
	esac

#
# Installed library (might be sharable if under AIX):
#
$(LIBDIR)/$(LIB_A):			$(LIB_A)
	$(INST) $(LIB_A) $@
	$(RANLIB) $@

#
# Installed, sharable-libraries under SunOS:
#
$(LIBDIR)/$(LIB_SA).$(RELEASE_NO):	$(LIB_SA).$(RELEASE_NO)
	$(INST) $(LIB_SA).$(RELEASE_NO) $@
	$(RANLIB) $@
$(LIBDIR)/$(LIB_SO).$(RELEASE_NO):	$(LIB_SO).$(RELEASE_NO)
	$(INST) $(LIB_SO).$(RELEASE_NO) $@

.SUFFIXES:	.o .ln .c .src

#
# The following implicit rule allows the user to conveniently set the
# DEFINES macro.
#
.c.o:
	$(CC) $(CFLAGS) -DOS_`echo $(OS) | sed 's/_.*//'` -c $<

.c.ln:
	lint -nuz $(CPPOPTS) -DOS_`echo $(OS) | sed 's/_.*//'` \
	    -c $< -lansic -lposix 2>&1

.src.c:
	$(FORTC) $< > $@

.src.o:
	$(FORTC) $< > $*.c
	$(CC) $(CFLAGS) -DOS_`echo $(OS) | sed 's/_.*//'` -c $*.c
	rm $*.c

lint:		$(LNS)
	lint -nuz -o fxgks $(LNS) ../src/llib-lxgks.ln 2>&1

tags:		$(CSRCS)
	ctags -t $(CSRCS)

saber:		bug.o
	#setopt ansi
	#setopt ccargs $(CFLAGS)
	#setopt load_flags $(CFLAGS)
	#unload all
	#load -C $(CFLAGS) bug.o -L. -lfxgks \
	    ../src/*.c \
	    -lX11 -lm /usr/5lib/libc.a

bug.o:		bug.f
	$(FC) $(FFLAGS) -c bug.f

bug:		bug.f
#	$(FC) $(FFLAGS) -o $@ bug.f -L. -lfxgks -L../src -lxgks -lX11 -lm
	$(FC) $(FFLAGS) -o $@ bug.f -L$(LIBDIR) -lfxgks \
	    $(UDPOSIX_LD) -L$(LIBDIR) -lxgks -lX11 -lm

control.o control.ln: ../src/xgks.h
control.o control.ln: ./fortmac.h
control.o control.ln: ./fortxgks.h
control.o control.ln: control.c
error.o error.ln: ../src/xgks.h
error.o error.ln: ./fortmac.h
error.o error.ln: ./fortxgks.h
error.o error.ln: error.c
escapes.o escapes.ln: ../src/xgks.h
escapes.o escapes.ln: ./fortmac.h
escapes.o escapes.ln: ./fortxgks.h
escapes.o escapes.ln: escapes.c
gerhnd.o gerhnd.ln: ../src/xgks.h
gerhnd.o gerhnd.ln: ./fortmac.h
gerhnd.o gerhnd.ln: ./fortxgks.h
gerhnd.o gerhnd.ln: gerhnd.c
inputevent.o inputevent.ln: ../src/xgks.h
inputevent.o inputevent.ln: ./fortmac.h
inputevent.o inputevent.ln: ./fortxgks.h
inputevent.o inputevent.ln: inputevent.c
inputinit.o inputinit.ln: ../src/xgks.h
inputinit.o inputinit.ln: ./fortmac.h
inputinit.o inputinit.ln: ./fortxgks.h
inputinit.o inputinit.ln: ./pdrutils.h
inputinit.o inputinit.ln: inputinit.c
inputmode.o inputmode.ln: ../src/xgks.h
inputmode.o inputmode.ln: ./fortmac.h
inputmode.o inputmode.ln: ./fortxgks.h
inputmode.o inputmode.ln: inputmode.c
inputreq.o inputreq.ln: ../src/xgks.h
inputreq.o inputreq.ln: ./fortmac.h
inputreq.o inputreq.ln: ./fortxgks.h
inputreq.o inputreq.ln: inputreq.c
inputsamp.o inputsamp.ln: ../src/xgks.h
inputsamp.o inputsamp.ln: ./fortmac.h
inputsamp.o inputsamp.ln: ./fortxgks.h
inputsamp.o inputsamp.ln: inputsamp.c
inqerrlist.o inqerrlist.ln: ../src/xgks.h
inqerrlist.o inqerrlist.ln: ./fortmac.h
inqerrlist.o inqerrlist.ln: ./fortxgks.h
inqerrlist.o inqerrlist.ln: inqerrlist.c
inqgksdesc.o inqgksdesc.ln: ../src/xgks.h
inqgksdesc.o inqgksdesc.ln: ./fortmac.h
inqgksdesc.o inqgksdesc.ln: ./fortxgks.h
inqgksdesc.o inqgksdesc.ln: inqgksdesc.c
inqgkslist.o inqgkslist.ln: ../src/xgks.h
inqgkslist.o inqgkslist.ln: ./fortmac.h
inqgkslist.o inqgkslist.ln: ./fortxgks.h
inqgkslist.o inqgkslist.ln: inqgkslist.c
inqlun.o inqlun.ln: inqlun.f
inqpixel.o inqpixel.ln: ../src/xgks.h
inqpixel.o inqpixel.ln: ./fortmac.h
inqpixel.o inqpixel.ln: ./fortxgks.h
inqpixel.o inqpixel.ln: inqpixel.c
inqseglist.o inqseglist.ln: ../src/xgks.h
inqseglist.o inqseglist.ln: ./fortmac.h
inqseglist.o inqseglist.ln: ./fortxgks.h
inqseglist.o inqseglist.ln: inqseglist.c
inqstate.o inqstate.ln: ../src/xgks.h
inqstate.o inqstate.ln: ./fortmac.h
inqstate.o inqstate.ln: ./fortxgks.h
inqstate.o inqstate.ln: inqstate.c
inqwsdesc.o inqwsdesc.ln: ../src/xgks.h
inqwsdesc.o inqwsdesc.ln: ./fortmac.h
inqwsdesc.o inqwsdesc.ln: ./fortxgks.h
inqwsdesc.o inqwsdesc.ln: inqwsdesc.c
inqwslist.o inqwslist.ln: ../src/xgks.h
inqwslist.o inqwslist.ln: ./fortmac.h
inqwslist.o inqwslist.ln: ./fortxgks.h
inqwslist.o inqwslist.ln: inqwslist.c
meta.o meta.ln: ../src/xgks.h
meta.o meta.ln: ./fortmac.h
meta.o meta.ln: ./fortxgks.h
meta.o meta.ln: meta.c
output.o output.ln: ../src/xgks.h
output.o output.ln: ./fortmac.h
output.o output.ln: ./fortxgks.h
output.o output.ln: output.c
rep.o rep.ln: ../src/xgks.h
rep.o rep.ln: ./fortmac.h
rep.o rep.ln: ./fortxgks.h
rep.o rep.ln: rep.c
segattr.o segattr.ln: ../src/xgks.h
segattr.o segattr.ln: ./fortmac.h
segattr.o segattr.ln: ./fortxgks.h
segattr.o segattr.ln: segattr.c
segment.o segment.ln: ../src/xgks.h
segment.o segment.ln: ./fortmac.h
segment.o segment.ln: ./fortxgks.h
segment.o segment.ln: segment.c
transform.o transform.ln: ../src/xgks.h
transform.o transform.ln: ./fortmac.h
transform.o transform.ln: ./fortxgks.h
transform.o transform.ln: transform.c
utils.o utils.ln: ../src/xgks.h
utils.o utils.ln: ./fortmac.h
utils.o utils.ln: ./fortxgks.h
utils.o utils.ln: ./pdrutils.h
utils.o utils.ln: utils.c
wsioutattr.o wsioutattr.ln: ../src/xgks.h
wsioutattr.o wsioutattr.ln: ./fortmac.h
wsioutattr.o wsioutattr.ln: ./fortxgks.h
wsioutattr.o wsioutattr.ln: wsioutattr.c
