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