Added DAG class and various minor improvements
[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="April 1, 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:=lib tests utils examples
38 ifdef WITH_MATLAB
39 TARGETS:=$(TARGETS) matlabs
40 endif
41 TARGETS:=$(TARGETS) unittests testregression testem
42 ifdef WITH_DOC
43 TARGETS:=$(TARGETS) doc
44 endif
45
46 # Define conditional build targets
47 NAMES:=graph dag bipgraph varset daialg alldai clustergraph factor factorgraph properties regiongraph util weightedgraph exceptions exactinf evidence emalg
48 ifdef WITH_BP
49 WITHFLAGS:=$(WITHFLAGS) -DDAI_WITH_BP
50 NAMES:=$(NAMES) bp
51 endif
52 ifdef WITH_FBP
53 WITHFLAGS:=$(WITHFLAGS) -DDAI_WITH_FBP
54 NAMES:=$(NAMES) fbp
55 endif
56 ifdef WITH_TRWBP
57 WITHFLAGS:=$(WITHFLAGS) -DDAI_WITH_TRWBP
58 NAMES:=$(NAMES) trwbp
59 endif
60 ifdef WITH_MF
61 WITHFLAGS:=$(WITHFLAGS) -DDAI_WITH_MF
62 NAMES:=$(NAMES) mf
63 endif
64 ifdef WITH_HAK
65 WITHFLAGS:=$(WITHFLAGS) -DDAI_WITH_HAK
66 NAMES:=$(NAMES) hak
67 endif
68 ifdef WITH_LC
69 WITHFLAGS:=$(WITHFLAGS) -DDAI_WITH_LC
70 NAMES:=$(NAMES) lc
71 endif
72 ifdef WITH_TREEEP
73 WITHFLAGS:=$(WITHFLAGS) -DDAI_WITH_TREEEP
74 NAMES:=$(NAMES) treeep
75 endif
76 ifdef WITH_JTREE
77 WITHFLAGS:=$(WITHFLAGS) -DDAI_WITH_JTREE
78 NAMES:=$(NAMES) jtree
79 endif
80 ifdef WITH_MR
81 WITHFLAGS:=$(WITHFLAGS) -DDAI_WITH_MR
82 NAMES:=$(NAMES) mr
83 endif
84 ifdef WITH_GIBBS
85 WITHFLAGS:=$(WITHFLAGS) -DDAI_WITH_GIBBS
86 NAMES:=$(NAMES) gibbs
87 endif
88 ifdef WITH_CBP
89 WITHFLAGS:=$(WITHFLAGS) -DDAI_WITH_CBP
90 NAMES:=$(NAMES) bbp cbp bp_dual
91 endif
92
93 # Define standard libDAI header dependencies, source file names and object file names
94 HEADERS=$(foreach name,graph dag bipgraph index var factor varset smallset prob daialg properties alldai enum exceptions util,$(INC)/$(name).h)
95 SOURCES:=$(foreach name,$(NAMES),$(SRC)/$(name).cpp)
96 OBJECTS:=$(foreach name,$(NAMES),$(name)$(OE))
97
98 # Setup final command for C++ compiler
99 ifneq ($(OS),WINDOWS)
100 CC:=$(CC) $(CCINC) $(CCFLAGS) $(WITHFLAGS) $(CCLIB)
101 else
102 CC:=$(CC) $(CCINC) $(CCFLAGS) $(WITHFLAGS)
103 LIBS:=$(LIBS) $(CCLIB)
104 endif
105
106 # Setup final command for MEX
107 ifdef NEW_MATLAB
108 MEXFLAGS:=$(MEXFLAGS) -largeArrayDims
109 else
110 MEXFLAGS:=$(MEXFLAGS) -DSMALLMEM
111 endif
112 MEX:=$(MEX) $(MEXINC) $(MEXFLAGS) $(WITHFLAGS) $(MEXLIB)
113
114
115 # META TARGETS
116 ###############
117
118 all : $(TARGETS)
119
120 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) examples/example_imagesegmentation$(EE)
121
122 matlabs : matlab/dai$(ME) matlab/dai_readfg$(ME) matlab/dai_writefg$(ME) matlab/dai_potstrength$(ME)
123
124 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)
125 echo Running unit tests...
126 tests/unit/var_test$(EE)
127 tests/unit/smallset_test$(EE)
128 tests/unit/varset_test$(EE)
129 tests/unit/graph_test$(EE)
130 tests/unit/dag_test$(EE)
131 tests/unit/bipgraph_test$(EE)
132 tests/unit/weightedgraph_test$(EE)
133 tests/unit/enum_test$(EE)
134 tests/unit/util_test$(EE)
135 tests/unit/exceptions_test$(EE)
136 tests/unit/properties_test$(EE)
137 tests/unit/index_test$(EE)
138 tests/unit/prob_test$(EE)
139 tests/unit/factor_test$(EE)
140 tests/unit/factorgraph_test$(EE)
141 tests/unit/clustergraph_test$(EE)
142 tests/unit/regiongraph_test$(EE)
143 tests/unit/daialg_test$(EE)
144 tests/unit/alldai_test$(EE)
145
146 tests : tests/testdai$(EE) tests/testem/testem$(EE) tests/testbbp$(EE) $(unittests)
147
148 utils : utils/createfg$(EE) utils/fg2dot$(EE) utils/fginfo$(EE) utils/uai2fg$(EE)
149
150 lib: $(LIB)/libdai$(LE)
151
152
153 # OBJECTS
154 ##########
155
156 %$(OE) : $(SRC)/%.cpp $(INC)/%.h $(HEADERS)
157 $(CC) -c $<
158
159 bbp$(OE) : $(SRC)/bbp.cpp $(INC)/bbp.h $(INC)/bp_dual.h $(HEADERS)
160 $(CC) -c $<
161
162 cbp$(OE) : $(SRC)/cbp.cpp $(INC)/cbp.h $(INC)/bbp.h $(INC)/bp_dual.h $(HEADERS)
163 $(CC) -c $<
164
165 hak$(OE) : $(SRC)/hak.cpp $(INC)/hak.h $(HEADERS) $(INC)/regiongraph.h
166 $(CC) -c $<
167
168 jtree$(OE) : $(SRC)/jtree.cpp $(INC)/jtree.h $(HEADERS) $(INC)/weightedgraph.h $(INC)/clustergraph.h $(INC)/regiongraph.h
169 $(CC) -c $<
170
171 treeep$(OE) : $(SRC)/treeep.cpp $(INC)/treeep.h $(HEADERS) $(INC)/weightedgraph.h $(INC)/clustergraph.h $(INC)/regiongraph.h $(INC)/jtree.h
172 $(CC) -c $<
173
174 emalg$(OE) : $(SRC)/emalg.cpp $(INC)/emalg.h $(INC)/evidence.h $(HEADERS)
175 $(CC) -c $<
176
177
178 # EXAMPLES
179 ###########
180
181 examples/%$(EE) : examples/%.cpp $(HEADERS) $(LIB)/libdai$(LE)
182 $(CC) $(CCO)$@ $< $(LIBS)
183
184 examples/example_imagesegmentation$(EE) : examples/example_imagesegmentation.cpp $(HEADERS) $(LIB)/libdai$(LE)
185 -$(CC) $(CCO)$@ $< $(LIBS) -lpthread -lX11
186
187
188 # UNIT TESTS
189 #############
190
191 tests/unit/%$(EE) : tests/unit/%.cpp $(HEADERS) $(LIB)/libdai$(LE)
192 ifneq ($(OS),WINDOWS)
193 $(CC) -DBOOST_TEST_DYN_LINK $(CCO)$@ $< $(LIBS) $(BOOSTLIBS_UTF)
194 else
195 $(CC) $(CCO)$@ $< $(LIBS) $(BOOSTLIBS_UTF) /SUBSYSTEM:CONSOLE
196 endif
197
198
199 # TESTS
200 ########
201
202 tests/testdai$(EE) : tests/testdai.cpp $(HEADERS) $(LIB)/libdai$(LE)
203 $(CC) $(CCO)$@ $< $(LIBS) $(BOOSTLIBS_PO)
204 tests/testem/testem$(EE) : tests/testem/testem.cpp $(HEADERS) $(LIB)/libdai$(LE)
205 $(CC) $(CCO)$@ $< $(LIBS) $(BOOSTLIBS_PO)
206 ifdef WITH_CBP
207 tests/testbbp$(EE) : tests/testbbp.cpp $(HEADERS) $(LIB)/libdai$(LE)
208 $(CC) $(CCO)$@ $< $(LIBS)
209 endif
210
211
212 # MATLAB INTERFACE
213 ###################
214
215 matlab/dai$(ME) : $(SRC)/matlab/dai.cpp $(HEADERS) $(SOURCES) $(SRC)/matlab/matlab.cpp
216 $(MEX) -output $@ $< $(SRC)/matlab/matlab.cpp $(SOURCES)
217
218 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
219 $(MEX) -output $@ $< $(SRC)/matlab/matlab.cpp $(SRC)/factorgraph.cpp $(SRC)/exceptions.cpp $(SRC)/bipgraph.cpp $(SRC)/graph.cpp $(SRC)/factor.cpp $(SRC)/util.cpp
220
221 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
222 $(MEX) -output $@ $< $(SRC)/matlab/matlab.cpp $(SRC)/factorgraph.cpp $(SRC)/exceptions.cpp $(SRC)/bipgraph.cpp $(SRC)/graph.cpp $(SRC)/factor.cpp $(SRC)/util.cpp
223
224 matlab/dai_potstrength$(ME) : $(SRC)/matlab/dai_potstrength.cpp $(HEADERS) $(SRC)/matlab/matlab.cpp $(SRC)/exceptions.cpp
225 $(MEX) -output $@ $< $(SRC)/matlab/matlab.cpp $(SRC)/exceptions.cpp
226
227
228 # UTILS
229 ########
230
231 utils/createfg$(EE) : utils/createfg.cpp $(HEADERS) $(LIB)/libdai$(LE)
232 $(CC) $(CCO)$@ $< $(LIBS) $(BOOSTLIBS_PO)
233
234 utils/fg2dot$(EE) : utils/fg2dot.cpp $(HEADERS) $(LIB)/libdai$(LE)
235 $(CC) $(CCO)$@ $< $(LIBS)
236
237 utils/fginfo$(EE) : utils/fginfo.cpp $(HEADERS) $(LIB)/libdai$(LE)
238 $(CC) $(CCO)$@ $< $(LIBS)
239
240 utils/uai2fg$(EE) : utils/uai2fg.cpp $(HEADERS) $(LIB)/libdai$(LE)
241 $(CC) $(CCO)$@ $< $(LIBS)
242
243
244 # LIBRARY
245 ##########
246
247 ifneq ($(OS),WINDOWS)
248 $(LIB)/libdai$(LE) : $(OBJECTS)
249 -mkdir -p lib
250 ar rcus $(LIB)/libdai$(LE) $(OBJECTS)
251 else
252 $(LIB)/libdai$(LE) : $(OBJECTS)
253 -mkdir lib
254 lib /out:$(LIB)/libdai$(LE) $(OBJECTS)
255 endif
256
257
258 # REGRESSION TESTS
259 ###################
260
261 testregression : tests/testdai$(EE)
262 @echo Starting regression test...this can take a minute or so!
263 ifneq ($(OS),WINDOWS)
264 cd tests && ./testregression && cd ..
265 else
266 cd tests && testregression.bat && cd ..
267 endif
268
269 testem : tests/testem/testem$(EE)
270 @echo Starting EM tests
271 ifneq ($(OS),WINDOWS)
272 cd tests/testem && ./runtests && cd ../..
273 else
274 cd tests\testem && runtests && cd ..\..
275 endif
276
277
278 # DOCUMENTATION
279 ################
280
281 doc : $(INC)/*.h $(SRC)/*.cpp examples/*.cpp doxygen.conf
282 doxygen doxygen.conf
283
284 README : doc scripts/makeREADME
285 DAI_VERSION=$(DAI_VERSION) DAI_DATE=$(DAI_DATE) scripts/makeREADME
286
287 TAGS :
288 etags src/*.cpp include/dai/*.h tests/*.cpp utils/*.cpp
289 ctags src/*.cpp include/dai/*.h tests/*.cpp utils/*.cpp
290
291
292 # CLEAN
293 ########
294
295 .PHONY : clean
296 ifneq ($(OS),WINDOWS)
297 clean :
298 -rm $(OBJECTS)
299 -rm matlab/*$(ME)
300 -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)
301 -rm tests/testdai$(EE) tests/testem/testem$(EE) tests/testbbp$(EE)
302 -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)
303 -rm factorgraph_test.fg alldai_test.aliases
304 -rm utils/fg2dot$(EE) utils/createfg$(EE) utils/fginfo$(EE) utils/uai2fg$(EE)
305 -rm -R doc
306 -rm -R lib
307 else
308 clean :
309 -del *.obj
310 -del *.ilk
311 -del *.pdb
312 -del matlab\*$(ME)
313 -del examples\*$(EE)
314 -del examples\*$(EE).manifest
315 -del examples\*.ilk
316 -del examples\*.pdb
317 -del tests\*$(EE)
318 -del tests\*$(EE).manifest
319 -del tests\*.pdb
320 -del tests\*.ilk
321 -del tests\testem\*$(EE)
322 -del tests\testem\*$(EE).manifest
323 -del tests\testem\*.pdb
324 -del tests\testem\*.ilk
325 -del utils\*$(EE)
326 -del utils\*$(EE).manifest
327 -del utils\*.pdb
328 -del utils\*.ilk
329 -del tests\unit\*_test$(EE)
330 -del tests\unit\*_test$(EE).manifest
331 -del tests\unit\*_test.pdb
332 -del tests\unit\*_test.ilk
333 -del factorgraph_test.fg
334 -del alldai_test.aliases
335 -del $(LIB)\libdai$(LE)
336 -rmdir lib
337 endif