# $Id: Makefile,v 1.11 1997/08/04 05:36:37 dhb Exp $
# $Log: Makefile,v $
# Revision 1.11  1997/08/04 05:36:37  dhb
# Added CPICOPT="" to environment for netcdf configuration to
# prevent configure from selecting -fpic gode generation option
# with gcc.  It results in link errors for some older Linux systems.
#
# Revision 1.10  1997/08/04 04:22:31  dhb
# Added setting of PATH to env - commands to pass along command path.
# Otherwise env - results in empty PATH.
#
# Revision 1.9  1997/08/03 19:48:51  dhb
# Added missing "env -" to call to netcdf configure.
#
# Revision 1.8  1997/08/03 19:19:10  dhb
# Added env - to call to netcdf configure command which avoids passing
# RANLIB macro value through the environment.  Have to set AR and YACC
# to avoid configure request for these programs.
#
# Revision 1.7  1997/07/31 23:58:59  dhb
# Suppress abnormal exit status from subdir cleans.  Netcdf, for example,
# comes without a Makefile and a clean before configure gives an error.
#
# Revision 1.6  1997/07/31 23:08:20  dhb
# Fixed comment leader from C style to Makefile hash
# ,
#
# Revision 1.5  1997/07/29 23:00:44  venkat
# Used the env command to clean the environment before compiling the
# netcdf library. Also added RCS Id and Log headers

CC = $(CC_IN)
CFLAGS = $(CFLAGS_IN)
CPP = $(CPP_IN)
LD = $(LD_IN)
LDFLAGS = $(LDFLAGS_IN)

INSTALL = $(INSTALL_IN)
RANLIB = $(RANLIB_IN)

# ===========================================
# File-format specific source-code locations 
# ===========================================

# 1. Netcdf-2.4.3
#  -----------
# Passing this thro from top-level makefiles would require an unset
# We just define it here instead

NCDFDIR = netcdf-2.4.3

# ========================================
# Generic file-format macro definitions 
# ========================================

FFDIRS = \
	$(NCDFDIR)/src 

FFINCLUDEDIR = \
	$(NCDFDIR)/src/libsrc

FFLIBS = \
	$(NCDFDIR)/src/libsrc/libnetcdf.a

# ========================================


OBJECTS = \
	netcdf_diskio.o \
	netcdf_variable.o \
	netcdf_metadata.o \
	netcdf_copyright.o \
	absff_metadata.o \
	absff_variable.o \
	absff_utilfunc.o


default: fflib.o


fflib.o: $(FFLIBS) $(OBJECTS) 
	$(LD) $(LDFLAGS) -r -o $@ $(OBJECTS) 

$(FFLIBS): fflibs

fflibs: 
	@(for subdir in $(FFDIRS); do echo cd $$subdir; cd $$subdir; env - PATH=$$PATH CPICOPT="" CXX="" FC="" CC="$(CC)" CFLAGS="$(CFLAGS)" CPP="$(CPP)" AR=ar YACC="$(YACC_IN)" ./configure; env - PATH=$$PATH make all; done)
	-(touch fflibs)

clean:
	@-(for subdir in $(FFDIRS); do echo cd $$subdir; cd $$subdir; make clean; done)
	-(rm -rf *.a *.o fflibs) 

install:
	cp $(FFLIBS) $(INSTALL)/lib	
	$(RANLIB) $(INSTALL)/lib/libnetcdf.a

#################################

# Suffix Rules

################################

.c.o:
	$(CC) $(CFLAGS) -I$(FFINCLUDEDIR) $< -c
