Release coccinelle-0.2.5-rc2
[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)/parsing_c
320 mkdir -p $(DESTDIR)$(MANDIR)/man1
321 $(INSTALL_DATA) standard.h $(DESTDIR)$(SHAREDIR)
322 $(INSTALL_DATA) standard.iso $(DESTDIR)$(SHAREDIR)
323 $(INSTALL_DATA) ocaml/coccilib.cmi $(DESTDIR)$(SHAREDIR)/ocaml/
324 $(INSTALL_DATA) parsing_c/*.cmi $(DESTDIR)$(SHAREDIR)/parsing_c/
325 $(INSTALL_DATA) commons/*.cmi $(DESTDIR)$(SHAREDIR)/commons/
326 $(INSTALL_DATA) docs/spatch.1 $(DESTDIR)$(MANDIR)/man1/
327 @if [ $(FEATURE_PYTHON) -eq 1 ]; then $(MAKE) install-python; fi
328
329 install-bash:
330 mkdir -p $(DESTDIR)$(BASH_COMPLETION_DIR)
331 $(INSTALL_DATA) scripts/spatch.bash_completion \
332 $(DESTDIR)$(BASH_COMPLETION_DIR)/spatch
333
334 install-tools:
335 mkdir -p $(DESTDIR)$(BINDIR)
336 $(INSTALL_PROGRAM) tools/splitpatch \
337 $(DESTDIR)$(BINDIR)/splitpatch
338 $(INSTALL_PROGRAM) tools/cocci-send-email.perl \
339 $(DESTDIR)$(BINDIR)/cocci-send-email.perl
340
341 install-python:
342 mkdir -p $(DESTDIR)$(SHAREDIR)/python/coccilib/coccigui
343 $(INSTALL_DATA) python/coccilib/*.py \
344 $(DESTDIR)$(SHAREDIR)/python/coccilib
345 $(INSTALL_DATA) python/coccilib/coccigui/*.py \
346 $(DESTDIR)$(SHAREDIR)/python/coccilib/coccigui
347 $(INSTALL_DATA) python/coccilib/coccigui/pygui.glade \
348 $(DESTDIR)$(SHAREDIR)/python/coccilib/coccigui
349 $(INSTALL_DATA) python/coccilib/coccigui/pygui.gladep \
350 $(DESTDIR)$(SHAREDIR)/python/coccilib/coccigui
351 if [ -f pycaml/dllpycaml_stubs.so ]; then \
352 $(INSTALL_LIB) pycaml/dllpycaml_stubs.so $(DESTDIR)$(LIBDIR) ; fi
353
354 install: install-common
355 @if test -x spatch -a ! -x spatch.opt ; then \
356 $(MAKE) install-byte;fi
357 @if test ! -x spatch -a -x spatch.opt ; then \
358 $(MAKE) install-def; $(MAKE) install-opt;fi
359 @if test -x spatch -a -x spatch.opt ; then \
360 $(MAKE) install-byte; $(MAKE) install-opt;fi
361 @if test ! -x spatch -a ! -x spatch.opt ; then \
362 echo "\n\n\t==> Run 'make', 'make opt', or both first. <==\n\n";fi
363 @echo ""
364 @echo "\tYou can also install spatch by copying the program spatch"
365 @echo "\t(available in this directory) anywhere you want and"
366 @echo "\tgive it the right options to find its configuration files."
367 @echo ""
368
369 # user will use spatch to run spatch.opt (native)
370 install-def:
371 $(INSTALL_PROGRAM) spatch.opt $(DESTDIR)$(SHAREDIR)
372 $(INSTALL_PROGRAM) scripts/spatch $(DESTDIR)$(BINDIR)/spatch
373
374 # user will use spatch to run spatch (bytecode)
375 install-byte:
376 $(INSTALL_PROGRAM) spatch $(DESTDIR)$(SHAREDIR)
377 $(INSTALL_PROGRAM) scripts/spatch.byte $(DESTDIR)$(BINDIR)/spatch
378
379 # user will use spatch.opt to run spatch.opt (native)
380 install-opt:
381 $(INSTALL_PROGRAM) spatch.opt $(DESTDIR)$(SHAREDIR)
382 $(INSTALL_PROGRAM) scripts/spatch.opt $(DESTDIR)$(BINDIR)/spatch.opt
383
384 uninstall:
385 rm -f $(DESTDIR)$(BINDIR)/spatch
386 rm -f $(DESTDIR)$(BINDIR)/spatch.opt
387 rm -f $(DESTDIR)$(LIBDIR)/dllpycaml_stubs.so
388 rm -f $(DESTDIR)$(SHAREDIR)/spatch
389 rm -f $(DESTDIR)$(SHAREDIR)/spatch.opt
390 rm -f $(DESTDIR)$(SHAREDIR)/standard.h
391 rm -f $(DESTDIR)$(SHAREDIR)/standard.iso
392 rm -f $(DESTDIR)$(SHAREDIR)/ocaml/coccilib.cmi
393 rm -f $(DESTDIR)$(SHAREDIR)/parsing_c/*.cmi
394 rm -f $(DESTDIR)$(SHAREDIR)/commons*.cmi
395 rm -f $(DESTDIR)$(SHAREDIR)/python/coccilib/coccigui/*
396 rm -f $(DESTDIR)$(SHAREDIR)/python/coccilib/*.py
397 rmdir --ignore-fail-on-non-empty -p \
398 $(DESTDIR)$(SHAREDIR)/python/coccilib/coccigui
399 rm -f $(DESTDIR)$(MANDIR)/man1/spatch.1
400
401 uninstall-bash:
402 rm -f $(DESTDIR)$(BASH_COMPLETION_DIR)/spatch
403 rmdir --ignore-fail-on-non-empty -p \
404 $(DESTDIR)$(BASH_COMPLETION_DIR)
405
406 uninstall-tools:
407 rm -f $(DESTDIR)$(BINDIR)/splitpatch
408 rm -f $(DESTDIR)$(BINDIR)/cocci-send-email.perl
409
410 version:
411 @echo "spatch $(VERSION)"
412 @echo "spatch $(PKGVERSION) ($(DISTRIB_ID))"
413 @echo "coccicheck $(CCVERSION)"
414
415
416 ##############################################################################
417 # Deb package (for Ubuntu) and release rules
418 ##############################################################################
419
420 include Makefile.release
421
422 ##############################################################################
423 # Developer rules
424 ##############################################################################
425
426 -include Makefile.dev
427
428 test: $(TARGET)
429 ./$(TARGET) -testall
430
431 testparsing:
432 ./$(TARGET) -D standard.h -parse_c -dir tests/
433
434
435
436 # -inline 0 to see all the functions in the profile.
437 # Can also use the profile framework in commons/ and run your program
438 # with -profile.
439 forprofiling:
440 $(MAKE) OPTFLAGS="-p -inline 0 " opt
441
442 clean::
443 rm -f gmon.out
444
445 tags:
446 otags -no-mli-tags -r .
447
448 dependencygraph:
449 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
450 ocamldot -lr /tmp/dependfull.depend > /tmp/dependfull.dot
451 dot -Tps /tmp/dependfull.dot > /tmp/dependfull.ps
452 ps2pdf /tmp/dependfull.ps /tmp/dependfull.pdf
453
454 ##############################################################################
455 # Misc rules
456 ##############################################################################
457
458 # each member of the project can have its own test.ml. this file is
459 # not under CVS.
460 test.ml:
461 echo "let foo_ctl () = failwith \"there is no foo_ctl formula\"" \
462 > test.ml
463
464 beforedepend:: test.ml
465
466
467 #INC=$(dir $(shell which ocaml))
468 #INCX=$(INC:/=)
469 #INCY=$(dir $(INCX))
470 #INCZ=$(INCY:/=)/lib/ocaml
471 #
472 #prim.o: prim.c
473 # gcc -c -o prim.o -I $(INCZ) prim.c
474
475
476 ##############################################################################
477 # Generic ocaml rules
478 ##############################################################################
479
480 .SUFFIXES: .ml .mli .cmo .cmi .cmx
481
482 .ml.cmo:
483 $(OCAMLC) -c $<
484 .mli.cmi:
485 $(OCAMLC) -c $<
486 .ml.cmx:
487 $(OCAMLOPT) -c $<
488
489 .ml.mldepend:
490 $(OCAMLC) -i $<
491
492 clean::
493 rm -f *.cm[iox] *.o *.annot
494 rm -f *~ .*~ *.exe #*#
495
496 distclean:: clean
497 set -e; for i in $(MAKESUBDIRS); do $(MAKE) -C $$i $@; done
498 rm -f .depend
499 rm -f Makefile.config
500 rm -f globals/config.ml
501 rm -f TAGS
502 rm -f tests/SCORE_actual.sexp
503 rm -f tests/SCORE_best_of_both.sexp
504 find -name ".#*1.*" | xargs rm -f
505
506 beforedepend::
507
508 depend:: beforedepend
509 $(OCAMLDEP) *.mli *.ml > .depend
510 set -e; for i in $(MAKESUBDIRS); do $(MAKE) -C $$i $@; done
511
512 .depend::
513 @if [ ! -f .depend ] ; then $(MAKE) depend ; fi
514
515 -include .depend