#===============================================================================
# CHOLMOD/MATLAB/Makefile
#===============================================================================

# If you compile CHOLMOD with -DNPARTITION, then you do not need METIS,
# CCOLAMD, or the Partition Module.

default: all

include ../../UFconfig/UFconfig.mk

#-------------------------------------------------------------------------------
# With METIS, CCOLAMD, and the Partition Module:
LIB = ../Lib/libcholmod.a $(METIS) ../../AMD/Lib/libamd.a \
	../../COLAMD/libcolamd.a ../../CCOLAMD/libccolamd.a \
	../../CAMD/Lib/libcamd.a
# with -DNPARTITION
# LIB = ../Lib/libcholmod.a $(METIS) ../../AMD/Lib/libamd.a \
	../../COLAMD/libcolamd.a
#-------------------------------------------------------------------------------

INC = -I. -I../Include -I../../UFconfig -I$(METIS_PATH)/Lib

all: rename library mread sdmult ldlsolve resymbol symbfact2 chol2 lchol \
	ldlchol cholmod ldlupdate metis bisect nesdis etree2 sparse2 analyze \
	other septree

# MX = $(MEX) $(CHOLMOD_CONFIG) -D'SPUMONI=1'
MX = $(MEX) $(CHOLMOD_CONFIG)

distclean: purge

purge: clean
	- $(RM) *.mex* *.dll

clean:
	- $(RM) $(CLEAN)

# patch METIS 4.0.1
rename:
	echo '/* do not edit this file; generated by CHOLMOD/MATLAB/Makefile */' > rename.h
	echo '#undef log2' >> rename.h
	echo '#include "$(METIS_PATH)/Lib/rename.h"' >> rename.h
	echo '#undef log2' >> rename.h
	echo '#define log2 METIS__log2' >> rename.h

cholmod_matlab.o: cholmod_matlab.c cholmod_matlab.h
	$(MX) -c $(INC) cholmod_matlab.c

analyze: analyze.c library cholmod_matlab.o
	$(MX) analyze.c cholmod_matlab.o $(INC) $(LIB)

mread: mread.c library cholmod_matlab.o
	$(MX) mread.c cholmod_matlab.o $(INC) $(LIB)

chol2: chol2.c library cholmod_matlab.o
	$(MX) chol2.c cholmod_matlab.o $(INC) $(LIB)

lchol: lchol.c library cholmod_matlab.o
	$(MX) lchol.c cholmod_matlab.o $(INC) $(LIB)

ldlchol: ldlchol.c library cholmod_matlab.o
	$(MX) ldlchol.c cholmod_matlab.o $(INC) $(LIB)

ldlupdate: ldlupdate.c library cholmod_matlab.o
	$(MX) ldlupdate.c cholmod_matlab.o $(INC) $(LIB)

ldlsolve: ldlsolve.c library cholmod_matlab.o
	$(MX) ldlsolve.c cholmod_matlab.o $(INC) $(LIB)

sdmult: sdmult.c library cholmod_matlab.o
	$(MX) sdmult.c cholmod_matlab.o $(INC) $(LIB)

resymbol: resymbol.c library cholmod_matlab.o
	$(MX) resymbol.c cholmod_matlab.o $(INC) $(LIB)

cholmod: cholmod.c library cholmod_matlab.o
	$(MX) cholmod.c cholmod_matlab.o $(INC) $(LIB)

nesdis: nesdis.c library cholmod_matlab.o
	$(MX) nesdis.c cholmod_matlab.o $(INC) $(LIB)

septree: septree.c library cholmod_matlab.o
	$(MX) septree.c cholmod_matlab.o $(INC) $(LIB)

metis: metis.c library cholmod_matlab.o
	$(MX) metis.c cholmod_matlab.o $(INC) $(LIB)

etree2: etree2.c library cholmod_matlab.o
	$(MX) etree2.c cholmod_matlab.o $(INC) $(LIB)

bisect: bisect.c library cholmod_matlab.o
	$(MX) bisect.c cholmod_matlab.o $(INC) $(LIB)

symbfact2: symbfact2.c library cholmod_matlab.o
	$(MX) symbfact2.c cholmod_matlab.o $(INC) $(LIB)

sparse2: sparse2.c library cholmod_matlab.o
	$(MX) -g sparse2.c cholmod_matlab.o $(INC) $(LIB)

#-------------------------------------------------------------------------------
# See below if you compile with -DNPARTITION
library:
	( cd ../Lib ; $(MAKE) )
	( cd ../../AMD ; $(MAKE) library )
	( cd ../../CAMD ; $(MAKE) library )
	( cd ../../COLAMD ; $(MAKE) )
	( cd ../../CCOLAMD ; $(MAKE) )
# use this rule instead, if you compile with -DNPARTITION:
# library:
# 	( cd ../Lib ; $(MAKE) )
# 	( cd ../../AMD ; $(MAKE) library )
# 	( cd ../../COLAMD ; $(MAKE) )
#-------------------------------------------------------------------------------

other:
	( cd ../../AMD ; $(MAKE) mex )
	( cd ../../CAMD ; $(MAKE) mex )
	( cd ../../COLAMD ; $(MAKE) mex )
	( cd ../../CCOLAMD ; $(MAKE) mex )
