999f2549bf62fad4742a39c8842fc64e79d8af01
[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-2009 Joris Mooij [joris dot mooij at libdai dot org]
8 # Copyright (C) 2006-2007 Radboud University Nijmegen, The Netherlands
9
10
11 # Load the local configuration from Makefile.conf
12 include Makefile.conf
13
14 # Set version and date
15 DAI_VERSION="git HEAD"
16 DAI_DATE="November 16, 2009 - or later"
17
18 # Directories of libDAI sources
19 # Location libDAI headers
20 INC=include/dai
21 # Location of libDAI source files
22 SRC=src
23 # Destination directory of libDAI library
24 LIB=lib
25
26 # Set final compiler flags
27 ifdef DEBUG
28 CCFLAGS:=$(CCFLAGS) $(CCDEBUGFLAGS)
29 else
30 CCFLAGS:=$(CCFLAGS) $(CCNODEBUGFLAGS)
31 endif
32
33 # Define build targets
34 TARGETS=tests utils lib examples testregression testem
35 ifdef WITH_DOC
36 TARGETS:=$(TARGETS) doc
37 endif
38 ifdef WITH_MATLAB
39 TARGETS:=$(TARGETS) matlabs
40 # Specify the same C++ compiler and flags to mex
41 ifneq ($(OS),WINDOWS)
42 MEXFLAGS=CXX\#$(CC) CXXFLAGS\#'$(CCFLAGS)'
43 else
44 MEXFLAGS=CXX\#$(CC) CXXFLAGS\#"$(CCFLAGS)"
45 endif
46 ifdef NEW_MATLAB
47 MEXFLAGS:=$(MEXFLAGS) -largeArrayDims
48 else
49 MEXFLAGS:=$(MEXFLAGS) -DSMALLMEM
50 endif
51 endif
52
53 # Define conditional build targets
54 OBJECTS:=exactinf$(OE) evidence$(OE) emalg$(OE)
55 ifdef WITH_BP
56 CCFLAGS:=$(CCFLAGS) -DDAI_WITH_BP
57 OBJECTS:=$(OBJECTS) bp$(OE)
58 endif
59 ifdef WITH_FBP
60 CCFLAGS:=$(CCFLAGS) -DDAI_WITH_FBP
61 OBJECTS:=$(OBJECTS) fbp$(OE)
62 endif
63 ifdef WITH_MF
64 CCFLAGS:=$(CCFLAGS) -DDAI_WITH_MF
65 OBJECTS:=$(OBJECTS) mf$(OE)
66 endif
67 ifdef WITH_HAK
68 CCFLAGS:=$(CCFLAGS) -DDAI_WITH_HAK
69 OBJECTS:=$(OBJECTS) hak$(OE)
70 endif
71 ifdef WITH_LC
72 CCFLAGS:=$(CCFLAGS) -DDAI_WITH_LC
73 OBJECTS:=$(OBJECTS) lc$(OE)
74 endif
75 ifdef WITH_TREEEP
76 CCFLAGS:=$(CCFLAGS) -DDAI_WITH_TREEEP
77 OBJECTS:=$(OBJECTS) treeep$(OE)
78 endif
79 ifdef WITH_JTREE
80 CCFLAGS:=$(CCFLAGS) -DDAI_WITH_JTREE
81 OBJECTS:=$(OBJECTS) jtree$(OE)
82 endif
83 ifdef WITH_MR
84 CCFLAGS:=$(CCFLAGS) -DDAI_WITH_MR
85 OBJECTS:=$(OBJECTS) mr$(OE)
86 endif
87 ifdef WITH_GIBBS
88 CCFLAGS:=$(CCFLAGS) -DDAI_WITH_GIBBS
89 OBJECTS:=$(OBJECTS) gibbs$(OE)
90 endif
91 ifdef WITH_CBP
92 CCFLAGS:=$(CCFLAGS) -DDAI_WITH_CBP
93 OBJECTS:=$(OBJECTS) bbp$(OE) cbp$(OE) bp_dual$(OE)
94 endif
95
96 # Define standard libDAI header dependencies
97 HEADERS=$(INC)/bipgraph.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
98
99 # Setup final command for C++ compiler and MEX
100 ifneq ($(OS),WINDOWS)
101 CC:=$(CC) $(CCINC) $(CCFLAGS) $(CCLIB)
102 else
103 CC:=$(CC) $(CCINC) $(CCFLAGS)
104 LIBS:=$(LIBS) $(CCLIB)
105 endif
106 MEX:=$(MEX) $(CCLIB) $(CCINC) $(MEXFLAGS)
107
108
109 # META TARGETS
110 ###############
111
112 all : $(TARGETS)
113
114 examples : examples/example$(EE) examples/example_bipgraph$(EE) examples/example_varset$(EE) examples/example_permute$(EE) examples/example_sprinkler$(EE)
115
116 matlabs : matlab/dai$(ME) matlab/dai_readfg$(ME) matlab/dai_writefg$(ME) matlab/dai_potstrength$(ME)
117
118 tests : tests/testdai$(EE) tests/testem/testem$(EE) tests/testbbp$(EE)
119
120 utils : utils/createfg$(EE) utils/fg2dot$(EE) utils/fginfo$(EE)
121
122 lib: $(LIB)/libdai$(LE)
123
124
125 # OBJECTS
126 ##########
127
128 bipgraph$(OE) : $(SRC)/bipgraph.cpp $(HEADERS)
129 $(CC) -c $(SRC)/bipgraph.cpp
130
131 varset$(OE) : $(SRC/varset.cpp $(HEADERS)
132 $(CC) -c $(SRC)/varset.cpp
133
134 daialg$(OE) : $(SRC)/daialg.cpp $(HEADERS)
135 $(CC) -c $(SRC)/daialg.cpp
136
137 exactinf$(OE) : $(SRC)/exactinf.cpp $(INC)/exactinf.h $(HEADERS)
138 $(CC) -c $(SRC)/exactinf.cpp
139
140 bp$(OE) : $(SRC)/bp.cpp $(INC)/bp.h $(HEADERS)
141 $(CC) -c $(SRC)/bp.cpp
142
143 fbp$(OE) : $(SRC)/fbp.cpp $(INC)/fbp.h $(HEADERS)
144 $(CC) -c $(SRC)/fbp.cpp
145
146 bp_dual$(OE) : $(SRC)/bp_dual.cpp $(INC)/bp_dual.h $(HEADERS)
147 $(CC) -c $(SRC)/bp_dual.cpp
148
149 bbp$(OE) : $(SRC)/bbp.cpp $(INC)/bbp.h $(INC)/bp_dual.h $(HEADERS)
150 $(CC) -c $(SRC)/bbp.cpp
151
152 cbp$(OE) : $(SRC)/cbp.cpp $(INC)/cbp.h $(INC)/bbp.h $(INC)/bp_dual.h $(HEADERS)
153 $(CC) -c $(SRC)/cbp.cpp
154
155 lc$(OE) : $(SRC)/lc.cpp $(INC)/lc.h $(HEADERS)
156 $(CC) -c $(SRC)/lc.cpp
157
158 mf$(OE) : $(SRC)/mf.cpp $(INC)/mf.h $(HEADERS)
159 $(CC) -c $(SRC)/mf.cpp
160
161 factorgraph$(OE) : $(SRC)/factorgraph.cpp $(INC)/factorgraph.h $(HEADERS)
162 $(CC) -c $(SRC)/factorgraph.cpp
163
164 util$(OE) : $(SRC)/util.cpp $(INC)/util.h $(HEADERS)
165 $(CC) -c $(SRC)/util.cpp
166
167 regiongraph$(OE) : $(SRC)/regiongraph.cpp $(INC)/regiongraph.h $(HEADERS)
168 $(CC) -c $(SRC)/regiongraph.cpp
169
170 hak$(OE) : $(SRC)/hak.cpp $(INC)/hak.h $(HEADERS) $(INC)/regiongraph.h
171 $(CC) -c $(SRC)/hak.cpp
172
173 clustergraph$(OE) : $(SRC)/clustergraph.cpp $(INC)/clustergraph.h $(HEADERS)
174 $(CC) -c $(SRC)/clustergraph.cpp
175
176 jtree$(OE) : $(SRC)/jtree.cpp $(INC)/jtree.h $(HEADERS) $(INC)/weightedgraph.h $(INC)/clustergraph.h $(INC)/regiongraph.h
177 $(CC) -c $(SRC)/jtree.cpp
178
179 treeep$(OE) : $(SRC)/treeep.cpp $(INC)/treeep.h $(HEADERS) $(INC)/weightedgraph.h $(INC)/clustergraph.h $(INC)/regiongraph.h $(INC)/jtree.h
180 $(CC) -c $(SRC)/treeep.cpp
181
182 weightedgraph$(OE) : $(SRC)/weightedgraph.cpp $(INC)/weightedgraph.h $(HEADERS)
183 $(CC) -c $(SRC)/weightedgraph.cpp
184
185 mr$(OE) : $(SRC)/mr.cpp $(INC)/mr.h $(HEADERS)
186 $(CC) -c $(SRC)/mr.cpp
187
188 gibbs$(OE) : $(SRC)/gibbs.cpp $(INC)/gibbs.h $(HEADERS)
189 $(CC) -c $(SRC)/gibbs.cpp
190
191 evidence$(OE) : $(SRC)/evidence.cpp $(INC)/evidence.h $(HEADERS)
192 $(CC) -c $(SRC)/evidence.cpp
193
194 emalg$(OE) : $(SRC)/emalg.cpp $(INC)/emalg.h $(INC)/evidence.h $(HEADERS)
195 $(CC) -c $(SRC)/emalg.cpp
196
197 properties$(OE) : $(SRC)/properties.cpp $(HEADERS)
198 $(CC) -c $(SRC)/properties.cpp
199
200 exceptions$(OE) : $(SRC)/exceptions.cpp $(HEADERS)
201 $(CC) -c $(SRC)/exceptions.cpp
202
203 alldai$(OE) : $(SRC)/alldai.cpp $(HEADERS)
204 $(CC) -c $(SRC)/alldai.cpp
205
206
207 # EXAMPLES
208 ###########
209
210 examples/example$(EE) : examples/example.cpp $(HEADERS) $(LIB)/libdai$(LE)
211 $(CC) $(CCO)examples/example$(EE) examples/example.cpp $(LIBS)
212
213 examples/example_bipgraph$(EE) : examples/example_bipgraph.cpp $(HEADERS) $(LIB)/libdai$(LE)
214 $(CC) $(CCO)examples/example_bipgraph$(EE) examples/example_bipgraph.cpp $(LIBS)
215
216 examples/example_varset$(EE) : examples/example_varset.cpp $(HEADERS) $(LIB)/libdai$(LE)
217 $(CC) $(CCO)examples/example_varset$(EE) examples/example_varset.cpp $(LIBS)
218
219 examples/example_permute$(EE) : examples/example_permute.cpp $(HEADERS) $(LIB)/libdai$(LE)
220 $(CC) $(CCO)examples/example_permute$(EE) examples/example_permute.cpp $(LIBS)
221
222 examples/example_sprinkler$(EE) : examples/example_sprinkler.cpp $(HEADERS) $(LIB)/libdai$(LE)
223 $(CC) $(CCO)examples/example_sprinkler$(EE) examples/example_sprinkler.cpp $(LIBS)
224
225
226 # TESTS
227 ########
228
229 tests/testdai$(EE) : tests/testdai.cpp $(HEADERS) $(LIB)/libdai$(LE)
230 $(CC) $(CCO)tests/testdai$(EE) tests/testdai.cpp $(LIBS) $(BOOSTLIBS)
231 tests/testem/testem$(EE) : tests/testem/testem.cpp $(HEADERS) $(LIB)/libdai$(LE)
232 $(CC) $(CCO)$@ $< $(LIBS) $(BOOSTLIBS)
233
234 tests/testbbp$(EE) : tests/testbbp.cpp $(HEADERS) $(LIB)/libdai$(LE)
235 $(CC) $(CCO)tests/testbbp$(EE) tests/testbbp.cpp $(LIBS)
236
237
238 # MATLAB INTERFACE
239 ###################
240
241 matlab/dai$(ME) : $(SRC)/matlab/dai.cpp $(HEADERS) matlab$(OE) $(LIB)/libdai$(LE)
242 $(MEX) -o matlab/dai $(SRC)/matlab/dai.cpp matlab$(OE) $(LIB)/libdai$(LE)
243
244 matlab/dai_readfg$(ME) : $(SRC)/matlab/dai_readfg.cpp $(HEADERS) factorgraph$(OE) matlab$(OE) exceptions$(OE) bipgraph$(OE)
245 $(MEX) -o matlab/dai_readfg $(SRC)/matlab/dai_readfg.cpp factorgraph$(OE) matlab$(OE) exceptions$(OE) bipgraph$(OE)
246
247 matlab/dai_writefg$(ME) : $(SRC)/matlab/dai_writefg.cpp $(HEADERS) factorgraph$(OE) matlab$(OE) exceptions$(OE) bipgraph$(OE)
248 $(MEX) -o matlab/dai_writefg $(SRC)/matlab/dai_writefg.cpp factorgraph$(OE) matlab$(OE) exceptions$(OE) bipgraph$(OE)
249
250 matlab/dai_potstrength$(ME) : $(SRC)/matlab/dai_potstrength.cpp $(HEADERS) matlab$(OE) exceptions$(OE)
251 $(MEX) -o matlab/dai_potstrength $(SRC)/matlab/dai_potstrength.cpp matlab$(OE) exceptions$(OE)
252
253 matlab$(OE) : $(SRC)/matlab/matlab.cpp $(INC)/matlab/matlab.h $(HEADERS)
254 $(MEX) -c $(SRC)/matlab/matlab.cpp
255
256
257 # UTILS
258 ########
259
260 utils/createfg$(EE) : utils/createfg.cpp $(HEADERS) $(LIB)/libdai$(LE)
261 $(CC) $(CCO)utils/createfg$(EE) utils/createfg.cpp $(LIBS) $(BOOSTLIBS)
262
263 utils/fg2dot$(EE) : utils/fg2dot.cpp $(HEADERS) $(LIB)/libdai$(LE)
264 $(CC) $(CCO)utils/fg2dot$(EE) utils/fg2dot.cpp $(LIBS)
265
266 utils/fginfo$(EE) : utils/fginfo.cpp $(HEADERS) $(LIB)/libdai$(LE)
267 $(CC) $(CCO)utils/fginfo$(EE) utils/fginfo.cpp $(LIBS)
268
269
270 # LIBRARY
271 ##########
272
273 ifneq ($(OS),WINDOWS)
274 $(LIB)/libdai$(LE) : bipgraph$(OE) varset$(OE) daialg$(OE) alldai$(OE) clustergraph$(OE) factorgraph$(OE) properties$(OE) regiongraph$(OE) util$(OE) weightedgraph$(OE) exceptions$(OE) $(OBJECTS)
275 -mkdir -p lib
276 ar rcus $(LIB)/libdai$(LE) bipgraph$(OE) varset$(OE) daialg$(OE) alldai$(OE) clustergraph$(OE) factorgraph$(OE) properties$(OE) regiongraph$(OE) util$(OE) weightedgraph$(OE) exceptions$(OE) $(OBJECTS)
277 else
278 $(LIB)/libdai$(LE) : bipgraph$(OE) varset$(OE) daialg$(OE) alldai$(OE) clustergraph$(OE) factorgraph$(OE) properties$(OE) regiongraph$(OE) util$(OE) weightedgraph$(OE) exceptions$(OE) $(OBJECTS)
279 -mkdir lib
280 lib /out:$(LIB)/libdai$(LE) bipgraph$(OE) varset$(OE) daialg$(OE) alldai$(OE) clustergraph$(OE) factorgraph$(OE) properties$(OE) regiongraph$(OE) util$(OE) weightedgraph$(OE) exceptions$(OE) $(OBJECTS)
281 endif
282
283
284 # REGRESSION TESTS
285 ###################
286
287 testregression : tests/testdai$(EE)
288 @echo Starting regression test...this can take a minute or so!
289 ifneq ($(OS),WINDOWS)
290 cd tests && ./testregression && cd ..
291 else
292 cd tests && testregression.bat && cd ..
293 endif
294
295 testem : tests/testem/testem$(EE)
296 @echo Starting EM tests
297 ifneq ($(OS),WINDOWS)
298 cd tests/testem && ./runtests && cd ../..
299 else
300 cd tests\testem && runtests && cd ..\..
301 endif
302
303
304 # DOCUMENTATION
305 ################
306
307 doc : $(INC)/*.h $(SRC)/*.cpp examples/*.cpp doxygen.conf
308 doxygen doxygen.conf
309 # DAI_VERSION=$(DAI_VERSION) DAI_DATE=$(DAI_DATE) scripts/makeREADME
310
311 TAGS:
312 etags src/*.cpp include/dai/*.h tests/*.cpp utils/*.cpp
313 ctags src/*.cpp include/dai/*.h tests/*.cpp utils/*.cpp
314
315
316 # CLEAN
317 ########
318
319 ifneq ($(OS),WINDOWS)
320 .PHONY : clean
321 clean :
322 -rm *$(OE)
323 -rm matlab/*$(ME)
324 -rm examples/example$(EE) examples/example_bipgraph$(EE) examples/example_varset$(EE) examples/example_permute$(EE) examples/example_sprinkler$(EE)
325 -rm tests/testdai$(EE) tests/testem/testem$(EE) tests/testbbp$(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 $(LIB)\libdai$(LE)
351 -rmdir lib
352 endif