Small misc changes
[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 DEBUG = true
30 NEW_MATLAB = true
31 WITH_MATLAB =
32
33 # Directories
34 INC = include/dai
35 SRC = src
36 LIB = lib
37
38 # We use the BOOST Program Options library
39 BOOSTFLAGS = -lboost_program_options
40
41 # Compile using GNU C++ Compiler
42 CC = g++
43
44 # Flags for the C++ compiler
45 CCFLAGS = -Wall -W -Wextra -fpic -I./include -Llib -O3 #-pg #-static -DVERBOSE
46 ifdef DEBUG
47 CCFLAGS := $(CCFLAGS) -g -DDAI_DEBUG
48 else
49 CCFLAGS := $(CCFLAGS)
50 endif
51
52 ifdef WITH_BP
53 CCFLAGS := $(CCFLAGS) -DWITH_BP
54 OBJECTS := $(OBJECTS) bp.o
55 endif
56 ifdef WITH_MF
57 CCFLAGS := $(CCFLAGS) -DWITH_MF
58 OBJECTS := $(OBJECTS) mf.o
59 endif
60 ifdef WITH_HAK
61 CCFLAGS := $(CCFLAGS) -DWITH_HAK
62 OBJECTS := $(OBJECTS) hak.o
63 endif
64 ifdef WITH_LC
65 CCFLAGS := $(CCFLAGS) -DWITH_LC
66 OBJECTS := $(OBJECTS) lc.o
67 endif
68 ifdef WITH_TREEEP
69 CCFLAGS := $(CCFLAGS) -DWITH_TREEEP
70 OBJECTS := $(OBJECTS) treeep.o
71 endif
72 ifdef WITH_JTREE
73 CCFLAGS := $(CCFLAGS) -DWITH_JTREE
74 OBJECTS := $(OBJECTS) jtree.o
75 endif
76 ifdef WITH_MR
77 CCFLAGS := $(CCFLAGS) -DWITH_MR
78 OBJECTS := $(OBJECTS) mr.o
79 endif
80
81 ifdef WITH_MATLAB
82 # Replace the following by the directory where Matlab has been installed
83 MATLABDIR = /opt/matlab/bin
84 # Replace the following with the extension of compiled MEX files on this platform, e.g. .mexglx for x86
85 MEXEXT = .mexglx
86 MEX = $(MATLABDIR)/mex
87 MEXFLAGS = -I.
88 ifdef DEBUG
89 MEXFLAGS := $(MEXFLAGS) -g -DDAI_DEBUG
90 endif
91 ifdef NEW_MATLAB
92 MEXFLAGS := $(MEXFLAGS) -largeArrayDims
93 else
94 MEXFLAGS := $(MEXFLAGS) -DSMALLMEM
95 endif
96 endif
97
98 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
99
100 TARGETS = tests utils $(LIB)/libdai.a example testregression doc
101 ifdef WITH_MATLAB
102 TARGETS := $(TARGETS) matlabs
103 endif
104 all : $(TARGETS)
105 echo -e "\a"
106
107 matlabs : matlab/dai.$(MEXEXT) matlab/dai_readfg.$(MEXEXT) matlab/dai_writefg.$(MEXEXT) matlab/dai_removeshortloops.$(MEXEXT) matlab/dai_potstrength.$(MEXEXT)
108
109 $(LIB)/libdai.a : daialg.o alldai.o clustergraph.o factorgraph.o properties.o regiongraph.o util.o weightedgraph.o x2x.o $(OBJECTS)
110 ar rcs $(LIB)/libdai.a daialg.o alldai.o clustergraph.o factorgraph.o properties.o regiongraph.o util.o weightedgraph.o x2x.o $(OBJECTS)
111
112 tests : tests/test
113
114 utils : utils/createfg utils/fg2dot utils/remove_short_loops utils/fginfo
115
116 testregression : tests/test
117 echo Testing...this can take a while...
118 cd tests; time ./testregression; cd ..
119
120 doc : $(INC)/*.h $(SRC)/*.cpp doxygen.conf
121 doxygen doxygen.conf
122
123 clean :
124 rm *.o example matlab/*.$(MEXEXT) matlab/*.o tests/test utils/fg2dot utils/createfg utils/remove_short_loops utils/fginfo $(LIB)/libdai.a; echo
125 rm -R doc; echo
126
127
128 daialg.o : $(SRC)/daialg.cpp $(HEADERS)
129 $(CC) $(CCFLAGS) -c $(SRC)/daialg.cpp
130
131 bp.o : $(SRC)/bp.cpp $(INC)/bp.h $(HEADERS)
132 $(CC) $(CCFLAGS) -c $(SRC)/bp.cpp
133
134 lc.o : $(SRC)/lc.cpp $(INC)/lc.h $(HEADERS)
135 $(CC) $(CCFLAGS) -c $(SRC)/lc.cpp
136
137 mf.o : $(SRC)/mf.cpp $(INC)/mf.h $(HEADERS)
138 $(CC) $(CCFLAGS) -c $(SRC)/mf.cpp
139
140 factorgraph.o : $(SRC)/factorgraph.cpp $(INC)/factorgraph.h $(HEADERS)
141 $(CC) $(CCFLAGS) -c $(SRC)/factorgraph.cpp
142
143 util.o : $(SRC)/util.cpp $(INC)/util.h $(HEADERS)
144 $(CC) $(CCFLAGS) -c $(SRC)/util.cpp
145
146 regiongraph.o : $(SRC)/regiongraph.cpp $(INC)/regiongraph.h $(HEADERS)
147 $(CC) $(CCFLAGS) -c $(SRC)/regiongraph.cpp
148
149 hak.o : $(SRC)/hak.cpp $(INC)/hak.h $(HEADERS) $(INC)/regiongraph.h
150 $(CC) $(CCFLAGS) -c $(SRC)/hak.cpp
151
152 clustergraph.o : $(SRC)/clustergraph.cpp $(INC)/clustergraph.h $(HEADERS)
153 $(CC) $(CCFLAGS) -c $(SRC)/clustergraph.cpp
154
155 jtree.o : $(SRC)/jtree.cpp $(INC)/jtree.h $(HEADERS) $(INC)/weightedgraph.h $(INC)/clustergraph.h $(INC)/regiongraph.h
156 $(CC) $(CCFLAGS) -c $(SRC)/jtree.cpp
157
158 treeep.o : $(SRC)/treeep.cpp $(INC)/treeep.h $(HEADERS) $(INC)/weightedgraph.h $(INC)/clustergraph.h $(INC)/regiongraph.h $(INC)/jtree.h
159 $(CC) $(CCFLAGS) -c $(SRC)/treeep.cpp
160
161 weightedgraph.o : $(SRC)/weightedgraph.cpp $(INC)/weightedgraph.h $(HEADERS)
162 $(CC) $(CCFLAGS) -c $(SRC)/weightedgraph.cpp
163
164 mr.o : $(SRC)/mr.cpp $(INC)/mr.h $(HEADERS)
165 $(CC) $(CCFLAGS) -c $(SRC)/mr.cpp
166
167 properties.o : $(SRC)/properties.cpp $(HEADERS)
168 $(CC) $(CCFLAGS) -c $(SRC)/properties.cpp
169
170 alldai.o : $(SRC)/alldai.cpp $(HEADERS)
171 $(CC) $(CCFLAGS) -c $(SRC)/alldai.cpp
172
173 x2x.o : $(SRC)/x2x.cpp $(HEADERS)
174 $(CC) $(CCFLAGS) -c $(SRC)/x2x.cpp
175
176 # EXAMPLE
177 ##########
178
179 example : example.cpp $(HEADERS) $(LIB)/libdai.a
180 $(CC) $(CCFLAGS) -o example example.cpp -ldai
181
182 # TESTS
183 ########
184
185 tests/test : tests/test.cpp $(HEADERS) $(LIB)/libdai.a
186 $(CC) $(CCFLAGS) -o tests/test tests/test.cpp -ldai $(BOOSTFLAGS)
187
188
189 # MATLAB INTERFACE
190 ###################
191
192 matlab/dai.$(MEXEXT) : matlab/dai.cpp $(HEADERS) matlab/matlab.o $(LIB)/libdai.a
193 $(MEX) $(MEXFLAGS) -o matlab/dai matlab/dai.cpp matlab/matlab.o $(LIB)/libdai.a
194
195 matlab/dai_readfg.$(MEXEXT) : matlab/dai_readfg.cpp $(HEADERS) factorgraph.o matlab/matlab.o
196 $(MEX) $(MEXFLAGS) -o matlab/dai_readfg matlab/dai_readfg.cpp factorgraph.o matlab/matlab.o
197
198 matlab/dai_writefg.$(MEXEXT) : matlab/dai_writefg.cpp $(HEADERS) factorgraph.o matlab/matlab.o
199 $(MEX) $(MEXFLAGS) -o matlab/dai_writefg matlab/dai_writefg.cpp factorgraph.o matlab/matlab.o
200
201 matlab/dai_removeshortloops.$(MEXEXT) : matlab/dai_removeshortloops.cpp $(HEADERS) factorgraph.o matlab/matlab.o
202 $(MEX) $(MEXFLAGS) -o matlab/dai_removeshortloops matlab/dai_removeshortloops.cpp factorgraph.o matlab/matlab.o
203
204 matlab/dai_potstrength.$(MEXEXT) : matlab/dai_potstrength.cpp $(HEADERS) matlab/matlab.o
205 $(MEX) $(MEXFLAGS) -o matlab/dai_potstrength matlab/dai_potstrength.cpp matlab/matlab.o
206
207 matlab/matlab.o : matlab/matlab.cpp matlab/matlab.h $(HEADERS)
208 $(MEX) $(MEXFLAGS) -outdir matlab -c matlab/matlab.cpp
209
210
211 # UTILS
212 ########
213
214 utils/createfg : utils/createfg.cpp $(HEADERS) factorgraph.o weightedgraph.o util.o
215 $(CC) $(CCFLAGS) -o utils/createfg utils/createfg.cpp factorgraph.o weightedgraph.o util.o $(BOOSTFLAGS)
216
217 utils/fg2dot : utils/fg2dot.cpp $(HEADERS) factorgraph.o
218 $(CC) $(CCFLAGS) -o utils/fg2dot utils/fg2dot.cpp factorgraph.o
219
220 utils/remove_short_loops : utils/remove_short_loops.cpp $(HEADERS) factorgraph.o
221 $(CC) $(CCFLAGS) -o utils/remove_short_loops utils/remove_short_loops.cpp factorgraph.o
222
223 utils/fginfo : utils/fginfo.cpp $(HEADERS) factorgraph.o
224 $(CC) $(CCFLAGS) -o utils/fginfo utils/fginfo.cpp factorgraph.o