Added some unit tests that I forgot earlier
[libdai.git] / Makefile
index b87d177..d76c56f 100644 (file)
--- a/Makefile
+++ b/Makefile
-#   Copyright (C) 2006-2008  Joris Mooij  [j dot mooij at science dot ru dot nl]
-#   Radboud University Nijmegen, The Netherlands
-#   
-#   This file is part of libDAI.
+# This file is part of libDAI - http://www.libdai.org/
 #
-#   libDAI is free software; you can redistribute it and/or modify
-#   it under the terms of the GNU General Public License as published by
-#   the Free Software Foundation; either version 2 of the License, or
-#   (at your option) any later version.
+# libDAI is licensed under the terms of the GNU General Public License version
+# 2, or (at your option) any later version. libDAI is distributed without any
+# warranty. See the file COPYING for more details.
 #
-#   libDAI is distributed in the hope that it will be useful,
-#   but WITHOUT ANY WARRANTY; without even the implied warranty of
-#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#   GNU General Public License for more details.
-#
-#   You should have received a copy of the GNU General Public License
-#   along with libDAI; if not, write to the Free Software
-#   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
-DEBUG = true
-NEW_MATLAB = true
-WITH_MATLAB =
-
-# Directories
-INC = include/dai
-SRC = src
-LIB = lib
-
-# We use the BOOST Program Options library
-BOOSTFLAGS = -lboost_program_options
-
-# Compile using GNU C++ Compiler
-CC = g++
-
-# Flags for the C++ compiler
-CCFLAGS = -Wall -W -Wextra -fpic -I./include -Llib -O3 #-pg #-static -DVERBOSE
+# Copyright (C) 2006-2010  Joris Mooij  [joris dot mooij at libdai dot org]
+# Copyright (C) 2006-2007  Radboud University Nijmegen, The Netherlands
+
+
+# Load the platform independent build configuration file
+include Makefile.ALL
+
+# Load the local configuration from Makefile.conf
+include Makefile.conf
+
+# Set version and date
+DAI_VERSION="git HEAD"
+DAI_DATE="May 12, 2010, or later"
+
+# Directories of libDAI sources
+# Location of libDAI headers
+INC=include/dai
+# Location of libDAI source files
+SRC=src
+# Destination directory of libDAI library
+LIB=lib
+
+# Set final compiler flags
 ifdef DEBUG
-CCFLAGS := $(CCFLAGS) -g -DDAI_DEBUG
+  CCFLAGS:=$(CCFLAGS) $(CCDEBUGFLAGS)
 else
-CCFLAGS := $(CCFLAGS)
+  CCFLAGS:=$(CCFLAGS) $(CCNODEBUGFLAGS)
+endif
+
+# Define build targets
+TARGETS:=lib tests utils examples
+ifdef WITH_MATLAB
+  TARGETS:=$(TARGETS) matlabs
+endif
+TARGETS:=$(TARGETS) unittests testregression testem
+ifdef WITH_DOC
+  TARGETS:=$(TARGETS) doc
 endif
 
+# Define conditional build targets
+NAMES:=graph dag bipgraph varset daialg alldai clustergraph factor factorgraph properties regiongraph util weightedgraph exceptions exactinf evidence emalg
 ifdef WITH_BP
-CCFLAGS := $(CCFLAGS) -DWITH_BP
-OBJECTS := $(OBJECTS) bp.o
+  WITHFLAGS:=$(WITHFLAGS) -DDAI_WITH_BP
+  NAMES:=$(NAMES) bp
+endif
+ifdef WITH_FBP
+  WITHFLAGS:=$(WITHFLAGS) -DDAI_WITH_FBP
+  NAMES:=$(NAMES) fbp
+endif
+ifdef WITH_TRWBP
+  WITHFLAGS:=$(WITHFLAGS) -DDAI_WITH_TRWBP
+  NAMES:=$(NAMES) trwbp
 endif
 ifdef WITH_MF
-CCFLAGS := $(CCFLAGS) -DWITH_MF
-OBJECTS := $(OBJECTS) mf.o
+  WITHFLAGS:=$(WITHFLAGS) -DDAI_WITH_MF
+  NAMES:=$(NAMES) mf
 endif
 ifdef WITH_HAK
-CCFLAGS := $(CCFLAGS) -DWITH_HAK
-OBJECTS := $(OBJECTS) hak.o
+  WITHFLAGS:=$(WITHFLAGS) -DDAI_WITH_HAK
+  NAMES:=$(NAMES) hak
 endif
 ifdef WITH_LC
