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