Added TProb<T>::operator==( const TProb<T> & ) and added some unit tests for prob...
[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) tests/unit/bipgraph$(EE) tests/unit/weightedgraph$(EE) tests/unit/enum$(EE) tests/unit/enum$(EE) tests/unit/util$(EE) tests/unit/properties$(EE) tests/unit/index$(EE) tests/unit/prob$(EE)
126 echo Running unit tests...
127 tests/unit/var$(EE)
128 tests/unit/smallset$(EE)
129 tests/unit/varset$(EE)
130 tests/unit/graph$(EE)
131 tests/unit/bipgraph$(EE)
132 tests/unit/weightedgraph$(EE)
133 tests/unit/enum$(EE)
134 tests/unit/util$(EE)
135 tests/unit/properties$(EE)
136 tests/unit/index$(EE)
137 tests/unit/prob$(EE)
138
139 tests : tests/testdai$(EE) tests/testem/testem$(EE) tests/testbbp$(EE) $(unittests)
140
141 utils : utils/createfg$(EE) utils/fg2dot$(EE) utils/fginfo$(EE)
142
143 lib: $(LIB)/libdai$(LE)
144
145
146 # OBJECTS
147 ##########
148
149 %$(OE) : $(SRC)/%.cpp $(INC)/%.h $(HEADERS)
150 $(CC) -c $< -o $@
151
152 bbp$(OE) : $(SRC)/bbp.cpp $(INC)/bbp.h $(INC)/bp_dual.h $(HEADERS)
153 $(CC) -c $<
154
155 cbp$(OE) : $(SRC)/cbp.cpp $(INC)/cbp.h $(INC)/bbp.h $(INC)/bp_dual.h $(HEADERS)
156 $(CC) -c $<
157
158 hak$(OE) : $(SRC)/hak.cpp $(INC)/hak.h $(HEADERS) $(INC)/regiongraph.h
159 $(CC) -c $<
160
161 jtree$(OE) : $(SRC)/jtree.cpp $(INC)/jtree.h $(HEADERS) $(INC)/weightedgraph.h $(INC)/clustergraph.h $(INC)/regiongraph.h
162 $(CC) -c $<
163
164 treeep$(OE) : $(SRC)/treeep.cpp $(INC)/treeep.h $(HEADERS) $(INC)/weightedgraph.h $(INC)/clustergraph.h $(INC)/regiongraph.h $(INC)/jtree.h
165 $(CC) -c $<
166
167 emalg$(OE) : $(SRC)/emalg.cpp $(INC)/emalg.h $(INC)/evidence.h $(HEADERS)
168 $(CC) -c $<
169
170
171 # EXAMPLES
172 ###########
173
174 examples/example$(EE) : examples/example.cpp $(HEADERS) $(LIB)/libdai$(LE)
175 $(CC) $(CCO)$@ $< $(LIBS)
176
177 examples/example_bipgraph$(EE) : examples/example_bipgraph.cpp $(HEADERS) $(LIB)/libdai$(LE)
178 $(CC) $(CCO)$@ $< $(LIBS)
179
180 examples/example_varset$(EE) : examples/example_varset.cpp $(HEADERS) $(LIB)/libdai$(LE)
181 $(CC) $(CCO)$@ $< $(LIBS)
182
183 examples/example_permute$(EE) : examples/example_permute.cpp $(HEADERS) $(LIB)/libdai$(LE)
184 $(CC) $(CCO)$@ $< $(LIBS)
185
186 examples/example_sprinkler$(EE) : examples/example_sprinkler.cpp $(HEADERS) $(LIB)/libdai$(LE)
187 $(CC) $(CCO)$@ $< $(LIBS)
188
189 examples/example_sprinkler_gibbs$(EE) : examples/example_sprinkler_gibbs.cpp $(HEADERS) $(LIB)/libdai$(LE)
190 $(CC) $(CCO)$@ $< $(LIBS)
191
192 examples/example_sprinkler_em$(EE) : examples/example_sprinkler_em.cpp $(HEADERS) $(LIB)/libdai$(LE)
193 $(CC) $(CCO)$@ $< $(LIBS)
194
195
196 # UNIT TESTS
197 #############
198
199 tests/unit/var$(EE) : tests/unit/var.cpp $(HEADERS) $(LIB)/libdai$(LE)
200 $(CC) $(CCO)$@ $< $(LIBS) $(BOOSTLIBS_UTF)
201 tests/unit/smallset$(EE) : tests/unit/smallset.cpp $(HEADERS) $(LIB)/libdai$(LE)
202 $(CC) $(CCO)$@ $< $(LIBS) $(BOOSTLIBS_UTF)
203 tests/unit/varset$(EE) : tests/unit/varset.cpp $(HEADERS) $(LIB)/libdai$(LE)
204 $(CC) $(CCO)$@ $< $(LIBS) $(BOOSTLIBS_UTF)
205 tests/unit/graph$(EE) : tests/unit/graph.cpp $(HEADERS) $(LIB)/libdai$(LE)
206 $(CC) $(CCO)$@ $< $(LIBS) $(BOOSTLIBS_UTF)
207 tests/unit/bipgraph$(EE) : tests/unit/bipgraph.cpp $(HEADERS) $(LIB)/libdai$(LE)
208 $(CC) $(CCO)$@ $< $(LIBS) $(BOOSTLIBS_UTF)
209 tests/unit/weightedgraph$(EE) : tests/unit/weightedgraph.cpp $(HEADERS) $(LIB)/libdai$(LE)
210 $(CC) $(CCO)$@ $< $(LIBS) $(BOOSTLIBS_UTF)
211 tests/unit/enum$(EE) : tests/unit/enum.cpp $(HEADERS) $(LIB)/libdai$(LE)
212 $(CC) $(CCO)$@ $< $(LIBS) $(BOOSTLIBS_UTF)
213 tests/unit/util$(EE) : tests/unit/util.cpp $(HEADERS) $(LIB)/libdai$(LE)
214 $(CC) $(CCO)$@ $< $(LIBS) $(BOOSTLIBS_UTF)
215 tests/unit/properties$(EE) : tests/unit/properties.cpp $(HEADERS) $(LIB)/libdai$(LE)
216 $(CC) $(CCO)$@ $< $(LIBS) $(BOOSTLIBS_UTF)
217 tests/unit/index$(EE) : tests/unit/index.cpp $(HEADERS) $(LIB)/libdai$(LE)
218 $(CC) $(CCO)$@ $< $(LIBS) $(BOOSTLIBS_UTF)
219 tests/unit/prob$(EE) : tests/unit/prob.cpp $(HEADERS) $(LIB)/libdai$(LE)
220 $(CC) $(CCO)$@ $< $(LIBS) $(BOOSTLIBS_UTF)
221
222
223 # TESTS
224 ########
225
226 tests/testdai$(EE) : tests/testdai.cpp $(HEADERS) $(LIB)/libdai$(LE)
227 $(CC) $(CCO)$@ $< $(LIBS) $(BOOSTLIBS_PO)
228 tests/testem/testem$(EE) : tests/testem/testem.cpp $(HEADERS) $(LIB)/libdai$(LE)
229 $(CC) $(CCO)$@ $< $(LIBS) $(BOOSTLIBS_PO)
230
231 tests/testbbp$(EE) : tests/testbbp.cpp $(HEADERS) $(LIB)/libdai$(LE)
232 $(CC) $(CCO)$@ $< $(LIBS)
233
234
235 # MATLAB INTERFACE
236 ###################
237
238 matlab/dai$(ME) : $(SRC)/matlab/dai.cpp $(HEADERS) matlab$(OE) $(LIB)/libdai$(LE)
239 $(MEX) -o$@ $< matlab$(OE) $(LIB)/libdai$(LE)
240
241 matlab/dai_readfg$(ME) : $(SRC)/matlab/dai_readfg.cpp $(HEADERS) factorgraph$(OE) matlab$(OE) exceptions$(OE) bipgraph$(OE)
242 $(MEX) -o$@ $< factorgraph$(OE) matlab$(OE) exceptions$(OE) bipgraph$(OE)
243
244 matlab/dai_writefg$(ME) : $(SRC)/matlab/dai_writefg.cpp $(HEADERS) factorgraph$(OE) matlab$(OE) exceptions$(OE) bipgraph$(OE)
245 $(MEX) -o$@ $< factorgraph$(OE) matlab$(OE) exceptions$(OE) bipgraph$(OE)
246
247 matlab/dai_potstrength$(ME) : $(SRC)/matlab/dai_potstrength.cpp $(HEADERS) matlab$(OE) exceptions$(OE)
248 $(MEX) -o$@ $< matlab$(OE) exceptions$(OE)
249
250 matlab$(OE) : $(SRC)/matlab/matlab.cpp $(INC)/matlab/matlab.h $(HEADERS)
251 $(MEX) -c $<
252
253
254 # UTILS
255 ########
256
257 utils/createfg$(EE) : utils/createfg.cpp $(HEADERS) $(LIB)/libdai$(LE)
258 $(CC) $(CCO)$@ $< $(LIBS) $(BOOSTLIBS_PO)
259
260 utils/fg2dot$(EE) : utils/fg2dot.cpp $(HEADERS) $(LIB)/libdai$(LE)
261 $(CC) $(CCO)$@ $< $(LIBS)
262
263 utils/fginfo$(EE) : utils/fginfo.cpp $(HEADERS) $(LIB)/libdai$(LE)
264 $(CC) $(CCO)$@ $< $(LIBS)
265
266
267 # LIBRARY
268 ##########
269
270 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)
271
272 ifneq ($(OS),WINDOWS)
273 $(LIB)/libdai$(LE) : $(OBJECTS)
274 -mkdir -p lib
275 ar rcus $(LIB)/libdai$(LE) $(OBJECTS)
276 else
277 $(LIB)/libdai$(LE) : $(OBJECTS)
278 -mkdir lib
279 lib /out:$(LIB)/libdai$(LE) $(OBJECTS)
280 endif
281
282
283 # REGRESSION TESTS
284 ###################
285
286 testregression : tests/testdai$(EE)
287 @echo Starting regression test...this can take a minute or so!
288 ifneq ($(OS),WINDOWS)
289 cd tests && ./testregression && cd ..
290 else
291 cd tests && testregression.bat && cd ..
292 endif
293
294 testem : tests/testem/testem$(EE)
295 @echo Starting EM tests
296 ifneq ($(OS),WINDOWS)
297 cd tests/testem && ./runtests && cd ../..
298 else
299 cd tests\testem && runtests && cd ..\..
300 endif
301
302
303 # DOCUMENTATION
304 ################
305
306 doc : $(INC)/*.h $(SRC)/*.cpp examples/*.cpp doxygen.conf
307 doxygen doxygen.conf
308
309 README : doc scripts/makeREADME
310 DAI_VERSION=$(DAI_VERSION) DAI_DATE=$(DAI_DATE) scripts/makeREADME
311
312 TAGS :
313 etags src/*.cpp include/dai/*.h tests/*.cpp utils/*.cpp
314 ctags src/*.cpp include/dai/*.h tests/*.cpp utils/*.cpp
315
316
317 # CLEAN
318 ########
319
320 ifneq ($(OS),WINDOWS)
321 .PHONY : clean
322 clean :
323 -rm *$(OE)
324 -rm matlab/*$(ME)
325 -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)
326 -rm tests/testdai$(EE) tests/testem/testem$(EE) tests/testbbp$(EE)
327 -rm tests/unit/var$(EE) tests/unit/smallset$(EE) tests/unit/varset$(EE) tests/unit/graph$(EE) tests/unit/bipgraph$(EE) tests/unit/weightedgraph$(EE) tests/unit/enum$(EE) tests/unit/util$(EE) tests/unit/properties$(EE) tests/unit/index$(EE) tests/unit/prob$(EE)
328 -rm utils/fg2dot$(EE) utils/createfg$(EE) utils/fginfo$(EE)
329 -rm -R doc
330 -rm -R lib
331 else
332 .PHONY : clean
333 clean :
334 -del *$(OE)
335 -del *.ilk
336 -del *.pdb
337 -del *$(EE)
338 -del matlab\*$(ME)
339 -del examples\*$(EE)
340 -del examples\*.ilk
341 -del examples\*.pdb
342 -del tests\testdai$(EE)
343 -del tests\testbbp$(EE)
344 -del tests\testem\testem$(EE)
345 -del tests\*.pdb
346 -del tests\*.ilk
347 -del tests\testem\*.pdb
348 -del tests\testem\*.ilk
349 -del utils\*$(EE)
350 -del utils\*.pdb
351 -del utils\*.ilk
352 -del tests\unit\*.pdk
353 -del tests\unit\*.ilk
354 -del tests\unit\var$(EE)
355 -del tests\unit\smallset$(EE)
356 -del tests\unit\varset$(EE)
357 -del tests\unit\graph$(EE)
358 -del tests\unit\bipgraph$(EE)
359 -del tests\unit\weightedgraph$(EE)
360 -del tests\unit\enum$(EE)
361 -del tests\unit\util$(EE)
362 -del tests\unit\properties$(EE)
363 -del tests\unit\index$(EE)
364 -del tests\unit\prob$(EE)
365 -del $(LIB)\libdai$(LE)
366 -rmdir lib
367 endif