-CCFLAGS := $(CCFLAGS) -DWITH_LC
-OBJECTS := $(OBJECTS) lc.o
+  WITHFLAGS:=$(WITHFLAGS) -DDAI_WITH_LC
+  NAMES:=$(NAMES) lc
 endif
 ifdef WITH_TREEEP
-CCFLAGS := $(CCFLAGS) -DWITH_TREEEP
-OBJECTS := $(OBJECTS) treeep.o
+  WITHFLAGS:=$(WITHFLAGS) -DDAI_WITH_TREEEP
+  NAMES:=$(NAMES) treeep
 endif
 ifdef WITH_JTREE
-CCFLAGS := $(CCFLAGS) -DWITH_JTREE
-OBJECTS := $(OBJECTS) jtree.o
+  WITHFLAGS:=$(WITHFLAGS) -DDAI_WITH_JTREE
+  NAMES:=$(NAMES) jtree
 endif
 ifdef WITH_MR
-CCFLAGS := $(CCFLAGS) -DWITH_MR
-OBJECTS := $(OBJECTS) mr.o
+  WITHFLAGS:=$(WITHFLAGS) -DDAI_WITH_MR
+  NAMES:=$(NAMES) mr
+endif
+ifdef WITH_GIBBS
+  WITHFLAGS:=$(WITHFLAGS) -DDAI_WITH_GIBBS
+  NAMES:=$(NAMES) gibbs
+endif
+ifdef WITH_CBP
+  WITHFLAGS:=$(WITHFLAGS) -DDAI_WITH_CBP
+  NAMES:=$(NAMES) bbp cbp bp_dual
+endif
+ifdef WITH_DECMAP
+  WITHFLAGS:=$(WITHFLAGS) -DDAI_WITH_DECMAP
+  NAMES:=$(NAMES) decmap
 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
-MEX = $(MATLABDIR)/mex
-MEXFLAGS = -I.
-ifdef DEBUG
-MEXFLAGS := $(MEXFLAGS) -g -DDAI_DEBUG
+# Define standard libDAI header dependencies, source file names and object file names
+HEADERS=$(foreach name,graph dag bipgraph index var factor varset smallset prob daialg properties alldai enum exceptions util,$(INC)/$(name).h)
+SOURCES:=$(foreach name,$(NAMES),$(SRC)/$(name).cpp)
+OBJECTS:=$(foreach name,$(NAMES),$(name)$(OE))
+
+# Setup final command for C++ compiler
+ifneq ($(OS),WINDOWS)
+  CC:=$(CC) $(CCINC) $(CCFLAGS) $(WITHFLAGS) $(CCLIB)
+else
+  CC:=$(CC) $(CCINC) $(CCFLAGS) $(WITHFLAGS)
+  LIBS:=$(LIBS) $(CCLIB)
 endif
+
+# Setup final command for MEX
 ifdef NEW_MATLAB
-MEXFLAGS := $(MEXFLAGS) -largeArrayDims
+  MEXFLAGS:=$(MEXFLAGS) -largeArrayDims
 else
-MEXFLAGS := $(MEXFLAGS) -DSMALLMEM
-endif
+  MEXFLAGS:=$(MEXFLAGS) -DSMALLMEM
 endif
+MEX:=$(MEX) $(MEXINC) $(MEXFLAGS) $(WITHFLAGS) $(MEXLIB)
 
-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
 
-TARGETS = tests utils $(LIB)/libdai.a example testregression doc
-ifdef WITH_MATLAB
-TARGETS := $(TARGETS) matlabs
-endif
+# META TARGETS
+###############
+
 all : $(TARGETS)
