Fixed some bugs and deprecated non-const operator[] of Prob,Factor
[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 ifdef NEW_MATLAB
45 MEXFLAGS:=$(MEXFLAGS) -largeArrayDims
46 else
47 MEXFLAGS:=$(MEXFLAGS) -DSMALLMEM
48 endif
49 endif
50
51 # Define conditional build targets
52 OBJECTS:=exactinf$(OE) evidence$(OE) emalg$(OE)
53 ifdef WITH_BP
54 CCFLAGS:=$(CCFLAGS) -DDAI_WITH_BP
55 OBJECTS:=$(OBJECTS) bp$(OE)
56 endif
57 ifdef WITH_FBP
58 CCFLAGS:=$(CCFLAGS) -DDAI_WITH_FBP
59 OBJECTS:=$(OBJECTS) fbp$(OE)
60 endif
61 ifdef WITH_TRWBP
62 CCFLAGS:=$(CCFLAGS) -DDAI_WITH_TRWBP
63 OBJECTS:=$(OBJECTS) trwbp$(OE)
64 endif
65 ifdef WITH_MF
66 CCFLAGS:=$(CCFLAGS) -DDAI_WITH_MF
67 OBJECTS:=$(OBJECTS) mf$(OE)
68 endif
69 ifdef WITH_HAK
70 CCFLAGS:=$(CCFLAGS) -DDAI_WITH_HAK
71 OBJECTS:=$(OBJECTS) hak$(OE)
72 endif
73 ifdef WITH_LC
74 CCFLAGS:=$(CCFLAGS) -DDAI_WITH_LC
75 OBJECTS:=$(OBJECTS) lc$(OE)
76 endif
77 ifdef WITH_TREEEP
78 CCFLAGS:=$(CCFLAGS) -DDAI_WITH_TREEEP
79 OBJECTS:=$(OBJECTS) treeep$(OE)
80 endif
81 ifdef WITH_JTREE
82 CCFLAGS:=$(CCFLAGS) -DDAI_WITH_JTREE
83 OBJECTS:=$(OBJECTS) jtree$(OE)
84 endif
85 ifdef WITH_MR
86 CCFLAGS:=$(CCFLAGS) -DDAI_WITH_MR
87 OBJECTS:=$(OBJECTS) mr$(OE)
88 endif
89 ifdef WITH_GIBBS
90 CCFLAGS:=$(CCFLAGS) -DDAI_WITH_GIBBS
91 OBJECTS:=$(OBJECTS) gibbs$(OE)
92 endif
93 ifdef WITH_CBP
94 CCFLAGS:=$(CCFLAGS) -DDAI_WITH_CBP
95 OBJECTS:=$(OBJECTS) bbp$(OE) cbp$(OE) bp_dual$(OE)
96 endif
97
98 # Define standard libDAI header dependencies
99 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
100
101 # Setup final command for C++ compiler and MEX
102 ifneq ($(OS),WINDOWS)
103 CC:=$(CC) $(CCINC) $(CCFLAGS) $(CCLIB)
104 else
105 CC:=$(CC) $(CCINC) $(CCFLAGS)
106 LIBS:=$(LIBS) $(CCLIB)
107 endif
108 MEX:=$(MEX) $(CCLIB) $(CCINC) $(MEXFLAGS)
109
110
111 # META TARGETS
112 ###############
113
114 all : $(TARGETS)
115
116 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)
117
118 matlabs : matlab/dai$(ME) matlab/dai_readfg$(ME) matlab/dai_writefg$(ME) matlab/dai_potstrength$(ME)
119
120 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)
121 echo Running unit tests...
122 tests/unit/var$(EE)
123 tests/unit/smallset$(EE)
124 tests/unit/varset$(EE)
125 tests/unit/graph$(EE)
126 tests/unit/bipgraph$(EE)
127 tests/unit/weightedgraph$(EE)
128 tests/unit/enum$(EE)
129 tests/unit/util$(EE)
130 tests/unit/properties$(EE)
131 tests/unit/index$(EE)
132 tests/unit/prob$(EE)
133
134 tests : tests/testdai$(EE) tests/testem/testem$(EE) tests/testbbp$(EE) $(unittests)
135
136 utils : utils/createfg$(EE) utils/fg2dot$(EE) utils/fginfo$(EE)
137
138 lib: $(LIB)/libdai$(LE)
139
140
141 # OBJECTS
142 ##########
143
144 %$(OE) : $(SRC)/%.cpp $(INC)/%.h $(HEADERS)
145 $(CC) -c $< -o $@
146
147 bbp$(OE) : $(SRC)/bbp.cpp $(INC)/bbp.h $(INC)/bp_dual.h $(HEADERS)
148 $(CC) -c $<
149
150 cbp$(OE) : $(SRC)/cbp.cpp $(INC)/cbp.h $(INC)/bbp.h $(INC)/bp_dual.h $(HEADERS)
151 $(CC) -c $<
152
153 hak$(OE) : $(SRC)/hak.cpp $(INC)/hak.h $(HEADERS) $(INC)/regiongraph.h
154 $(CC) -c $<
155
156 jtree$(OE) : $(SRC)/jtree.cpp $(INC)/jtree.h $(HEADERS) $(INC)/weightedgraph.h $(INC)/clustergraph.h $(INC)/regiongraph.h
157 $(CC) -c $<
158
159 treeep$(OE) : $(SRC)/treeep.cpp $(INC)/treeep.h $(HEADERS) $(INC)/weightedgraph.h $(INC)/clustergraph.h $(INC)/regiongraph.h $(INC)/jtree.h
160 $(CC) -c $<
161
162 emalg$(OE) : $(SRC)/emalg.cpp $(INC)/emalg.h $(INC)/evidence.h $(HEADERS)
163 $(CC) -c $<
164
165
166 # EXAMPLES
167 ###########
168
169 examples/example$(EE) : examples/example.cpp $(HEADERS) $(LIB)/libdai$(LE)
170 $(CC) $(CCO)$@ $< $(LIBS)
171
172 examples/example_bipgraph$(EE) : examples/example_bipgraph.cpp $(HEADERS) $(LIB)/libdai$(LE)
173 $(CC) $(CCO)$@ $< $(LIBS)
174
175 examples/example_varset$(EE) : examples/example_varset.cpp $(HEADERS) $(LIB)/libdai$(LE)
176 $(CC) $(CCO)$@ $< $(LIBS)
177
178 examples/example_permute$(EE) : examples/example_permute.cpp $(HEADERS) $(LIB)/libdai$(LE)
179 $(CC) $(CCO)$@ $< $(LIBS)
180
181 examples/example_sprinkler$(EE) : examples/example_sprinkler.cpp $(HEADERS) $(LIB)/libdai$(LE)
182 $(CC) $(CCO)$@ $< $(LIBS)
183
184 examples/example_sprinkler_gibbs$(EE) : examples/example_sprinkler_gibbs.cpp $(HEADERS) $(LIB)/libdai$(LE)
185 $(CC) $(CCO)$@ $< $(LIBS)
186
187 examples/example_sprinkler_em$(EE) : examples/example_sprinkler_em.cpp $(HEADERS) $(LIB)/libdai$(LE)
188 $(CC) $(CCO)$@ $< $(LIBS)
189
190
191 # UNIT TESTS
192 #############
193
194 tests/unit/var$(EE) : tests/unit/var.cpp $(HEADERS) $(LIB)/libdai$(LE)
195 $(CC) $(CCO)$@ $< $(LIBS) $(BOOSTLIBS_UTF)
196 tests/unit/smallset$(EE) : tests/unit/smallset.cpp $(HEADERS) $(LIB)/libdai$(LE)
197 $(CC) $(CCO)$@ $< $(LIBS) $(BOOSTLIBS_UTF)
198 tests/unit/varset$(EE) : tests/unit/varset.cpp $(HEADERS) $(LIB)/libdai$(LE)
199 $(CC) $(CCO)$@ $< $(LIBS) $(BOOSTLIBS_UTF)
200 tests/unit/graph$(EE) : tests/unit/graph.cpp $(HEADERS) $(LIB)/libdai$(LE)
201 $(CC) $(CCO)$@ $< $(LIBS) $(BOOSTLIBS_UTF)
202 tests/unit/bipgraph$(EE) : tests/unit/bipgraph.cpp $(HEADERS) $(LIB)/libdai$(LE)
203 $(CC) $(CCO)$@ $< $(LIBS) $(BOOSTLIBS_UTF)
204 tests/unit/weightedgraph$(EE) : tests/unit/weightedgraph.cpp $(HEADERS) $(LIB)/libdai$(LE)
205 $(CC) $(CCO)$@ $< $(LIBS) $(BOOSTLIBS_UTF)
206 tests/unit/enum$(EE) : tests/unit/enum.cpp $(HEADERS) $(LIB)/libdai$(LE)
207 $(CC) $(CCO)$@ $< $(LIBS) $(BOOSTLIBS_UTF)
208 tests/unit/util$(EE) : tests/unit/util.cpp $(HEADERS) $(LIB)/libdai$(LE)
209 $(CC) $(CCO)$@ $< $(LIBS) $(BOOSTLIBS_UTF)
210 tests/unit/properties$(EE) : tests/unit/properties.cpp $(HEADERS) $(LIB)/libdai$(LE)
211 $(CC) $(CCO)$@ $< $(LIBS) $(BOOSTLIBS_UTF)
212 tests/unit/index$(EE) : tests/unit/index.cpp $(HEADERS) $(LIB)/libdai$(LE)
213 $(CC) $(CCO)$@ $< $(LIBS) $(BOOSTLIBS_UTF)
214 tests/unit/prob$(EE) : tests/unit/prob.cpp $(HEADERS) $(LIB)/libdai$(LE)
215 $(CC) $(CCO)$@ $< $(LIBS) $(BOOSTLIBS_UTF)
216
217
218 # TESTS
219 ########
220
221 tests/testdai$(EE) : tests/testdai.cpp $(HEADERS) $(LIB)/libdai$(LE)
222 $(CC) $(CCO)$@ $< $(LIBS) $(BOOSTLIBS_PO)
223 tests/testem/testem$(EE) : tests/testem/testem.cpp $(HEADERS) $(LIB)/libdai$(LE)
224 $(CC) $(CCO)$@ $< $(LIBS) $(BOOSTLIBS_PO)
225
226 tests/testbbp$(EE) : tests/testbbp.cpp $(HEADERS) $(LIB)/libdai$(LE)
227 $(CC) $(CCO)$@ $< $(LIBS)
228
229
230 # MATLAB INTERFACE
231 ###################
232
233 matlab/dai$(ME) : $(SRC)/matlab/dai.cpp $(HEADERS) matlab$(OE) $(LIB)/libdai$(LE)
234 $(MEX) -output $@ $< matlab$(OE) $(LIB)/libdai$(LE)
235
236 matlab/dai_readfg$(ME) : $(SRC)/matlab/dai_readfg.cpp $(HEADERS) factorgraph$(OE) matlab$(OE) exceptions$(OE) bipgraph$(OE)
237 $(MEX) -output $@ $< factorgraph$(OE) matlab$(OE) exceptions$(OE) bipgraph$(OE)
238
239 matlab/dai_writefg$(ME) : $(SRC)/matlab/dai_writefg.cpp $(HEADERS) factorgraph$(OE) matlab$(OE) exceptions$(OE) bipgraph$(OE)
240 $(MEX) -output $@ $< factorgraph$(OE) matlab$(OE) exceptions$(OE) bipgraph$(OE)
241
242 matlab/dai_potstrength$(ME) : $(SRC)/matlab/dai_potstrength.cpp $(HEADERS) matlab$(OE) exceptions$(OE)
243 $(MEX) -output $@ $< matlab$(OE) exceptions$(OE)
244
245 matlab$(OE) : $(SRC)/matlab/matlab.cpp $(INC)/matlab/matlab.h $(HEADERS)
246 $(MEX) -c $<
247
248
249 # UTILS
250 ########
251
252 utils/createfg$(EE) : utils/createfg.cpp $(HEADERS) $(LIB)/libdai$(LE)
253 $(CC) $(CCO)$@ $< $(LIBS) $(BOOSTLIBS_PO)
254
255 utils/fg2dot$(EE) : utils/fg2dot.cpp $(HEADERS) $(LIB)/libdai$(LE)
256 $(CC) $(CCO)$@ $< $(LIBS)
257
258 utils/fginfo$(EE) : utils/fginfo.cpp $(HEADERS) $(LIB)/libdai$(LE)
259 $(CC) $(CCO)$@ $< $(LIBS)
260
261
262 # LIBRARY
263 ##########
264
265 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)
266
267 ifneq ($(OS),WINDOWS)
268 $(LIB)/libdai$(LE) : $(OBJECTS)
269 -mkdir -p lib
270 ar rcus $(LIB)/libdai$(LE) $(OBJECTS)
271 else
272 $(LIB)/libdai$(LE) : $(OBJECTS)
273 -mkdir lib
274 lib /out:$(LIB)/libdai$(LE) $(OBJECTS)
275 endif
276
277
278 # REGRESSION TESTS
279 ###################
280
281 testregression : tests/testdai$(EE)
282 @echo Starting regression test...this can take a minute or so!
283 ifneq ($(OS),WINDOWS)
284 cd tests && ./testregression && cd ..
285 else
286 cd tests && testregression.bat && cd ..
287 endif
288
289 testem : tests/testem/testem$(EE)
290 @echo Starting EM tests
291 ifneq ($(OS),WINDOWS)
292 cd tests/testem && ./runtests && cd ../..
293 else
294 cd tests\testem && runtests && cd ..\..
295 endif
296
297
298 # DOCUMENTATION
299 ################
300
301 doc : $(INC)/*.h $(SRC)/*.cpp examples/*.cpp doxygen.conf
302 doxygen doxygen.conf
303
304 README : doc scripts/makeREADME
305 DAI_VERSION=$(DAI_VERSION) DAI_DATE=$(DAI_DATE) scripts/makeREADME
306
307 TAGS :
308 etags src/*.cpp include/dai/*.h tests/*.cpp utils/*.cpp
309 ctags src/*.cpp include/dai/*.h tests/*.cpp utils/*.cpp
310
311
312 # CLEAN
313 ########
314
315 ifneq ($(OS),WINDOWS)
316 .PHONY : clean
317 clean :
318 -rm *$(OE)
319 -rm matlab/*$(ME)
320 -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)
321 -rm tests/testdai$(EE) tests/testem/testem$(EE) tests/testbbp$(EE)
322 -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)
323 -rm utils/fg2dot$(EE) utils/createfg$(EE) utils/fginfo$(EE)
324 -rm -R doc
325 -rm -R lib
326 else
327 .PHONY : clean
328 clean :
329 -del *$(OE)
330 -del *.ilk
331 -del *.pdb
332 -del *$(EE)
333 -del matlab\*$(ME)
334 -del examples\*$(EE)
335 -del examples\*.ilk
336 -del examples\*.pdb
337 -del tests\testdai$(EE)
338 -del tests\testbbp$(EE)
339 -del tests\testem\testem$(EE)
340 -del tests\*.pdb
341 -del tests\*.ilk
342 -del tests\testem\*.pdb
343 -del tests\testem\*.ilk
344 -del utils\*$(EE)
345 -del utils\*.pdb
346 -del utils\*.ilk
347 -del tests\unit\*.pdk
348 -del tests\unit\*.ilk
349 -del tests\unit\var$(EE)
350 -del tests\unit\smallset$(EE)
351 -del tests\unit\varset$(EE)
352 -del tests\unit\graph$(EE)
353 -del tests\unit\bipgraph$(EE)
354 -del tests\unit\weightedgraph$(EE)
355 -del tests\unit\enum$(EE)
356 -del tests\unit\util$(EE)
357 -del tests\unit\properties$(EE)
358 -del tests\unit\index$(EE)
359 -del tests\unit\prob$(EE)
360 -del $(LIB)\libdai$(LE)
361 -rmdir lib
362 endif