2d63911bb038e619844c9131e0466c0ddd3496d6
[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 # Choose OS from {LINUX, WINDOWS, CYGWIN, MACOSX}
23 # LINUX: GNU/Linux and other UNIX variants
24 # WINDOWS: Visual C++ with GNU Make
25 # CYGWIN: CygWin
26 # MACOSX: MacOSX
27 OS=LINUX
28
29 # Enable/disable various approximate inference methods
30 WITH_BP=true
31 WITH_MF=true
32 WITH_HAK=true
33 WITH_LC=true
34 WITH_TREEEP=true
35 WITH_JTREE=true
36 WITH_MR=true
37 WITH_GIBBS=true
38
39 # Build with debug info?
40 DEBUG=true
41
42 # Build matlab interface?
43 WITH_MATLAB=
44 # New/old matlab version?
45 NEW_MATLAB=true
46
47 # Directories
48 # Location libDAI headers
49 INC=include/dai
50 # Location of libDAI source files
51 SRC=src
52 # Destination directory of libDAI library
53 LIB=lib
54 # Additional iclude paths for C compiler
55 CCINC=-Iinclude
56
57 # Extensions (library, object, executable, matlab compiled MEX file)
58 ifneq ($(OS),WINDOWS)
59 LE=.a
60 OE=.o
61 EE=
62 ME=.mexglx
63 else
64 LE=.lib
65 OE=.obj
66 EE=.exe
67 ME=.mexglx
68 endif
69
70 # Libraries
71 ifneq ($(OS),WINDOWS)
72 LIBS=-ldai
73 # Additional library paths for linker
74 CCLIB=-Llib
75 else
76 # For some reason, we have to add the VC library path, although it is in the environment
77 LIBS=/link $(LIB)/libdai$(LE) /LIBPATH:"C:\Program Files\Microsoft Visual Studio 9.0\VC\ATLMFC\LIB" /LIBPATH:"C:\Program Files\Microsoft Visual Studio 9.0\VC\LIB" /LIBPATH:"C:\Program Files\Microsoft SDKs\Windows\v6.0A\lib"
78 endif
79
80 # Tell the linker to link with the BOOST Program Options library
81 ifeq ($(OS),CYGWIN)
82 BOOSTLIBS=-lboost_program_options-gcc34-mt
83 endif
84 ifeq ($(OS),MACOSX)
85 BOOSTLIBS=-lboost_program_options-mt
86 endif
87 ifeq ($(OS),LINUX)
88 BOOSTLIBS=-lboost_program_options-mt
89 endif
90 ifeq ($(OS),WINDOWS)
91 BOOSTLIBS=/LIBPATH:C:\boost_1_36_0\stage\lib
92 endif
93
94 # Compiler specific options
95 ifneq ($(OS),WINDOWS)
96 # Compile using GNU C++ Compiler
97 CC=g++
98 # Output filename option of the compiler
99 CCO=-o
100 else
101 # Compile using Visual C++ Compiler
102 CC=cl
103 # Output filename option
104 CCO=/Fe
105 endif
106
107 # Flags for the C++ compiler
108 ifneq ($(OS),WINDOWS)
109 CCFLAGS=-O3 -Wno-deprecated -Wall -W -Wextra -fpic
110 CCDEBUGFLAGS=-g -DDAI_DEBUG
111 else
112 CCFLAGS=/Iinclude /IC:\boost_1_36_0 /EHsc /Ox
113 CCDEBUGFLAGS=/Zi -DDAI_DEBUG
114 endif
115
116 ifeq ($(OS),CYGWIN)
117 CCINC:=$(CCINC) -I/usr/local/include/boost-1_37
118 # dynamic linking of Boost libraries seems not to work on Cygwin
119 CCFLAGS:=$(CCFLAGS) -DCYGWIN -static
120 endif
121 ifeq ($(OS),MACOSX)
122 # indicate where your boost headers and libraries are (likely where macports installs libraries)
123 CCINC:=$(CCINC) -I/opt/local/include
124 CCLIB:=$(CCLIB) -L/opt/local/lib
125 endif
126
127 # Build targets
128 TARGETS=tests utils lib examples testregression
129 ifneq ($(OS),WINDOWS)
130 TARGETS:=$(TARGETS) doc
131 endif
132
133 ifdef WITH_MATLAB
134 ifneq ($(OS),WINDOWS)
135 # Replace the following by the directory where Matlab has been installed
136 MATLABDIR=/agbs/share/sw/matlab
137 MEX=$(MATLABDIR)/bin/mex
138 MEXFLAGS=CXX\#$(CC) CXXFLAGS\#'$(CCFLAGS)'
139 else
140 # Replace the following by the directory where Matlab has been installed
141 MATLABDIR=c:\matlab
142 MEX=$(MATLABDIR)\bin\mex
143 MEXFLAGS=-Iinclude CXX\#$(CC) CXXFLAGS\#"/EHsc /Ox"
144 endif
145 endif
146
147
148 ifdef DEBUG
149 CCFLAGS:=$(CCFLAGS) $(CCDEBUGFLAGS)
150 endif
151 ifeq ($(OS),WINDOWS)
152 CCFLAGS:=$(CCFLAGS) -DWINDOWS
153 endif
154 ifdef WITH_MATLAB
155 TARGETS:=$(TARGETS) matlabs
156 ifdef NEW_MATLAB
157 MEXFLAGS:=$(MEXFLAGS) -largeArrayDims
158 else
159 MEXFLAGS:=$(MEXFLAGS) -DSMALLMEM
160 endif
161 endif
162
163
164 OBJECTS:=exactinf$(OE)
165 ifdef WITH_BP
166 CCFLAGS:=$(CCFLAGS) -DDAI_WITH_BP
167 OBJECTS:=$(OBJECTS) bp$(OE)
168 endif
169 ifdef WITH_MF
170 CCFLAGS:=$(CCFLAGS) -DDAI_WITH_MF
171 OBJECTS:=$(OBJECTS) mf$(OE)
172 endif
173 ifdef WITH_HAK
174 CCFLAGS:=$(CCFLAGS) -DDAI_WITH_HAK
175 OBJECTS:=$(OBJECTS) hak$(OE)
176 endif
177 ifdef WITH_LC
178 CCFLAGS:=$(CCFLAGS) -DDAI_WITH_LC
179 OBJECTS:=$(OBJECTS) lc$(OE)
180 endif
181 ifdef WITH_TREEEP
182 CCFLAGS:=$(CCFLAGS) -DDAI_WITH_TREEEP
183 OBJECTS:=$(OBJECTS) treeep$(OE)
184 endif
185 ifdef WITH_JTREE
186 CCFLAGS:=$(CCFLAGS) -DDAI_WITH_JTREE
187 OBJECTS:=$(OBJECTS) jtree$(OE)
188 endif
189 ifdef WITH_MR
190 CCFLAGS:=$(CCFLAGS) -DDAI_WITH_MR
191 OBJECTS:=$(OBJECTS) mr$(OE)
192 endif
193 ifdef WITH_GIBBS
194 CCFLAGS:=$(CCFLAGS) -DDAI_WITH_GIBBS
195 OBJECTS:=$(OBJECTS) gibbs$(OE)
196 endif
197
198
199 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
200
201
202 CC:=$(CC) $(CCINC) $(CCLIB) $(CCFLAGS)
203 MEX:=$(MEX) $(CCLIB) $(CCINC) $(MEXFLAGS)
204
205
206 # META TARGETS
207 ###############
208
209 all : $(TARGETS)
210
211 examples : examples/example$(EE) examples/example_bipgraph$(EE) examples/example_varset$(EE) examples/example_sprinkler$(EE)
212
213 matlabs : matlab/dai$(ME) matlab/dai_readfg$(ME) matlab/dai_writefg$(ME) matlab/dai_potstrength$(ME)
214
215 tests : tests/testdai$(EE)
216
217 utils : utils/createfg$(EE) utils/fg2dot$(EE) utils/fginfo$(EE)
218
219 lib: $(LIB)/libdai$(LE)
220
221
222 # OBJECTS
223 ##########
224
225 bipgraph$(OE) : $(SRC)/bipgraph.cpp $(HEADERS)
226 $(CC) -c $(SRC)/bipgraph.cpp
227
228 daialg$(OE) : $(SRC)/daialg.cpp $(HEADERS)
229 $(CC) -c $(SRC)/daialg.cpp
230
231 exactinf$(OE) : $(SRC)/exactinf.cpp $(INC)/exactinf.h $(HEADERS)
232 $(CC) -c $(SRC)/exactinf.cpp
233
234 bp$(OE) : $(SRC)/bp.cpp $(INC)/bp.h $(HEADERS)
235 $(CC) -c $(SRC)/bp.cpp
236
237 lc$(OE) : $(SRC)/lc.cpp $(INC)/lc.h $(HEADERS)
238 $(CC) -c $(SRC)/lc.cpp
239
240 mf$(OE) : $(SRC)/mf.cpp $(INC)/mf.h $(HEADERS)
241 $(CC) -c $(SRC)/mf.cpp
242
243 factorgraph$(OE) : $(SRC)/factorgraph.cpp $(INC)/factorgraph.h $(HEADERS)
244 $(CC) -c $(SRC)/factorgraph.cpp
245
246 util$(OE) : $(SRC)/util.cpp $(INC)/util.h $(HEADERS)
247 $(CC) -c $(SRC)/util.cpp
248
249 regiongraph$(OE) : $(SRC)/regiongraph.cpp $(INC)/regiongraph.h $(HEADERS)
250 $(CC) -c $(SRC)/regiongraph.cpp
251
252 hak$(OE) : $(SRC)/hak.cpp $(INC)/hak.h $(HEADERS) $(INC)/regiongraph.h
253 $(CC) -c $(SRC)/hak.cpp
254
255 clustergraph$(OE) : $(SRC)/clustergraph.cpp $(INC)/clustergraph.h $(HEADERS)
256 $(CC) -c $(SRC)/clustergraph.cpp
257
258 jtree$(OE) : $(SRC)/jtree.cpp $(INC)/jtree.h $(HEADERS) $(INC)/weightedgraph.h $(INC)/clustergraph.h $(INC)/regiongraph.h
259 $(CC) -c $(SRC)/jtree.cpp
260
261 treeep$(OE) : $(SRC)/treeep.cpp $(INC)/treeep.h $(HEADERS) $(INC)/weightedgraph.h $(INC)/clustergraph.h $(INC)/regiongraph.h $(INC)/jtree.h
262 $(CC) -c $(SRC)/treeep.cpp
263
264 weightedgraph$(OE) : $(SRC)/weightedgraph.cpp $(INC)/weightedgraph.h $(HEADERS)
265 $(CC) -c $(SRC)/weightedgraph.cpp
266
267 mr$(OE) : $(SRC)/mr.cpp $(INC)/mr.h $(HEADERS)
268 $(CC) -c $(SRC)/mr.cpp
269
270 gibbs$(OE) : $(SRC)/gibbs.cpp $(INC)/gibbs.h $(HEADERS)
271 $(CC) -c $(SRC)/gibbs.cpp
272
273 properties$(OE) : $(SRC)/properties.cpp $(HEADERS)
274 $(CC) -c $(SRC)/properties.cpp
275
276 exceptions$(OE) : $(SRC)/exceptions.cpp $(HEADERS)
277 $(CC) -c $(SRC)/exceptions.cpp
278
279 alldai$(OE) : $(SRC)/alldai.cpp $(HEADERS)
280 $(CC) -c $(SRC)/alldai.cpp
281
282
283 # EXAMPLES
284 ###########
285
286 examples/example$(EE) : examples/example.cpp $(HEADERS) $(LIB)/libdai$(LE)
287 $(CC) $(CCO)examples/example$(EE) examples/example.cpp $(LIBS)
288
289 examples/example_bipgraph$(EE) : examples/example_bipgraph.cpp $(HEADERS) $(LIB)/libdai$(LE)
290 $(CC) $(CCO)examples/example_bipgraph$(EE) examples/example_bipgraph.cpp $(LIBS)
291
292 examples/example_varset$(EE) : examples/example_varset.cpp $(HEADERS) $(LIB)/libdai$(LE)
293 $(CC) $(CCO)examples/example_varset$(EE) examples/example_varset.cpp $(LIBS)
294
295 examples/example_sprinkler$(EE) : examples/example_sprinkler.cpp $(HEADERS) $(LIB)/libdai$(LE)
296 $(CC) $(CCO)examples/example_sprinkler$(EE) examples/example_sprinkler.cpp $(LIBS)
297
298
299 # TESTS
300 ########
301
302 tests/testdai$(EE) : tests/testdai.cpp $(HEADERS) $(LIB)/libdai$(LE)
303 $(CC) $(CCO)tests/testdai$(EE) tests/testdai.cpp $(LIBS) $(BOOSTLIBS)
304
305
306 # MATLAB INTERFACE
307 ###################
308
309 matlab/dai$(ME) : $(SRC)/matlab/dai.cpp $(HEADERS) matlab$(OE) $(LIB)/libdai$(LE)
310 $(MEX) -o matlab/dai $(SRC)/matlab/dai.cpp matlab$(OE) $(LIB)/libdai$(LE)
311
312 matlab/dai_readfg$(ME) : $(SRC)/matlab/dai_readfg.cpp $(HEADERS) factorgraph$(OE) matlab$(OE) exceptions$(OE)
313 $(MEX) -o matlab/dai_readfg $(SRC)/matlab/dai_readfg.cpp factorgraph$(OE) matlab$(OE) exceptions$(OE)
314
315 matlab/dai_writefg$(ME) : $(SRC)/matlab/dai_writefg.cpp $(HEADERS) factorgraph$(OE) matlab$(OE) exceptions$(OE)
316 $(MEX) -o matlab/dai_writefg $(SRC)/matlab/dai_writefg.cpp factorgraph$(OE) matlab$(OE) exceptions$(OE)
317
318 matlab/dai_potstrength$(ME) : $(SRC)/matlab/dai_potstrength.cpp $(HEADERS) matlab$(OE) exceptions$(OE)
319 $(MEX) -o matlab/dai_potstrength $(SRC)/matlab/dai_potstrength.cpp matlab$(OE) exceptions$(OE)
320
321 matlab$(OE) : $(SRC)/matlab/matlab.cpp $(INC)/matlab/matlab.h $(HEADERS)
322 $(MEX) -c $(SRC)/matlab/matlab.cpp
323
324
325 # UTILS
326 ########
327
328 utils/createfg$(EE) : utils/createfg.cpp $(HEADERS) $(LIB)/libdai$(LE)
329 $(CC) $(CCO)utils/createfg$(EE) utils/createfg.cpp $(LIBS) $(BOOSTLIBS)
330
331 utils/fg2dot$(EE) : utils/fg2dot.cpp $(HEADERS) $(LIB)/libdai$(LE)
332 $(CC) $(CCO)utils/fg2dot$(EE) utils/fg2dot.cpp $(LIBS)
333
334 utils/fginfo$(EE) : utils/fginfo.cpp $(HEADERS) $(LIB)/libdai$(LE)
335 $(CC) $(CCO)utils/fginfo$(EE) utils/fginfo.cpp $(LIBS)
336
337
338 # LIBRARY
339 ##########
340
341 ifneq ($(OS),WINDOWS)
342 $(LIB)/libdai$(LE) : bipgraph$(OE) daialg$(OE) alldai$(OE) clustergraph$(OE) factorgraph$(OE) properties$(OE) regiongraph$(OE) util$(OE) weightedgraph$(OE) exceptions$(OE) $(OBJECTS)
343 -mkdir -p lib
344 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)
345 else
346 $(LIB)/libdai$(LE) : bipgraph$(OE) daialg$(OE) alldai$(OE) clustergraph$(OE) factorgraph$(OE) properties$(OE) regiongraph$(OE) util$(OE) weightedgraph$(OE) exceptions$(OE) $(OBJECTS)
347 -mkdir lib
348 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)
349 endif
350
351
352 # REGRESSION TESTS
353 ###################
354
355 ifneq ($(OS),WINDOWS)
356 testregression : tests/testdai$(EE)
357 @echo Starting regression test...this can take a minute or so!
358 cd tests && ./testregression && cd ..
359 else
360 testregression : tests/testdai$(EE)
361 @echo Starting regression test...this can take a minute or so!
362 cd tests && testregression.bat && cd ..
363 endif
364
365
366 # DOCUMENTATION
367 ################
368
369 doc : $(INC)/*.h $(SRC)/*.cpp examples/*.cpp doxygen.conf
370 doxygen doxygen.conf
371
372 TAGS:
373 etags src/*.cpp include/dai/*.h tests/*.cpp utils/*.cpp
374 ctags src/*.cpp include/dai/*.h tests/*.cpp utils/*.cpp
375
376
377 # CLEAN
378 ########
379
380 ifneq ($(OS),WINDOWS)
381 .PHONY : clean
382 clean :
383 -rm *$(OE)
384 -rm matlab/*$(ME)
385 -rm examples/example$(EE) examples/example_bipgraph$(EE) examples/example_varset$(EE) examples/example_sprinkler$(EE)
386 -rm tests/testdai$(EE)
387 -rm utils/fg2dot$(EE) utils/createfg$(EE) utils/fginfo$(EE)
388 -rm -R doc
389 -rm -R lib
390 else
391 .PHONY : clean
392 clean :
393 -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)
394 endif