# $Id: Makefile,v 1.35 1992/01/02 20:57:35 steve Exp $
#
#	Makefile for the Unidata LDM and related software


# What products to build.  Valid values for the following macros are "yes"
# and "no".  From the Unidata SDM workshop, you should know what products
# you want.  If you can't find your notes, then see the README file for 
# product descriptions.
#
WANT_NETCDF	= "yes"#	Network Common Data Form for network-
#				transparent scientific, data storage and 
#				access.
WANT_LDM	= "yes"#	Unidata Local Data Manager.  Requires 
#				WANT_NETCDF == "yes".
WANT_XGKS	= "yes"#	GKS interface-library to the X Window System.
#				required).
WANT_MCIDAS	= "yes"#	Bridging software for accessing McIDAS data.


# Anticipated, changeable macros (others won't be passed to recursive makes):
# Change the following as appropriate.
#
#	Compilation options (e.g. "-g", "-O"):
#
COPTS	= -O#	User-selectable options for $(CC) (e.g. "-g", "-DDEBUG")
#		On DECstations, if optimization is requested (-O) then the
#		option "-Olimit 1000" should also be specified due to the
#		large number of blocks in some files.
FOPTS	= -O#	User-selectable options for $(FC) (e.g. "-g", "-DDEBUG")

#	Root of the installation.  This directory is assumed to contain 
#	"bin", "etc", "include", "lib", and "man" subdirectories
#
DESTDIR	= /usr/local/ldm

#	Unix, chapter 1 utilities:
#
AR	= ar#			Archiver.  Unset => make(1) default (which 
#				AIX 3.1 make(1) doesn't define).
#CC	=#			C compiler.  Unset => make(1) default.
#				    SunOS 4.1.1 /usr/5bin/cc fails on 
#				    `netcdf/src/array.c'.
#FC	=#			Fortran compiler.  Unset => make(1) default.
#				If your platform doesn't have a Fortran 
#				compiler, then set this macro to the empty
#				string.
INSTALL	= install#		Must understand "-c" (copy) and "-m" (mode) 
#				options.  For AIX, set to /usr/ucb/install 
#				(rather than /usr/bin/install).
RANLIB	= ranlib#		AIX's /usr/bin/ranlib is OK.
SHELL	= /bin/sh#		Which shell make(1) will use.  Unset => make(1)
#				default.
TBL	= tbl#			A tbl(1)-like command
TROFF	= ptroff#		A troff(1)-like command.
CATMAN	= /usr/etc/catman#	A catman(8)-like command.  Unset => doesn't
#				exist => don't touch `$(DESTDIR)/man/whatis'.
#				This should be undefined for ULTRIX and
#				AIX platforms.

#	Installed-file protection-modes:
#
BINMODE	= 775#		For executable programs
INCMODE	= 664#		For C header-files
LIBMODE	= 664#		For installed libraries
MANMODE	= 664#		For man(1)ual pages

#	Type of libraries to create and/or use.  Valid values are:
#
#	    nonsharable		for non-sharable libraries
#	    sharable		for sharable libraries
#
#	You may leave this macro defined as "sharable".  If the operating-
#	system doesn't support sharable libraries, then the Makefiles will 
#	create and use only nonsharable ones.
#
LIBTYPE	= sharable

#	Type of operating-system.  Valid values are:
#
#	    aix_3.1
#	    sunos_4.0.3
#	    sunos_4.1
#	    sunos_4.1.1
#	    ultrix_3.5
#	    ultrix_4.0
#	    ultrix_4.1
#	    ultrix_4.2
#
OS	= sunos_4.1.1

#	netCDF configuration:
#
WANT_FORTRAN_NETCDF	= yes#	Include Fortran interface in netCDF library? 
#				    `yes' or `no'.
XDR_INC	=/usr/include/rpc#	Include-directory containing <xdr.h>.
#				Unset => Unidata's XDR is used.  Due to a bug
#				in the XDR implementation, you should use
#				Unidata's XDR on DECstations.
XDR_LD	=#			ld(1)-style specification of XDR library
#				    Unset && XDR_INC also unset => Unidata's
#				    XDR used; else $(XDR_LD) or default
#				    C-library used.

#	LDM configuration: If you do not plan to capture and decode NPS data,
#	then undefine the following macros for a significantly smaller LDM
#	server.
#
GRIB_DEF	= -DGRIB_DECODE
LIBUNITS	= -ludape
SUNLINK_DEF	= -DSUNLINK=2

#	The following is the ld(1) specification for the X11 library.  This
#	particular definition expands to "-L$OPENWINHOME/lib -lX11" iff the 
#	OPENWINHOME environment variable is set, and to "-L/usr/lib -lX11" 
#	otherwise.
#
X11_LIB	= -L$${OPENWINHOME-/usr/lib}$${OPENWINHOME+/lib} -lX11

# End of anticipated macros

BINDIR		= $(DESTDIR)/bin
ETCDIR		= $(DESTDIR)/etc
INCDIR		= $(DESTDIR)/include
LIBDIR		= $(DESTDIR)/lib
MANDIR		= $(DESTDIR)/man

