AM_CPPFLAGS = @DAKOTAINCL@ @MATLABINCL@ @PETSCINCL@ @MPIINCL@ @SPOOLESINCL@ @METISINCL@ @TRIANGLEINCL@ @CHACOINCL@ @SCOTCHINCL@ @SHAPELIBINCL@

lib_LIBRARIES = libISSMMatlab.a 

EXEEXT=$(MATLABWRAPPEREXT)

#matlab io{{{
io_sources = ./include/matlabincludes.h\
				./io/matlabio.h\
				./io/MatlabNArrayToNArray.cpp\
				./io/CheckNumMatlabArguments.cpp\
				./io/mxGetAssignedField.cpp\
				./io/WriteMatlabData.cpp\
				./io/FetchMatlabData.cpp\
				./io/OptionParse.cpp\
				./io/MatlabMatrixToMatrix.cpp\
				./io/MatlabVectorToVector.cpp\
				./io/MatlabVectorToDoubleVector.cpp\
				./io/MatlabMatrixToDoubleMatrix.cpp\
				./io/MatlabMatrixToIssmMat.cpp\
				./io/MatlabVectorToIssmVec.cpp
				
if PETSC
io_sources += ./io/MatlabMatrixToPetscMat.cpp\
				./io/MatlabVectorToPetscVec.cpp
endif

ALLCXXFLAGS = /D_GNU_SOURCE /D_CPP_ /D_WRAPPERS_ $(CXXFLAGS) $(CXXOPTFLAGS) 
libISSMMatlab_a_SOURCES = $(io_sources)
libISSMMatlab_a_CXXFLAGS = $(ALLCXXFLAGS)

#}}}
#Wrappers {{{
if WRAPPERS
bin_PROGRAMS =  AverageFilter\
						 BamgMesher\
						 BamgConvertMesh\
						 BamgTriangulate\
						 ContourToMesh\
						 ContourToNodes\
						 EdgeDetection\
						 ElementConnectivity\
						 EnumToString\
						 ExpSimplify\
						 HoleFiller\
						 InternalFront\
						 InterpFromGridToMesh\
						 InterpFromMeshToMesh2d\
						 InterpFromMeshToMesh3d\
						 InterpFromMeshToGrid\
						 InterpFromMesh2d\
						 Ll2xy\
						 NodeConnectivity\
						 MeshPartition\
						 MeshProfileIntersection\
						 PointCloudFindNeighbors\
						 PropagateFlagsFromConnectivity\
						 StringToEnum\
						 TriaSearch\
						 TriMesh\
						 TriMeshProcessRifts\
						 Scotch\
						 Xy2ll\
						 Chaco

if KRIGING
bin_PROGRAMS +=  Kriging
endif
if KML
bin_PROGRAMS +=  KMLFileRead\
				   KMLMeshWrite\
				   KMLOverlay\
				   Exp2Kml\
				   Kml2Exp\
				   Shp2Exp\
				   Shp2Kml
endif
endif
#}}}
#Flags and libraries {{{
#if SHAREDLIBS
#deps = ../../c/libISSMCore ../../c/libISSMModules.la
#else
#deps = ../../c/libISSMCore.a ../../c/libISSMModules.a
#endif
#deps +=  $(MATHLIB)
deps =  $(MATHLIB)

#Triangle library
AM_CXXFLAGS =  /DTRILIBRARY /DANSI_DECLARATORS /DNO_TIMER

#Matlab part
AM_LDFLAGS = 
if VERSION
AM_LDFLAGS +=
else
AM_LDFLAGS += -avoid-version
endif
deps += ./libISSMMatlab.a
AM_LDFLAGS += --no-warnings 

AM_CXXFLAGS +=  /D_HAVE_MATLAB_MODULES_  /D_GNU_SOURCE 

deps += ../../c/libISSMModules.a ../../c/libISSMCore.a  
if ADOLC
deps += $(ADOLCLIB)
endif

#MEXLIB needs to be the last (undefined references on larsen)
deps += ${MEXLIB}

#Optimization flags:
AM_CXXFLAGS += $(CXXOPTFLAGS) 
#}}}
#Bin sources {{{
AverageFilter_SOURCES = ../AverageFilter/AverageFilter.cpp\
									../AverageFilter/AverageFilter.h
AverageFilter_LDADD = ${deps} $(MPILIB) $(PETSCLIB) $(GSLLIB)

BamgMesher_SOURCES = ../BamgMesher/BamgMesher.cpp\
								../BamgMesher/BamgMesher.h
BamgMesher_LDADD = ${deps} $(MPILIB) $(PETSCLIB) $(GSLLIB)

BamgConvertMesh_SOURCES = ../BamgConvertMesh/BamgConvertMesh.cpp\
									  ../BamgConvertMesh/BamgConvertMesh.h
BamgConvertMesh_LDADD = ${deps} $(MPILIB) $(PETSCLIB) $(GSLLIB)

