# To run makefile:
#    1) Before running the makefile, you should run the script 'installer'.
#        This script will create a file
#        called make_$(ARCH).variables that will set `INC_PATH', `LIBRARIES'
#        and some other environment variables appropriately.
#
#
include ../make_$(ARCH).variables
include ../etc/makefile.$(ARCH)

DEFINES= -D$(ARCH) $(PACKAGES) -DML_CLASSIC_BUILD

INCLUDES=-I. $(INC_PATH) 
LIB_PATHS=$(LIBRARIES) 

CFLAGS=$(ARCH_FLAGS) $(DEFINES) $(INCLUDES) $(TESTING) $(TESTING2)
#c++ compiler flags
CXXFLAGS=$(CFLAGS)
#VPATH=../examples:../src
#=======================================================================
# ML source files
#=======================================================================

ML_C = ml_aztec_utils.c  ml_ggraph.c       ml_memory.c \
       ml_struct.c       ml_comm.c         ml_gridagx.c \
       ml_operatoragx.c  ml_superlu.c      ml_comminfoagx.c \
       ml_grid.c         ml_rap.c          ml_aggregate.c \
       ml_elementagx.c   ml_intlist.c      ml_rap_utils.c \
       ml_utils.c        ml_exch_row.c     \
       ml_setup.c        ml_vec.c          ml_get_basis.c \
       ml_matmat_mult.c  ml_solver.c       ml_check.c \
       ml_bdrypts.c      ml_mapper.c       ml_gridfunc.c \
       ml_smoother.c     ml_csolve.c       ml_operator.c \
       ml_op_utils.c     ml_comminfoop.c   ml_mat_formats.c \
       ml_agg_genP.c ml_lapack.c mli_solver.c ml_agg_coupled.c \
       ml_krylov.c       ml_cg.c           ml_gmres.c \
       ml_agg_uncoupled.c ml_agg_dd.c      ml_read_utils.c \
       ml_bicgstabl.c    ml_pde.c          ml_xyt.c ml_agg_MIS.c \
       ml_amg.c 		 ml_amg_MIS.c	   ml_amg_genP.c \
       ml_agg_reitzinger.c ml_twogrid_analysis.c ml_operator_blockmat.c \
       ml_vampir.c ml_agg_METIS.c ml_agg_ParMETIS.c ml_agg_info.c \
       ml_viz_opendx.c
#ML_CPP=ml_epetra_utils.cpp ml_epetra_operator.cpp

#=======================================================================
# ML include files
#=======================================================================

ML_INC = ml_1level.h         ml_ggraph.h         ml_operatoragx.h       \
	 ml_aggregate.h      ml_grid.h           ml_rap.h               \
	 ml_aztec_utils.h    ml_gridagx.h        ml_smooth_prolongator.h\
	ml_bdrypts.h         ml_gridfunc.h       ml_smoother.h          \
	ml_check.h           ml_include.h        ml_solver.h            \
	ml_comm.h            ml_intlist.h        ml_struct.h            \
	ml_comminfoagx.h     ml_mapper.h         ml_utils.h             \
	ml_comminfoop.h      ml_mat_formats.h    ml_vec.h               \
	ml_csolve.h          ml_memory.h         ml_krylov.h            \
	ml_defs.h            ml_op_utils.h       ml_gmres.h             \
	ml_elementagx.h      ml_operator.h       ml_bicgstabl.h         \
	mli_solver.h         ml_superlu.h        ml_twogrid_analysis.h  \
    ml_epetra_utils.h    ml_epetra_operator.h    ml_operator_blockmat.h \
    ml_vampir.h ml_agg_METIS.h ml_agg_ParMETIS.h ml_agg_info.h \
    ml_viz_opendx.h

#=======================================================================
# Sample application files
#=======================================================================

#DEFAULT : libml.a

APPLICATION_C = mlguide.c

# For information on how to contruct rules such as the next one,
# see the Gnu make manual, under "Substition References".
ML_OBJ          = $(ML_C:.c=.o) $(ML_CPP:.cpp=.o)
APPLICATION_OBJ = $(APPLICATION_C:.c=.o)
APPLICATION     = $(APPLICATION_C:.c= )

$(APPLICATION): $(APPLICATION_OBJ) libml.a
	echo "Linking"; \
	$(LINKER) $(APPLICATION_OBJ) $(ARCH_FLAGS) $(DEFINES) \
	   $(INCLUDES) \
	   -o $(APPLICATION) libml.a \
	   $(LIB_PATHS) \
	   $(ARCH_LIBS)

libml.a: $(ML_OBJ)
	$(AR) rc libml.a $(ML_OBJ); \
	$(RANLIB) libml.a

driver: libml.a driver.c
	cc -c $(PACKAGES) $(MPI_INC_PATH) driver.c
	cc -o driver driver.o -L. -lml \
           $(SUPERLU_LIB_PATH) \
           $(MPI_LIB_PATH) -lsocket -lnsl -L/usr/local/lib -lblas -lm
#          -lrpc -lgs -lpthread -ldxml -lm -lmpi

#
# dependencies for 'c' files
#
include ../etc/depends.ml

clean:
	@echo "junk" > dummy.o
	@rm -f *.o libml.a $(APPLICATION) core ml_example1d ml_example2d ml_example3d ml_readex mlguide mlguide_par ml_readfile ml_read_elas
