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