Multiple changes: changes in build system, one workaround and one bug fix
[libdai.git] / Makefile
1 # This file is part of libDAI - http://www.libdai.org/
2 #
3 # Copyright (c) 2006-2011, The libDAI authors. All rights reserved.
4 #
5 # Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
6
7
8 # Load the platform independent build configuration file
9 include Makefile.ALL
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="September 17, 2012 - or later"
17
18 # Directories of libDAI sources
19 # Location of 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:=lib tests utils examples
35 ifdef WITH_MATLAB
36 TARGETS:=$(TARGETS) matlabs
37 endif
38 TARGETS:=$(TARGETS) unittests testregression testem
39 ifdef WITH_DOC
40 TARGETS:=$(TARGETS) doc
41 endif
42
43 # Define conditional build targets
44 NAMES:=graph dag bipgraph varset daialg alldai clustergraph factor factorgraph properties regiongraph cobwebgraph util weightedgraph exceptions exactinf evidence emalg io
45 NAMES:=$(NAMES) bp fbp trwbp mf hak lc treeep jtree mr gibbs bbp cbp bp_dual decmap glc
46
47
48 # Define standard libDAI header dependencies, source file names and object file names
49 HEADERS=$(foreach name,graph dag bipgraph index var factor varset smallset prob daialg properties alldai enum exceptions util,$(INC)/$(name).h)
50 SOURCES:=$(foreach name,$(NAMES),$(SRC)/$(name).cpp)
51 OBJECTS:=$(foreach name,$(NAMES),$(name)$(OE))
52
53 # Setup final command for C++ compiler
54 ifneq ($(OS),WINDOWS)
55 CC:=$(CC) $(CCINC) $(CCFLAGS) $(WITHFLAGS) $(CCLIB)
56 else
57 CC:=$(CC) $(CCINC) $(CCFLAGS) $(WITHFLAGS)
58 LIBS:=$(LIBS) $(CCLIB)
59 endif
60
61 # Setup final command for MEX
62 ifdef NEW_MATLAB
63 MEXFLAGS:=$(MEXFLAGS) -largeArrayDims
64 else
65 MEXFLAGS:=$(MEXFLAGS) -DSMALLMEM
66 endif
67 MEX:=$(MEX) $(MEXINC) $(MEXFLAGS) $(WITHFLAGS) $(MEXLIBS) $(MEXLIB)
68
69
70 # META TARGETS
71 ###############
72
73 all : $(TARGETS)
74 @echo
75 @echo libDAI built successfully!
76
77 EXAMPLES=$(foreach name,example example_bipgraph example_varset example_permute example_sprinkler example_sprinkler_em,examples/$(name)$(EE))
78 EXAMPLES:=$(EXAMPLES) examples/example_sprinkler_gibbs$(EE)
79 ifdef WITH_CIMG
80 EXAMPLES:=$(EXAMPLES) examples/example_imagesegmentation$(EE)
81 endif
82 examples : $(EXAMPLES)
83
84 matlabs : matlab/dai$(ME) matlab/dai_readfg$(ME) matlab/dai_writefg$(ME) matlab/dai_potstrength$(ME) matlab/dai_jtree$(ME)
85
86 unittests : tests/unit/var_test$(EE) tests/unit/smallset_test$(EE) tests/unit/varset_test$(EE) tests/unit/graph_test$(EE) tests/unit/dag_test$(EE) tests/unit/bipgraph_test$(EE) tests/unit/weightedgraph_test$(EE) tests/unit/enum_test$(EE) tests/unit/enum_test$(EE) tests/unit/util_test$(EE) tests/unit/exceptions_test$(EE) tests/unit/properties_test$(EE) tests/unit/index_test$(EE) tests/unit/prob_test$(EE) tests/unit/factor_test$(EE) tests/unit/factorgraph_test$(EE) tests/unit/clustergraph_test$(EE) tests/unit/regiongraph_test$(EE) tests/unit/daialg_test$(EE) tests/unit/alldai_test$(EE)
87 @echo 'Running unit tests...'
88 @echo
89 tests/unit/var_test$(EE)
90 tests/unit/smallset_test$(EE)
91 tests/unit/varset_test$(EE)
92 tests/unit/graph_test$(EE)
93 tests/unit/dag_test$(EE)
94 tests/unit/bipgraph_test$(EE)
95 tests/unit/weightedgraph_test$(EE)
96 tests/unit/enum_test$(EE)
97 tests/unit/util_test$(EE)
98 tests/unit/exceptions_test$(EE)
99 tests/unit/properties_test$(EE)
100 tests/unit/index_test$(EE)
101 tests/unit/prob_test$(EE)
102 tests/unit/factor_test$(EE)
103 tests/unit/factorgraph_test$(EE)
104 tests/unit/clustergraph_test$(EE)
105 tests/unit/regiongraph_test$(EE)
106 tests/unit/daialg_test$(EE)
107 tests/unit/alldai_test$(EE)
108 @echo
109 @echo 'All unit tests completed successfully!'
110 @echo
111
112 tests : tests/testdai$(EE) tests/testem/testem$(EE) tests/testbbp$(EE) $(unittests)
113
114 utils : utils/createfg$(EE) utils/fg2dot$(EE) utils/fginfo$(EE) utils/uai2fg$(EE)
115
116 lib: $(LIB)/libdai$(LE)
117
118
119 # OBJECTS
120 ##########
121
122 %$(OE) : $(SRC)/%.cpp $(INC)/%.h $(HEADERS)
123 $(CC) -c $<
124
125 bbp$(OE) : $(SRC)/bbp.cpp $(INC)/bbp.h $(INC)/bp_dual.h $(HEADERS)
126 $(CC) -c $<
127
128 cbp$(OE) : $(SRC)/cbp.cpp $(INC)/cbp.h $(INC)/bbp.h $(INC)/bp_dual.h $(HEADERS)
129 $(CC) -c $<
130
131 hak$(OE) : $(SRC)/hak.cpp $(INC)/hak.h $(HEADERS) $(INC)/regiongraph.h
132 $(CC) -c $<
133
134 jtree$(OE) : $(SRC)/jtree.cpp $(INC)/jtree.h $(HEADERS) $(INC)/weightedgraph.h $(INC)/clustergraph.h $(INC)/regiongraph.h
135 $(CC) -c $<
136
137 treeep$(OE) : $(SRC)/treeep.cpp $(INC)/treeep.h $(HEADERS) $(INC)/weightedgraph.h $(INC)/clustergraph.h $(INC)/regiongraph.h $(INC)/jtree.h
138 $(CC) -c $<
139
140 emalg$(OE) : $(SRC)/emalg.cpp $(INC)/emalg.h $(INC)/evidence.h $(HEADERS)
141 $(CC) -c $<
142
143 decmap$(OE) : $(SRC)/decmap.cpp $(INC)/decmap.h $(HEADERS)
144 $(CC) -c $<
145
146 glc$(OE) : $(SRC)/glc.cpp $(INC)/glc.h $(HEADERS) $(INC)/cobwebgraph.h
147 $(CC) -c $<
148
149
150 # EXAMPLES
151 ###########
152
153 examples/%$(EE) : examples/%.cpp $(HEADERS) $(LIB)/libdai$(LE)
154 $(CC) $(CCO)$@ $< $(LIBS)
155
156 examples/example_sprinkler_gibbs$(EE) : examples/example_sprinkler_gibbs.cpp $(HEADERS) $(LIB)/libdai$(LE)
157 $(CC) $(CCO)$@ $< $(LIBS)
158
159 examples/example_imagesegmentation$(EE) : examples/example_imagesegmentation.cpp $(HEADERS) $(LIB)/libdai$(LE)
160 ifdef NEW_CIMG
161 $(CC) -DNEW_CIMG $(CIMGINC) $(CCO)$@ $< $(LIBS) $(CIMGLIBS)
162 else
163 $(CC) $(CIMGINC) $(CCO)$@ $< $(LIBS) $(CIMGLIBS)
164 endif
165
166
167 # UNIT TESTS
168 #############
169
170 tests/unit/%$(EE) : tests/unit/%.cpp $(HEADERS) $(LIB)/libdai$(LE)
171 ifneq ($(OS),WINDOWS)
172 $(CC) -DBOOST_TEST_DYN_LINK $(CCO)$@ $< $(LIBS) $(BOOSTLIBS_UTF)
173 else
174 $(CC) $(CCO)$@ $< $(LIBS) $(BOOSTLIBS_UTF) /SUBSYSTEM:CONSOLE
175 endif
176
177
178 # TESTS
179 ########
180
181 tests/testdai$(EE) : tests/testdai.cpp $(HEADERS) $(LIB)/libdai$(LE)
182 $(CC) $(CCO)$@ $< $(LIBS) $(BOOSTLIBS_PO)
183 tests/testem/testem$(EE) : tests/testem/testem.cpp $(HEADERS) $(LIB)/libdai$(LE)
184 $(CC) $(CCO)$@ $< $(LIBS) $(BOOSTLIBS_PO)
185 tests/testbbp$(EE) : tests/testbbp.cpp $(HEADERS) $(LIB)/libdai$(LE)
186 $(CC) $(CCO)$@ $< $(LIBS)
187
188
189 # MATLAB INTERFACE
190 ###################
191
192 matlab/dai$(ME) : $(SRC)/matlab/dai.cpp $(HEADERS) $(SOURCES) $(SRC)/matlab/matlab.cpp
193 $(MEX) -output $@ $< $(SRC)/matlab/matlab.cpp $(SOURCES)
194
195 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
196 $(MEX) -output $@ $< $(SRC)/matlab/matlab.cpp $(SRC)/factorgraph.cpp $(SRC)/exceptions.cpp $(SRC)/bipgraph.cpp $(SRC)/graph.cpp $(SRC)/factor.cpp $(SRC)/util.cpp
197
198 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
199 $(MEX) -output $@ $< $(SRC)/matlab/matlab.cpp $(SRC)/factorgraph.cpp $(SRC)/exceptions.cpp $(SRC)/bipgraph.cpp $(SRC)/graph.cpp $(SRC)/factor.cpp $(SRC)/util.cpp
200
201 matlab/dai_potstrength$(ME) : $(SRC)/matlab/dai_potstrength.cpp $(HEADERS) $(SRC)/matlab/matlab.cpp $(SRC)/exceptions.cpp
202 $(MEX) -output $@ $< $(SRC)/matlab/matlab.cpp $(SRC)/exceptions.cpp
203
204 matlab/dai_jtree$(ME) : $(SRC)/matlab/dai_jtree.cpp $(HEADERS) $(SOURCES) $(SRC)/matlab/matlab.cpp
205 $(MEX) -output $@ $< $(SRC)/matlab/matlab.cpp $(SOURCES)
206
207
208 # UTILS
209 ########
210
211 utils/createfg$(EE) : utils/createfg.cpp $(HEADERS) $(LIB)/libdai$(LE)
212 $(CC) $(CCO)$@ $< $(LIBS) $(BOOSTLIBS_PO)
213
214 utils/fg2dot$(EE) : utils/fg2dot.cpp $(HEADERS) $(LIB)/libdai$(LE)
215 $(CC) $(CCO)$@ $< $(LIBS)
216
217 utils/fginfo$(EE) : utils/fginfo.cpp $(HEADERS) $(LIB)/libdai$(LE)
218 $(CC) $(CCO)$@ $< $(LIBS)
219
220 utils/uai2fg$(EE) : utils/uai2fg.cpp $(HEADERS) $(LIB)/libdai$(LE)
221 $(CC) $(CCO)$@ $< $(LIBS)
222
223
224 # LIBRARY
225 ##########
226
227 ifneq ($(OS),WINDOWS)
228 $(LIB)/libdai$(LE) : $(OBJECTS)
229 -mkdir -p lib
230 ar rcus $(LIB)/libdai$(LE) $(OBJECTS)
231 else
232 $(LIB)/libdai$(LE) : $(OBJECTS)
233 -mkdir lib
234 lib /out:$(LIB)/libdai$(LE) $(OBJECTS)
235 endif
236
237
238 # REGRESSION TESTS
239 ###################
240
241 testregression : tests/testdai$(EE)
242 @echo Starting regression test...this can take a minute or so!
243 ifneq ($(OS),WINDOWS)
244 cd tests && ./testregression && cd ..
245 else
246 cd tests && testregression.bat && cd ..
247 endif
248
249 testem : tests/testem/testem$(EE)
250 @echo Starting EM tests
251 ifneq ($(OS),WINDOWS)
252 cd tests/testem && ./runtests && cd ../..
253 else
254 cd tests\testem && runtests && cd ..\..
255 endif
256
257
258 # DOCUMENTATION
259 ################
260
261 doc : $(INC)/*.h $(SRC)/*.cpp examples/*.cpp doxygen.conf
262 doxygen doxygen.conf
263
264 README : doc scripts/makeREADME Makefile
265 DAI_VERSION=$(DAI_VERSION) DAI_DATE=$(DAI_DATE) scripts/makeREADME
266
267 TAGS :
268 etags src/*.cpp include/dai/*.h tests/*.cpp utils/*.cpp
269 ctags src/*.cpp include/dai/*.h tests/*.cpp utils/*.cpp
270
271
272 # CLEAN
273 ########
274
275 .PHONY : clean
276 ifneq ($(OS),WINDOWS)
277 clean :
278 -rm $(OBJECTS)
279 -rm matlab/*$(ME)
280 -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) examples/example_imagesegmentation$(EE)
281 -rm tests/testdai$(EE) tests/testem/testem$(EE) tests/testbbp$(EE)
282 -rm tests/unit/var_test$(EE) tests/unit/smallset_test$(EE) tests/unit/varset_test$(EE) tests/unit/graph_test$(EE) tests/unit/dag_test$(EE) tests/unit/bipgraph_test$(EE) tests/unit/weightedgraph_test$(EE) tests/unit/enum_test$(EE) tests/unit/util_test$(EE) tests/unit/exceptions_test$(EE) tests/unit/properties_test$(EE) tests/unit/index_test$(EE) tests/unit/prob_test$(EE) tests/unit/factor_test$(EE) tests/unit/factorgraph_test$(EE) tests/unit/clustergraph_test$(EE) tests/unit/regiongraph_test$(EE) tests/unit/daialg_test$(EE) tests/unit/alldai_test$(EE)
283 -rm factorgraph_test.fg alldai_test.aliases
284 -rm utils/fg2dot$(EE) utils/createfg$(EE) utils/fginfo$(EE) utils/uai2fg$(EE)
285 -rm -R doc
286 -rm -R lib
287 else
288 clean :
289 -del *.obj
290 -del *.ilk
291 -del *.pdb
292 -del matlab\*$(ME)
293 -del examples\*$(EE)
294 -del examples\*$(EE).manifest
295 -del examples\*.ilk
296 -del examples\*.pdb
297 -del tests\*$(EE)
298 -del tests\*$(EE).manifest
299 -del tests\*.pdb
300 -del tests\*.ilk
301 -del tests\testem\*$(EE)
302 -del tests\testem\*$(EE).manifest
303 -del tests\testem\*.pdb
304 -del tests\testem\*.ilk
305 -del utils\*$(EE)
306 -del utils\*$(EE).manifest
307 -del utils\*.pdb
308 -del utils\*.ilk
309 -del tests\unit\*_test$(EE)
310 -del tests\unit\*_test$(EE).manifest
311 -del tests\unit\*_test.pdb
312 -del tests\unit\*_test.ilk
313 -del factorgraph_test.fg
314 -del alldai_test.aliases
315 -del $(LIB)\libdai$(LE)
316 -rmdir lib
317 endif