Wrote alldai.h/cpp 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) tests/unit/daialg$(EE) tests/unit/alldai$(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 tests/unit/daialg$(EE)
146 tests/unit/alldai$(EE)
147
148 tests : tests/testdai$(EE) tests/testem/testem$(EE) tests/testbbp$(EE) $(unittests)
149
150 utils : utils/createfg$(EE) utils/fg2dot$(EE) utils/fginfo$(EE)
151
152 lib: $(LIB)/libdai$(LE)
153
154
155 # OBJECTS
156 ##########
157
158 %$(OE) : $(SRC)/%.cpp $(INC)/%.h $(HEADERS)
159 $(CC) -c $<
160
161 bbp$(OE) : $(SRC)/bbp.cpp $(INC)/bbp.h $(INC)/bp_dual.h $(HEADERS)
162 $(CC) -c $<
163
164 cbp$(OE) : $(SRC)/cbp.cpp $(INC)/cbp.h $(INC)/bbp.h $(INC)/bp_dual.h $(HEADERS)
165 $(CC) -c $<
166
167 hak$(OE) : $(SRC)/hak.cpp $(INC)/hak.h $(HEADERS) $(INC)/regiongraph.h
168 $(CC) -c $<
169
170 jtree$(OE) : $(SRC)/jtree.cpp $(INC)/jtree.h $(HEADERS) $(INC)/weightedgraph.h $(INC)/clustergraph.h $(INC)/regiongraph.h
171 $(CC) -c $<
172
173 treeep$(OE) : $(SRC)/treeep.cpp $(INC)/treeep.h $(HEADERS) $(INC)/weightedgraph.h $(INC)/clustergraph.h $(INC)/regiongraph.h $(INC)/jtree.h
174 $(CC) -c $<
175
176 emalg$(OE) : $(SRC)/emalg.cpp $(INC)/emalg.h $(INC)/evidence.h $(HEADERS)
177 $(CC) -c $<
178
179
180 # EXAMPLES
181 ###########
182
183 examples/%$(EE) : examples/%.cpp $(HEADERS) $(LIB)/libdai$(LE)
184 $(CC) $(CCO)$@ $< $(LIBS)
185
186
187 # UNIT TESTS
188 #############
189
190 tests/unit/%$(EE) : tests/unit/%.cpp $(HEADERS) $(LIB)/libdai$(LE)
191 $(CC) $(CCO)$@ $< $(LIBS) $(BOOSTLIBS_UTF)
192
193
194 # TESTS
195 ########
196
197 tests/testdai$(EE) : tests/testdai.cpp $(HEADERS) $(LIB)/libdai$(LE)
198 $(CC) $(CCO)$@ $< $(LIBS) $(BOOSTLIBS_PO)
199 tests/testem/testem$(EE) : tests/testem/testem.cpp $(HEADERS) $(LIB)/libdai$(LE)
200 $(CC) $(CCO)$@ $< $(LIBS) $(BOOSTLIBS_PO)
201 ifdef WITH_CBP
202 tests/testbbp$(EE) : tests/testbbp.cpp $(HEADERS) $(LIB)/libdai$(LE)
203 $(CC) $(CCO)$@ $< $(LIBS)
204 endif
205
206
207 # MATLAB INTERFACE
208 ###################
209
210 matlab/dai$(ME) : $(SRC)/matlab/dai.cpp $(HEADERS) $(SOURCES) $(SRC)/matlab/matlab.cpp
211 $(MEX) -output $@ $< $(SRC)/matlab/matlab.cpp $(SOURCES)
212
213 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
214 $(MEX) -output $@ $< $(SRC)/matlab/matlab.cpp $(SRC)/factorgraph.cpp $(SRC)/exceptions.cpp $(SRC)/bipgraph.cpp $(SRC)/graph.cpp $(SRC)/factor.cpp $(SRC)/util.cpp
215
216 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
217 $(MEX) -output $@ $< $(SRC)/matlab/matlab.cpp $(SRC)/factorgraph.cpp $(SRC)/exceptions.cpp $(SRC)/bipgraph.cpp $(SRC)/graph.cpp $(SRC)/factor.cpp $(SRC)/util.cpp
218
219 matlab/dai_potstrength$(ME) : $(SRC)/matlab/dai_potstrength.cpp $(HEADERS) $(SRC)/matlab/matlab.cpp $(SRC)/exceptions.cpp
220 $(MEX) -output $@ $< $(SRC)/matlab/matlab.cpp $(SRC)/exceptions.cpp
221
222
223 # UTILS
224 ########
225
226 utils/createfg$(EE) : utils/createfg.cpp $(HEADERS) $(LIB)/libdai$(LE)
227 $(CC) $(CCO)$@ $< $(LIBS) $(BOOSTLIBS_PO)
228
229 utils/fg2dot$(EE) : utils/fg2dot.cpp $(HEADERS) $(LIB)/libdai$(LE)
230 $(CC) $(CCO)$@ $< $(LIBS)
231
232 utils/fginfo$(EE) : utils/fginfo.cpp $(HEADERS) $(LIB)/libdai$(LE)
233 $(CC) $(CCO)$@ $< $(LIBS)
234
235
236 # LIBRARY
237 ##########
238
239 ifneq ($(OS),WINDOWS)
240 $(LIB)/libdai$(LE) : $(OBJECTS)
241 -mkdir -p lib
242 ar rcus $(LIB)/libdai$(LE) $(OBJECTS)
243 else
244 $(LIB)/libdai$(LE) : $(OBJECTS)
245 -mkdir lib
246 lib /out:$(LIB)/libdai$(LE) $(OBJECTS)
247 endif
248
249
250 # REGRESSION TESTS
251 ###################
252
253 testregression : tests/testdai$(EE)
254 @echo Starting regression test...this can take a minute or so!
255 ifneq ($(OS),WINDOWS)
256 cd tests && ./testregression && cd ..
257 else
258 cd tests && testregression.bat && cd ..
259 endif
260
261 testem : tests/testem/testem$(EE)
262 @echo Starting EM tests
263 ifneq ($(OS),WINDOWS)
264 cd tests/testem && ./runtests && cd ../..
265 else
266 cd tests\testem && runtests && cd ..\..
267 endif
268
269
270 # DOCUMENTATION
271 ################
272
273 doc : $(INC)/*.h $(SRC)/*.cpp examples/*.cpp doxygen.conf
274 doxygen doxygen.conf
275
276 README : doc scripts/makeREADME
277 DAI_VERSION=$(DAI_VERSION) DAI_DATE=$(DAI_DATE) scripts/makeREADME
278
279 TAGS :
280 etags src/*.cpp include/dai/*.h tests/*.cpp utils/*.cpp
281 ctags src/*.cpp include/dai/*.h tests/*.cpp utils/*.cpp
282
283
284 # CLEAN
285 ########
286
287 .PHONY : clean
288 ifneq ($(OS),WINDOWS)
289 clean :
290 -rm $(OBJECTS)
291 -rm matlab/*$(ME)
292 -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)
293 -rm tests/testdai$(EE) tests/testem/testem$(EE) tests/testbbp$(EE)
294 -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) tests/unit/daialg$(EE) tests/unit/alldai$(EE)
295 -rm factorgraph_test.fg alldai_test.aliases
296 -rm utils/fg2dot$(EE) utils/createfg$(EE) utils/fginfo$(EE)
297 -rm -R doc
298 -rm -R lib
299 else
300 clean :
301 -del *.obj
302 -del *.ilk
303 -del *.pdb
304 -del matlab\*$(ME)
305 -del examples\*$(EE)
306 -del examples\*$(EE).manifest
307 -del examples\*.ilk
308 -del examples\*.pdb
309 -del tests\testdai$(EE)
310 -del tests\testbbp$(EE)
311 -del tests\testdai$(EE).manifest
312 -del tests\testbbp$(EE).manifest
313 -del tests\testem\testem$(EE)
314 -del tests\testem\testem$(EE).manifest
315 -del tests\*.pdb
316 -del tests\*.ilk
317 -del tests\testem\*.pdb
318 -del tests\testem\*.ilk
319 -del utils\*$(EE)
320 -del utils\*$(EE).manifest
321 -del utils\*.pdb
322 -del utils\*.ilk
323 -del tests\unit\*.ilk
324 -del tests\unit\*.pdb
325 -del tests\unit\var$(EE)
326 -del tests\unit\smallset$(EE)
327 -del tests\unit\varset$(EE)
328 -del tests\unit\graph$(EE)
329 -del tests\unit\bipgraph$(EE)
330 -del tests\unit\weightedgraph$(EE)
331 -del tests\unit\enum$(EE)
332 -del tests\unit\util$(EE)
333 -del tests\unit\exceptions$(EE)
334 -del tests\unit\properties$(EE)
335 -del tests\unit\index$(EE)
336 -del tests\unit\prob$(EE)
337 -del tests\unit\factor$(EE)
338 -del tests\unit\factorgraph$(EE)
339 -del tests\unit\clustergraph$(EE)
340 -del tests\unit\regiongraph$(EE)
341 -del tests\unit\daialg$(EE)
342 -del tests\unit\alldai$(EE)
343 -del factorgraph_test.fg
344 -del alldai_test.aliases
345 -del $(LIB)\libdai$(LE)
346 -rmdir lib
347 endif