Merged prob.h, factorgraph.h, factograph.cpp from SVN head (broken!)
[libdai.git] / Makefile
index f845617..64a6ab9 100644 (file)
--- a/Makefile
+++ b/Makefile
 #   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
 
+# Enable/disable various approximate inference methods
+WITH_BP=true
+WITH_MF=true
+WITH_HAK=true
+WITH_LC=true
+WITH_TREEEP=true
+WITH_JTREE=true
+WITH_MR=true
+# Build with debug info?
+DEBUG=true
+# Build matlab interface?
+WITH_MATLAB=
+# New/old matlab version?
+NEW_MATLAB=true
+# Windows or linux (default)?
+WINDOWS=
+
 # Directories
-INC = include/dai
-SRC = src
-LIB = lib
+INC=include/dai
+SRC=src
+LIB=lib
+
+# Extensions (library, object, executable extensions)
+LE=.a
+OE=.o
+EE=
+
+# Libraries
+LIBS=-ldai
 
 # We use the BOOST Program Options library
-BOOSTFLAGS = -lboost_program_options
+BOOSTLIBS=-lboost_program_options
 
 # Compile using GNU C++ Compiler
-CC = g++
+CC=g++
 
 # Flags for the C++ compiler
-CCFLAGS = -Wall -W -Wextra -fpic -I./include -Llib -O3 -g -DDAI_DEBUG #-static #-pg #-DVERBOSE
+CCFLAGS=-Wall -W -Wextra -fpic -I./include -Llib -O3 #-pg #-static #-DVERBOSE
+ifdef DEBUG
+CCFLAGS:=$(CCFLAGS) -g -DDAI_DEBUG
+endif
 
-# To enable the Matlab interface, define WITH_MATLAB = yes
-WITH_MATLAB = 
-ifdef WITH_MATLAB
-# Replace the following by the directory where Matlab has been installed
-MATLABDIR = /opt/matlab/bin
-MEX = $(MATLABDIR)/mex
-MEXFLAGS = -g -I. -DDAI_DEBUG -largeArrayDims #-g means debugging
+ifdef WINDOWS
+CCFLAGS=$(CCFLAGS) -DWINDOWS
+endif
+
+OBJECTS:=exactinf$(OE)
+ifdef WITH_BP
+CCFLAGS:=$(CCFLAGS) -DWITH_BP
+OBJECTS:=$(OBJECTS) bp$(OE)
+endif
+ifdef WITH_MF
+CCFLAGS:=$(CCFLAGS) -DWITH_MF
+OBJECTS:=$(OBJECTS) mf$(OE)
+endif
+ifdef WITH_HAK
+CCFLAGS:=$(CCFLAGS) -DWITH_HAK
+OBJECTS:=$(OBJECTS) hak$(OE)
+endif
+ifdef WITH_LC
+CCFLAGS:=$(CCFLAGS) -DWITH_LC
+OBJECTS:=$(OBJECTS) lc$(OE)
+endif
+ifdef WITH_TREEEP
+CCFLAGS:=$(CCFLAGS) -DWITH_TREEEP
+OBJECTS:=$(OBJECTS) treeep$(OE)
+endif
+ifdef WITH_JTREE
+CCFLAGS:=$(CCFLAGS) -DWITH_JTREE
+OBJECTS:=$(OBJECTS) jtree$(OE)
+endif
+ifdef WITH_MR
+CCFLAGS:=$(CCFLAGS) -DWITH_MR
+OBJECTS:=$(OBJECTS) mr$(OE)
 endif
 
+ifdef WITH_MATLAB
+# Replace the following by the directory where Matlab has been installed
+MATLABDIR=/opt/matlab/bin
 # Replace the following with the extension of compiled MEX files on this platform, e.g. .mexglx for x86
-MEXEXT = .mexglx
+ME=.mexglx
+MEX=$(MATLABDIR)/mex
+MEXFLAGS=-I.
+ifdef DEBUG
+MEXFLAGS:=$(MEXFLAGS) -g -DDAI_DEBUG
+endif
+ifdef NEW_MATLAB
+MEXFLAGS:=$(MEXFLAGS) -largeArrayDims
+else
+MEXFLAGS:=$(MEXFLAGS) -DSMALLMEM
+endif
+endif
 
