Miscellaneuos changes thanks to Dan Preston
[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
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)/libdai$(LE) 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)
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
220 # OBJECTS
221 ##########
222
223 bipgraph$(OE) : $(SRC)/bipgraph.cpp $(HEADERS)
224 $(CC) -c $(SRC)/bipgraph.cpp
225
226 daialg$(OE) : $(SRC)/daialg.cpp $(HEADERS)
227 $(CC) -c $(SRC)/daialg.cpp
228
229 exactinf$(OE) : $(SRC)/exactinf.cpp $(INC)/exactinf.h $(HEADERS)
230 $(CC) -c $(SRC)/exactinf.cpp
231
232 bp$(OE) : $(SRC)/bp.cpp $(INC)/bp.h $(HEADERS)
233 $(CC) -c $(SRC)/bp.cpp
234
235 lc$(OE) : $(SRC)/lc.cpp $(INC)/lc.h $(HEADERS)
236 $(CC) -c $(SRC)/lc.cpp
237
238 mf$(OE) : $(SRC)/mf.cpp $(INC)/mf.h $(HEADERS)
239 $(CC) -c $(SRC)/mf.cpp
240
241 factorgraph$(OE) : $(SRC)/factorgraph.cpp $(INC)/factorgraph.h $(HEADERS)
242 $(CC) -c $(SRC)/factorgraph.cpp
243
244 util$(OE) : $(SRC)/util.cpp $(INC)/util.h $(HEADERS)
245 $(CC) -c $(SRC)/util.cpp
246
247 regiongraph$(OE) : $(SRC)/regiongraph.cpp $(INC)/regiongraph.h $(HEADERS)
248 $(CC) -c $(SRC)/regiongraph.cpp
249
250 hak$(OE) : $(SRC)/hak.cpp $(INC)/hak.h $(HEADERS) $(INC)/regiongraph.h
251 $(CC) -c $(SRC)/hak.cpp
252
253 clustergraph$(OE) : $(SRC)/clustergraph.cpp $(INC)/clustergraph.h $(HEADERS)
254 $(CC) -c $(SRC)/clustergraph.cpp
255
256 jtree$(OE) : $(SRC)/jtree.cpp $(INC)/jtree.h $(HEADERS) $(INC)/weightedgraph.h $(INC)/clustergraph.h $(INC)/regiongraph.h
257 $(CC) -c $(SRC)/jtree.cpp
258
259 treeep$(OE) : $(SRC)/treeep.cpp $(INC)/treeep.h $(HEADERS) $(INC)/weightedgraph.h $(INC)/clustergraph.h $(INC)/regiongraph.h $(INC)/jtree.h
260 $(CC) -c $(SRC)/treeep.cpp
261
262 weightedgraph$(OE) : $(SRC)/weightedgraph.cpp $(INC)/weightedgraph.h $(HEADERS)
263 $(CC) -c $(SRC)/weightedgraph.cpp
264
265 mr$(OE) : $(SRC)/mr.cpp $(INC)/mr.h $(HEADERS)
266 $(CC) -c $(SRC)/mr.cpp
267
268 gibbs$(OE) : $(SRC)/gibbs.cpp $(INC)/gibbs.h $(HEADERS)
269 $(CC) -c $(SRC)/gibbs.cpp
270
271 properties$(OE) : $(SRC)/properties.cpp $(HEADERS)
272 $(CC) -c $(SRC)/properties.cpp
273
274 exceptions$(OE) : $(SRC)/exceptions.cpp $(HEADERS)
275 $(CC) -c $(SRC)/exceptions.cpp
276
277 alldai$(OE) : $(SRC)/alldai.cpp $(HEADERS)
278 $(CC) -c $(SRC)/alldai.cpp
279
280
281 # EXAMPLES
282 ###########
283
284 examples/example$(EE) : examples/example.cpp $(HEADERS) $(LIB)/libdai$(LE)
285 $(CC) $(CCO)examples/example$(EE) examples/example.cpp $(LIBS)
286
287 examples/example_bipgraph$(EE) : examples/example_bipgraph.cpp $(HEADERS) $(LIB)/libdai$(LE)
288 $(CC) $(CCO)examples/example_bipgraph$(EE) examples/example_bipgraph.cpp $(LIBS)
289
290 examples/example_varset$(EE) : examples/example_varset.cpp $(HEADERS) $(LIB)/libdai$(LE)
291 $(CC) $(CCO)examples/example_varset$(EE) examples/example_varset.cpp $(LIBS)
292
293
294 # TESTS
295 ########
296
297 tests/testdai$(EE) : tests/testdai.cpp $(HEADERS) $(LIB)/libdai$(LE)
298 $(CC) $(CCO)tests/testdai$(EE) tests/testdai.cpp $(LIBS) $(BOOSTLIBS)
299
300
301 # MATLAB INTERFACE
302 ###################
303
304 matlab/dai$(ME) : $(SRC)/matlab/dai.cpp $(HEADERS) matlab$(OE) $(LIB)/libdai$(LE)
305 $(MEX) -o matlab/dai $(SRC)/matlab/dai.cpp matlab$(OE) $(LIB)/libdai$(LE)
306
307 matlab/dai_readfg$(ME) : $(SRC)/matlab/dai_readfg.cpp $(HEADERS) factorgraph$(OE) matlab$(OE) exceptions$(OE)
308 $(MEX) -o matlab/dai_readfg $(SRC)/matlab/dai_readfg.cpp factorgraph$(OE) matlab$(OE) exceptions$(OE)
309
310 matlab/dai_writefg$(ME) : $(SRC)/matlab/dai_writefg.cpp $(HEADERS) factorgraph$(OE) matlab$(OE) exceptions$(OE)
311 $(MEX) -o matlab/dai_writefg $(SRC)/matlab/dai_writefg.cpp factorgraph$(OE) matlab$(OE) exceptions$(OE)
312
313 matlab/dai_potstrength$(ME) : $(SRC)/matlab/dai_potstrength.cpp $(HEADERS) matlab$(OE) exceptions$(OE)
314 $(MEX) -o matlab/dai_potstrength $(SRC)/matlab/dai_potstrength.cpp matlab$(OE) exceptions$(OE)
315
316 matlab$(OE) : $(SRC)/matlab/matlab.cpp $(INC)/matlab/matlab.h $(HEADERS)
317 $(MEX) -c $(SRC)/matlab/matlab.cpp
318
319
320 # UTILS
321 ########
322
323 utils/createfg$(EE) : utils/createfg.cpp $(HEADERS) $(LIB)/libdai$(LE)
324 $(CC) $(CCO)utils/createfg$(EE) utils/createfg.cpp $(LIBS) $(BOOSTLIBS)
325
326 utils/fg2dot$(EE) : utils/fg2dot.cpp $(HEADERS) $(LIB)/libdai$(LE)
327 $(CC) $(CCO)utils/fg2dot$(EE) utils/fg2dot.cpp $(LIBS)
328
329 utils/fginfo$(EE) : utils/fginfo.cpp $(HEADERS) $(LIB)/libdai$(LE)
330 $(CC) $(CCO)utils/fginfo$(EE) utils/fginfo.cpp $(LIBS)
331
332
333 # LIBRARY
334 ##########
335
336 ifneq ($(OS),WINDOWS)
337 $(LIB)/libdai$(LE) : bipgraph$(OE) daialg$(OE) alldai$(OE) clustergraph$(OE) factorgraph$(OE) properties$(OE) regiongraph$(OE) util$(OE) weightedgraph$(OE) exceptions$(OE) $(OBJECTS)
338 -mkdir -p lib
339 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)
340 else
341 $(LIB)/libdai$(LE) : bipgraph$(OE) daialg$(OE) alldai$(OE) clustergraph$(OE) factorgraph$(OE) properties$(OE) regiongraph$(OE) util$(OE) weightedgraph$(OE) exceptions$(OE) $(OBJECTS)
342 -mkdir lib
343 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)
344 endif
345
346
347 # REGRESSION TESTS
348 ###################
349
350 ifneq ($(OS),WINDOWS)
351 testregression : tests/testdai$(EE)
352 @echo Starting regression test...this can take a minute or so!
353 cd tests && ./testregression && cd ..
354 else
355 testregression : tests/testdai$(EE)
356 @echo Starting regression test...this can take a minute or so!
357 cd tests && testregression.bat && cd ..
358 endif
359
360
361 # DOCUMENTATION
362 ################
363
364 doc : $(INC)/*.h $(SRC)/*.cpp examples/*.cpp doxygen.conf
365 doxygen doxygen.conf
366
367
368 # CLEAN
369 ########
370
371 ifneq ($(OS),WINDOWS)
372 .PHONY : clean
373 clean :
374 -rm *$(OE)
375 -rm matlab/*$(ME)
376 -rm examples/example$(EE) examples/example_bipgraph$(EE) examples/example_varset$(EE)
377 -rm tests/testdai$(EE)
378 -rm utils/fg2dot$(EE) utils/createfg$(EE) utils/fginfo$(EE)
379 -rm -R doc
380 -rm -R lib
381 else
382 .PHONY : clean
383 clean :
384 -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)
385 endif