# These are the installation directories we will need:
INSTALL_DIRS	= $(BINDIR) $(ETCDIR) $(INCDIR) $(INCDIR)/udposix \
		    $(LIBDIR) $(LIBDIR)/fortc \
		    $(MANDIR) $(MANDIR)/man1 $(MANDIR)/man3

# These are the libraries we will need:
LIBREGEXP	= $(LIBDIR)/libregexp.a
LIBGDBM		= $(LIBDIR)/libgdbm.a
LIBNETCDF	= $(LIBDIR)/libnetcdf.a
LIBUDAPE	= $(LIBDIR)/libudape.a

ORIG_MFLAGS	= 			\
		DESTDIR="$(DESTDIR)"	\
		CFLAGS="$(COPTS)"	\
		BINDIR="$(BINDIR)"	\
		GRIB_DEF="$(GRIB_DEF)"	\
		LIBDIR="$(LIBDIR)"	\
		LIBUNITS="$(LIBUNITS)"	\
		SHELL="$(SHELL)"	\
		SUNLINK_DEF="$(SUNLINK_DEF)"

NEW_MFLAGS	= 			\
		AR="$(AR)" 		\
		BINMODE="$(BINMODE)"	\
		CC="$(CC)"		\
		COPTS="$(COPTS)"	\
		DESTDIR="$(DESTDIR)"	\
		FC="$(FC)"		\
		FOPTS="$(FOPTS)"	\
		WANT_XGKS="$(WANT_XGKS)"\
		INCMODE="$(INCMODE)"	\
		INSTALL="$(INSTALL)"	\
		LIBMODE="$(LIBMODE)"	\
		LIBTYPE="$(LIBTYPE)"	\
		MANMODE="$(MANMODE)"	\
		OS="$(OS)"		\
		RANLIB="$(RANLIB)"	\
		SHELL="$(SHELL)"	\
		WANT_FORTRAN_NETCDF="$(WANT_FORTRAN_NETCDF)"	\
		TBL="$(TBL)"		\
		TROFF="$(TROFF)"	\
		X11_LIB="$(X11_LIB)"

PROGS = $(BINDIR)/rpc.ldmd $(BINDIR)/ingestd $(BINDIR)/feedtest $(BINDIR)/ldm

# The following target builds and installs everything requested.
#
default:	install

#
# NB: The LDM needs the netCDF package to be installed.
#
all:
	@if [ $(WANT_NETCDF) = "yes" ]; then \
	    $(MAKE) $(MFLAGS) $(NEW_MFLAGS)  netcdf/install; \
	else true; fi
	@if [ $(WANT_LDM) = "yes" ]; then \
	    $(MAKE) $(MFLAGS) $(ORIG_MFLAGS) ldm/all; \
	else true; fi
	@if [ $(WANT_XGKS) = "yes" ]; then \
	    $(MAKE) $(MFLAGS) $(NEW_MFLAGS)  xgks/all; \
	else true; fi
	@if [ $(WANT_MCIDAS) = "yes" ]; then \
	    $(MAKE) $(MFLAGS) $(NEW_MFLAGS)  mcidas/all; \
	else true; fi
	$(MAKE) $(MFLAGS) $(NEW_MFLAGS) whatis

install:
	@if [ $(WANT_NETCDF) = "yes" ]; then \
	    $(MAKE) $(MFLAGS) $(NEW_MFLAGS)  netcdf/install; \
	else true; fi
	@if [ $(WANT_LDM) = "yes" ]; then \
	    $(MAKE) $(MFLAGS) $(ORIG_MFLAGS) ldm/install; \
	else true; fi
	@if [ $(WANT_XGKS) = "yes" ]; then \
	    $(MAKE) $(MFLAGS) $(NEW_MFLAGS)  xgks/install; \
	else true; fi
	@if [ $(WANT_MCIDAS) = "yes" ]; then \
	    $(MAKE) $(MFLAGS) $(NEW_MFLAGS)  mcidas/install; \
	else true; fi
	$(MAKE) $(MFLAGS) $(NEW_MFLAGS) whatis

clean:
	@if [ $(WANT_NETCDF) = "yes" ]; then \
	    $(MAKE) $(MFLAGS) $(NEW_MFLAGS)  netcdf/clean; \
	else true; fi
	@if [ $(WANT_LDM) = "yes" ]; then \
	    $(MAKE) $(MFLAGS) $(ORIG_MFLAGS) ldm/clean; \
	else true; fi
	@if [ $(WANT_XGKS) = "yes" ]; then \
	    $(MAKE) $(MFLAGS) $(NEW_MFLAGS)  xgks/clean; \
	else true; fi
	@if [ $(WANT_MCIDAS) = "yes" ]; then \
	    $(MAKE) $(MFLAGS) $(NEW_MFLAGS)  mcidas/clean; \
	else true; fi

#
# NB: the LDM needs the regexp, gdbm, and netcdf libraries and possibly
# the UDAPE library installed.
#
netcdf/all:
	@$(MAKE) $(MFLAGS) $(NEW_MFLAGS)  GOAL=all _netcdf
