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