BamgTriangulate_SOURCES = ../BamgTriangulate/BamgTriangulate.cpp\
									  ../BamgTriangulate/BamgTriangulate.h
BamgTriangulate_LDADD = ${deps} $(MPILIB) $(PETSCLIB) $(GSLLIB)

Chaco_SOURCES = ../Chaco/Chaco.cpp\
						 ../Chaco/Chaco.h
Chaco_LDADD = ${deps} $(MPILIB) $(PETSCLIB) $(CHACOLIB) $(GSLLIB)

ContourToMesh_SOURCES = ../ContourToMesh/ContourToMesh.cpp\
									../ContourToMesh/ContourToMesh.h
ContourToMesh_LDADD = ${deps} $(MPILIB) $(PETSCLIB) $(MULTITHREADINGLIB) $(GSLLIB)

ContourToNodes_SOURCES = ../ContourToNodes/ContourToNodes.cpp\
									 ../ContourToNodes/ContourToNodes.h
ContourToNodes_LDADD = ${deps} $(MPILIB) $(PETSCLIB) $(GSLLIB)

ElementConnectivity_SOURCES = ../ElementConnectivity/ElementConnectivity.cpp\
											../ElementConnectivity/ElementConnectivity.h
ElementConnectivity_LDADD = ${deps} $(MPILIB) $(PETSCLIB) $(GSLLIB)

EnumToString_SOURCES = ../EnumToString/EnumToString.cpp\
								  ../EnumToString/EnumToString.h
EnumToString_LDADD = ${deps} $(MPILIB) $(PETSCLIB) $(GSLLIB)

StringToEnum_SOURCES = ../StringToEnum/StringToEnum.cpp\
								  ../StringToEnum/StringToEnum.h
StringToEnum_LDADD = ${deps} $(MPILIB) $(PETSCLIB) $(GSLLIB)

HoleFiller_SOURCES = ../HoleFiller/HoleFiller.cpp\
								../HoleFiller/HoleFiller.h
HoleFiller_LDADD = ${deps} $(MPILIB) $(PETSCLIB)  $(GSLLIB)

InternalFront_SOURCES = ../InternalFront/InternalFront.cpp\
									../InternalFront/InternalFront.h
InternalFront_LDADD = ${deps} $(MPILIB) $(PETSCLIB) $(GSLLIB)

InterpFromGridToMesh_SOURCES = ../InterpFromGridToMesh/InterpFromGridToMesh.cpp\
											 ../InterpFromGridToMesh/InterpFromGridToMesh.h
InterpFromGridToMesh_LDADD = ${deps} $(MPILIB) $(PETSCLIB) $(MULTITHREADINGLIB) $(GSLLIB)

InterpFromMeshToMesh2d_SOURCES = ../InterpFromMeshToMesh2d/InterpFromMeshToMesh2d.cpp\
												../InterpFromMeshToMesh2d/InterpFromMeshToMesh2d.h
InterpFromMeshToMesh2d_LDADD = ${deps} $(MPILIB) $(PETSCLIB) $(MULTITHREADINGLIB) $(GSLLIB)

InterpFromMeshToMesh3d_SOURCES = ../InterpFromMeshToMesh3d/InterpFromMeshToMesh3d.cpp\
												../InterpFromMeshToMesh3d/InterpFromMeshToMesh3d.h
InterpFromMeshToMesh3d_LDADD = ${deps} $(MPILIB) $(PETSCLIB) $(GSLLIB)

InterpFromMeshToGrid_SOURCES = ../InterpFromMeshToGrid/InterpFromMeshToGrid.cpp\
											 ../InterpFromMeshToGrid/InterpFromMeshToGrid.h
InterpFromMeshToGrid_LDADD = ${deps} $(MPILIB) $(PETSCLIB) $(GSLLIB)

InterpFromMesh2d_SOURCES = ../InterpFromMesh2d/InterpFromMesh2d.cpp\
										../InterpFromMesh2d/InterpFromMesh2d.h
InterpFromMesh2d_LDADD = ${deps} $(MPILIB) $(PETSCLIB) $(MULTITHREADINGLIB) $(GSLLIB)

KMLFileRead_SOURCES = ../KMLFileRead/KMLFileRead.cpp\
								 ../KMLFileRead/KMLFileRead.h
KMLFileRead_LDADD = ${deps} $(MPILIB) $(PETSCLIB) $(GSLLIB)

KMLMeshWrite_SOURCES = ../KMLMeshWrite/KMLMeshWrite.cpp\
								  ../KMLMeshWrite/KMLMeshWrite.h
KMLMeshWrite_LDADD = ${deps} $(MPILIB) $(PETSCLIB) $(GSLLIB)

KMLOverlay_SOURCES = ../KMLOverlay/KMLOverlay.cpp\
								../KMLOverlay/KMLOverlay.h
KMLOverlay_LDADD = ${deps} $(MPILIB) $(PETSCLIB) $(GSLLIB)

Xy2ll_SOURCES = ../Xy2ll/Xy2ll.cpp\
						 ../Xy2ll/Xy2ll.h
