Fixed some more BOOST_CHECK_CLOSE misuse
[libdai.git] / Makefile
1 # This file is part of libDAI - http://www.libdai.org/
2 #
3 # Copyright (c) 2006-2011, The libDAI authors. All rights reserved.
4 #
5 # Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
6
7
8 # Load the platform independent build configuration file
9 include Makefile.ALL
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="September 17, 2012 - or later"
17
18 # Directories of libDAI sources
19 # Location of 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:=lib tests utils examples
35 ifdef WITH_MATLAB
36 TARGETS:=$(TARGETS) matlabs
37 endif
38 TARGETS:=$(TARGETS) unittests testregression testem
39 ifdef WITH_DOC
40 TARGETS:=$(TARGETS) doc
41 endif
42
43 # Define conditional build targets
44 NAMES:=graph dag bipgraph varset daialg alldai clustergraph factor factorgraph properties regiongraph cobwebgraph util weightedgraph exceptions exactinf evidence emalg io
45 ifdef WITH_BP
46 WITHFLAGS:=$(WITHFLAGS) -DDAI_WITH_BP
47 NAMES:=$(NAMES) bp
48 endif
49 ifdef WITH_FBP
50 WITHFLAGS:=$(WITHFLAGS) -DDAI_WITH_FBP
51 NAMES:=$(NAMES) fbp
52 endif
53 ifdef WITH_TRWBP
54 WITHFLAGS:=$(WITHFLAGS) -DDAI_WITH_TRWBP
55 NAMES:=$(NAMES) trwbp
56 endif
57 ifdef WITH_MF
58 WITHFLAGS:=$(WITHFLAGS) -DDAI_WITH_MF
59 NAMES:=$(NAMES) mf
60 endif
61 ifdef WITH_HAK
62 WITHFLAGS:=$(WITHFLAGS) -DDAI_WITH_HAK
63 NAMES:=$(NAMES) hak
64 endif
65 ifdef WITH_LC
66 WITHFLAGS:=$(WITHFLAGS) -DDAI_WITH_LC
67 NAMES:=$(NAMES) lc
68 endif
69 ifdef WITH_TREEEP
70 WITHFLAGS:=$(WITHFLAGS) -DDAI_WITH_TREEEP
71 NAMES:=$(NAMES) treeep
72 endif
73 ifdef WITH_JTREE
74 WITHFLAGS:=$(WITHFLAGS) -DDAI_WITH_JTREE
75 NAMES:=$(NAMES) jtree
76 endif
77 ifdef WITH_MR
78 WITHFLAGS:=$(WITHFLAGS) -DDAI_WITH_MR
79 NAMES:=$(NAMES) mr
80 endif
81 ifdef WITH_GIBBS
82 WITHFLAGS:=$(WITHFLAGS) -DDAI_WITH_GIBBS
83 NAMES:=$(NAMES) gibbs
84 endif
85 ifdef WITH_CBP
86 WITHFLAGS:=$(WITHFLAGS) -DDAI_WITH_CBP
87 NAMES:=$(NAMES) bbp cbp bp_dual
88 endif
89 ifdef WITH_DECMAP
90 WITHFLAGS:=$(WITHFLAGS) -DDAI_WITH_DECMAP
91 NAMES:=$(NAMES) decmap
92 endif
93 ifdef WITH_GLC
94 WITHFLAGS:=$(WITHFLAGS) -DDAI_WITH_GLC
95 NAMES:=$(NAMES) glc
96 endif
97
98
99 # Define standard libDAI header dependencies, source file names and object file names
100 HEADERS=$(foreach name,graph dag bipgraph index var factor varset smallset prob daialg properties alldai enum exceptions util,$(INC)/$(name).h)
101 SOURCES:=$(foreach name,$(NAMES),$(SRC)/$(name).cpp)
102 OBJECTS:=$(foreach name,$(NAMES),$(name)$(OE))
103
104 # Setup final command for C++ compiler
105 ifneq ($(OS),WINDOWS)
106 CC:=$(CC) $(CCINC) $(CCFLAGS) $(WITHFLAGS) $(CCLIB)
107 else
108 CC:=$(CC) $(CCINC) $(CCFLAGS) $(WITHFLAGS)
109 LIBS:=$(LIBS) $(CCLIB)
110 endif
111
112 # Setup final command for MEX
113 ifdef NEW_MATLAB
114 MEXFLAGS:=$(MEXFLAGS) -largeArrayDims
115 else
116 MEXFLAGS:=$(MEXFLAGS) -DSMALLMEM
117 endif
118 MEX:=$(MEX) $(MEXINC) $(MEXFLAGS) $(WITHFLAGS) $(MEXLIBS) $(MEXLIB)
119
120
121 # META TARGETS
122 ###############
123
124 all : $(TARGETS)
125 @echo
126 @echo libDAI built successfully!
127
128 EXAMPLES=$(foreach name,example example_bipgraph example_varset example_permute example_sprinkler example_sprinkler_em,examples/$(name)$(EE))
129 ifdef WITH_GIBBS
130 EXAMPLES:=$(EXAMPLES) examples/example_sprinkler_gibbs$(EE)
131 endif
132 ifdef WITH_CIMG
133 EXAMPLES:=$(EXAMPLES) examples/example_imagesegmentation$(EE)
134 endif
135 examples : $(EXAMPLES)
136
137 matlabs : matlab/dai$(ME) matlab/dai_readfg$(ME) matlab/dai_writefg$(ME) matlab/dai_potstrength$(ME) matlab/dai_jtree$(ME)
138
139 unittests : tests/unit/var_test$(EE) tests/unit/smallset_test$(EE) tests/unit/varset_test$(EE) tests/unit/graph_test$(EE) tests/unit/dag_test$(EE) tests/unit/bipgraph_test$(EE) tests/unit/weightedgraph_test$(EE) tests/unit/enum_test$(EE) tests/unit/enum_test$(EE) tests/unit/util_test$(EE) tests/unit/exceptions_test$(EE) tests/unit/properties_test$(EE) tests/unit/index_test$(EE) tests/unit/prob_test$(EE) tests/unit/factor_test$(EE) tests/unit/factorgraph_test$(EE) tests/unit/clustergraph_test$(EE) tests/unit/regiongraph_test$(EE) tests/unit/daialg_test$(EE) tests/unit/alldai_test$(EE)
140 @echo 'Running unit tests...'
141 @echo
142 tests/unit/var_test$(EE)
143 tests/unit/smallset_test$(EE)
144 tests/unit/varset_test$(EE)
145 tests/unit/graph_test$(EE)
146 tests/unit/dag_test$(EE)
147 tests/unit/bipgraph_test$(EE)
148 tests/unit/weightedgraph_test$(EE)
149 tests/unit/enum_test$(EE)
150 tests/unit/util_test$(EE)
151 tests/unit/exceptions_test$(EE)
152 tests/unit/properties_test$(EE)
153 tests/unit/index_test$(EE)
154 tests/unit/prob_test$(EE)
155 tests/unit/factor_test$(EE)
156 tests/unit/factorgraph_test$(EE)
157 tests/unit/clustergraph_test$(EE)
158 tests/unit/regiongraph_test$(EE)
159 tests/unit/daialg_test$(EE)
160 tests/unit/alldai_test$(EE)
161 @echo
162 @echo 'All unit tests completed successfully!'
163 @echo
164
165 tests : tests/testdai$(EE) tests/testem/testem$(EE) tests/testbbp$(EE) $(unittests)
166
167 utils : utils/createfg$(EE) utils/fg2dot$(EE) utils/fginfo$(EE) utils/uai2fg$(EE)
168
169 lib: $(LIB)/libdai$(LE)
170
171
172 # OBJECTS
173 ##########
174
175 %$(OE) : $(SRC)/%.cpp $(INC)/%.h $(HEADERS)
176 $(CC) -c $<
177
178 bbp$(OE) : $(SRC)/bbp.cpp $(INC)/bbp.h $(INC)/bp_dual.h $(HEADERS)
179 $(CC) -c $<
180
181 cbp$(OE) : $(SRC)/cbp.cpp $(INC)/cbp.h $(INC)/bbp.h $(INC)/bp_dual.h $(HEADERS)
182 $(CC) -c $<
183
184 hak$(OE) : $(SRC)/hak.cpp $(INC)/hak.h $(HEADERS) $(INC)/regiongraph.h
185 $(CC) -c $<
186
187 jtree$(OE) : $(SRC)/jtree.cpp $(INC)/jtree.h $(HEADERS) $(INC)/weightedgraph.h $(INC)/clustergraph.h $(INC)/regiongraph.h
188 $(CC) -c $<
189
190 treeep$(OE) : $(SRC)/treeep.cpp $(INC)/treeep.h $(HEADERS) $(INC)/weightedgraph.h $(INC)/clustergraph.h $(INC)/regiongraph.h $(INC)/jtree.h
191 $(CC) -c $<
192
193 emalg$(OE) : $(SRC)/emalg.cpp $(INC)/emalg.h $(INC)/evidence.h $(HEADERS)
194 $(CC) -c $<
195
196 decmap$(OE) : $(SRC)/decmap.cpp $(INC)/decmap.h $(HEADERS)
197 $(CC) -c $<
198
199 glc$(OE) : $(SRC)/glc.cpp $(INC)/glc.h $(HEADERS) $(INC)/cobwebgraph.h
200 $(CC) -c $<
201
202
203 # EXAMPLES
204 ###########
205
206 examples/%$(EE) : examples/%.cpp $(HEADERS) $(LIB)/libdai$(LE)
207 $(CC) $(CCO)$@ $< $(LIBS)
208
209 examples/example_sprinkler_gibbs$(EE) : examples/example_sprinkler_gibbs.cpp $(HEADERS) $(LIB)/libdai$(LE)
210 $(CC) $(CCO)$@ $< $(LIBS)
211
212 examples/example_imagesegmentation$(EE) : examples/example_imagesegmentation.cpp $(HEADERS) $(LIB)/libdai$(LE)
213 ifdef NEW_CIMG
214 $(CC) -DNEW_CIMG $(CIMGINC) $(CCO)$@ $< $(LIBS) $(CIMGLIBS)
215 else
216 $(CC) $(CIMGINC) $(CCO)$@ $< $(LIBS) $(CIMGLIBS)
217 endif
218
219
220 # UNIT TESTS
221 #############
222
223 tests/unit/%$(EE) : tests/unit/%.cpp $(HEADERS) $(LIB)/libdai$(LE)
224 ifneq ($(OS),WINDOWS)
225 $(CC) -DBOOST_TEST_DYN_LINK $(CCO)$@ $< $(LIBS) $(BOOSTLIBS_UTF)
226 else
227 $(CC) $(CCO)$@ $< $(LIBS) $(BOOSTLIBS_UTF) /SUBSYSTEM:CONSOLE
228 endif
229
230
231 # TESTS
232 ########
233
234 tests/testdai$(EE) : tests/testdai.cpp $(HEADERS) $(LIB)/libdai$(LE)
235 $(CC) $(CCO)$@ $< $(LIBS) $(BOOSTLIBS_PO)
236 tests/testem/testem$(EE) : tests/testem/testem.cpp $(HEADERS) $(LIB)/libdai$(LE)
237 $(CC) $(CCO)$@ $< $(LIBS) $(BOOSTLIBS_PO)
238 tests/testbbp$(EE) : tests/testbbp.cpp $(HEADERS) $(LIB)/libdai$(LE)
239 ifdef WITH_CBP
240 $(CC) $(CCO)$@ $< $(LIBS)
241 else
242 @echo Skipping $@
243 endif
244
245
246 # MATLAB INTERFACE
247 ###################
248
249 matlab/dai$(ME) : $(SRC)/matlab/dai.cpp $(HEADERS) $(SOURCES) $(SRC)/matlab/matlab.cpp
250 $(MEX) -output $@ $< $(SRC)/matlab/matlab.cpp $(SOURCES)
251
252 matlab/dai_readfg$(ME) : $(SRC)/matlab/dai_readfg.cpp $(HEADERS) $(SRC)/matlab/matlab.cpp $(SRC)/factorgraph.cpp $(SRC)/exceptions.cpp $(SRC)/bipgraph.cpp $(SRC)/graph.cpp $(SRC)/factor.cpp $(SRC)/util.cpp
253 $(MEX) -output $@ $< $(SRC)/matlab/matlab.cpp $(SRC)/factorgraph.cpp $(SRC)/exceptions.cpp $(SRC)/bipgraph.cpp $(SRC)/graph.cpp $(SRC)/factor.cpp $(SRC)/util.cpp
254
255 matlab/dai_writefg$(ME) : $(SRC)/matlab/dai_writefg.cpp $(HEADERS) $(SRC)/matlab/matlab.cpp $(SRC)/factorgraph.cpp $(SRC)/exceptions.cpp $(SRC)/bipgraph.cpp $(SRC)/graph.cpp $(SRC)/factor.cpp $(SRC)/util.cpp
256 $(MEX) -output $@ $< $(SRC)/matlab/matlab.cpp $(SRC)/factorgraph.cpp $(SRC)/exceptions.cpp $(SRC)/bipgraph.cpp $(SRC)/graph.cpp $(SRC)/factor.cpp $(SRC)/util.cpp
257
258 matlab/dai_potstrength$(ME) : $(SRC)/matlab/dai_potstrength.cpp $(HEADERS) $(SRC)/matlab/matlab.cpp $(SRC)/exceptions.cpp
259 $(MEX) -output $@ $< $(SRC)/matlab/matlab.cpp $(SRC)/exceptions.cpp
260
261 matlab/dai_jtree$(ME) : $(SRC)/matlab/dai_jtree.cpp $(HEADERS) $(SOURCES) $(SRC)/matlab/matlab.cpp
262 $(MEX) -output $@ $< $(SRC)/matlab/matlab.cpp $(SOURCES)
263
264
265 # UTILS
266 ########
267
268 utils/createfg$(EE) : utils/createfg.cpp $(HEADERS) $(LIB)/libdai$(LE)
269 $(CC) $(CCO)$@ $< $(LIBS) $(BOOSTLIBS_PO)
270
271 utils/fg2dot$(EE) : utils/fg2dot.cpp $(HEADERS) $(LIB)/libdai$(LE)
272 $(CC) $(CCO)$@ $< $(LIBS)
273
274 utils/fginfo$(EE) : utils/fginfo.cpp $(HEADERS) $(LIB)/libdai$(LE)
275 $(CC) $(CCO)$@ $< $(LIBS)
276
277 utils/uai2fg$(EE) : utils/uai2fg.cpp $(HEADERS) $(LIB)/libdai$(LE)
278 $(CC) $(CCO)$@ $< $(LIBS)
279
280
281 # LIBRARY
282 ##########
283
284 ifneq ($(OS),WINDOWS)
285 $(LIB)/libdai$(LE) : $(OBJECTS)
286 -mkdir -p lib
287 ar rcus $(LIB)/libdai$(LE) $(OBJECTS)
288 else
289 $(LIB)/libdai$(LE) : $(OBJECTS)
290 -mkdir lib
291 lib /out:$(LIB)/libdai$(LE) $(OBJECTS)
292 endif
293
294
295 # REGRESSION TESTS
296 ###################
297
298 testregression : tests/testdai$(EE)
299 @echo Starting regression test...this can take a minute or so!
300 ifneq ($(OS),WINDOWS)
301 cd tests && ./testregression && cd ..
302 else
303 cd tests && testregression.bat && cd ..
304 endif
305
306 testem : tests/testem/testem$(EE)
307 @echo Starting EM tests
308 ifneq ($(OS),WINDOWS)
309 cd tests/testem && ./runtests && cd ../..
310 else
311 cd tests\testem && runtests && cd ..\..
312 endif
313
314
315 # DOCUMENTATION
316 ################
317
318 doc : $(INC)/*.h $(SRC)/*.cpp examples/*.cpp doxygen.conf
319 doxygen doxygen.conf
320
321 README : doc scripts/makeREADME Makefile
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 .PHONY : clean
333 ifneq ($(OS),WINDOWS)
334 clean :
335 -rm $(OBJECTS)
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) examples/example_imagesegmentation$(EE)
338 -rm tests/testdai$(EE) tests/testem/testem$(EE) tests/testbbp$(EE)
339 -rm tests/unit/var_test$(EE) tests/unit/smallset_test$(EE) tests/unit/varset_test$(EE) tests/unit/graph_test$(EE) tests/unit/dag_test$(EE) tests/unit/bipgraph_test$(EE) tests/unit/weightedgraph_test$(EE) tests/unit/enum_test$(EE) tests/unit/util_test$(EE) tests/unit/exceptions_test$(EE) tests/unit/properties_test$(EE) tests/unit/index_test$(EE) tests/unit/prob_test$(EE) tests/unit/factor_test$(EE) tests/unit/factorgraph_test$(EE) tests/unit/clustergraph_test$(EE) tests/unit/regiongraph_test$(EE) tests/unit/daialg_test$(EE) tests/unit/alldai_test$(EE)
340 -rm factorgraph_test.fg alldai_test.aliases
341 -rm utils/fg2dot$(EE) utils/createfg$(EE) utils/fginfo$(EE) utils/uai2fg$(EE)
342 -rm -R doc
343 -rm -R lib
344 else
345 clean :
346 -del *.obj
347 -del *.ilk
348 -del *.pdb
349 -del matlab\*$(ME)
350 -del examples\*$(EE)
351 -del examples\*$(EE).manifest
352 -del examples\*.ilk
353 -del examples\*.pdb
354 -del tests\*$(EE)
355 -del tests\*$(EE).manifest
356 -del tests\*.pdb
357 -del tests\*.ilk
358 -del tests\testem\*$(EE)
359 -del tests\testem\*$(EE).manifest
360 -del tests\testem\*.pdb
361 -del tests\testem\*.ilk
362 -del utils\*$(EE)
363 -del utils\*$(EE).manifest
364 -del utils\*.pdb
365 -del utils\*.ilk
366 -del tests\unit\*_test$(EE)
367 -del tests\unit\*_test$(EE).manifest
368 -del tests\unit\*_test.pdb
369 -del tests\unit\*_test.ilk
370 -del factorgraph_test.fg
371 -del alldai_test.aliases
372 -del $(LIB)\libdai$(LE)
373 -rmdir lib
374 endif