# -*-Mode: indented-text;-*-
# Makefile:    cdms makefile
#
# Copyright:   1996, Regents of the University of California
#	       This software may not be distributed to others without
#	       permission of the author.
#
# Author:      Bob Drach, Lawrence Livermore National Laboratory
#              drach@llnl.gov
#
# Version:     $Id$
#
# Revision History:
#
# $Log: Makefile.in,v $
# Revision 1.4  1997/11/10  19:22:11  drach
# - Added cuvargets to cdunif, cdSlabRead to cdms
#
# Revision 1.3  1997/09/26  21:44:29  drach
# Added HDF
#
# Revision 1.2  1996/10/31  19:09:54  drach
# Added drscdf.h to distribution
#
# Revision 1.1  1996/09/09  18:25:59  drach
# - Integrated with configuration scripts
# - Recursive make
#
#
# Note: Makefile is generated from Makefile.in by top level configure
#

# Install prefix for architecture-independent files
prefix=         /usr/local

# Install prefix for architecture-dependent files
exec_prefix=    ${prefix}

# Expanded directories
BINDIR=$(exec_prefix)/bin
INCLUDEDIR=$(prefix)/include
LIBDIR=$(exec_prefix)/lib
MANDIR=$(prefix)/man
PARMDIR=$(prefix)/lib/lats

CC = cc
CFLAGS = -I../../include -fPIC $(DEBUG) -Dgrads -I 
CPPFLAGS =  -Dnetcdf -DBYTESWAP -DpgiFortran
DEBUG = -O
DEFS = -DPACKAGE_NAME=\"\" -DPACKAGE_TARNAME=\"\" -DPACKAGE_VERSION=\"\" -DPACKAGE_STRING=\"\" -DPACKAGE_BUGREPORT=\"\" -DOS_NAME=Linux -DOS_MAJOR=2 -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1
FC = gfortran
FFLAGS = -I../../include  -I/usr/include $(DEBUG)
INSTALL = /usr/bin/install -c
INSTALL_PROGRAM = /usr/bin/install -c
LDFLAGS = -L../../../lib -lcdms -L/usr/lib64 -lnetcdf -L/usr/lib64 -lhdf5_hl -lhdf5 -lm -lz   -L/usr/lib64 -lnetcdf -L/usr/lib64 -lhdf5_hl -lhdf5 -lm -lz 
OS = linux
RANLIB = ranlib

# Shell to run make subcommands
SHELL = /bin/sh

# Do not change values below this line
#
LIBRARY		= libcdms.a

# all:		cddrs cdunif db_util cddrstest cduniftest 
all:		cddrs cdunif db_util cduniftest

debug:		cddrs_debug cdunif_debug db_util_debug cddrstest_debug cduniftest_debug 

cddrs:
	cd src/cddrs; $(MAKE)

cdunif:
	cd src/cdunif; $(MAKE)

cdms:
	cd src/api; $(MAKE)

cddrstest:
	cd src/cddrs/test; $(MAKE)

cduniftest:
	cd src/cdunif/test; $(MAKE)

cdmstest:
	cd src/api/test; $(MAKE)

db_util:
	cd src/db_util; $(MAKE)

cddrs_debug:
	cd src/cddrs; $(MAKE) DEBUG=-g

cdunif_debug:
	cd src/cdunif; $(MAKE) DEBUG=-g

cdms_debug:
	cd src/api; $(MAKE) DEBUG=-g

cddrstest_debug:
	cd src/cddrs/test; $(MAKE) DEBUG=-g

cduniftest_debug:
	cd src/cdunif/test; $(MAKE) DEBUG=-g

cdmstest_debug:
	cd src/api/test; $(MAKE) DEBUG=-g

db_util_debug:
	cd src/db_util; $(MAKE) DEBUG=-g

install:	bininstall libinstall maninstall

bininstall:
	$(INSTALL_PROGRAM) -m 755 src/cdunif/test/cudump $(BINDIR)/cudump
	$(INSTALL_PROGRAM) -m 755 src/cdunif/test/cuget $(BINDIR)/cuget
	$(INSTALL_PROGRAM) -m 755 src/cdunif/test/cdfile $(BINDIR)/cdfile
	# $(INSTALL_PROGRAM) -m 755 src/python/cdscan $(BINDIR)/cdscan
	$(INSTALL_PROGRAM) -m 755 src/python/cddump $(BINDIR)/cddump
	$(INSTALL_PROGRAM) -m 755 src/python/cdimport $(BINDIR)/cdimport

libinstall:	
	$(INSTALL_PROGRAM) -m 644 lib/$(LIBRARY) $(LIBDIR)/$(LIBRARY)
	(cd $(LIBDIR); $(RANLIB) $(LIBRARY))
	$(INSTALL_PROGRAM) -m 644 include/cdms.h $(INCLUDEDIR)/cdms.h
	$(INSTALL_PROGRAM) -m 644 include/cdms.inc $(INCLUDEDIR)/cdms.inc
	$(INSTALL_PROGRAM) -m 644 include/cddrs.h $(INCLUDEDIR)/cddrs.h
	$(INSTALL_PROGRAM) -m 644 include/cdunif.h $(INCLUDEDIR)/cdunif.h
	$(INSTALL_PROGRAM) -m 644 include/fcddrs.h $(INCLUDEDIR)/fcddrs.h
	$(INSTALL_PROGRAM) -m 644 include/drscdf.h $(INCLUDEDIR)/drscdf.h