Xy2ll_LDADD = ${deps} $(MPILIB) $(PETSCLIB) $(GSLLIB)

Ll2xy_SOURCES = ../Ll2xy/Ll2xy.cpp\
						 ../Ll2xy/Ll2xy.h
Ll2xy_LDADD = ${deps} $(MPILIB) $(PETSCLIB) $(GSLLIB)

EdgeDetection_SOURCES = ../EdgeDetection/EdgeDetection.cpp\
							../EdgeDetection/EdgeDetection.h
EdgeDetection_LDADD= ${deps} $(MPILIB) $(PETSCLIB) $(GSLLIB)

ExpSimplify_SOURCES = ../ExpSimplify/ExpSimplify.cpp\
							../ExpSimplify/ExpSimplify.h
ExpSimplify_LDADD = ${deps} $(MPILIB) $(PETSCLIB) $(GSLLIB)

Exp2Kml_SOURCES = ../Exp2Kml/Exp2Kml.cpp\
							../Exp2Kml/Exp2Kml.h
Exp2Kml_LDADD = ${deps} $(MPILIB) $(PETSCLIB) $(GSLLIB)

Kml2Exp_SOURCES = ../Kml2Exp/Kml2Exp.cpp\
							../Kml2Exp/Kml2Exp.h
Kml2Exp_LDADD = ${deps} $(MPILIB) $(PETSCLIB) $(GSLLIB)

Kriging_SOURCES = ../Kriging/Kriging.cpp\
							../Kriging/Kriging.h
Kriging_LDADD = ${deps} $(MPILIB) $(PETSCLIB) $(GSLLIB) $(MULTITHREADINGLIB) $(GSLLIB)

MeshPartition_SOURCES = ../MeshPartition/MeshPartition.cpp\
									../MeshPartition/MeshPartition.h
MeshPartition_LDADD = ${deps} $(MPILIB) $(PETSCLIB) $(METISLIB) $(GSLLIB)

MeshProfileIntersection_SOURCES = ../MeshProfileIntersection/MeshProfileIntersection.cpp\
												 ../MeshProfileIntersection/MeshProfileIntersection.h
MeshProfileIntersection_LDADD = ${deps} $(MPILIB) $(PETSCLIB) $(GSLLIB)

NodeConnectivity_SOURCES = ../NodeConnectivity/NodeConnectivity.cpp\
										../NodeConnectivity/NodeConnectivity.h
NodeConnectivity_LDADD = ${deps} $(MPILIB) $(PETSCLIB) $(GSLLIB)

PointCloudFindNeighbors_SOURCES = ../PointCloudFindNeighbors/PointCloudFindNeighbors.cpp\
												 ../PointCloudFindNeighbors/PointCloudFindNeighbors.h
PointCloudFindNeighbors_LDADD = ${deps} $(MPILIB) $(PETSCLIB) $(MULTITHREADINGLIB) $(GSLLIB)

PropagateFlagsFromConnectivity_SOURCES = ../PropagateFlagsFromConnectivity/PropagateFlagsFromConnectivity.cpp\
														  ../PropagateFlagsFromConnectivity/PropagateFlagsFromConnectivity.h
PropagateFlagsFromConnectivity_LDADD = ${deps} $(MPILIB) $(PETSCLIB) $(GSLLIB)

Scotch_SOURCES = ../Scotch/Scotch.cpp\
						  ../Scotch/Scotch.h
Scotch_LDADD = ${deps} $(SCOTCHLIB) $(MPILIB)

Shp2Exp_SOURCES = ../Shp2Exp/Shp2Exp.cpp\
							../Shp2Exp/Shp2Exp.h
Shp2Exp_LDADD = ${deps} $(SHAPELIBLIB) $(MPILIB) $(PETSCLIB) $(GSLLIB)

Shp2Kml_SOURCES = ../Shp2Kml/Shp2Kml.cpp\
							../Shp2Kml/Shp2Kml.h
Shp2Kml_LDADD = ${deps} $(SHAPELIBLIB) $(MPILIB) $(PETSCLIB) $(GSLLIB)

TriaSearch_SOURCES = ../TriaSearch/TriaSearch.cpp\
								../TriaSearch/TriaSearch.h
TriaSearch_LDADD = ${deps} $(MPILIB) $(PETSCLIB) $(GSLLIB)

TriMesh_SOURCES = ../TriMesh/TriMesh.cpp\
							../TriMesh/TriMesh.h
TriMesh_LDADD = ${deps} $(MPILIB) $(PETSCLIB) $(TRIANGLELIB) $(GSLLIB)

TriMeshProcessRifts_SOURCES = ../TriMeshProcessRifts/TriMeshProcessRifts.cpp\
											../TriMeshProcessRifts/TriMeshProcessRifts.h
TriMeshProcessRifts_LDADD = ${deps} $(MPILIB) $(PETSCLIB) $(GSLLIB)
#}}}
