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