- [Frederik Eaton]: Misc smaller changes
[libdai.git] / Makefile
1 # Copyright (C) 2006-2009 Joris Mooij [joris dot mooij at tuebingen dot mpg dot de]
2 # Radboud University Nijmegen, The Netherlands /
3 # Max Planck Institute for Biological Cybernetics, Germany
4 #
5 # This file is part of libDAI.
6 #
7 # libDAI is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
11 #
12 # libDAI is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with libDAI; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
21
22 # Load the local configuration from Makefile.conf
23 include Makefile.conf
24
25 # Directories of libDAI sources
26 # Location libDAI headers
27 INC=include/dai
28 # Location of libDAI source files
29 SRC=src
30 # Destination directory of libDAI library
31 LIB=lib
32
33 # Define build targets
34 TARGETS=tests utils lib examples testregression
35 ifdef WITH_DOC
36 TARGETS:=$(TARGETS) doc
37 endif
38 ifdef WITH_MATLAB
39 TARGETS:=$(TARGETS) matlabs
40 ifdef NEW_MATLAB
41 MEXFLAGS:=$(MEXFLAGS) -largeArrayDims
42 else
43 MEXFLAGS:=$(MEXFLAGS) -DSMALLMEM
44 endif
45 endif
46
47 # Define conditional build targets
48 OBJECTS:=exactinf$(OE)
49 ifdef WITH_BP
50 CCFLAGS:=$(CCFLAGS) -DDAI_WITH_BP
51 OBJECTS:=$(OBJECTS) bp$(OE)
52 endif
53 ifdef WITH_MF
54 CCFLAGS:=$(CCFLAGS) -DDAI_WITH_MF
55 OBJECTS:=$(OBJECTS) mf$(OE)
56 endif
57 ifdef WITH_HAK
58 CCFLAGS:=$(CCFLAGS) -DDAI_WITH_HAK
59 OBJECTS:=$(OBJECTS) hak$(OE)
60 endif
61 ifdef WITH_LC
62 CCFLAGS:=$(CCFLAGS) -DDAI_WITH_LC
63 OBJECTS:=$(OBJECTS) lc$(OE)
64 endif
65 ifdef WITH_TREEEP
66 CCFLAGS:=$(CCFLAGS) -DDAI_WITH_TREEEP
67 OBJECTS:=$(OBJECTS) treeep$(OE)
68 endif
69 ifdef WITH_JTREE
70 CCFLAGS:=$(CCFLAGS) -DDAI_WITH_JTREE
71 OBJECTS:=$(OBJECTS) jtree$(OE)
72 endif
73 ifdef WITH_MR
74 CCFLAGS:=$(CCFLAGS) -DDAI_WITH_MR
75 OBJECTS:=$(OBJECTS) mr$(OE)
76 endif
77 ifdef WITH_GIBBS
78 CCFLAGS:=$(CCFLAGS) -DDAI_WITH_GIBBS
79 OBJECTS:=$(OBJECTS) gibbs$(OE)
80 endif
81 ifdef WITH_BP_DUAL
82 CCFLAGS:=$(CCFLAGS) -DDAI_WITH_BP_DUAL
83 OBJECTS:=$(OBJECTS) bp_dual$(OE)
84 endif
85 ifdef WITH_CBP
86 CCFLAGS:=$(CCFLAGS) -DDAI_WITH_CBP
87 OBJECTS:=$(OBJECTS) bbp$(OE) cbp$(OE)
88 endif
89
90
91 # Define standard libDAI header dependencies
92 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
93
94 # Setup final command for C++ compiler and MEX
95 ifdef DEBUG
96 CCFLAGS:=$(CCFLAGS) $(CCDEBUGFLAGS)
97 endif
98 ifneq ($(OS),WINDOWS)
99 CC:=$(CC) $(CCINC) $(CCFLAGS) $(CCLIB)
100 else
101 CC:=$(CC) $(CCINC) $(CCFLAGS)
102 LIBS:=$(LIBS) $(CCLIB)
103 endif
104 MEX:=$(MEX) $(CCLIB) $(CCINC) $(MEXFLAGS)
105
106
107 # META TARGETS
108 ###############
109
110 all : $(TARGETS)
111
112 examples : examples/example$(EE) examples/example_bipgraph$(EE) examples/example_varset$(EE) examples/example_sprinkler$(EE)
113
114 matlabs : matlab/dai$(ME) matlab/dai_readfg$(ME) matlab/dai_writefg$(ME) matlab/dai_potstrength$(ME)
115
116 tests : tests/testdai$(EE)
117
118 utils : utils/createfg$(EE) utils/fg2dot$(EE) utils/fginfo$(EE)
119
120 lib: $(LIB)/libdai$(LE)
121
122
123 # OBJECTS
124 ##########
125
126 bipgraph$(OE) : $(SRC)/bipgraph.cpp $(HEADERS)
127 $(CC) -c $(SRC)/bipgraph.cpp
128
129 daialg$(OE) : $(SRC)/daialg.cpp $(HEADERS)
130 $(CC) -c $(SRC)/daialg.cpp
131
132 exactinf$(OE) : $(SRC)/exactinf.cpp $(INC)/exactinf.h $(HEADERS)
133 $(CC) -c $(SRC)/exactinf.cpp
134
135 bp$(OE) : $(SRC)/bp.cpp $(INC)/bp.h $(HEADERS)
136 $(CC) -c $(SRC)/bp.cpp
137
138 bp_dual$(OE) : $(SRC)/bp_dual.cpp $(INC)/bp_dual.h $(HEADERS)
139 $(CC) -c $(SRC)/bp_dual.cpp
140
141 bbp$(OE) : $(SRC)/bbp.cpp $(INC)/bbp.h $(INC)/bp_dual.h $(HEADERS)
142 $(CC) -c $(SRC)/bbp.cpp
143
144 cbp$(OE) : $(SRC)/cbp.cpp $(INC)/cbp.h $(INC)/bbp.h $(INC)/bp_dual.h $(HEADERS)
145 $(CC) -c $(SRC)/cbp.cpp
146
147 lc$(OE) : $(SRC)/lc.cpp $(INC)/lc.h $(HEADERS)
148 $(CC) -c $(SRC)/lc.cpp
149
150 mf$(OE) : $(SRC)/mf.cpp $(INC)/mf.h $(HEADERS)
151 $(CC) -c $(SRC)/mf.cpp
152
153 factorgraph$(OE) : $(SRC)/factorgraph.cpp $(INC)/factorgraph.h $(HEADERS)
154 $(CC) -c $(SRC)/factorgraph.cpp
155
156 util$(OE) : $(SRC)/util.cpp $(INC)/util.h $(HEADERS)
157 $(CC) -c $(SRC)/util.cpp
158
159 regiongraph$(OE) : $(SRC)/regiongraph.cpp $(INC)/regiongraph.h $(HEADERS)
160 $(CC) -c $(SRC)/regiongraph.cpp
161
162 hak$(OE) : $(SRC)/hak.cpp $(INC)/hak.h $(HEADERS) $(INC)/regiongraph.h
163 $(CC) -c $(SRC)/hak.cpp
164
165 clustergraph$(OE) : $(SRC)/clustergraph.cpp $(INC)/clustergraph.h $(HEADERS)
166 $(CC) -c $(SRC)/clustergraph.cpp
167
168 jtree$(OE) : $(SRC)/jtree.cpp $(INC)/jtree.h $(HEADERS) $(INC)/weightedgraph.h $(INC)/clustergraph.h $(INC)/regiongraph.h
169 $(CC) -c $(SRC)/jtree.cpp
170
171 treeep$(OE) : $(SRC)/treeep.cpp $(INC)/treeep.h $(HEADERS) $(INC)/weightedgraph.h $(INC)/clustergraph.h $(INC)/regiongraph.h $(INC)/jtree.h
172 $(CC) -c $(SRC)/treeep.cpp
173
174 weightedgraph$(OE) : $(SRC)/weightedgraph.cpp $(INC)/weightedgraph.h $(HEADERS)
175 $(CC) -c $(SRC)/weightedgraph.cpp
176
177 mr$(OE) : $(SRC)/mr.cpp $(INC)/mr.h $(HEADERS)
178 $(CC) -c $(SRC)/mr.cpp
179
180 gibbs$(OE) : $(SRC)/gibbs.cpp $(INC)/gibbs.h $(HEADERS)
181 $(CC) -c $(SRC)/gibbs.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
215
216 # MATLAB INTERFACE
217 ###################
218
219 matlab/dai$(ME) : $(SRC)/matlab/dai.cpp $(HEADERS) matlab$(OE) $(LIB)/libdai$(LE)
220 $(MEX) -o matlab/dai $(SRC)/matlab/dai.cpp matlab$(OE) $(LIB)/libdai$(LE)
221
222 matlab/dai_readfg$(ME) : $(SRC)/matlab/dai_readfg.cpp $(HEADERS) factorgraph$(OE) matlab$(OE) exceptions$(OE)
223 $(MEX) -o matlab/dai_readfg $(SRC)/matlab/dai_readfg.cpp factorgraph$(OE) matlab$(OE) exceptions$(OE)
224
225 matlab/dai_writefg$(ME) : $(SRC)/matlab/dai_writefg.cpp $(HEADERS) factorgraph$(OE) matlab$(OE) exceptions$(OE)
226 $(MEX) -o matlab/dai_writefg $(SRC)/matlab/dai_writefg.cpp factorgraph$(OE) matlab$(OE) exceptions$(OE)
227
228 matlab/dai_potstrength$(ME) : $(SRC)/matlab/dai_potstrength.cpp $(HEADERS) matlab$(OE) exceptions$(OE)
229 $(MEX) -o matlab/dai_potstrength $(SRC)/matlab/dai_potstrength.cpp matlab$(OE) exceptions$(OE)
230
231 matlab$(OE) : $(SRC)/matlab/matlab.cpp $(INC)/matlab/matlab.h $(HEADERS)
232 $(MEX) -c $(SRC)/matlab/matlab.cpp
233
234
235 # UTILS
236 ########
237
238 utils/createfg$(EE) : utils/createfg.cpp $(HEADERS) $(LIB)/libdai$(LE)
239 $(CC) $(CCO)utils/createfg$(EE) utils/createfg.cpp $(LIBS) $(BOOSTLIBS)
240
241 utils/fg2dot$(EE) : utils/fg2dot.cpp $(HEADERS) $(LIB)/libdai$(LE)
242 $(CC) $(CCO)utils/fg2dot$(EE) utils/fg2dot.cpp $(LIBS)
243
244 utils/fginfo$(EE) : utils/fginfo.cpp $(HEADERS) $(LIB)/libdai$(LE)
245 $(CC) $(CCO)utils/fginfo$(EE) utils/fginfo.cpp $(LIBS)
246
247
248 # LIBRARY
249 ##########
250
251 ifneq ($(OS),WINDOWS)
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 -p lib
254 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)
255 else
256 $(LIB)/libdai$(LE) : bipgraph$(OE) daialg$(OE) alldai$(OE) clustergraph$(OE) factorgraph$(OE) properties$(OE) regiongraph$(OE) util$(OE) weightedgraph$(OE) exceptions$(OE) $(OBJECTS)
257 -mkdir lib
258 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)
259 endif
260
261
262 # REGRESSION TESTS
263 ###################
264
265 ifneq ($(OS),WINDOWS)
266 testregression : tests/testdai$(EE)
267 @echo Starting regression test...this can take a minute or so!
268 cd tests && ./testregression && cd ..
269 else
270 testregression : tests/testdai$(EE)
271 @echo Starting regression test...this can take a minute or so!
272 cd tests && testregression.bat && cd ..
273 endif
274
275
276 # DOCUMENTATION
277 ################
278
279 doc : $(INC)/*.h $(SRC)/*.cpp examples/*.cpp doxygen.conf
280 doxygen doxygen.conf
281
282 TAGS:
283 etags src/*.cpp include/dai/*.h tests/*.cpp utils/*.cpp
284 ctags src/*.cpp include/dai/*.h tests/*.cpp utils/*.cpp
285
286
287 # CLEAN
288 ########
289
290 ifneq ($(OS),WINDOWS)
291 .PHONY : clean
292 clean :
293 -rm *$(OE)
294 -rm matlab/*$(ME)
295 -rm examples/example$(EE) examples/example_bipgraph$(EE) examples/example_varset$(EE) examples/example_sprinkler$(EE)
296 -rm tests/testdai$(EE)
297 -rm utils/fg2dot$(EE) utils/createfg$(EE) utils/fginfo$(EE)
298 -rm -R doc
299 -rm -R lib
300 else
301 .PHONY : clean
302 clean :
303 -del *$(OE) *.ilk *.pdb *$(EE) matlab\*$(ME) examples\*$(EE) examples\*.ilk examples\*.pdb tests\testdai$(EE) tests\*.pdb tests\*.ilk utils\*$(EE) utils\*.pdb utils\*.ilk $(LIB)\libdai$(LE)
304 endif