Fixed typo in Priya's name
[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) $(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)
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
254 # UTILS
255 ########
256
257 utils/createfg$(EE) : utils/createfg.cpp $(HEADERS) $(LIB)/libdai$(LE)
258 $(CC) $(CCO)$@ $< $(LIBS) $(BOOSTLIBS_PO)
259
260 utils/fg2dot$(EE) : utils/fg2dot.cpp $(HEADERS) $(LIB)/libdai$(LE)
261 $(CC) $(CCO)$@ $< $(LIBS)
262
263 utils/fginfo$(EE) : utils/fginfo.cpp $(HEADERS) $(LIB)/libdai$(LE)
264 $(CC) $(CCO)$@ $< $(LIBS)
265
266 utils/uai2fg$(EE) : utils/uai2fg.cpp $(HEADERS) $(LIB)/libdai$(LE)
267 $(CC) $(CCO)$@ $< $(LIBS)
268
269
270 # LIBRARY
271 ##########
272
273 ifneq ($(OS),WINDOWS)
274 $(LIB)/libdai$(LE) : $(OBJECTS)
275 -mkdir -p lib
276 ar rcus $(LIB)/libdai$(LE) $(OBJECTS)
277 else
278 $(LIB)/libdai$(LE) : $(OBJECTS)
279 -mkdir lib
280 lib /out:$(LIB)/libdai$(LE) $(OBJECTS)
281 endif
282
283
284 # REGRESSION TESTS
285 ###################
286
287 testregression : tests/testdai$(EE)
288 @echo Starting regression test...this can take a minute or so!
289 ifneq ($(OS),WINDOWS)
290 cd tests && ./testregression && cd ..
291 else
292 cd tests && testregression.bat && cd ..
293 endif
294
295 testem : tests/testem/testem$(EE)
296 @echo Starting EM tests
297 ifneq ($(OS),WINDOWS)
298 cd tests/testem && ./runtests && cd ../..
299 else
300 cd tests\testem && runtests && cd ..\..
301 endif
302
303
304 # DOCUMENTATION
305 ################
306
307 doc : $(INC)/*.h $(SRC)/*.cpp examples/*.cpp doxygen.conf
308 doxygen doxygen.conf
309
310 README : doc scripts/makeREADME Makefile
311 DAI_VERSION=$(DAI_VERSION) DAI_DATE=$(DAI_DATE) scripts/makeREADME
312
313 TAGS :
314 etags src/*.cpp include/dai/*.h tests/*.cpp utils/*.cpp
315 ctags src/*.cpp include/dai/*.h tests/*.cpp utils/*.cpp
316
317
318 # CLEAN
319 ########
320
321 .PHONY : clean
322 ifneq ($(OS),WINDOWS)
323 clean :
324 -rm $(OBJECTS)
325 -rm matlab/*$(ME)
326 -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)
327 -rm tests/testdai$(EE) tests/testem/testem$(EE) tests/testbbp$(EE)
328 -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)
329 -rm factorgraph_test.fg alldai_test.aliases
330 -rm utils/fg2dot$(EE) utils/createfg$(EE) utils/fginfo$(EE) utils/uai2fg$(EE)
331 -rm -R doc
332 -rm -R lib
333 else
334 clean :
335 -del *.obj
336 -del *.ilk
337 -del *.pdb
338 -del matlab\*$(ME)
339 -del examples\*$(EE)
340 -del examples\*$(EE).manifest
341 -del examples\*.ilk
342 -del examples\*.pdb
343 -del tests\*$(EE)
344 -del tests\*$(EE).manifest
345 -del tests\*.pdb
346 -del tests\*.ilk
347 -del tests\testem\*$(EE)
348 -del tests\testem\*$(EE).manifest
349 -del tests\testem\*.pdb
350 -del tests\testem\*.ilk
351 -del utils\*$(EE)
352 -del utils\*$(EE).manifest
353 -del utils\*.pdb
354 -del utils\*.ilk
355 -del tests\unit\*_test$(EE)
356 -del tests\unit\*_test$(EE).manifest
357 -del tests\unit\*_test.pdb
358 -del tests\unit\*_test.ilk
359 -del factorgraph_test.fg
360 -del alldai_test.aliases
361 -del $(LIB)\libdai$(LE)
362 -rmdir lib
363 endif