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