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