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