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