ldm/all:	regexp/install gdbm/install $(LIBNETCDF)
	@if [ "$(GRIB_DEF)" = "-DGRIB_DECODE" ]; then \
	    $(MAKE) $(MFLAGS) $(NEW_MFLAGS) $(LIBUDAPE); \
	else true; fi
	@$(MAKE) $(MFLAGS) $(ORIG_MFLAGS) GOAL=all _ldm
xgks/all:	$(LIBUDAPE)
	@$(MAKE) $(MFLAGS) $(NEW_MFLAGS)  GOAL=all _xgks
mcidas/all:
	@$(MAKE) $(MFLAGS) $(NEW_MFLAGS)  GOAL=all _mcidas

#
# NB: The regexp and gdbm libraries are built *and installed* by their
# respective "all" targets.
#
regexp/install:	$(INSTALL_DIRS)
	@$(MAKE) $(MFLAGS) $(ORIG_MFLAGS) GOAL=all     _regexp
gdbm/install:	$(INSTALL_DIRS)
	@$(MAKE) $(MFLAGS) $(ORIG_MFLAGS) GOAL=all     _gdbm
netcdf/install:	netcdf/all $(INSTALL_DIRS)
	@$(MAKE) $(MFLAGS) $(NEW_MFLAGS)  GOAL=install _netcdf
ldm/install:	ldm/all	$(INSTALL_DIRS)
	@$(MAKE) $(MFLAGS) $(ORIG_MFLAGS) GOAL=install _ldm
xgks/install:	xgks/all $(INSTALL_DIRS)
	@$(MAKE) $(MFLAGS) $(NEW_MFLAGS)  GOAL=install _xgks
mcidas/install:	mcidas/all $(INSTALL_DIRS)
	@$(MAKE) $(MFLAGS) $(NEW_MFLAGS)  GOAL=install _mcidas

regexp/clean:
	@$(MAKE) $(MFLAGS) $(ORIG_MFLAGS) GOAL=all   _regexp
gdbm/clean:
	@$(MAKE) $(MFLAGS) $(ORIG_MFLAGS) GOAL=all   _gdbm
netcdf/clean:
	@$(MAKE) $(MFLAGS) $(NEW_MFLAGS)  GOAL=clean _netcdf
ldm/clean:
	@$(MAKE) $(MFLAGS) $(ORIG_MFLAGS) GOAL=clean _ldm
xgks/clean:
	@$(MAKE) $(MFLAGS) $(NEW_MFLAGS)  GOAL=clean _xgks
mcidas/clean:
	@$(MAKE) $(MFLAGS) $(NEW_MFLAGS)  GOAL=clean _mcidas

whatis:
	@if [ -f "$(CATMAN)" ]; then \
	    $(CATMAN) -M $(MANDIR) -w; \
	else true; fi

$(PROGS):	libraries
	@$(MAKE) $(MFLAGS) $(ORIG_MFLAGS) GOAL=install _ldm

libraries:	$(LIBREGEXP) $(LIBGDBM) $(LIBNETCDF)

$(LIBREGEXP):	$(INSTALL_DIRS)
	@$(MAKE) $(MFLAGS) $(ORIG_MFLAGS) GOAL=$@      _regexp

$(LIBGDBM):	$(INSTALL_DIRS)
	@$(MAKE) $(MFLAGS) $(ORIG_MFLAGS) GOAL=$@      _gdbm

$(LIBNETCDF):	$(INSTALL_DIRS)
	@$(MAKE) $(MFLAGS) $(NEW_MFLAGS)  GOAL=install _netcdf

$(INSTALL_DIRS):
	mkdir $@

_ldm:
	@echo 'Making "$(GOAL)" in directory ldm3/'
	@cd ldm3; \
	    $(MAKE) $(MFLAGS) $(ORIG_MFLAGS) OS=$(OS) $(GOAL)

_xgks:
	@echo 'Making "$(GOAL)" in directory xgks/'
	@cd xgks; \
	    $(MAKE) $(MFLAGS) $(NEW_MFLAGS) $(GOAL)

_mcidas:
	@echo 'Making "$(GOAL)" in directory mcidas/'
	@cd mcidas; \
	    $(MAKE) $(MFLAGS) $(NEW_MFLAGS) $(GOAL)

_netcdf:
	@echo 'Making "$(GOAL)" in directory netcdf/'
	@cd netcdf; \
	    $(MAKE) $(MFLAGS) $(NEW_MFLAGS) $(GOAL)

#
# NB: The Unidata-supplied, minimal makefile "lib.mk" is used rather than
# the original, third-party Makefile.
#
_gdbm:
	@echo 'Making "$(GOAL)" in directory gdbm/'
	@cd gdbm; \
	    $(MAKE) -f lib.mk $(MFLAGS) $(ORIG_MFLAGS) $(GOAL)

#
# NB: The Unidata-supplied, minimal makefile "lib.mk" is used rather than
# the original, third-party Makefile.
#
_regexp:
	@echo 'Making "$(GOAL)" in directory regexp/'
	@cd regexp; \
	    $(MAKE) -f lib.mk $(MFLAGS) $(ORIG_MFLAGS) $(GOAL)