-HEADERS = $(INC)/bipgraph.h $(INC)/diffs.h $(INC)/index.h $(INC)/var.h $(INC)/factor.h $(INC)/varset.h $(INC)/prob.h $(INC)/daialg.h $(INC)/properties.h $(INC)/alldai.h $(INC)/enum.h $(INC)/x2x.h
+HEADERS=$(INC)/bipgraph.h $(INC)/diffs.h $(INC)/index.h $(INC)/var.h $(INC)/factor.h $(INC)/varset.h $(INC)/prob.h $(INC)/daialg.h $(INC)/properties.h $(INC)/alldai.h $(INC)/enum.h $(INC)/x2x.h $(INC)/exceptions.h
 
-# target matlabs is disabled by default since it only compiles with a very recent MatLab version
-TARGETS = tests utils $(LIB)/libdai.a example testregression
+TARGETS=tests utils $(LIB)/libdai$(LE) example$(EE) testregression doc
 ifdef WITH_MATLAB
-TARGETS := $(TARGETS) matlabs
+TARGETS:=$(TARGETS) matlabs
 endif
 all : $(TARGETS)
        echo -e "\a"
 
-matlabs : matlab/dai.$(MEXEXT) matlab/dai_readfg.$(MEXEXT) matlab/dai_writefg.$(MEXEXT) matlab/dai_removeshortloops.$(MEXEXT) matlab/dai_potstrength.$(MEXEXT)
+matlabs : matlab/dai.$(ME) matlab/dai_readfg.$(ME) matlab/dai_writefg.$(ME) matlab/dai_potstrength.$(ME)
 
-$(LIB)/libdai.a : daialg.o alldai.o bp.o clustergraph.o factorgraph.o hak.o jtree.o lc.o mf.o mr.o properties.o regiongraph.o util.o treeep.o weightedgraph.o x2x.o
-       ar rcs $(LIB)/libdai.a daialg.o alldai.o bp.o clustergraph.o factorgraph.o hak.o jtree.o lc.o mf.o mr.o properties.o regiongraph.o util.o treeep.o weightedgraph.o x2x.o
+$(LIB)/libdai$(LE) : bipgraph$(OE) daialg$(OE) alldai$(OE) clustergraph$(OE) factorgraph$(OE) properties$(OE) regiongraph$(OE) util$(OE) weightedgraph$(OE) x2x$(OE) exceptions$(OE) $(OBJECTS)
+       ar rcus $(LIB)/libdai$(LE) bipgraph$(OE) daialg$(OE) alldai$(OE) clustergraph$(OE) factorgraph$(OE) properties$(OE) regiongraph$(OE) util$(OE) weightedgraph$(OE) x2x$(OE) exceptions$(OE) $(OBJECTS)
 
-tests : tests/test
+tests : tests/test$(EE)
 
-utils : utils/createfg utils/fg2dot utils/remove_short_loops utils/fginfo
+utils : utils/createfg$(EE) utils/fg2dot$(EE) utils/fginfo$(EE)
 
 testregression : tests/test
        echo Testing...this can take a while...
