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