-       echo -e "\a"
+       @echo libDAI built successfully!
+
+examples : examples/example$(EE) examples/example_bipgraph$(EE) examples/example_varset$(EE) examples/example_permute$(EE) examples/example_sprinkler$(EE) examples/example_sprinkler_gibbs$(EE) examples/example_sprinkler_em$(EE) examples/example_imagesegmentation$(EE)
+
+matlabs : matlab/dai$(ME) matlab/dai_readfg$(ME) matlab/dai_writefg$(ME) matlab/dai_potstrength$(ME)
+
+unittests : tests/unit/var_test$(EE) tests/unit/smallset_test$(EE) tests/unit/varset_test$(EE) tests/unit/graph_test$(EE) tests/unit/dag_test$(EE) tests/unit/bipgraph_test$(EE) tests/unit/weightedgraph_test$(EE) tests/unit/enum_test$(EE) tests/unit/enum_test$(EE) tests/unit/util_test$(EE) tests/unit/exceptions_test$(EE) tests/unit/properties_test$(EE) tests/unit/index_test$(EE) tests/unit/prob_test$(EE) tests/unit/factor_test$(EE) tests/unit/factorgraph_test$(EE) tests/unit/clustergraph_test$(EE) tests/unit/regiongraph_test$(EE) tests/unit/daialg_test$(EE) tests/unit/alldai_test$(EE)
+       echo Running unit tests...
+       tests/unit/var_test$(EE)
+       tests/unit/smallset_test$(EE)
+       tests/unit/varset_test$(EE)
+       tests/unit/graph_test$(EE)
+       tests/unit/dag_test$(EE)
+       tests/unit/bipgraph_test$(EE)
+       tests/unit/weightedgraph_test$(EE)
+       tests/unit/enum_test$(EE)
+       tests/unit/util_test$(EE)
+       tests/unit/exceptions_test$(EE)
+       tests/unit/properties_test$(EE)
+       tests/unit/index_test$(EE)
+       tests/unit/prob_test$(EE)
+       tests/unit/factor_test$(EE)
+       tests/unit/factorgraph_test$(EE)
+       tests/unit/clustergraph_test$(EE)
+       tests/unit/regiongraph_test$(EE)
+       tests/unit/daialg_test$(EE)
+       tests/unit/alldai_test$(EE)
+
+tests : tests/testdai$(EE) tests/testem/testem$(EE) tests/testbbp$(EE) $(unittests)
+
+utils : utils/createfg$(EE) utils/fg2dot$(EE) utils/fginfo$(EE) utils/uai2fg$(EE)
+
+lib: $(LIB)/libdai$(LE)
+
+
+# OBJECTS
+##########
 
-matlabs : matlab/dai.$(MEXEXT) matlab/dai_readfg.$(MEXEXT) matlab/dai_writefg.$(MEXEXT) matlab/dai_removeshortloops.$(MEXEXT) matlab/dai_potstrength.$(MEXEXT)
+%$(OE) : $(SRC)/%.cpp $(INC)/%.h $(HEADERS)
+       $(CC) -c $<
 
-$(LIB)/libdai.a : daialg.o alldai.o clustergraph.o factorgraph.o properties.o regiongraph.o util.o weightedgraph.o x2x.o $(OBJECTS)
-       ar rcs $(LIB)/libdai.a daialg.o alldai.o clustergraph.o factorgraph.o properties.o regiongraph.o util.o weightedgraph.o x2x.o $(OBJECTS)
+bbp$(OE) : $(SRC)/bbp.cpp $(INC)/bbp.h $(INC)/bp_dual.h $(HEADERS)
+       $(CC) -c $<
 
-tests : tests/test
+cbp$(OE) : $(SRC)/cbp.cpp $(INC)/cbp.h $(INC)/bbp.h $(INC)/bp_dual.h $(HEADERS)
+       $(CC) -c $<
 
-utils : utils/createfg utils/fg2dot utils/remove_short_loops utils/fginfo
+hak$(OE) : $(SRC)/hak.cpp $(INC)/hak.h $(HEADERS) $(INC)/regiongraph.h
+       $(CC) -c $<
 
-testregression : tests/test
-       echo Testing...this can take a while...
-       cd tests; time ./testregression; cd ..
+jtree$(OE) : $(SRC)/jtree.cpp $(INC)/jtree.h $(HEADERS) $(INC)/weightedgraph.h $(INC)/clustergraph.h $(INC)/regiongraph.h
+       $(CC) -c $<
 
