576488dcf6111ff5e243fd4e4a3844a54a964cde
[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="July 12, 2011 - 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 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
94 # Define standard libDAI header dependencies, source file names and object file names
95 HEADERS=$(foreach name,graph dag bipgraph index var factor varset smallset prob daialg properties alldai enum exceptions util,$(INC)/$(name).h)
96 SOURCES:=$(foreach name,$(NAMES),$(SRC)/$(name).cpp)
97 OBJECTS:=$(foreach name,$(NAMES),$(name)$(OE))
98
99 # Setup final command for C++ compiler
100 ifneq ($(OS),WINDOWS)
101 CC:=$(CC) $(CCINC) $(CCFLAGS) $(WITHFLAGS) $(CCLIB)
102 else
103 CC:=$(CC) $(CCINC) $(CCFLAGS) $(WITHFLAGS)
104 LIBS:=$(LIBS) $(CCLIB)
105 endif
106
107 # Setup final command for MEX
108 ifdef NEW_MATLAB
109 MEXFLAGS:=$(MEXFLAGS) -largeArrayDims
110 else
111 MEXFLAGS:=$(MEXFLAGS) -DSMALLMEM
112 endif
113 MEX:=$(MEX) $(MEXINC) $(MEXFLAGS) $(WITHFLAGS) $(MEXLIBS) $(MEXLIB)
114
115
116 # META TARGETS
117 ###############
118
119 all : $(TARGETS)
120 @echo
121 @echo libDAI built successfully!
122
123 EXAMPLES=$(foreach name,example example_bipgraph example_varset example_permute example_sprinkler example_sprinkler_em,examples/$(name)$(EE))
124 ifdef WITH_GIBBS
125 EXAMPLES:=$(EXAMPLES) examples/example_sprinkler_gibbs$(EE)
126 endif
127 ifdef WITH_CIMG
128 EXAMPLES:=$(EXAMPLES) examples/example_imagesegmentation$(EE)
129 endif
130 examples : $(EXAMPLES)
131
132 matlabs : matlab/dai$(ME) matlab/dai_readfg$(ME) matlab/dai_writefg$(ME) matlab/dai_potstrength$(ME) matlab/dai_jtree$(ME)
133
134 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)
135 @echo 'Running unit tests...'
136 @echo
137 tests/unit/var_test$(EE)
138 tests/unit/smallset_test$(EE)
139 tests/unit/varset_test$(EE)
140 tests/unit/graph_test$(EE)
141 tests/unit/dag_test$(EE)
142 tests/unit/bipgraph_test$(EE)
143 tests/unit/weightedgraph_test$(EE)
144 tests/unit/enum_test$(EE)
145 tests/unit/util_test$(EE)
146 tests/unit/exceptions_test$(EE)
147 tests/unit/properties_test$(EE)
148 tests/unit/index_test$(EE)
149 tests/unit/prob_test$(EE)
150 tests/unit/factor_test$(EE)
151 tests/unit/factorgraph_test$(EE)
152 tests/unit/clustergraph_test$(EE)
153 tests/unit/regiongraph_test$(EE)
154 tests/unit/daialg_test$(EE)
155 tests/unit/alldai_test$(EE)
156 @echo
157 @echo 'All unit tests completed successfully!'
158 @echo
159
160 tests : tests/testdai$(EE) tests/testem/testem$(EE) tests/testbbp$(EE) $(unittests)
161
162 utils : utils/createfg$(EE) utils/fg2dot$(EE) utils/fginfo$(EE) utils/uai2fg$(EE)
163
164 lib: $(LIB)/libdai$(LE)
165
166
167 # OBJECTS
168 ##########
169
170 %$(OE) : $(SRC)/%.cpp $(INC)/%.h $(HEADERS)
171 $(CC) -c $<
172
173 bbp$(OE) : $(SRC)/bbp.cpp $(INC)/bbp.h $(INC)/bp_dual.h $(HEADERS)
174 $(CC) -c $<
175
176 cbp$(OE) : $(SRC)/cbp.cpp $(INC)/cbp.h $(INC)/bbp.h $(INC)/bp_dual.h $(HEADERS)
177 $(CC) -c $<
178
179 hak$(OE) : $(SRC)/hak.cpp $(INC)/hak.h $(HEADERS) $(INC)/regiongraph.h
180 $(CC) -c $<
181
182 jtree$(OE) : $(SRC)/jtree.cpp $(INC)/jtree.h $(HEADERS) $(INC)/weightedgraph.h $(INC)/clustergraph.h $(INC)/regiongraph.h
183 $(CC) -c $<
184
185 treeep$(OE) : $(SRC)/treeep.cpp $(INC)/treeep.h $(HEADERS) $(INC)/weightedgraph.h $(INC)/clustergraph.h $(INC)/regiongraph.h $(INC)/jtree.h
186 $(CC) -c $<
187
188 emalg$(OE) : $(SRC)/emalg.cpp $(INC)/emalg.h $(INC)/evidence.h $(HEADERS)
189 $(CC) -c $<
190
191 decmap$(OE) : $(SRC)/decmap.cpp $(INC)/decmap.h $(HEADERS)
192 $(CC) -c $<
193
194
195 # EXAMPLES
196 ###########
197
198 examples/%$(EE) : examples/%.cpp $(HEADERS) $(LIB)/libdai$(LE)
199 $(CC) $(CCO)$@ $< $(LIBS)
200
201 examples/example_sprinkler_gibbs$(EE) : examples/example_sprinkler_gibbs.cpp $(HEADERS) $(LIB)/libdai$(LE)
202 $(CC) $(CCO)$@ $< $(LIBS)
203
204 examples/example_imagesegmentation$(EE) : examples/example_imagesegmentation.cpp $(HEADERS) $(LIB)/libdai$(LE)
205 ifdef NEW_CIMG
206 $(CC) -DNEW_CIMG $(CIMGINC) $(CCO)$@ $< $(LIBS) $(CIMGLIBS)
207 else
208 $(CC) $(CIMGINC) $(CCO)$@ $< $(LIBS) $(CIMGLIBS)
209 endif
210
211
212 # UNIT TESTS
213 #############
214
215 tests/unit/%$(EE) : tests/unit/%.cpp $(HEADERS) $(LIB)/libdai$(LE)
216 ifneq ($(OS),WINDOWS)
217 $(CC) -DBOOST_TEST_DYN_LINK $(CCO)$@ $< $(LIBS) $(BOOSTLIBS_UTF)
218 else
219 $(CC) $(CCO)$@ $< $(LIBS) $(BOOSTLIBS_UTF) /SUBSYSTEM:CONSOLE
220 endif
221
222
223 # TESTS
224 ########
225
226 tests/testdai$(EE) : tests/testdai.cpp $(HEADERS) $(LIB)/libdai$(LE)
227 $(CC) $(CCO)$@ $< $(LIBS) $(BOOSTLIBS_PO)
228 tests/testem/testem$(EE) : tests/testem/testem.cpp $(HEADERS) $(LIB)/libdai$(LE)
229 $(CC) $(CCO)$@ $< $(LIBS) $(BOOSTLIBS_PO)
230 tests/testbbp$(EE) : tests/testbbp.cpp $(HEADERS) $(LIB)/libdai$(LE)
231 ifdef WITH_CBP
232 $(CC) $(CCO)$@ $< $(LIBS)
233 else
234 @echo Skipping $@
235 endif
236
237
238 # MATLAB INTERFACE
239 ###################
240
241 matlab/dai$(ME) : $(SRC)/matlab/dai.cpp $(HEADERS) $(SOURCES) $(SRC)/matlab/matlab.cpp
242 $(MEX) -output $@ $< $(SRC)/matlab/matlab.cpp $(SOURCES)
243
244 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
245 $(MEX) -output $@ $< $(SRC)/matlab/matlab.cpp $(SRC)/factorgraph.cpp $(SRC)/exceptions.cpp $(SRC)/bipgraph.cpp $(SRC)/graph.cpp $(SRC)/factor.cpp $(SRC)/util.cpp
246
247 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
248 $(MEX) -output $@ $< $(SRC)/matlab/matlab.cpp $(SRC)/factorgraph.cpp $(SRC)/exceptions.cpp $(SRC)/bipgraph.cpp $(SRC)/graph.cpp $(SRC)/factor.cpp $(SRC)/util.cpp
249
250 matlab/dai_potstrength$(ME) : $(SRC)/matlab/dai_potstrength.cpp $(HEADERS) $(SRC)/matlab/matlab.cpp $(SRC)/exceptions.cpp
251 $(MEX) -output $@ $< $(SRC)/matlab/matlab.cpp $(SRC)/exceptions.cpp
252
253 matlab/dai_jtree$(ME) : $(SRC)/matlab/dai_jtree.cpp $(HEADERS) $(SOURCES) $(SRC)/matlab/matlab.cpp
254 $(MEX) -output $@ $< $(SRC)/matlab/matlab.cpp $(SOURCES)
255
256
257 # UTILS
258 ########
259
260 utils/createfg$(EE) : utils/createfg.cpp $(HEADERS) $(LIB)/libdai$(LE)
261 $(CC) $(CCO)$@ $< $(LIBS) $(BOOSTLIBS_PO)
262
263 utils/fg2dot$(EE) : utils/fg2dot.cpp $(HEADERS) $(LIB)/libdai$(LE)
264 $(CC) $(CCO)$@ $< $(LIBS)
265
266 utils/fginfo$(EE) : utils/fginfo.cpp $(HEADERS) $(LIB)/libdai$(LE)
267 $(CC) $(CCO)$@ $< $(LIBS)
268
269 utils/uai2fg$(EE) : utils/uai2fg.cpp $(HEADERS) $(LIB)/libdai$(LE)
270 $(CC) $(CCO)$@ $< $(LIBS)
271
272
273 # LIBRARY
274 ##########
275
276 ifneq ($(OS),WINDOWS)
277 $(LIB)/libdai$(LE) : $(OBJECTS)
278 -mkdir -p lib
279 ar rcus $(LIB)/libdai$(LE) $(OBJECTS)
280 else
281 $(LIB)/libdai$(LE) : $(OBJECTS)
282 -mkdir lib
283 lib /out:$(LIB)/libdai$(LE) $(OBJECTS)
284 endif
285
286
287 # REGRESSION TESTS
288 ###################
289
290 testregression : tests/testdai$(EE)
291 @echo Starting regression test...this can take a minute or so!
292 ifneq ($(OS),WINDOWS)
293 cd tests && ./testregression && cd ..
294 else
295 cd tests && testregression.bat && cd ..
296 endif
297
298 testem : tests/testem/testem$(EE)
299 @echo Starting EM tests
300 ifneq ($(OS),WINDOWS)
301 cd tests/testem && ./runtests && cd ../..
302 else
303 cd tests\testem && runtests && cd ..\..
304 endif
305
306
307 # DOCUMENTATION
308 ################
309
310 doc : $(INC)/*.h $(SRC)/*.cpp examples/*.cpp doxygen.conf
311 doxygen doxygen.conf
312
313 README : doc scripts/makeREADME Makefile
314 DAI_VERSION=$(DAI_VERSION) DAI_DATE=$(DAI_DATE) scripts/makeREADME
315
316 TAGS :
317 etags src/*.cpp include/dai/*.h tests/*.cpp utils/*.cpp
318 ctags src/*.cpp include/dai/*.h tests/*.cpp utils/*.cpp
319
320
321 # CLEAN
322 ########
323
324 .PHONY : clean
325 ifneq ($(OS),WINDOWS)
326 clean :
327 -rm $(OBJECTS)
328 -rm matlab/*$(ME)
329 -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)
330 -rm tests/testdai$(EE) tests/testem/testem$(EE) tests/testbbp$(EE)
331 -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)
332 -rm factorgraph_test.fg alldai_test.aliases
333 -rm utils/fg2dot$(EE) utils/createfg$(EE) utils/fginfo$(EE) utils/uai2fg$(EE)
334 -rm -R doc
335 -rm -R lib
336 else
337 clean :
338 -del *.obj
339 -del *.ilk
340 -del *.pdb
341 -del matlab\*$(ME)
342 -del examples\*$(EE)
343 -del examples\*$(EE).manifest
344 -del examples\*.ilk
345 -del examples\*.pdb
346 -del tests\*$(EE)
347 -del tests\*$(EE).manifest
348 -del tests\*.pdb
349 -del tests\*.ilk
350 -del tests\testem\*$(EE)
351 -del tests\testem\*$(EE).manifest
352 -del tests\testem\*.pdb
353 -del tests\testem\*.ilk
354 -del utils\*$(EE)
355 -del utils\*$(EE).manifest
356 -del utils\*.pdb
357 -del utils\*.ilk
358 -del tests\unit\*_test$(EE)
359 -del tests\unit\*_test$(EE).manifest
360 -del tests\unit\*_test.pdb
361 -del tests\unit\*_test.ilk
362 -del factorgraph_test.fg
363 -del alldai_test.aliases
364 -del $(LIB)\libdai$(LE)
365 -rmdir lib
366 endif