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