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