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