Removed remove_short_loops functionality.
[libdai.git] / Makefile
1 # Copyright (C) 2006-2008 Joris Mooij [j dot mooij at science dot ru dot nl]
2 # Radboud University Nijmegen, The Netherlands
3 #
4 # This file is part of libDAI.
5 #
6 # libDAI is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10 #
11 # libDAI is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with libDAI; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
20
21 # Enable/disable various approximate inference methods
22 WITH_BP = true
23 WITH_MF = true
24 WITH_HAK = true
25 WITH_LC = true
26 WITH_TREEEP = true
27 WITH_JTREE = true
28 WITH_MR = true
29 # Build with debug info?
30 DEBUG = true
31 # Build matlab interface?
32 WITH_MATLAB =
33 # New/old matlab version?
34 NEW_MATLAB = true
35 # Windows or linux (default)?
36 WINDOWS =
37
38 # Directories
39 INC = include/dai
40 SRC = src
41 LIB = lib
42
43 # We use the BOOST Program Options library
44 BOOSTFLAGS = -lboost_program_options
45
46 # Compile using GNU C++ Compiler
47 CC = g++
48
49 # Flags for the C++ compiler
50 CCFLAGS = -Wall -W -Wextra -fpic -I./include -Llib -O3 #-pg #-static #-DVERBOSE
51 ifdef DEBUG
52 CCFLAGS := $(CCFLAGS) -g -DDAI_DEBUG
53 else
54 CCFLAGS := $(CCFLAGS)
55 endif
56
57 ifdef WITH_BP
58 CCFLAGS := $(CCFLAGS) -DWITH_BP
59 OBJECTS := $(OBJECTS) bp.o
60 endif
61 ifdef WITH_MF
62 CCFLAGS := $(CCFLAGS) -DWITH_MF
63 OBJECTS := $(OBJECTS) mf.o
64 endif
65 ifdef WITH_HAK
66 CCFLAGS := $(CCFLAGS) -DWITH_HAK
67 OBJECTS := $(OBJECTS) hak.o
68 endif
69 ifdef WITH_LC
70 CCFLAGS := $(CCFLAGS) -DWITH_LC
71 OBJECTS := $(OBJECTS) lc.o
72 endif
73 ifdef WITH_TREEEP
74 CCFLAGS := $(CCFLAGS) -DWITH_TREEEP
75 OBJECTS := $(OBJECTS) treeep.o
76 endif
77 ifdef WITH_JTREE
78 CCFLAGS := $(CCFLAGS) -DWITH_JTREE
79 OBJECTS := $(OBJECTS) jtree.o
80 endif
81 ifdef WITH_MR
82 CCFLAGS := $(CCFLAGS) -DWITH_MR
83 OBJECTS := $(OBJECTS) mr.o
84 endif
85
86 ifdef WITH_MATLAB
87 # Replace the following by the directory where Matlab has been installed
88 MATLABDIR = /opt/matlab/bin
89 # Replace the following with the extension of compiled MEX files on this platform, e.g. .mexglx for x86
90 MEXEXT = .mexglx
91 MEX = $(MATLABDIR)/mex
92 MEXFLAGS = -I.
93 ifdef DEBUG
94 MEXFLAGS := $(MEXFLAGS) -g -DDAI_DEBUG
95 endif
96 ifdef NEW_MATLAB
97 MEXFLAGS := $(MEXFLAGS) -largeArrayDims
98 else
99 MEXFLAGS := $(MEXFLAGS) -DSMALLMEM
100 endif
101 endif
102
103 HEADERS = $(INC)/bipgraph.h $(INC)/diffs.h $(INC)/index.h $(INC)/var.h $(INC)/factor.h $(INC)/varset.h $(INC)/prob.h $(INC)/daialg.h $(INC)/properties.h $(INC)/alldai.h $(INC)/enum.h $(INC)/x2x.h $(INC)/exceptions.h
104
105 TARGETS = tests utils $(LIB)/libdai.a example testregression doc
106 ifdef WITH_MATLAB
107 TARGETS := $(TARGETS) matlabs
108 endif
109 all : $(TARGETS)
110 echo -e "\a"
111
112 matlabs : matlab/dai.$(MEXEXT) matlab/dai_readfg.$(MEXEXT) matlab/dai_writefg.$(MEXEXT) matlab/dai_potstrength.$(MEXEXT)
113
114 $(LIB)/libdai.a : bipgraph.o daialg.o alldai.o clustergraph.o factorgraph.o properties.o regiongraph.o util.o weightedgraph.o x2x.o exceptions.o $(OBJECTS)
115 ar rcs $(LIB)/libdai.a bipgraph.o daialg.o alldai.o clustergraph.o factorgraph.o properties.o regiongraph.o util.o weightedgraph.o x2x.o exceptions.o $(OBJECTS)
116
117 tests : tests/test
118
119 utils : utils/createfg utils/fg2dot utils/fginfo
120
121 testregression : tests/test
122 echo Testing...this can take a while...
123 cd tests; time ./testregression; cd ..
124
125 doc : $(INC)/*.h $(SRC)/*.cpp doxygen.conf
126 doxygen doxygen.conf
127
128 clean :
129 rm *.o example matlab/*.$(MEXEXT) matlab/*.o tests/test utils/fg2dot utils/createfg utils/fginfo $(LIB)/libdai.a; echo
130 rm -R doc; echo
131
132 bipgraph.o : $(SRC)/bipgraph.cpp $(HEADERS)
133 $(CC) $(CCFLAGS) -c $(SRC)/bipgraph.cpp
134
135 daialg.o : $(SRC)/daialg.cpp $(HEADERS)
136 $(CC) $(CCFLAGS) -c $(SRC)/daialg.cpp
137
138 bp.o : $(SRC)/bp.cpp $(INC)/bp.h $(HEADERS)
139 $(CC) $(CCFLAGS) -c $(SRC)/bp.cpp
140
141 lc.o : $(SRC)/lc.cpp $(INC)/lc.h $(HEADERS)
142 $(CC) $(CCFLAGS) -c $(SRC)/lc.cpp
143
144 mf.o : $(SRC)/mf.cpp $(INC)/mf.h $(HEADERS)
145 $(CC) $(CCFLAGS) -c $(SRC)/mf.cpp
146
147 factorgraph.o : $(SRC)/factorgraph.cpp $(INC)/factorgraph.h $(HEADERS)
148 $(CC) $(CCFLAGS) -c $(SRC)/factorgraph.cpp
149
150 util.o : $(SRC)/util.cpp $(INC)/util.h $(HEADERS)
151 $(CC) $(CCFLAGS) -c $(SRC)/util.cpp
152
153 regiongraph.o : $(SRC)/regiongraph.cpp $(INC)/regiongraph.h $(HEADERS)
154 $(CC) $(CCFLAGS) -c $(SRC)/regiongraph.cpp
155
156 hak.o : $(SRC)/hak.cpp $(INC)/hak.h $(HEADERS) $(INC)/regiongraph.h
157 $(CC) $(CCFLAGS) -c $(SRC)/hak.cpp
158
159 clustergraph.o : $(SRC)/clustergraph.cpp $(INC)/clustergraph.h $(HEADERS)
160 $(CC) $(CCFLAGS) -c $(SRC)/clustergraph.cpp
161
162 jtree.o : $(SRC)/jtree.cpp $(INC)/jtree.h $(HEADERS) $(INC)/weightedgraph.h $(INC)/clustergraph.h $(INC)/regiongraph.h
163 $(CC) $(CCFLAGS) -c $(SRC)/jtree.cpp
164
165 treeep.o : $(SRC)/treeep.cpp $(INC)/treeep.h $(HEADERS) $(INC)/weightedgraph.h $(INC)/clustergraph.h $(INC)/regiongraph.h $(INC)/jtree.h
166 $(CC) $(CCFLAGS) -c $(SRC)/treeep.cpp
167
168 weightedgraph.o : $(SRC)/weightedgraph.cpp $(INC)/weightedgraph.h $(HEADERS)
169 $(CC) $(CCFLAGS) -c $(SRC)/weightedgraph.cpp
170
171 mr.o : $(SRC)/mr.cpp $(INC)/mr.h $(HEADERS)
172 $(CC) $(CCFLAGS) -c $(SRC)/mr.cpp
173
174 properties.o : $(SRC)/properties.cpp $(HEADERS)
175 $(CC) $(CCFLAGS) -c $(SRC)/properties.cpp
176
177 exceptions.o: $(SRC)/exceptions.cpp $(HEADERS)
178 $(CC) $(CCFLAGS) -c $(SRC)/exceptions.cpp
179
180 alldai.o : $(SRC)/alldai.cpp $(HEADERS)
181 $(CC) $(CCFLAGS) -c $(SRC)/alldai.cpp
182
183 x2x.o : $(SRC)/x2x.cpp $(HEADERS)
184 $(CC) $(CCFLAGS) -c $(SRC)/x2x.cpp
185
186 # EXAMPLE
187 ##########
188
189 example : example.cpp $(HEADERS) $(LIB)/libdai.a
190 $(CC) $(CCFLAGS) -o example example.cpp -ldai
191
192 # TESTS
193 ########
194
195 tests/test : tests/test.cpp $(HEADERS) $(LIB)/libdai.a
196 $(CC) $(CCFLAGS) -o tests/test tests/test.cpp -ldai $(BOOSTFLAGS)
197
198
199 # MATLAB INTERFACE
200 ###################
201
202 matlab/dai.$(MEXEXT) : matlab/dai.cpp $(HEADERS) matlab/matlab.o $(LIB)/libdai.a
203 $(MEX) $(MEXFLAGS) -o matlab/dai matlab/dai.cpp matlab/matlab.o $(LIB)/libdai.a
204
205 matlab/dai_readfg.$(MEXEXT) : matlab/dai_readfg.cpp $(HEADERS) factorgraph.o matlab/matlab.o
206 $(MEX) $(MEXFLAGS) -o matlab/dai_readfg matlab/dai_readfg.cpp factorgraph.o matlab/matlab.o
207
208 matlab/dai_writefg.$(MEXEXT) : matlab/dai_writefg.cpp $(HEADERS) factorgraph.o matlab/matlab.o
209 $(MEX) $(MEXFLAGS) -o matlab/dai_writefg matlab/dai_writefg.cpp factorgraph.o matlab/matlab.o
210
211 matlab/dai_potstrength.$(MEXEXT) : matlab/dai_potstrength.cpp $(HEADERS) matlab/matlab.o
212 $(MEX) $(MEXFLAGS) -o matlab/dai_potstrength matlab/dai_potstrength.cpp matlab/matlab.o
213
214 matlab/matlab.o : matlab/matlab.cpp matlab/matlab.h $(HEADERS)
215 $(MEX) $(MEXFLAGS) -outdir matlab -c matlab/matlab.cpp
216
217
218 # UTILS
219 ########
220
221 utils/createfg : utils/createfg.cpp $(HEADERS) factorgraph.o weightedgraph.o util.o bipgraph.o exceptions.o
222 $(CC) $(CCFLAGS) -o utils/createfg utils/createfg.cpp factorgraph.o weightedgraph.o util.o bipgraph.o exceptions.o $(BOOSTFLAGS)
223
224 utils/fg2dot : utils/fg2dot.cpp $(HEADERS) factorgraph.o exceptions.o
225 $(CC) $(CCFLAGS) -o utils/fg2dot utils/fg2dot.cpp factorgraph.o exceptions.o
226
227 utils/fginfo : utils/fginfo.cpp $(HEADERS) factorgraph.o bipgraph.o exceptions.o
228 $(CC) $(CCFLAGS) -o utils/fginfo utils/fginfo.cpp factorgraph.o bipgraph.o exceptions.o