-       cd tests; ./testregression; cd ..
+       cd tests; time ./testregression; cd ..
 
 doc : $(INC)/*.h $(SRC)/*.cpp doxygen.conf
        doxygen doxygen.conf
 
 clean :
-       rm *.o *.$(MEXEXT) example matlab/*.$(MEXEXT) matlab/*.o tests/test utils/fg2dot utils/createfg utils/remove_short_loops utils/fginfo $(LIB)/libdai.a; echo
+       rm *$(OE) example$(EE) matlab/*.$(ME) matlab/*$(OE) tests/test$(EE) utils/fg2dot$(EE) utils/createfg$(EE) utils/fginfo$(EE) $(LIB)/libdai$(LE); echo
        rm -R doc; echo
 
+bipgraph$(OE) : $(SRC)/bipgraph.cpp $(HEADERS)
+       $(CC) $(CCFLAGS) -c $(SRC)/bipgraph.cpp
 
-daialg.o : $(SRC)/daialg.cpp $(HEADERS)
+daialg$(OE) : $(SRC)/daialg.cpp $(HEADERS)
        $(CC) $(CCFLAGS) -c $(SRC)/daialg.cpp
 
-bp.o : $(SRC)/bp.cpp $(INC)/bp.h $(HEADERS)
+exactinf$(OE) : $(SRC)/exactinf.cpp $(INC)/exactinf.h $(HEADERS)
+       $(CC) $(CCFLAGS) -c $(SRC)/exactinf.cpp
+
+bp$(OE) : $(SRC)/bp.cpp $(INC)/bp.h $(HEADERS)
        $(CC) $(CCFLAGS) -c $(SRC)/bp.cpp
 
-lc.o : $(SRC)/lc.cpp $(INC)/lc.h $(HEADERS)
+lc$(OE) : $(SRC)/lc.cpp $(INC)/lc.h $(HEADERS)
        $(CC) $(CCFLAGS) -c $(SRC)/lc.cpp
 
-mf.o : $(SRC)/mf.cpp $(INC)/mf.h $(HEADERS)
+mf$(OE) : $(SRC)/mf.cpp $(INC)/mf.h $(HEADERS)
        $(CC) $(CCFLAGS) -c $(SRC)/mf.cpp
 
-factorgraph.o : $(SRC)/factorgraph.cpp $(INC)/factorgraph.h $(HEADERS)
+factorgraph$(OE) : $(SRC)/factorgraph.cpp $(INC)/factorgraph.h $(HEADERS)
        $(CC) $(CCFLAGS) -c $(SRC)/factorgraph.cpp
 
-util.o : $(SRC)/util.cpp $(INC)/util.h $(HEADERS)
+util$(OE) : $(SRC)/util.cpp $(INC)/util.h $(HEADERS)
        $(CC) $(CCFLAGS) -c $(SRC)/util.cpp
 
-regiongraph.o : $(SRC)/regiongraph.cpp $(INC)/regiongraph.h $(HEADERS)
+regiongraph$(OE) : $(SRC)/regiongraph.cpp $(INC)/regiongraph.h $(HEADERS)
        $(CC) $(CCFLAGS) -c $(SRC)/regiongraph.cpp
 
-hak.o : $(SRC)/hak.cpp $(INC)/hak.h $(HEADERS) $(INC)/regiongraph.h
+hak$(OE) : $(SRC)/hak.cpp $(INC)/hak.h $(HEADERS) $(INC)/regiongraph.h
        $(CC) $(CCFLAGS) -c $(SRC)/hak.cpp
 
-clustergraph.o : $(SRC)/clustergraph.cpp $(INC)/clustergraph.h $(HEADERS)
+clustergraph$(OE) : $(SRC)/clustergraph.cpp $(INC)/clustergraph.h $(HEADERS)
        $(CC) $(CCFLAGS) -c $(SRC)/clustergraph.cpp
 
-jtree.o : $(SRC)/jtree.cpp $(INC)/jtree.h $(HEADERS) $(INC)/weightedgraph.h $(INC)/clustergraph.h $(INC)/regiongraph.h
+jtree$(OE) : $(SRC)/jtree.cpp $(INC)/jtree.h $(HEADERS) $(INC)/weightedgraph.h $(INC)/clustergraph.h $(INC)/regiongraph.h
        $(CC) $(CCFLAGS) -c $(SRC)/jtree.cpp
 
-treeep.o : $(SRC)/treeep.cpp $(INC)/treeep.h $(HEADERS) $(INC)/weightedgraph.h $(INC)/clustergraph.h $(INC)/regiongraph.h $(INC)/jtree.h
+treeep$(OE) : $(SRC)/treeep.cpp $(INC)/treeep.h $(HEADERS) $(INC)/weightedgraph.h $(INC)/clustergraph.h $(INC)/regiongraph.h $(INC)/jtree.h
        $(CC) $(CCFLAGS) -c $(SRC)/treeep.cpp
 
-weightedgraph.o : $(SRC)/weightedgraph.cpp $(INC)/weightedgraph.h $(HEADERS)
+weightedgraph$(OE) : $(SRC)/weightedgraph.cpp $(INC)/weightedgraph.h $(HEADERS)
        $(CC) $(CCFLAGS) -c $(SRC)/weightedgraph.cpp
 
-mr.o : $(SRC)/mr.cpp $(INC)/mr.h $(HEADERS)
+mr$(OE) : $(SRC)/mr.cpp $(INC)/mr.h $(HEADERS)
        $(CC) $(CCFLAGS) -c $(SRC)/mr.cpp
 
-properties.o : $(SRC)/properties.cpp $(HEADERS)
+properties$(OE) : $(SRC)/properties.cpp $(HEADERS)
        $(CC) $(CCFLAGS) -c $(SRC)/properties.cpp
 
-alldai.o : $(SRC)/alldai.cpp $(HEADERS)
+exceptions$(OE) : $(SRC)/exceptions.cpp $(HEADERS)
+       $(CC) $(CCFLAGS) -c $(SRC)/exceptions.cpp
+
+alldai$(OE) : $(SRC)/alldai.cpp $(HEADERS)
        $(CC) $(CCFLAGS) -c $(SRC)/alldai.cpp
 
-x2x.o : $(SRC)/x2x.cpp $(HEADERS)
+x2x$(OE) : $(SRC)/x2x.cpp $(HEADERS)
        $(CC) $(CCFLAGS) -c $(SRC)/x2x.cpp
 
+
 # EXAMPLE
 ##########
 
-example : $(SRC)/example.cpp $(HEADERS) $(LIB)/libdai.a
-       $(CC) $(CCFLAGS) -o example $(SRC)/example.cpp -ldai
+example$(EE) : example.cpp $(HEADERS) $(LIB)/libdai$(LE)
+       $(CC) $(CCFLAGS) -o example$(EE) example.cpp $(LIBS)
 
 # TESTS
 ########
 
-tests/test : tests/test.cpp $(HEADERS) lib/libdai.a
-       $(CC) $(CCFLAGS) -o tests/test tests/test.cpp -ldai $(BOOSTFLAGS)
+tests/test$(EE) : tests/test.cpp $(HEADERS) $(LIB)/libdai$(LE)
+       $(CC) $(CCFLAGS) -o tests/test$(EE) tests/test.cpp $(LIBS) $(BOOSTLIBS)
 
 
 # MATLAB INTERFACE
 ###################
 
-matlab/dai.$(MEXEXT) : matlab/dai.cpp $(HEADERS) matlab/matlab.o daialg.o alldai.o bp.o clustergraph.o factorgraph.o hak.o jtree.o lc.o mf.o mr.o properties.o regiongraph.o util.o treeep.o weightedgraph.o x2x.o
-       $(MEX) $(MEXFLAGS) -o matlab/dai matlab/dai.cpp matlab/matlab.o daialg.o alldai.o bp.o clustergraph.o factorgraph.o hak.o jtree.o lc.o mf.o mr.o properties.o regiongraph.o util.o treeep.o weightedgraph.o x2x.o
-
-matlab/dai_readfg.$(MEXEXT) : matlab/dai_readfg.cpp $(HEADERS) factorgraph.o matlab/matlab.o
-       $(MEX) $(MEXFLAGS) -o matlab/dai_readfg matlab/dai_readfg.cpp factorgraph.o matlab/matlab.o
+matlab/dai.$(ME) : matlab/dai.cpp $(HEADERS) matlab/matlab$(OE) $(LIB)/libdai$(LE)
+       $(MEX) $(MEXFLAGS) -o matlab/dai matlab/dai.cpp matlab/matlab$(OE) $(LIB)/libdai$(LE)
 
-matlab/dai_writefg.$(MEXEXT) : matlab/dai_writefg.cpp $(HEADERS) factorgraph.o matlab/matlab.o
-       $(MEX) $(MEXFLAGS) -o matlab/dai_writefg matlab/dai_writefg.cpp factorgraph.o matlab/matlab.o
+matlab/dai_readfg.$(ME) : matlab/dai_readfg.cpp $(HEADERS) factorgraph$(OE) matlab/matlab$(OE) exceptions$(OE)
+       $(MEX) $(MEXFLAGS) -o matlab/dai_readfg matlab/dai_readfg.cpp factorgraph$(OE) matlab/matlab$(OE) exceptions$(OE)
 
-matlab/dai_removeshortloops.$(MEXEXT) : matlab/dai_removeshortloops.cpp $(HEADERS) factorgraph.o matlab/matlab.o
-       $(MEX) $(MEXFLAGS) -o matlab/dai_removeshortloops matlab/dai_removeshortloops.cpp factorgraph.o matlab/matlab.o
+matlab/dai_writefg.$(ME) : matlab/dai_writefg.cpp $(HEADERS) factorgraph$(OE) matlab/matlab$(OE) exceptions$(OE)
+       $(MEX) $(MEXFLAGS) -o matlab/dai_writefg matlab/dai_writefg.cpp factorgraph$(OE) matlab/matlab$(OE) exceptions$(OE)
 
-matlab/dai_potstrength.$(MEXEXT) : matlab/dai_potstrength.cpp $(HEADERS) matlab/matlab.o
-       $(MEX) $(MEXFLAGS) -o matlab/dai_potstrength matlab/dai_potstrength.cpp matlab/matlab.o
+matlab/dai_potstrength.$(ME) : matlab/dai_potstrength.cpp $(HEADERS) matlab/matlab$(OE) exceptions$(OE)
+       $(MEX) $(MEXFLAGS) -o matlab/dai_potstrength matlab/dai_potstrength.cpp matlab/matlab$(OE) exceptions$(OE)
 
-matlab/matlab.o : matlab/matlab.cpp matlab/matlab.h $(HEADERS)
+matlab/matlab$(OE) : matlab/matlab.cpp matlab/matlab.h $(HEADERS)
        $(MEX) $(MEXFLAGS) -outdir matlab -c matlab/matlab.cpp
 
 
 # UTILS
 ########
 
-utils/createfg : utils/createfg.cpp $(HEADERS) factorgraph.o weightedgraph.o util.o
-       $(CC) $(CCFLAGS) -o utils/createfg utils/createfg.cpp factorgraph.o weightedgraph.o util.o $(BOOSTFLAGS)
-
-utils/fg2dot : utils/fg2dot.cpp $(HEADERS) factorgraph.o
-       $(CC) $(CCFLAGS) -o utils/fg2dot utils/fg2dot.cpp factorgraph.o
+utils/createfg$(EE) : utils/createfg.cpp $(HEADERS) $(LIB)/libdai$(LE)
+       $(CC) $(CCFLAGS) -o utils/createfg utils/createfg.cpp $(LIBS) $(BOOSTLIBS)
 
-utils/remove_short_loops : utils/remove_short_loops.cpp $(HEADERS) factorgraph.o
-       $(CC) $(CCFLAGS) -o utils/remove_short_loops utils/remove_short_loops.cpp factorgraph.o
+utils/fg2dot$(EE) : utils/fg2dot.cpp $(HEADERS) $(LIB)/libdai$(LE)
+       $(CC) $(CCFLAGS) -o utils/fg2dot utils/fg2dot.cpp $(LIBS)
 
-utils/fginfo : utils/fginfo.cpp $(HEADERS) factorgraph.o
-       $(CC) $(CCFLAGS) -o utils/fginfo utils/fginfo.cpp factorgraph.o
+utils/fginfo$(EE) : utils/fginfo.cpp $(HEADERS) $(LIB)/libdai$(LE)
+       $(CC) $(CCFLAGS) -o utils/fginfo utils/fginfo.cpp $(LIBS)