Added GraphAL unit tests, fixed 6 bugs in GraphAL and added functionality:
[libdai.git] / Makefile
1 # This file is part of libDAI - http://www.libdai.org/
2 #
3 # libDAI is licensed under the terms of the GNU General Public License version
4 # 2, or (at your option) any later version. libDAI is distributed without any
5 # warranty. See the file COPYING for more details.
6 #
7 # Copyright (C) 2006-2010 Joris Mooij [joris dot mooij at libdai dot org]
8 # Copyright (C) 2006-2007 Radboud University Nijmegen, The Netherlands
9
10
11 # Load the platform independent build configuration file
12 include Makefile.ALL
13
14 # Load the local configuration from Makefile.conf
15 include Makefile.conf
16
17 # Set version and date
18 DAI_VERSION="git HEAD"
19 DAI_DATE="February 11, 2010 - or later"
20
21 # Directories of libDAI sources
22 # Location libDAI headers
23 INC=include/dai
24 # Location of libDAI source files
25 SRC=src
26 # Destination directory of libDAI library
27 LIB=lib
28
29 # Set final compiler flags
30 ifdef DEBUG
31 CCFLAGS:=$(CCFLAGS) $(CCDEBUGFLAGS)
32 else
33 CCFLAGS:=$(CCFLAGS) $(CCNODEBUGFLAGS)
34 endif
35
36 # Define build targets
37 TARGETS=tests utils lib examples unittests testregression testem
38 ifdef WITH_DOC
39 TARGETS:=$(TARGETS) doc
40 endif
41 ifdef WITH_MATLAB
42 TARGETS:=$(TARGETS) matlabs
43 # Specify the same C++ compiler and flags to mex
44 ifneq ($(OS),WINDOWS)
45 MEXFLAGS=CXX\#$(CC) CXXFLAGS\#'$(CCFLAGS)'
46 else
47 MEXFLAGS=CXX\#$(CC) CXXFLAGS\#"$(CCFLAGS)"
48 endif
49 ifdef NEW_MATLAB
50 MEXFLAGS:=$(MEXFLAGS) -largeArrayDims
51 else
52 MEXFLAGS:=$(MEXFLAGS) -DSMALLMEM
53 endif
54 endif
55
56 # Define conditional build targets
57 OBJECTS:=exactinf$(OE) evidence$(OE) emalg$(OE)
58 ifdef WITH_BP
59 CCFLAGS:=$(CCFLAGS) -DDAI_WITH_BP
60 OBJECTS:=$(OBJECTS) bp$(OE)
61 endif
62 ifdef WITH_FBP
63 CCFLAGS:=$(CCFLAGS) -DDAI_WITH_FBP
64 OBJECTS:=$(OBJECTS) fbp$(OE)
65 endif
66 ifdef WITH_TRWBP
67 CCFLAGS:=$(CCFLAGS) -DDAI_WITH_TRWBP
68 OBJECTS:=$(OBJECTS) trwbp$(OE)
69 endif
70 ifdef WITH_MF
71 CCFLAGS:=$(CCFLAGS) -DDAI_WITH_MF
72 OBJECTS:=$(OBJECTS) mf$(OE)
73 endif
74 ifdef WITH_HAK
75 CCFLAGS:=$(CCFLAGS) -DDAI_WITH_HAK
76 OBJECTS:=$(OBJECTS) hak$(OE)
77 endif
78 ifdef WITH_LC
79 CCFLAGS:=$(CCFLAGS) -DDAI_WITH_LC
80 OBJECTS:=$(OBJECTS) lc$(OE)
81 endif
82 ifdef WITH_TREEEP
83 CCFLAGS:=$(CCFLAGS) -DDAI_WITH_TREEEP
84 OBJECTS:=$(OBJECTS) treeep$(OE)
85 endif
86 ifdef WITH_JTREE
87 CCFLAGS:=$(CCFLAGS) -DDAI_WITH_JTREE
88 OBJECTS:=$(OBJECTS) jtree$(OE)
89 endif
90 ifdef WITH_MR
91 CCFLAGS:=$(CCFLAGS) -DDAI_WITH_MR
92 OBJECTS:=$(OBJECTS) mr$(OE)
93 endif
94 ifdef WITH_GIBBS
95 CCFLAGS:=$(CCFLAGS) -DDAI_WITH_GIBBS
96 OBJECTS:=$(OBJECTS) gibbs$(OE)
97 endif
98 ifdef WITH_CBP
99 CCFLAGS:=$(CCFLAGS) -DDAI_WITH_CBP
100 OBJECTS:=$(OBJECTS) bbp$(OE) cbp$(OE) bp_dual$(OE)
101 endif
102
103 # Define standard libDAI header dependencies
104 HEADERS=$(INC)/bipgraph.h $(INC)/graph.h $(INC)/index.h $(INC)/var.h $(INC)/factor.h $(INC)/varset.h $(INC)/smallset.h $(INC)/prob.h $(INC)/daialg.h $(INC)/properties.h $(INC)/alldai.h $(INC)/enum.h $(INC)/exceptions.h $(INC)/util.h
105
106 # Setup final command for C++ compiler and MEX
107 ifneq ($(OS),WINDOWS)
108 CC:=$(CC) $(CCINC) $(CCFLAGS) $(CCLIB)
109 else
110 CC:=$(CC) $(CCINC) $(CCFLAGS)
111 LIBS:=$(LIBS) $(CCLIB)
112 endif
113 MEX:=$(MEX) $(CCLIB) $(CCINC) $(MEXFLAGS)
114
115
116 # META TARGETS
117 ###############
118
119 all : $(TARGETS)
120
121 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)
122
123 matlabs : matlab/dai$(ME) matlab/dai_readfg$(ME) matlab/dai_writefg$(ME) matlab/dai_potstrength$(ME)
124
125 unittests : tests/unit/var$(EE) tests/unit/smallset$(EE) tests/unit/varset$(EE) tests/unit/graph$(EE)
126 echo Running unit tests...
127 tests/unit/var
128 tests/unit/smallset
129 tests/unit/varset
130 tests/unit/graph
131
132 tests : tests/testdai$(EE) tests/testem/testem$(EE) tests/testbbp$(EE) $(unittests)
133
134 utils : utils/createfg$(EE) utils/fg2dot$(EE) utils/fginfo$(EE)
135
136 lib: $(LIB)/libdai$(LE)
137
138
139 # OBJECTS
140 ##########
141
142 %$(OE) : $(SRC)/%.cpp $(INC)/%.h $(HEADERS)
143 $(CC) -c $< -o $@
144
145 bbp$(OE) : $(SRC)/bbp.cpp $(INC)/bbp.h $(INC)/bp_dual.h $(HEADERS)
146 $(CC) -c $<
147
148 cbp$(OE) : $(SRC)/cbp.cpp $(INC)/cbp.h $(INC)/bbp.h $(INC)/bp_dual.h $(HEADERS)
149 $(CC) -c $<
150
151 hak$(OE) : $(SRC)/hak.cpp $(INC)/hak.h $(HEADERS) $(INC)/regiongraph.h
152 $(CC) -c $<
153
154 jtree$(OE) : $(SRC)/jtree.cpp $(INC)/jtree.h $(HEADERS) $(INC)/weightedgraph.h $(INC)/clustergraph.h $(INC)/regiongraph.h
155 $(CC) -c $<
156
157 treeep$(OE) : $(SRC)/treeep.cpp $(INC)/treeep.h $(HEADERS) $(INC)/weightedgraph.h $(INC)/clustergraph.h $(INC)/regiongraph.h $(INC)/jtree.h
158 $(CC) -c $<
159
160 emalg$(OE) : $(SRC)/emalg.cpp $(INC)/emalg.h $(INC)/evidence.h $(HEADERS)
161 $(CC) -c $<
162
163
164 # EXAMPLES
165 ###########
166
167 examples/example$(EE) : examples/example.cpp $(HEADERS) $(LIB)/libdai$(LE)
168 $(CC) $(CCO)$@ $< $(LIBS)
169
170 examples/example_bipgraph$(EE) : examples/example_bipgraph.cpp $(HEADERS) $(LIB)/libdai$(LE)
171 $(CC) $(CCO)$@ $< $(LIBS)
172
173 examples/example_varset$(EE) : examples/example_varset.cpp $(HEADERS) $(LIB)/libdai$(LE)
174 $(CC) $(CCO)$@ $< $(LIBS)
175
176 examples/example_permute$(EE) : examples/example_permute.cpp $(HEADERS) $(LIB)/libdai$(LE)
177 $(CC) $(CCO)$@ $< $(LIBS)
178
179 examples/example_sprinkler$(EE) : examples/example_sprinkler.cpp $(HEADERS) $(LIB)/libdai$(LE)
180 $(CC) $(CCO)$@ $< $(LIBS)
181
182 examples/example_sprinkler_gibbs$(EE) : examples/example_sprinkler_gibbs.cpp $(HEADERS) $(LIB)/libdai$(LE)
183 $(CC) $(CCO)$@ $< $(LIBS)
184
185 examples/example_sprinkler_em$(EE) : examples/example_sprinkler_em.cpp $(HEADERS) $(LIB)/libdai$(LE)
186 $(CC) $(CCO)$@ $< $(LIBS)
187
188
189 # UNIT TESTS
190 #############
191
192 tests/unit/var$(EE) : tests/unit/var.cpp $(HEADERS) $(LIB)/libdai$(LE)
193 $(CC) $(CCO)$@ $< $(LIBS) $(BOOSTLIBS_UTF)
194 tests/unit/smallset$(EE) : tests/unit/smallset.cpp $(HEADERS) $(LIB)/libdai$(LE)
195 $(CC) $(CCO)$@ $< $(LIBS) $(BOOSTLIBS_UTF)
196 tests/unit/varset$(EE) : tests/unit/varset.cpp $(HEADERS) $(LIB)/libdai$(LE)
197 $(CC) $(CCO)$@ $< $(LIBS) $(BOOSTLIBS_UTF)
198 tests/unit/graph$(EE) : tests/unit/graph.cpp $(HEADERS) $(LIB)/libdai$(LE)
199 $(CC) $(CCO)$@ $< $(LIBS) $(BOOSTLIBS_UTF)
200
201
202 # TESTS
203 ########
204
205 tests/testdai$(EE) : tests/testdai.cpp $(HEADERS) $(LIB)/libdai$(LE)
206 $(CC) $(CCO)$@ $< $(LIBS) $(BOOSTLIBS_PO)
207 tests/testem/testem$(EE) : tests/testem/testem.cpp $(HEADERS) $(LIB)/libdai$(LE)
208 $(CC) $(CCO)$@ $< $(LIBS) $(BOOSTLIBS_PO)
209
210 tests/testbbp$(EE) : tests/testbbp.cpp $(HEADERS) $(LIB)/libdai$(LE)
211 $(CC) $(CCO)$@ $< $(LIBS)
212
213
214 # MATLAB INTERFACE
215 ###################
216
217 matlab/dai$(ME) : $(SRC)/matlab/dai.cpp $(HEADERS) matlab$(OE) $(LIB)/libdai$(LE)
218 $(MEX) -o$@ $< matlab$(OE) $(LIB)/libdai$(LE)
219
220 matlab/dai_readfg$(ME) : $(SRC)/matlab/dai_readfg.cpp $(HEADERS) factorgraph$(OE) matlab$(OE) exceptions$(OE) bipgraph$(OE)
221 $(MEX) -o$@ $< factorgraph$(OE) matlab$(OE) exceptions$(OE) bipgraph$(OE)
222
223 matlab/dai_writefg$(ME) : $(SRC)/matlab/dai_writefg.cpp $(HEADERS) factorgraph$(OE) matlab$(OE) exceptions$(OE) bipgraph$(OE)
224 $(MEX) -o$@ $< factorgraph$(OE) matlab$(OE) exceptions$(OE) bipgraph$(OE)
225
226 matlab/dai_potstrength$(ME) : $(SRC)/matlab/dai_potstrength.cpp $(HEADERS) matlab$(OE) exceptions$(OE)
227 $(MEX) -o$@ $< matlab$(OE) exceptions$(OE)
228
229 matlab$(OE) : $(SRC)/matlab/matlab.cpp $(INC)/matlab/matlab.h $(HEADERS)
230 $(MEX) -c $<
231
232
233 # UTILS
234 ########
235
236 utils/createfg$(EE) : utils/createfg.cpp $(HEADERS) $(LIB)/libdai$(LE)
237 $(CC) $(CCO)$@ $< $(LIBS) $(BOOSTLIBS_PO)
238
239 utils/fg2dot$(EE) : utils/fg2dot.cpp $(HEADERS) $(LIB)/libdai$(LE)
240 $(CC) $(CCO)$@ $< $(LIBS)
241
242 utils/fginfo$(EE) : utils/fginfo.cpp $(HEADERS) $(LIB)/libdai$(LE)
243 $(CC) $(CCO)$@ $< $(LIBS)
244
245
246 # LIBRARY
247 ##########
248
249 OBJECTS:=bipgraph$(OE) graph$(OE) varset$(OE) daialg$(OE) alldai$(OE) clustergraph$(OE) factor$(OE) factorgraph$(OE) properties$(OE) regiongraph$(OE) util$(OE) weightedgraph$(OE) exceptions$(OE) $(OBJECTS)
250
251 ifneq ($(OS),WINDOWS)
252 $(LIB)/libdai$(LE) : $(OBJECTS)
253 -mkdir -p lib
254 ar rcus $(LIB)/libdai$(LE) $(OBJECTS)
255 else
256 $(LIB)/libdai$(LE) : $(OBJECTS)
257 -mkdir lib
258 lib /out:$(LIB)/libdai$(LE) $(OBJECTS)
259 endif
260
261
262 # REGRESSION TESTS
263 ###################
264
265 testregression : tests/testdai$(EE)
266 @echo Starting regression test...this can take a minute or so!
267 ifneq ($(OS),WINDOWS)
268 cd tests && ./testregression && cd ..
269 else
270 cd tests && testregression.bat && cd ..
271 endif
272
273 testem : tests/testem/testem$(EE)
274 @echo Starting EM tests
275 ifneq ($(OS),WINDOWS)
276 cd tests/testem && ./runtests && cd ../..
277 else
278 cd tests\testem && runtests && cd ..\..
279 endif
280
281
282 # DOCUMENTATION
283 ################
284
285 doc : $(INC)/*.h $(SRC)/*.cpp examples/*.cpp doxygen.conf
286 doxygen doxygen.conf
287
288 README : doc scripts/makeREADME
289 DAI_VERSION=$(DAI_VERSION) DAI_DATE=$(DAI_DATE) scripts/makeREADME
290
291 TAGS :
292 etags src/*.cpp include/dai/*.h tests/*.cpp utils/*.cpp
293 ctags src/*.cpp include/dai/*.h tests/*.cpp utils/*.cpp
294
295
296 # CLEAN
297 ########
298
299 ifneq ($(OS),WINDOWS)
300 .PHONY : clean
301 clean :
302 -rm *$(OE)
303 -rm matlab/*$(ME)
304 -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)
305 -rm tests/testdai$(EE) tests/testem/testem$(EE) tests/testbbp$(EE)
306 -rm tests/unit/var$(EE) tests/unit/smallset$(EE) tests/unit/varset$(EE) tests/unit/graph$(EE)
307 -rm utils/fg2dot$(EE) utils/createfg$(EE) utils/fginfo$(EE)
308 -rm -R doc
309 -rm -R lib
310 else
311 .PHONY : clean
312 clean :
313 -del *$(OE)
314 -del *.ilk
315 -del *.pdb
316 -del *$(EE)
317 -del matlab\*$(ME)
318 -del examples\*$(EE)
319 -del examples\*.ilk
320 -del examples\*.pdb
321 -del tests\testdai$(EE)
322 -del tests\testbbp$(EE)
323 -del tests\testem\testem$(EE)
324 -del tests\*.pdb
325 -del tests\*.ilk
326 -del tests\testem\*.pdb
327 -del tests\testem\*.ilk
328 -del utils\*$(EE)
329 -del utils\*.pdb
330 -del utils\*.ilk
331 -del tests\unit\*.pdk
332 -del tests\unit\*.ilk
333 -del tests\unit\var$(EE)
334 -del tests\unit\smallset$(EE)
335 -del tests\unit\varset$(EE)
336 -del tests\unit\graph$(EE)
337 -del $(LIB)\libdai$(LE)
338 -rmdir lib
339 endif