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