Release coccinelle-0.2.3rc1
[bpt/coccinelle.git] / Makefile
1 # Copyright 2005-2010, Ecole des Mines de Nantes, University of Copenhagen
2 # Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix
3 # This file is part of Coccinelle.
4 #
5 # Coccinelle is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, according to version 2 of the License.
8 #
9 # Coccinelle is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with Coccinelle. If not, see <http://www.gnu.org/licenses/>.
16 #
17 # The authors reserve the right to distribute this or future versions of
18 # Coccinelle under other licenses.
19
20
21
22 #############################################################################
23 # Configuration section
24 #############################################################################
25
26 -include Makefile.config
27 -include /etc/lsb-release
28
29 VERSION=$(shell cat globals/config.ml.in |grep version |perl -p -e 's/.*"(.*)".*/$$1/;')
30 CCVERSION=$(shell cat scripts/coccicheck/README |grep "Coccicheck version" |perl -p -e 's/.*version (.*)[ ]*/$$1/;')
31 PKGVERSION=$(shell dpkg-parsechangelog -ldebian/changelog.$(DISTRIB_CODENAME) 2> /dev/null \
32 | sed -n 's/^Version: \(.*\)/\1/p' )
33
34 ##############################################################################
35 # Variables
36 ##############################################################################
37 TARGET=spatch
38 PRJNAME=coccinelle
39
40 SRC=flag_cocci.ml cocci.ml testing.ml test.ml main.ml
41
42 ifeq ($(FEATURE_PYTHON),1)
43 PYCMA=pycaml/pycaml.cma
44 PYDIR=pycaml
45 PYLIB=dllpycaml_stubs.so
46 # the following is essential for Coccinelle to compile under gentoo (weird)
47 OPTLIBFLAGS=-cclib dllpycaml_stubs.so
48 else
49 PYCMA=
50 PYDIR=
51 PYLIB=
52 OPTLIBFLAGS=
53 endif
54
55 SEXPSYSCMA=bigarray.cma nums.cma
56
57 SYSLIBS=str.cma unix.cma $(SEXPSYSCMA)
58 LIBS=commons/commons.cma \
59 ocamlsexp/sexplib1.cma commons/commons_sexp.cma \
60 globals/globals.cma \
61 ctl/ctl.cma \
62 parsing_cocci/cocci_parser.cma parsing_c/parsing_c.cma \
63 engine/cocciengine.cma popl09/popl.cma \
64 extra/extra.cma $(PYCMA) python/coccipython.cma
65
66 #used for clean: and depend: and a little for rec & rec.opt
67 MAKESUBDIRS=commons ocamlsexp \
68 globals menhirlib $(PYDIR) ctl parsing_cocci parsing_c \
69 engine popl09 extra python
70 INCLUDEDIRS=commons commons/ocamlextra ocamlsexp \
71 globals menhirlib $(PYDIR) ctl \
72 parsing_cocci parsing_c engine popl09 extra python
73
74 ##############################################################################
75 # Generic variables
76 ##############################################################################
77
78 INCLUDES=$(INCLUDEDIRS:%=-I %)
79
80 OBJS= $(SRC:.ml=.cmo)
81 OPTOBJS= $(SRC:.ml=.cmx)
82
83 EXEC=$(TARGET)
84
85 ##############################################################################
86 # Generic ocaml variables
87 ##############################################################################
88
89 OCAMLCFLAGS=
90
91 # for profiling add -p -inline 0
92 # but 'make forprofiling' below does that for you.
93 # This flag is also used in subdirectories so don't change its name here.
94 # To enable backtrace support for native code, you need to put -g in OPTFLAGS
95 # to also link with -g, but even in 3.11 the backtrace support seems buggy so
96 # not worth it.
97 OPTFLAGS=
98 # the following is essential for Coccinelle to compile under gentoo
99 # but is now defined above in this file
100 #OPTLIBFLAGS=-cclib dllpycaml_stubs.so
101
102 OCAMLC=ocamlc$(OPTBIN) $(OCAMLCFLAGS) $(INCLUDES)
103 OCAMLOPT=ocamlopt$(OPTBIN) $(OPTFLAGS) $(INCLUDES)
104 OCAMLLEX=ocamllex #-ml # -ml for debugging lexer, but slightly slower
105 OCAMLYACC=ocamlyacc -v
106 OCAMLDEP=ocamldep $(INCLUDES)
107 OCAMLMKTOP=ocamlmktop -g -custom $(INCLUDES)
108
109 # can also be set via 'make static'
110 STATIC= #-ccopt -static
111
112 # can also be unset via 'make purebytecode'
113 BYTECODE_STATIC=-custom
114
115 ##############################################################################
116 # Top rules
117 ##############################################################################
118 .PHONY:: all all.opt byte opt top clean distclean configure
119 .PHONY:: $(MAKESUBDIRS) $(MAKESUBDIRS:%=%.opt) subdirs subdirs.opt
120
121 all: Makefile.config byte preinstall
122
123 opt: all.opt
124 all.opt: opt-compil preinstall
125
126 world: preinstall
127 $(MAKE) byte
128 $(MAKE) opt-compil
129
130 byte: .depend
131 $(MAKE) subdirs
132 $(MAKE) $(EXEC)
133
134 opt-compil: .depend
135 $(MAKE) subdirs.opt
136 $(MAKE) $(EXEC).opt
137
138 top: $(EXEC).top
139
140 subdirs:
141 $(MAKE) -C commons OCAMLCFLAGS="$(OCAMLCFLAGS)"
142 $(MAKE) -C ocamlsexp OCAMLCFLAGS="$(OCAMLCFLAGS)"
143 $(MAKE) -C commons sexp OCAMLCFLAGS="$(OCAMLCFLAGS)"
144 +for D in $(MAKESUBDIRS); do $(MAKE) $$D || exit 1 ; done
145
146 subdirs.opt:
147 $(MAKE) -C commons all.opt OCAMLCFLAGS="$(OCAMLCFLAGS)"
148 $(MAKE) -C ocamlsexp all.opt OCAMLCFLAGS="$(OCAMLCFLAGS)"
149 $(MAKE) -C commons sexp.opt OCAMLCFLAGS="$(OCAMLCFLAGS)"
150 +for D in $(MAKESUBDIRS); do $(MAKE) $$D.opt || exit 1 ; done
151
152 $(MAKESUBDIRS):
153 $(MAKE) -C $@ OCAMLCFLAGS="$(OCAMLCFLAGS)" all
154
155 $(MAKESUBDIRS:%=%.opt):
156 $(MAKE) -C $(@:%.opt=%) OCAMLCFLAGS="$(OCAMLCFLAGS)" all.opt
157
158 #dependencies:
159 # commons:
160 # globals:
161 # menhirlib:
162 # parsing_cocci: commons globals menhirlib
163 # parsing_c:parsing_cocci
164 # ctl:globals commons
165 # engine: parsing_cocci parsing_c ctl
166 # popl09:engine
167 # extra: parsing_cocci parsing_c ctl
168 # pycaml:
169 # python:pycaml parsing_cocci parsing_c
170
171 clean::
172 set -e; for i in $(MAKESUBDIRS); do $(MAKE) -C $$i $@; done
173 $(MAKE) -C demos/spp $@
174
175 $(LIBS): $(MAKESUBDIRS)
176 $(LIBS:.cma=.cmxa): $(MAKESUBDIRS:%=%.opt)
177
178 $(OBJS):$(LIBS)
179 $(OPTOBJS):$(LIBS:.cma=.cmxa)
180
181 $(EXEC): $(LIBS) $(OBJS)
182 $(OCAMLC) $(BYTECODE_STATIC) -o $@ $(SYSLIBS) $^
183
184 $(EXEC).opt: $(LIBS:.cma=.cmxa) $(OPTOBJS)
185 $(OCAMLOPT) $(STATIC) -o $@ $(SYSLIBS:.cma=.cmxa) $(OPTLIBFLAGS) $^
186
187 $(EXEC).top: $(LIBS) $(OBJS)
188 $(OCAMLMKTOP) -custom -o $@ $(SYSLIBS) $^
189
190 clean::
191 rm -f $(TARGET) $(TARGET).opt $(TARGET).top
192 rm -f dllpycaml_stubs.so
193
194 .PHONY:: tools configure
195
196 configure:
197 ./configure
198
199 Makefile.config:
200 @echo "Makefile.config is missing. Have you run ./configure?"
201 @exit 1
202
203 tools:
204 $(MAKE) -C tools
205
206 clean::
207 if [ -d tools ] ; then $(MAKE) -C tools clean ; fi
208
209 static:
210 rm -f spatch.opt spatch
211 $(MAKE) STATIC="-ccopt -static" spatch.opt
212 cp spatch.opt spatch
213
214 purebytecode:
215 rm -f spatch.opt spatch
216 $(MAKE) BYTECODE_STATIC="" spatch
217 perl -p -i -e 's/^#!.*/#!\/usr\/bin\/ocamlrun/' spatch
218
219
220 ##############################################################################
221 # Build documentation
222 ##############################################################################
223 .PHONY:: docs
224
225 docs:
226 make -C docs
227
228 clean::
229 make -C docs clean
230
231 distclean::
232 make -C docs distclean
233
234 ##############################################################################
235 # Pre-Install (customization of spatch frontend script)
236 ##############################################################################
237
238 preinstall: scripts/spatch scripts/spatch.opt scripts/spatch.byte
239
240 # user will use spatch to run spatch.opt (native)
241 scripts/spatch: Makefile.config
242 cp scripts/spatch.sh scripts/spatch.tmp2
243 sed "s|SHAREDIR|$(SHAREDIR)|g" scripts/spatch.tmp2 > scripts/spatch.tmp
244 sed "s|LIBDIR|$(LIBDIR)|g" scripts/spatch.tmp > scripts/spatch
245 rm -f scripts/spatch.tmp2 scripts/spatch.tmp
246
247 # user will use spatch to run spatch (bytecode)
248 scripts/spatch.byte: Makefile.config
249 cp scripts/spatch.sh scripts/spatch.byte.tmp3
250 sed "s|\.opt||" scripts/spatch.byte.tmp3 > scripts/spatch.byte.tmp2
251 sed "s|SHAREDIR|$(SHAREDIR)|g" scripts/spatch.byte.tmp2 \
252 > scripts/spatch.byte.tmp
253 sed "s|LIBDIR|$(LIBDIR)|g" scripts/spatch.byte.tmp \
254 > scripts/spatch.byte
255 rm -f scripts/spatch.byte.tmp3 \
256 scripts/spatch.byte.tmp2 \
257 scripts/spatch.byte.tmp
258
259 # user will use spatch.opt to run spatch.opt (native)
260 scripts/spatch.opt: Makefile.config
261 cp scripts/spatch.sh scripts/spatch.opt.tmp2
262 sed "s|SHAREDIR|$(SHAREDIR)|g" scripts/spatch.opt.tmp2 \
263 > scripts/spatch.opt.tmp
264 sed "s|LIBDIR|$(LIBDIR)|g" scripts/spatch.opt.tmp \
265 > scripts/spatch.opt
266 rm -f scripts/spatch.opt.tmp scripts/spatch.opt.tmp2
267
268 clean::
269 rm -f scripts/spatch scripts/spatch.byte scripts/spatch.opt
270
271 ##############################################################################
272 # Install
273 ##############################################################################
274
275 # don't remove DESTDIR, it can be set by package build system like ebuild
276 # for staged installation.
277 install-common:
278 mkdir -p $(DESTDIR)$(BINDIR)
279 mkdir -p $(DESTDIR)$(LIBDIR)
280 mkdir -p $(DESTDIR)$(SHAREDIR)
281 mkdir -p $(DESTDIR)$(MANDIR)/man1
282 $(INSTALL_DATA) standard.h $(DESTDIR)$(SHAREDIR)
283 $(INSTALL_DATA) standard.iso $(DESTDIR)$(SHAREDIR)
284 $(INSTALL_DATA) docs/spatch.1 $(DESTDIR)$(MANDIR)/man1/
285 @if [ $(FEATURE_PYTHON) -eq 1 ]; then $(MAKE) install-python; fi
286
287 install-python:
288 mkdir -p $(DESTDIR)$(SHAREDIR)/python/coccilib/coccigui
289 $(INSTALL_DATA) python/coccilib/*.py \
290 $(DESTDIR)$(SHAREDIR)/python/coccilib
291 $(INSTALL_DATA) python/coccilib/coccigui/*.py \
292 $(DESTDIR)$(SHAREDIR)/python/coccilib/coccigui
293 $(INSTALL_DATA) python/coccilib/coccigui/pygui.glade \
294 $(DESTDIR)$(SHAREDIR)/python/coccilib/coccigui
295 $(INSTALL_DATA) python/coccilib/coccigui/pygui.gladep \
296 $(DESTDIR)$(SHAREDIR)/python/coccilib/coccigui
297 $(INSTALL_LIB) dllpycaml_stubs.so $(DESTDIR)$(LIBDIR)
298
299 install: install-common
300 @if test -x spatch -a ! -x spatch.opt ; then \
301 $(MAKE) install-byte;fi
302 @if test ! -x spatch -a -x spatch.opt ; then \
303 $(MAKE) install-def; $(MAKE) install-opt;fi
304 @if test -x spatch -a -x spatch.opt ; then \
305 $(MAKE) install-byte; $(MAKE) install-opt;fi
306 @if test ! -x spatch -a ! -x spatch.opt ; then \
307 echo "\n\n\t==> Run 'make', 'make opt', or both first. <==\n\n";fi
308 @echo ""
309 @echo "\tYou can also install spatch by copying the program spatch"
310 @echo "\t(available in this directory) anywhere you want and"
311 @echo "\tgive it the right options to find its configuration files."
312 @echo ""
313
314 # user will use spatch to run spatch.opt (native)
315 install-def:
316 $(INSTALL_PROGRAM) spatch.opt $(DESTDIR)$(SHAREDIR)
317 $(INSTALL_PROGRAM) scripts/spatch $(DESTDIR)$(BINDIR)/spatch
318
319 # user will use spatch to run spatch (bytecode)
320 install-byte:
321 $(INSTALL_PROGRAM) spatch $(DESTDIR)$(SHAREDIR)
322 $(INSTALL_PROGRAM) scripts/spatch.byte $(DESTDIR)$(BINDIR)/spatch
323
324 # user will use spatch.opt to run spatch.opt (native)
325 install-opt:
326 $(INSTALL_PROGRAM) spatch.opt $(DESTDIR)$(SHAREDIR)
327 $(INSTALL_PROGRAM) scripts/spatch.opt $(DESTDIR)$(BINDIR)/spatch.opt
328
329 uninstall:
330 rm -f $(DESTDIR)$(BINDIR)/spatch
331 rm -f $(DESTDIR)$(BINDIR)/spatch.opt
332 rm -f $(DESTDIR)$(LIBDIR)/dllpycaml_stubs.so
333 rm -f $(DESTDIR)$(SHAREDIR)/standard.h
334 rm -f $(DESTDIR)$(SHAREDIR)/standard.iso
335 rm -rf $(DESTDIR)$(SHAREDIR)/python/coccilib
336 rm -f $(DESTDIR)$(MANDIR)/man1/spatch.1
337
338 version:
339 @echo "spatch $(VERSION)"
340 @echo "spatch $(PKGVERSION) ($(DISTRIB_ID))"
341 @echo "coccicheck $(CCVERSION)"
342
343
344 ##############################################################################
345 # Deb package (for Ubuntu) and release rules
346 ##############################################################################
347
348 include Makefile.release
349
350 ##############################################################################
351 # Developer rules
352 ##############################################################################
353
354 -include Makefile.dev
355
356 test: $(TARGET)
357 ./$(TARGET) -testall
358
359 testparsing:
360 ./$(TARGET) -D standard.h -parse_c -dir tests/
361
362
363
364 # -inline 0 to see all the functions in the profile.
365 # Can also use the profile framework in commons/ and run your program
366 # with -profile.
367 forprofiling:
368 $(MAKE) OPTFLAGS="-p -inline 0 " opt
369
370 clean::
371 rm -f gmon.out
372
373 tags:
374 otags -no-mli-tags -r .
375
376 dependencygraph:
377 find -name "*.ml" |grep -v "scripts" | xargs ocamldep -I commons -I globals -I ctl -I parsing_cocci -I parsing_c -I engine -I popl09 -I extra > /tmp/dependfull.depend
378 ocamldot -lr /tmp/dependfull.depend > /tmp/dependfull.dot
379 dot -Tps /tmp/dependfull.dot > /tmp/dependfull.ps
380 ps2pdf /tmp/dependfull.ps /tmp/dependfull.pdf
381
382 ##############################################################################
383 # Misc rules
384 ##############################################################################
385
386 # each member of the project can have its own test.ml. this file is
387 # not under CVS.
388 test.ml:
389 echo "let foo_ctl () = failwith \"there is no foo_ctl formula\"" \
390 > test.ml
391
392 beforedepend:: test.ml
393
394
395 #INC=$(dir $(shell which ocaml))
396 #INCX=$(INC:/=)
397 #INCY=$(dir $(INCX))
398 #INCZ=$(INCY:/=)/lib/ocaml
399 #
400 #prim.o: prim.c
401 # gcc -c -o prim.o -I $(INCZ) prim.c
402
403
404 ##############################################################################
405 # Generic ocaml rules
406 ##############################################################################
407
408 .SUFFIXES: .ml .mli .cmo .cmi .cmx
409
410 .ml.cmo:
411 $(OCAMLC) -c $<
412 .mli.cmi:
413 $(OCAMLC) -c $<
414 .ml.cmx:
415 $(OCAMLOPT) -c $<
416
417 .ml.mldepend:
418 $(OCAMLC) -i $<
419
420 clean::
421 rm -f *.cm[iox] *.o *.annot
422 rm -f *~ .*~ *.exe #*#
423
424 distclean:: clean
425 set -e; for i in $(MAKESUBDIRS); do $(MAKE) -C $$i $@; done
426 rm -f .depend
427 rm -f Makefile.config
428 rm -f python/pycocci.ml
429 rm -f python/pycocci_aux.ml
430 rm -f globals/config.ml
431 rm -f TAGS
432 rm -f tests/SCORE_actual.sexp
433 rm -f tests/SCORE_best_of_both.sexp
434 find -name ".#*1.*" | xargs rm -f
435
436 beforedepend::
437
438 depend:: beforedepend
439 $(OCAMLDEP) *.mli *.ml > .depend
440 set -e; for i in $(MAKESUBDIRS); do $(MAKE) -C $$i $@; done
441
442 .depend::
443 @if [ ! -f .depend ] ; then $(MAKE) depend ; fi
444
445 -include .depend