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