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