##############################################################################
# Zoltan Library for Parallel Applications                                   #
# Copyright (c) 2000,2001,2002, Sandia National Laboratories.                #
# For more info, see the README file in the top-level Zoltan directory.      # 
##############################################################################
##############################################################################
# CVS File Information
#    $RCSfile: makefile_sub,v $
#    $Author: kddevin $
#    $Date: 2008/09/22 18:20:30 $
#    $Revision: 1.1.2.1 $
##############################################################################

#
# Dynamic Load Balance Library Makefile for machine dependent directories
#

include $(ZOLTAN_CONFIG)

ifndef DCC
DCC=$(CC)
endif

ifndef DEPS
DEPS=-M
endif

include $(OBJ_FILES:.o=.d)

DEPENDENCIES := $(subst .o,.d,$(subst .O,.d, $(MAIN_OBJ)))

ifdef MAIN_OBJ
include $(DEPENDENCIES)
endif

# On Solaris machines, the C++ include directories may contain .cc files
# with the same name as headers (i.e. string.cc and string).  make will
# try to build the .cc file if it's newer than the header.
#
%:	%.cc
	@echo "IGNORE attempt to compile $< "
#
#########################################################################

%.o:	%.cpp
	@echo "Compiling $<..."
	@$(CC) $(DEFS) -c $<

%.o:	%.c
	@echo "Compiling $<..."
	@$(CC) $(DEFS) -c $<

%.O:	%.c
	@echo "$< -> $@ (C++), to avoid conflict with C object"
	@$(CC) $(DEFS) -o $@ -c $<


%.d:	%.cpp
	@echo "(Re)Building dependency for $<..."
	@$(SHELL) -ec '$(DCC) $(DEPS) $(DEFS) $< | sed '\''s/$*\.o/& $@/g'\'' > $@'

%.d:	%.c
	@echo "(Re)Building dependency for $<..."
	@$(SHELL) -ec '$(DCC) $(DEPS) $(DEFS) $< | sed '\''s/$*\.o/& $@/g'\'' > $@'

inc_fortran:
	@cd ../fort; $(MAKE) "CC=$(CC) $(DEFS)" "F90=$(F90)" \
	   "F90_MODULE_PREFIX=$(F90_MODULE_PREFIX)" \
	   "ZOLTAN_OBJ_DIR=$(ZOLTAN_OBJ_DIR)" \
	   "SPPR_HEAD=$(SPPR_HEAD)" "LOCAL_F90=$(LOCAL_F90)"

$(LIB_NAME):	FORCE $(OBJ_FILES:.o=.d) $(OBJ_FILES) $(INC_FORTRAN)
		@echo "creating library..."
		@$(AR) $(LIB_NAME) $(OBJ_FILES) $(FOBJ_FILES)
		@$(RANLIB) $(LIB_NAME)

FORCE:

$(ZTARGET):	$(DEP_LIBS) $(LIB_NAME) $(DEPENDENCIES) $(MAIN_OBJ)
		@echo "linking $(ZTARGET)"
		@$(PURE_CC) $(CC) $(MAIN_OBJ) -o $(ZTARGET) $(LNK_LIBS)

#		@purify -best_effort -follow-child-processes=yes -cache-dir=/tmp/purify $(CC) $(MAIN_OBJ) -o $(ZTARGET) $(LNK_LIBS)