maninstall:
	$(INSTALL_PROGRAM) -m 644 man/man3/cdtime.3 $(MANDIR)/man3/cdtime.3 
	$(INSTALL_PROGRAM) -m 644 man/man3/fcddrs.3 $(MANDIR)/man3/fcddrs.3 
	$(INSTALL_PROGRAM) -m 644 man/man3/cdunif.3 $(MANDIR)/man3/cdunif.3 
	$(INSTALL_PROGRAM) -m 644 man/man3/cddrs.3 $(MANDIR)/man3/cddrs.3 
	$(INSTALL_PROGRAM) -m 644 man/man3/cdms.3 $(MANDIR)/man3/cdms.3 

distinstall:
	$(INSTALL_PROGRAM) -m 644 $(LIBRARY) $(LIBDIR)/$(LIBRARY)
	(cd $(LIBDIR); $(RANLIB) $(LIBRARY))
	$(INSTALL_PROGRAM) -m 644 cdms.h $(INCLUDEDIR)/cdms.h
	$(INSTALL_PROGRAM) -m 644 cdms.inc $(INCLUDEDIR)/cdms.inc
	$(INSTALL_PROGRAM) -m 644 cddrs.h $(INCLUDEDIR)/cddrs.h
	$(INSTALL_PROGRAM) -m 644 cdunif.h $(INCLUDEDIR)/cdunif.h
	$(INSTALL_PROGRAM) -m 644 fcddrs.h $(INCLUDEDIR)/fcddrs.h
	$(INSTALL_PROGRAM) -m 644 drscdf.h $(INCLUDEDIR)/drscdf.h
	$(INSTALL_PROGRAM) -m 644 cdtime.3 $(MANDIR)/man3/cdtime.3 
	$(INSTALL_PROGRAM) -m 644 fcddrs.3 $(MANDIR)/man3/fcddrs.3 
	$(INSTALL_PROGRAM) -m 644 cdunif.3 $(MANDIR)/man3/cdunif.3 
	$(INSTALL_PROGRAM) -m 644 cddrs.3 $(MANDIR)/man3/cddrs.3 
	$(INSTALL_PROGRAM) -m 644 cdms.3 $(MANDIR)/man3/cdms.3 
	$(INSTALL_PROGRAM) -m 755 cudump $(BINDIR)/cudump
	$(INSTALL_PROGRAM) -m 755 cuget $(BINDIR)/cuget
	$(INSTALL_PROGRAM) -m 755 cdfile $(BINDIR)/cdfile
	/bin/rm -fr $(BINDIR)/cdimport $(BINDIR)/cddump
	/bin/cp src/python/cdimport $(BINDIR)/cdimport
	# /bin/cp src/python/cdscan $(BINDIR)/cdscan
	/bin/cp src/python/cddump $(BINDIR)/cddump

test:
	cd src/cdunif/test; $(MAKE) test
	cd src/cddrs/test; $(MAKE) test

.SUFFIXES: .F

.c.o:
	$(CC) $(CPPFLAGS) $(DEFS) $(CFLAGS) -c $<

.c:
	case $(OS) in \
	     'aix') \
		    $(CC) $(CPPFLAGS) $(DEFS) $(CFLAGS) -c $< -o $@.o; \
		    $(FC) $(FFLAGS) $@.o -o $@ $(LDFLAGS) $(LIBS); \
		    rm $@.o; \
		    ;; \
	     *) \
		    $(CC) $(CPPFLAGS) $(DEFS) $(CFLAGS) -o $@ $< $(LDFLAGS); \
		    ;; \
	esac

.F:
	case $(OS) in \
	     'aix') \
		    /usr/ccs/lib/cpp -P $(CPPFLAGS) $(CFLAGS) $(DEFS) $< $@.f; \
		    $(FC) $(FFLAGS) $(LDFLAGS) $(LIBS) $@.f -o $@; \
		    rm $@.f; \
		    ;; \
	     *) \
		    $(FC) $(CPPFLAGS) $(INCLUDES) $(DEFS) $(FFLAGS) -o $@ $< $(LDFLAGS) $(LIBS); \
		    ;; \
	esac

clean:
	cd src/cddrs; $(MAKE) clean
	cd src/cddrs/test; $(MAKE) clean
	cd src/cdunif; $(MAKE) clean
	cd src/cdunif/test; $(MAKE) clean
	cd src/db_util; $(MAKE) clean
	cd src/api; $(MAKE) clean
	cd src/api/test; $(MAKE) clean
	cd include; rm -f *.~*~
	rm -f *.~*~

distclean: testclean
	rm -f lib/libcdms.a
	cd src/cddrs; $(MAKE) distclean
	cd src/cdunif; $(MAKE) distclean
	cd src/db_util; $(MAKE) distclean
	cd src/api; $(MAKE) distclean

testclean:
	cd src/cddrs/test; $(MAKE) distclean
	cd src/cdunif/test; $(MAKE) distclean
	cd src/api/test; $(MAKE) distclean
