/*
 * Copyright (c) 1998 Sandia Corporation. Under the terms of Contract
 * DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government
 * retains certain rights in this software.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 * 
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 * 
 *     * Redistributions in binary form must reproduce the above
 *       copyright notice, this list of conditions and the following
 *       disclaimer in the documentation and/or other materials provided
 *       with the distribution.  
 * 
 *     * Neither the name of Sandia Corporation nor the names of its
 *       contributors may be used to endorse or promote products derived
 *       from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 * 
 */
XCOMM $Id: Imakefile,v 1.15 2008/01/24 19:43:41 gdsjaar Exp $
XCOMM Imakefile for Nemesis libraries
/* Building Nemesis libraries for installation
 * % accmkmf
 * % make Makefiles
 * % make all
 * % make install
 *
 * Building Nemesis libraries for debugging
 * % accmkmf
 * % make Makefiles
 * % make DEBUG=-g
 *
 */

#define IHaveSubdirs

#define PassDebugFlags	"DEBUG=$(DEBUG)" \
	                "CDEBUGFLAGS=$(CDEBUGFLAGS)" \
	                "CXXDEBUGFLAGS=$(CXXDEBUGFLAGS)" \
			"F90DEBUGFLAGS=$(F90DEBUGFLAGS)" \
			"F77DEBUGFLAGS=$(F77DEBUGFLAGS)"

#define ExtraOptions "CCOPTIONS=$(CCOPTIONS)"

#ifndef BuildSharedExodusLibrary
#define BuildSharedExodusLibrary NO
#endif

#define DoNormalLib YES
#define DoSharedLib BuildSharedExodusLibrary
#define LibName nemesis
SOREV = 4
#define SoRev SOREV

#ifdef PARALLEL
CCOPTIONS  = ParallelCCOptions
F77OPTIONS = ParallelF77Options
LIBDIR     = $(PLIBDIR)
#endif

DEFINES = $(PICFLAGS)
SUBDIRS = forbind

INCLIST = ne_nemesisI.h ne_nemesisI_int.h

SRCS = 	nemesis_wrapper.c

OBJS = ${SRCS:.c=.o}

REQUIREDLIBS = -L$(SHLIBDIR) $(EXOIIV2C) $(NETCDF) 
LIBS = $(NETCDF) $(EXOIIV2C)

#include <Library.tmpl>

#if Build64BitAccess == YES
AllTarget(libnemesis.a libnemIf.a libnemIf32.a)
#else
AllTarget(libnemesis.a libnemIf.a)
#endif

InstallIncludeList(makeincludes,$(INCLIST),$(INCDIR))
InstallIncludeList(install,$(INCLIST),$(INCDIR))

/* Directory for nemesis c library */
NormalLibraryTarget(nemesis,$(OBJS))

/* Directory for nemesis fortran wrappers */
NamedTargetSubdirs(libnemIf.a,forbind,"making nemIf ",PassDebugFlags ExtraOptions,libnemIf.a)

#if Build64BitAccess == YES
NamedTargetSubdirs(libnemIf32.a,forbind,"making nemIf32 ",PassDebugFlags ExtraOptions,libnemIf32.a)
#endif

InstallLibrary(nemesis,$(LIBDIR))
InstallLibraryAlias(nemesis,nemIc,$(LIBDIR))
InstallLibrary(nemIf,$(LIBDIR))

#if Build64BitAccess == YES
InstallLibrary(nemIf32,$(LIBDIR))
#endif

#if Parallel
InstallParallelLibrary(nemesis,$(PLIBDIR))
InstallParallelLibrary(nemIf,$(PLIBDIR))

#if Build64BitAccess == YES
InstallParallelLibrary(nemIf32,$(PLIBDIR))
#endif

#endif


CTESTLIBS = $(EXOIIV2C) $(NETCDF) -lm
FTESTLIBS = $(EXOIIV2FOR) $(EXOIIV2C) $(NETCDF) -lm

test: libnemesis.a libnemIf.a ne_ctest_wrap.c forbind/ne_ftest.F
	$(CC) -c $(CFLAGS) ne_ctest_wrap.c
	$(CC) $(LDOPTIONS) -o ne_ctest_wrap ne_ctest_wrap.o libnemesis.a $(LIBPATH) $(CTESTLIBS)
	$(FC) -c $(FFLAGS) $(STD_DEFINES) -I./forbind forbind/ne_ftest.F
	$(FC) $(LDOPTIONS) -o ne_ftest ne_ftest.o libnemIf.a $(LIBPATH) $(FTESTLIBS)

ExtraStuffToClean(ne_ctest_wrap ne_ftest ne_test.exoII  ne_test.nemI)

$(OBJS): ne_nemesisI.h

DependTarget()
LibraryObjectRule()