-doc : $(INC)/*.h $(SRC)/*.cpp doxygen.conf
-       doxygen doxygen.conf
+treeep$(OE) : $(SRC)/treeep.cpp $(INC)/treeep.h $(HEADERS) $(INC)/weightedgraph.h $(INC)/clustergraph.h $(INC)/regiongraph.h $(INC)/jtree.h
+       $(CC) -c $<
 
-clean :
-       rm *.o example matlab/*.$(MEXEXT) matlab/*.o tests/test utils/fg2dot utils/createfg utils/remove_short_loops utils/fginfo $(LIB)/libdai.a; echo
-       rm -R doc; echo
+emalg$(OE) : $(SRC)/emalg.cpp $(INC)/emalg.h $(INC)/evidence.h $(HEADERS)
+       $(CC) -c $<
 
+decmap$(OE) : $(SRC)/decmap.cpp $(INC)/decmap.h $(HEADERS)
+       $(CC) -c $<
 
-daialg.o : $(SRC)/daialg.cpp $(HEADERS)
-       $(CC) $(CCFLAGS) -c $(SRC)/daialg.cpp
 
-bp.o : $(SRC)/bp.cpp $(INC)/bp.h $(HEADERS)
-       $(CC) $(CCFLAGS) -c $(SRC)/bp.cpp
+# EXAMPLES
+###########
 
-lc.o : $(SRC)/lc.cpp $(INC)/lc.h $(HEADERS)
-       $(CC) $(CCFLAGS) -c $(SRC)/lc.cpp
+examples/%$(EE) : examples/%.cpp $(HEADERS) $(LIB)/libdai$(LE)
+       $(CC) $(CCO)$@ $< $(LIBS)
 
-mf.o : $(SRC)/mf.cpp $(INC)/mf.h $(HEADERS)
-       $(CC) $(CCFLAGS) -c $(SRC)/mf.cpp
+examples/example_sprinkler_gibbs$(EE) : examples/example_sprinkler_gibbs.cpp $(HEADERS) $(LIB)/libdai$(LE)
+ifdef WITH_GIBBS
+       $(CC) $(CCO)$@ $< $(LIBS)
+else
+       @echo Skipping $@
+endif
 
-factorgraph.o : $(SRC)/factorgraph.cpp $(INC)/factorgraph.h $(HEADERS)
-       $(CC) $(CCFLAGS) -c $(SRC)/factorgraph.cpp
+examples/example_imagesegmentation$(EE) : examples/example_imagesegmentation.cpp $(HEADERS) $(LIB)/libdai$(LE)
+       -$(CC) $(CIMGINC) $(CCO)$@ $< $(LIBS) $(CIMGLIBS)
 
-util.o : $(SRC)/util.cpp $(INC)/util.h $(HEADERS)
-       $(CC) $(CCFLAGS) -c $(SRC)/util.cpp
 
-regiongraph.o : $(SRC)/regiongraph.cpp $(INC)/regiongraph.h $(HEADERS)
-       $(CC) $(CCFLAGS) -c $(SRC)/regiongraph.cpp
+# UNIT TESTS
+#############
 
-hak.o : $(SRC)/hak.cpp $(INC)/hak.h $(HEADERS) $(INC)/regiongraph.h
-       $(CC) $(CCFLAGS) -c $(SRC)/hak.cpp
+tests/unit/%$(EE) : tests/unit/%.cpp $(HEADERS) $(LIB)/libdai$(LE)
+ifneq ($(OS),WINDOWS)
+       $(CC) -DBOOST_TEST_DYN_LINK $(CCO)$@ $< $(LIBS) $(BOOSTLIBS_UTF)
+else
+       $(CC) $(CCO)$@ $< $(LIBS) $(BOOSTLIBS_UTF) /SUBSYSTEM:CONSOLE
+endif
 
-clustergraph.o : $(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
-       $(CC) $(CCFLAGS) -c $(SRC)/jtree.cpp
+# TESTS
+########
 
-treeep.o : $(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
+tests/testdai$(EE) : tests/testdai.cpp $(HEADERS) $(LIB)/libdai$(LE)
+       $(CC) $(CCO)$@ $< $(LIBS) $(BOOSTLIBS_PO)
+tests/testem/testem$(EE) : tests/testem/testem.cpp $(HEADERS) $(LIB)/libdai$(LE)
+       $(CC) $(CCO)$@ $< $(LIBS) $(BOOSTLIBS_PO)
+tests/testbbp$(EE) : tests/testbbp.cpp $(HEADERS) $(LIB)/libdai$(LE)
+ifdef WITH_CBP
+       $(CC) $(CCO)$@ $< $(LIBS)
+else
+       @echo Skipping $@
+endif
 
-weightedgraph.o : $(SRC)/weightedgraph.cpp $(INC)/weightedgraph.h $(HEADERS)
-       $(CC) $(CCFLAGS) -c $(SRC)/weightedgraph.cpp
 
-mr.o : $(SRC)/mr.cpp $(INC)/mr.h $(HEADERS)
-       $(CC) $(CCFLAGS) -c $(SRC)/mr.cpp
+# MATLAB INTERFACE
+###################
 
-properties.o : $(SRC)/properties.cpp $(HEADERS)
-       $(CC) $(CCFLAGS) -c $(SRC)/properties.cpp
+matlab/dai$(ME) : $(SRC)/matlab/dai.cpp $(HEADERS) $(SOURCES) $(SRC)/matlab/matlab.cpp
+       $(MEX) -output $@ $< $(SRC)/matlab/matlab.cpp $(SOURCES)
 
-alldai.o : $(SRC)/alldai.cpp $(HEADERS)
-       $(CC) $(CCFLAGS) -c $(SRC)/alldai.cpp
+matlab/dai_readfg$(ME) : $(SRC)/matlab/dai_readfg.cpp $(HEADERS) $(SRC)/matlab/matlab.cpp $(SRC)/factorgraph.cpp $(SRC)/exceptions.cpp $(SRC)/bipgraph.cpp $(SRC)/graph.cpp $(SRC)/factor.cpp $(SRC)/util.cpp
+       $(MEX) -output $@ $< $(SRC)/matlab/matlab.cpp $(SRC)/factorgraph.cpp $(SRC)/exceptions.cpp $(SRC)/bipgraph.cpp $(SRC)/graph.cpp $(SRC)/factor.cpp $(SRC)/util.cpp
 
-x2x.o : $(SRC)/x2x.cpp $(HEADERS)
-       $(CC) $(CCFLAGS) -c $(SRC)/x2x.cpp
+matlab/dai_writefg$(ME) : $(SRC)/matlab/dai_writefg.cpp $(HEADERS) $(SRC)/matlab/matlab.cpp $(SRC)/factorgraph.cpp $(SRC)/exceptions.cpp $(SRC)/bipgraph.cpp $(SRC)/graph.cpp $(SRC)/factor.cpp $(SRC)/util.cpp
+       $(MEX) -output $@ $< $(SRC)/matlab/matlab.cpp $(SRC)/factorgraph.cpp $(SRC)/exceptions.cpp $(SRC)/bipgraph.cpp $(SRC)/graph.cpp $(SRC)/factor.cpp $(SRC)/util.cpp
 
-# EXAMPLE
-##########
+matlab/dai_potstrength$(ME) : $(SRC)/matlab/dai_potstrength.cpp $(HEADERS) $(SRC)/matlab/matlab.cpp $(SRC)/exceptions.cpp
+       $(MEX) -output $@ $< $(SRC)/matlab/matlab.cpp $(SRC)/exceptions.cpp
 
-example : example.cpp $(HEADERS) $(LIB)/libdai.a
-       $(CC) $(CCFLAGS) -o example example.cpp -ldai
 
-# TESTS
+# UTILS
 ########
 
-tests/test : tests/test.cpp $(HEADERS) $(LIB)/libdai.a
-       $(CC) $(CCFLAGS) -o tests/test tests/test.cpp -ldai $(BOOSTFLAGS)
+utils/createfg$(EE) : utils/createfg.cpp $(HEADERS) $(LIB)/libdai$(LE)
+       $(CC) $(CCO)$@ $< $(LIBS) $(BOOSTLIBS_PO)
 
+utils/fg2dot$(EE) : utils/fg2dot.cpp $(HEADERS) $(LIB)/libdai$(LE)
+       $(CC) $(CCO)$@ $< $(LIBS)
 
-# MATLAB INTERFACE
-###################
+utils/fginfo$(EE) : utils/fginfo.cpp $(HEADERS) $(LIB)/libdai$(LE)
+       $(CC) $(CCO)$@ $< $(LIBS)
 
-matlab/dai.$(MEXEXT) : matlab/dai.cpp $(HEADERS) matlab/matlab.o $(LIB)/libdai.a
-       $(MEX) $(MEXFLAGS) -o matlab/dai matlab/dai.cpp matlab/matlab.o $(LIB)/libdai.a
+utils/uai2fg$(EE) : utils/uai2fg.cpp $(HEADERS) $(LIB)/libdai$(LE)
+       $(CC) $(CCO)$@ $< $(LIBS)
 
-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_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
+# LIBRARY
+##########
 
-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
+ifneq ($(OS),WINDOWS)
+$(LIB)/libdai$(LE) : $(OBJECTS)
+       -mkdir -p lib
+       ar rcus $(LIB)/libdai$(LE) $(OBJECTS)
+else
+$(LIB)/libdai$(LE) : $(OBJECTS)
+       -mkdir lib
+       lib /out:$(LIB)/libdai$(LE) $(OBJECTS)
+endif
 
-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/matlab.o : matlab/matlab.cpp matlab/matlab.h $(HEADERS)
-       $(MEX) $(MEXFLAGS) -outdir matlab -c matlab/matlab.cpp
+# REGRESSION TESTS
+###################
 
+testregression : tests/testdai$(EE)
+       @echo Starting regression test...this can take a minute or so!
+ifneq ($(OS),WINDOWS)
+       cd tests && ./testregression && cd ..
+else
+       cd tests && testregression.bat && cd ..
+endif
+
+testem : tests/testem/testem$(EE)
+       @echo Starting EM tests
+ifneq ($(OS),WINDOWS)
+       cd tests/testem && ./runtests && cd ../..
+else
+       cd tests\testem && runtests && cd ..\..
+endif
 
-# 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)
+# DOCUMENTATION
+################
+
+doc : $(INC)/*.h $(SRC)/*.cpp examples/*.cpp doxygen.conf
+       doxygen doxygen.conf
 
-utils/fg2dot : utils/fg2dot.cpp $(HEADERS) factorgraph.o
-       $(CC) $(CCFLAGS) -o utils/fg2dot utils/fg2dot.cpp factorgraph.o
+README : doc scripts/makeREADME
+       DAI_VERSION=$(DAI_VERSION) DAI_DATE=$(DAI_DATE) scripts/makeREADME
 
-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
+TAGS :
+       etags src/*.cpp include/dai/*.h tests/*.cpp utils/*.cpp
+       ctags src/*.cpp include/dai/*.h tests/*.cpp utils/*.cpp
 
-utils/fginfo : utils/fginfo.cpp $(HEADERS) factorgraph.o
-       $(CC) $(CCFLAGS) -o utils/fginfo utils/fginfo.cpp factorgraph.o
+
+# CLEAN
+########
+
+.PHONY : clean
+ifneq ($(OS),WINDOWS)
+clean :
+       -rm $(OBJECTS)
+       -rm matlab/*$(ME)
+       -rm examples/example$(EE) examples/example_bipgraph$(EE) examples/example_varset$(EE) examples/example_permute$(EE) examples/example_sprinkler$(EE) examples/example_sprinkler_gibbs$(EE) examples/example_sprinkler_em$(EE) examples/example_imagesegmentation$(EE)
+       -rm tests/testdai$(EE) tests/testem/testem$(EE) tests/testbbp$(EE)
+       -rm tests/unit/var_test$(EE) tests/unit/smallset_test$(EE) tests/unit/varset_test$(EE) tests/unit/graph_test$(EE) tests/unit/dag_test$(EE) tests/unit/bipgraph_test$(EE) tests/unit/weightedgraph_test$(EE) tests/unit/enum_test$(EE) tests/unit/util_test$(EE) tests/unit/exceptions_test$(EE) tests/unit/properties_test$(EE) tests/unit/index_test$(EE) tests/unit/prob_test$(EE) tests/unit/factor_test$(EE) tests/unit/factorgraph_test$(EE) tests/unit/clustergraph_test$(EE) tests/unit/regiongraph_test$(EE) tests/unit/daialg_test$(EE) tests/unit/alldai_test$(EE)
+       -rm factorgraph_test.fg alldai_test.aliases
+       -rm utils/fg2dot$(EE) utils/createfg$(EE) utils/fginfo$(EE) utils/uai2fg$(EE)
+       -rm -R doc
+       -rm -R lib
+else
+clean :
+       -del *.obj
+       -del *.ilk
+       -del *.pdb
+       -del matlab\*$(ME)
+       -del examples\*$(EE)
+       -del examples\*$(EE).manifest
+       -del examples\*.ilk
+       -del examples\*.pdb
+       -del tests\*$(EE)
+       -del tests\*$(EE).manifest
+       -del tests\*.pdb
+       -del tests\*.ilk
+       -del tests\testem\*$(EE)
+       -del tests\testem\*$(EE).manifest
+       -del tests\testem\*.pdb
+       -del tests\testem\*.ilk
+       -del utils\*$(EE)
+       -del utils\*$(EE).manifest
+       -del utils\*.pdb
+       -del utils\*.ilk
+       -del tests\unit\*_test$(EE)
+       -del tests\unit\*_test$(EE).manifest
+       -del tests\unit\*_test.pdb
+       -del tests\unit\*_test.ilk
+       -del factorgraph_test.fg
+       -del alldai_test.aliases
+       -del $(LIB)\libdai$(LE)
+       -rmdir lib
+endif