4073a1fe8dd6da467f7a317685a8c1fa38168c6b
[bpt/coccinelle.git] / commons / Makefile
1 ##############################################################################
2 # Variables
3 ##############################################################################
4
5 # The main library
6 -include ../Makefile.config
7
8 TARGET=commons
9
10 # note: if you add a file (a .mli or .ml), dont forget to redo a 'make depend'
11 MYSRC=common.ml common_extra.ml \
12 interfaces.ml objet.ml \
13 ocollection.ml \
14 seti.ml \
15 oset.ml oassoc.ml osequence.ml ograph.ml \
16 ocollection/oseti.ml ocollection/oseth.ml ocollection/osetb.ml ocollection/osetpt.ml \
17 ocollection/oassocb.ml ocollection/oassoch.ml ocollection/oassoc_buffer.ml ocollection/oassoc_cache.ml ocollection/oassocid.ml \
18 oarray.ml \
19 ocollection/ograph2way.ml ograph_extended.ml \
20 ofullcommon.ml \
21 glimpse.ml parser_combinators.ml
22
23 # src from other authors, got from the web or caml hump
24 SRC=ocamlextra/dumper.ml
25 SRC+=ocamlextra/ANSITerminal.ml
26 SRC+=ocamlextra/setb.ml ocamlextra/mapb.ml # defunctorized version of standard set/map
27 SRC+=ocamlextra/setPt.ml
28 SRC+=$(MYSRC)
29 SRC+=ocamlextra/enum.ml ocamlextra/dynArray.ml
30 SRC+=ocamlextra/suffix_tree.ml ocamlextra/suffix_tree_ext.ml
31
32 SYSLIBS=str.cma unix.cma
33
34 INCLUDEDIRS=ocamlextra ocollection
35 SUBDIRS=ocamlextra ocollection
36
37 #-----------------------------------------------------------------------------
38 # Other common (thin wrapper) libraries
39 #-----------------------------------------------------------------------------
40
41 #format: XXXSRC, XXXINCLUDE, XXXSYSLIBS
42
43 #gdbm
44 MYGDBMSRC=ocollection/oassocdbm.ml
45 GDBMSYSLIBS=dbm.cma
46
47 #berkeley db (ocamlbdb)
48 MYBDBSRC=ocollection/oassocbdb.ml ocollection/oassocbdb_string.ml
49 BDBINCLUDES=-I ../ocamlbdb
50 BDBSYSLIBS=bdb.cma
51
52
53 #lablgtk (ocamlgtk)
54 MYGUISRC=gui.ml
55 GUIINCLUDES=-I +lablgtk2 -I +lablgtksourceview -I ../ocamlgtk/src
56 GUISYSLIBS=lablgtk.cma lablgtksourceview.cma
57
58 #pycaml (ocamlpython)
59 MYPYSRC=python.ml
60 PYINCLUDES=-I ../ocamlpython -I ../../ocamlpython
61 PYSYSLIBS=python.cma
62
63 #ocamlmpi
64 MYMPISRC=distribution.ml
65 MPIINCLUDES=-I ../ocamlmpi -I ../../ocamlmpi -I +ocamlmpi
66 MPISYSLIBS=mpi.cma
67
68 #pcre
69 #REGEXPINCLUDES=-I +pcre
70 MYREGEXPSRC=regexp.ml
71 REGEXPINCLUDES=-I ../ocamlpcre/lib -I ../../ocamlpcre/lib
72
73 #sexplib
74 MYSEXPSRC=sexp_common.ml
75 SEXPINCLUDES=-I ../ocamlsexp -I ../ocamltarzan/lib-sexp -I ../../ocamltarzan/lib-sexp
76 #binprot
77 MYBINSRC=bin_common.ml
78 BININCLUDES=-I ../ocamltarzan/lib-binprot -I ../../ocamltarzan/lib-binprot
79
80 #-----------------------------------------------------------------------------
81 # Other stuff
82 #-----------------------------------------------------------------------------
83
84 #backtrace
85 MYBACKTRACESRC=backtrace.ml
86 BACKTRACEINCLUDES=-I $(shell ocamlc -where)
87
88
89 ##############################################################################
90 # Generic variables
91 ##############################################################################
92
93 INCLUDES=$(INCLUDEDIRS:%=-I %) $(INCLUDESEXTRA)
94
95 ##############################################################################
96 # Generic ocaml variables
97 ##############################################################################
98
99 # This flag can also be used in subdirectories so don't change its name here.
100 # For profiling use: -p -inline 0
101 OPTFLAGS=
102 #-thread
103
104 # The OPTBIN variable is here to allow to use ocamlc.opt instead of
105 # ocaml, when it is available, which speeds up compilation. So
106 # if you want the fast version of the ocaml chain tools, set this var
107 # or setenv it to ".opt" in your startup script.
108 #OPTBIN= #.opt
109
110 OCAMLCFLAGS ?= -g -dtypes
111
112 # The OCaml tools.
113 OCAMLC =ocamlc$(OPTBIN) $(OCAMLCFLAGS) $(INCLUDES)
114 OCAMLOPT=ocamlopt$(OPTBIN) $(OPTFLAGS) $(INCLUDES)
115 OCAMLLEX = ocamllex$(OPTBIN)
116 OCAMLYACC= ocamlyacc -v
117 OCAMLDEP = ocamldep$(OPTBIN) $(INCLUDES)
118 OCAMLMKTOP=ocamlmktop -g -custom $(INCLUDES)
119
120 # if need C code
121 OCAMLMKLIB=ocamlmklib
122 CC=gcc
123
124 ##############################################################################
125 # Top rules
126 ##############################################################################
127 LIB=$(TARGET).cma
128 OPTLIB=$(LIB:.cma=.cmxa)
129
130 OBJS = $(SRC:.ml=.cmo)
131 OPTOBJS = $(SRC:.ml=.cmx)
132
133
134 all: $(LIB)
135 all.opt: $(OPTLIB)
136 opt: all.opt
137 top: $(TARGET).top
138
139 $(LIB): $(OBJS)
140 $(OCAMLC) -a -o $@ $^
141
142 $(OPTLIB): $(OPTOBJS)
143 $(OCAMLOPT) -a -o $@ $^
144
145 $(TARGET).top: $(OBJS)
146 $(OCAMLMKTOP) -o $@ $(SYSLIBS) $^
147
148 clean::
149 rm -f $(TARGET).top
150
151 ##############################################################################
152 # Other commons libs target
153 ##############################################################################
154
155 all_libs: gdbm bdb gui mpi regexp backtrace
156
157 #-----------------------------------------------------------------------------
158 gdbm: commons_gdbm.cma
159 gdbm.opt: commons_gdbm.cmxa
160
161 commons_gdbm.cma: $(MYGDBMSRC:.ml=.cmo)
162 $(OCAMLC) -a -o $@ $^
163
164 commons_gdbm.cmxa: $(MYGDBMSRC:.ml=.cmx)
165 $(OCAMLOPT) -a -o $@ $^
166
167
168 #-----------------------------------------------------------------------------
169 bdb:
170 $(MAKE) INCLUDESEXTRA="$(BDBINCLUDES)" commons_bdb.cma
171 bdb.opt:
172 $(MAKE) INCLUDESEXTRA="$(BDBINCLUDES)" commons_bdb.cmxa
173
174 commons_bdb.cma: $(MYBDBSRC:.ml=.cmo)
175 $(OCAMLC) -a -o $@ $^
176
177 commons_bdb.cmxa: $(MYBDBSRC:.ml=.cmx)
178 $(OCAMLOPT) -a -o $@ $^
179
180
181
182 #-----------------------------------------------------------------------------
183 gui:
184 $(MAKE) INCLUDESEXTRA="$(GUIINCLUDES)" commons_gui.cma
185 gui.opt:
186 $(MAKE) INCLUDESEXTRA="$(GUIINCLUDES)" commons_gui.cmxa
187
188 commons_gui.cma: $(MYGUISRC:.ml=.cmo)
189 $(OCAMLC) -a -o $@ $^
190
191 commons_gui.cmxa: $(MYGUISRC:.ml=.cmx)
192 $(OCAMLOPT) -a -o $@ $^
193
194
195
196 #-----------------------------------------------------------------------------
197 mpi:
198 $(MAKE) INCLUDESEXTRA="$(MPIINCLUDES)" commons_mpi.cma
199 mpi.opt:
200 $(MAKE) INCLUDESEXTRA="$(MPIINCLUDES)" commons_mpi.cmxa
201
202 commons_mpi.cma: $(MYMPISRC:.ml=.cmo)
203 $(OCAMLC) -a -o $@ $^
204
205 commons_mpi.cmxa: $(MYMPISRC:.ml=.cmx)
206 $(OCAMLOPT) -a -o $@ $^
207
208 #alias
209 distribution: mpi
210 distribution.opt: mpi.opt
211
212
213
214 #-----------------------------------------------------------------------------
215 python:
216 $(MAKE) INCLUDESEXTRA="$(PYINCLUDES)" commons_python.cma
217 python.opt:
218 $(MAKE) INCLUDESEXTRA="$(PYINCLUDES)" commons_python.cmxa
219
220
221 commons_python.cma: $(MYPYSRC:.ml=.cmo)
222 $(OCAMLC) -a -o $@ $^
223
224 commons_python.cmxa: $(MYPYSRC:.ml=.cmx)
225 $(OCAMLOPT) -a -o $@ $^
226
227
228 #-----------------------------------------------------------------------------
229 regexp:
230 $(MAKE) INCLUDESEXTRA="$(REGEXPINCLUDES)" commons_regexp.cma
231 regexp.opt:
232 $(MAKE) INCLUDESEXTRA="$(REGEXPINCLUDES)" commons_regexp.cmxa
233
234 commons_regexp.cma: $(MYREGEXPSRC:.ml=.cmo)
235 $(OCAMLC) -a -o $@ $^
236
237 commons_regexp.cmxa: $(MYREGEXPSRC:.ml=.cmx)
238 $(OCAMLOPT) -a -o $@ $^
239
240
241 #-----------------------------------------------------------------------------
242 backtrace: commons_backtrace.cma
243 backtrace.opt: commons_backtrace.cmxa
244
245 backtrace_c.o: backtrace_c.c
246 $(CC) $(BACKTRACEINCLUDES) -c $^
247
248 commons_backtrace.cma: $(MYBACKTRACESRC:.ml=.cmo) backtrace_c.o
249 $(OCAMLMKLIB) -o commons_backtrace $^
250
251 commons_backtrace.cmxa: $(MYBACKTRACESRC:.ml=.cmx) backtrace_c.o
252 $(OCAMLMKLIB) -o commons_backtrace $^
253
254 clean::
255 rm -f dllcommons_backtrace.so
256
257
258
259 #-----------------------------------------------------------------------------
260 sexp:
261 $(MAKE) INCLUDESEXTRA="$(SEXPINCLUDES)" commons_sexp.cma
262 sexp.opt:
263 $(MAKE) INCLUDESEXTRA="$(SEXPINCLUDES)" commons_sexp.cmxa
264
265 commons_sexp.cma: $(MYSEXPSRC:.ml=.cmo)
266 $(OCAMLC) -a -o $@ $^
267
268 commons_sexp.cmxa: $(MYSEXPSRC:.ml=.cmx)
269 $(OCAMLOPT) -a -o $@ $^
270
271 binprot:
272 $(MAKE) INCLUDESEXTRA="$(BININCLUDES)" commons_bin.cma
273 binprot.opt:
274 $(MAKE) INCLUDESEXTRA="$(BININCLUDES)" commons_bin.cmxa
275
276 commons_bin.cma: $(MYBINSRC:.ml=.cmo)
277 $(OCAMLC) -a -o $@ $^
278
279 commons_bin.cmxa: $(MYBINSRC:.ml=.cmx)
280 $(OCAMLOPT) -a -o $@ $^
281
282 ##############################################################################
283 # The global "features" lib wrapper
284 ##############################################################################
285
286 features: commons_features.cma
287 features.opt: commons_features.cmxa
288
289 commons_features.cma: features.cmo
290 $(OCAMLC) -a -o $@ $^
291
292 commons_features.cmxa: features.cmx
293 $(OCAMLOPT) -a -o $@ $^
294
295
296 ##############################################################################
297 # Developer rules
298 ##############################################################################
299
300 tags:
301 otags -no-mli-tags -r .
302
303 clean::
304 rm -f gmon.out
305
306 forprofiling:
307 $(MAKE) OPTFLAGS="-p -inline 0 " opt
308
309 dependencygraph:
310 ocamldep *.mli *.ml > /tmp/dependfull.depend
311 ocamldot -fullgraph /tmp/dependfull.depend > /tmp/dependfull.dot
312 dot -Tps /tmp/dependfull.dot > /tmp/dependfull.ps
313
314 dependencygraph2:
315 find -name "*.ml" |grep -v "scripts" | xargs ocamldep -I commons -I globals -I ctl -I parsing_cocci -I parsing_c -I engine -I popl -I extra > /tmp/dependfull.depend
316 ocamldot -fullgraph /tmp/dependfull.depend > /tmp/dependfull.dot
317 dot -Tps /tmp/dependfull.dot > /tmp/dependfull.ps
318
319
320 ##############################################################################
321 # Generic rules
322 ##############################################################################
323 .SUFFIXES:
324 .SUFFIXES: .ml .mli .cmo .cmi .cmx
325
326 .ml.cmo:
327 $(OCAMLC) -c $<
328 .mli.cmi:
329 $(OCAMLC) -c $<
330 .ml.cmx:
331 $(OCAMLOPT) -c $<
332
333 clean::
334 rm -f *.cm[iox] *.o *.a *.cma *.cmxa *.annot
335 rm -f *~ .*~ #*#
336
337 clean::
338 for i in $(SUBDIRS); do (cd $$i; \
339 rm -f *.cm[iox] *.o *.a *.cma *.cmxa *.annot *~ .*~ ; \
340 cd ..; ) \
341 done
342
343 depend:
344 $(OCAMLDEP) *.mli *.ml > .depend
345 for i in $(SUBDIRS); do $(OCAMLDEP) $$i/*.ml $$i/*.mli >> .depend; done
346
347 distclean::
348 rm -f .depend
349
350 -include .depend