052ff9fde130e5095765811475d812a4a5515b38
[bpt/coccinelle.git] / Makefile
1 # Copyright 2012, INRIA
2 # Julia Lawall, Gilles Muller
3 # Copyright 2010-2011, INRIA, University of Copenhagen
4 # Julia Lawall, Rene Rydhof Hansen, Gilles Muller, Nicolas Palix
5 # Copyright 2005-2009, Ecole des Mines de Nantes, University of Copenhagen
6 # Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix
7 # This file is part of Coccinelle.
8 #
9 # Coccinelle is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation, according to version 2 of the License.
12 #
13 # Coccinelle is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with Coccinelle. If not, see <http://www.gnu.org/licenses/>.
20 #
21 # The authors reserve the right to distribute this or future versions of
22 # Coccinelle under other licenses.
23
24
25 #############################################################################
26 # Configuration section
27 #############################################################################
28
29 include Makefile.libs
30
31 # 'distclean' does not require configure to have run, and should also
32 # clean all the bundled directories. Hence, a special case.
33 ifeq ($(MAKECMDGOALS),distclean)
34 MAKELIBS:=$(dir $(wildcard ./bundles/*/Makefile))
35 else
36 ifneq ($(MAKECMDGOALS),configure)
37 -include Makefile.config
38 endif
39 endif
40
41 -include /etc/lsb-release
42 -include Makefile.override # local customizations, if any
43 -include /etc/Makefile.coccinelle # local customizations, if any
44
45
46 VERSION=$(shell cat ./version | tr -d '\n')
47 CCVERSION=$(shell cat scripts/coccicheck/README | egrep -o '[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+' | head -n1)
48 PKGVERSION=$(shell dpkg-parsechangelog -ldebian/changelog.$(DISTRIB_CODENAME) 2> /dev/null \
49 | sed -n 's/^Version: \(.*\)/\1/p' )
50
51 ##############################################################################
52 # Variables
53 ##############################################################################
54
55 TARGET=spatch
56 PRJNAME=coccinelle
57 SRC=flag_cocci.ml cocci.ml testing.ml test.ml $(LEXER_SOURCES:.mll=.ml) main.ml
58
59 ifeq ($(FEATURE_PYTHON),1)
60 PYTHON_INSTALL_TARGET=install-python
61 else
62 PYTHON_INSTALL_TARGET=
63 endif
64
65 SYSLIBS=str.cma unix.cma bigarray.cma nums.cma
66 LIBS=commons/commons.cma \
67 globals/globals.cma \
68 ctl/ctl.cma \
69 parsing_cocci/cocci_parser.cma parsing_c/parsing_c.cma \
70 engine/cocciengine.cma popl09/popl.cma \
71 extra/extra.cma python/coccipython.cma ocaml/cocciocaml.cma
72
73 MAKESUBDIRS=$(MAKELIBS) commons \
74 globals ctl parsing_cocci parsing_c \
75 engine popl09 extra python ocaml
76
77 CLEANSUBDIRS=commons \
78 globals ctl parsing_cocci parsing_c \
79 engine popl09 extra python ocaml docs \
80 $(MAKELIBS)
81
82 INCLUDEDIRSDEP=commons commons/ocamlextra \
83 globals ctl \
84 parsing_cocci parsing_c engine popl09 extra python ocaml \
85 $(MAKELIBS)
86
87 INCLUDEDIRS=$(INCLUDEDIRSDEP) $(PCREDIR) $(INCLIBS)
88
89 ##############################################################################
90 # Generic variables
91 ##############################################################################
92
93 # sort to remove duplicates
94 INCLUDESET=$(sort $(INCLUDEDIRS))
95 INCLUDES=$(INCLUDESET:%=-I %)
96
97 OBJS= $(SRC:.ml=.cmo)
98 OPTOBJS= $(SRC:.ml=.cmx)
99
100 EXEC=$(TARGET)
101
102 ##############################################################################
103 # Generic ocaml variables
104 ##############################################################################
105
106 OCAMLC_CMD=$(OCAMLC) $(OCAMLCFLAGS) $(INCLUDES)
107 OCAMLOPT_CMD=$(OCAMLOPT) $(OPTFLAGS) $(INCLUDES)
108 OCAMLYACC_CMD=$(OCAMLYACC) -v
109 OCAMLDEP_CMD=$(OCAMLDEP) $(INCLUDEDIRSDEP:%=-I %)
110 OCAMLMKTOP_CMD=$(OCAMLMKTOP) -g -custom $(INCLUDES)
111
112 # these are unused at the moment (todo: remove)
113 EXTRA_CFLAGS= # -static -pie -fpie -fPIE -static-libgcc
114 EXTRA_OCAML_CFLAGS=$(EXTRA_CFLAGS:%=-ccopt %)
115
116 # 'make purebytecode' unsets this definition
117 BYTECODE_EXTRA=-custom $(EXTRA_OCAML_FLAGS)
118
119 ##############################################################################
120 # Top rules
121 ##############################################################################
122 .PHONY:: all all.opt byte opt top clean distclean configure opt-compil
123 .PHONY:: $(MAKESUBDIRS:%=%.all) $(MAKESUBDIRS:%=%.opt) subdirs.all subdirs.opt
124 .PHONY:: all-opt all-byte byte-only opt-only
125 .PHONY:: copy-stubs install-stubs install install-man install-python install-common
126
127
128 # All make targets that are expected to be an entry point have a dependency on
129 # 'Makefile.config' to ensure that if Makefile.config is not present, an error
130 # message is printed first before any other actions are executed.
131 # In addition, the targets that actually build something have a dependency on
132 # '.depend' and 'version.ml'.
133
134 # dispatches to either 'all-dev' or 'all-release'
135 all: Makefile.config
136 @$(MAKE) .depend
137 $(MAKE) $(TARGET_ALL)
138
139 # make "all" comes in three flavours
140 world: Makefile.config version.ml
141 @echo "building both versions of spatch"
142 $(MAKE) .depend
143 $(MAKE) byte
144 $(MAKE) opt-compil
145 $(MAKE) preinstall
146 $(MAKE) docs
147 @echo ""
148 @echo -e "\tcoccinelle can now be installed via 'make install'"
149
150 # note: the 'all-dev' target excludes the documentation
151 all-dev: Makefile.config version.ml
152 @$(MAKE) .depend
153 @echo "building the unoptimized version of spatch"
154 $(MAKE) byte
155 @$(MAKE) preinstall
156 @echo ""
157 @echo -e "\tcoccinelle can now be installed via 'make install'"
158
159 all-release: Makefile.config version.ml
160 @echo building $(TARGET_SPATCH)
161 $(MAKE) .depend
162 $(MAKE) $(TARGET_SPATCH)
163 $(MAKE) preinstall
164 $(MAKE) docs
165 @echo ""
166 @echo -e "\tcoccinelle can now be installed via 'make install'"
167
168 all.opt: Makefile.config
169 @$(MAKE) .depend
170 $(MAKE) opt-only
171 $(MAKE) preinstall
172
173 # aliases for "byte" and "opt-compil"
174 opt opt-only: Makefile.config opt-compil
175 byte-only: Makefile.config byte
176
177 byte: Makefile.config version.ml
178 @$(MAKE) .depend
179 @$(MAKE) subdirs.all
180 @$(MAKE) $(EXEC)
181 @echo the compilation of $(EXEC) finished
182 @echo $(EXEC) can be installed or used
183
184 opt-compil: Makefile.config version.ml
185 $(MAKE) .depend
186 $(MAKE) subdirs.opt BUILD_OPT=yes
187 $(MAKE) $(EXEC).opt BUILD_OPT=yes
188 @echo the compilation of $(EXEC).opt finished
189 @echo $(EXEC).opt can be installed or used
190
191 top: $(EXEC).top
192
193 subdirs.all:
194 @+for D in $(MAKESUBDIRS); do $(MAKE) $$D.all || exit 1 ; done
195
196 subdirs.opt:
197 @+for D in $(MAKESUBDIRS); do $(MAKE) $$D.opt || exit 1 ; done
198
199 $(MAKESUBDIRS:%=%.all):
200 @$(MAKE) -C $(@:%.all=%) all
201
202 $(MAKESUBDIRS:%=%.opt):
203 @$(MAKE) -C $(@:%.opt=%) all.opt
204
205 #dependencies:
206 # commons:
207 # globals:
208 # menhirLib:
209 # parsing_cocci: commons globals menhirLib
210 # parsing_c:parsing_cocci
211 # ctl:globals commonsg
212 # engine: parsing_cocci parsing_c ctl
213 # popl09:engine
214 # extra: parsing_cocci parsing_c ctl
215 # pycaml:
216 # python:pycaml parsing_cocci parsing_c
217
218 clean:: Makefile.config
219 @set -e; for i in $(CLEANSUBDIRS); do $(MAKE) -C $$i $@; done
220 @$(MAKE) -C demos/spp $@
221
222 $(LIBS): $(MAKESUBDIRS:%=%.all)
223 $(LIBS:.cma=.cmxa): $(MAKESUBDIRS:%=%.opt)
224 $(LNKLIBS) : $(MAKESUBDIRS:%=%.all)
225 $(LNKOPTLIBS) : $(MAKESUBDIRS:%=%.opt)
226
227 $(OBJS):$(LIBS)
228 $(OPTOBJS):$(LIBS:.cma=.cmxa)
229
230 $(EXEC): $(LNKLIBS) $(LIBS) $(OBJS)
231 $(OCAMLC_CMD) $(BYTECODE_EXTRA) $(FLAGSLIBS) -o $@ $(SYSLIBS) $^
232
233 $(EXEC).opt: $(OPTLNKLIBS) $(LIBS:.cma=.cmxa) $(OPTOBJS)
234 $(OCAMLOPT_CMD) $(OPTFLAGSLIBS) -o $@ $(SYSLIBS:.cma=.cmxa) $^
235
236 $(EXEC).top: $(LNKLIBS) $(LIBS) $(OBJS)
237 $(OCAMLMKTOP_CMD) -custom -o $@ $(SYSLIBS) $(FLAGSLIBS) $^
238
239 clean distclean::
240 rm -f $(TARGET) $(TARGET).opt $(TARGET).top
241
242 .PHONY:: tools configure
243
244 configure:
245 ./configure $(CONFIGURE_FLAGS)
246
247 # the dependencies on Makefile.config should give a hint to the programmer that
248 # configure should be run again
249 Makefile.config: Makefile.config.in configure.ac
250 @echo "Makefile.config needs to be (re)build. Run ./configure $(CONFIGURE_FLAGS) to generate it."
251 @false
252
253 tools: $(LIBS) $(LNKLIBS)
254 $(MAKE) -C tools
255
256 distclean::
257 @if [ -d tools ] ; then $(MAKE) -C tools distclean ; fi
258
259 # it seems impossible to pass "-static" unless all dependent
260 # libraries are also available as static archives.
261 # set $(STATIC) to -static if you have such libraries.
262 static:
263 rm -f spatch.opt spatch
264 $(MAKE) $(STATIC) opt-only
265 cp spatch.opt spatch
266
267 # creates a portable version of spatch, which, however, may
268 # be dependent on non-portably dynamic libraries. You
269 # may need the stubs, see 'copy-stubs'.
270 purebytecode:
271 rm -f spatch.opt spatch
272 $(MAKE) BYTECODE_EXTRA="" byte-only
273 sed -i '1 s,^#!.*$$,#!/usr/bin/ocamlrun,g' spatch
274
275 # copies the stubs libraries (if any) to the root directory
276 copy-stubs:
277 @if test -f ./bundles/pycaml/dllpycaml_stubs.so; then \
278 cp -fv ./bundles/pycaml/dllpycaml_stubs.so .; fi
279 @if test -f ./bundles/pcre/dllpcre_stubs.so; then \
280 cp -fv ./bundles/pcre/dllpcre_stubs.so .; fi
281
282 ##############################################################################
283 # Build version information
284 ##############################################################################
285
286 version.ml:
287 @echo "version.ml is missing. Run ./configure to generate it."
288 @false
289
290 ##############################################################################
291 # Build documentation
292 ##############################################################################
293 .PHONY:: docs
294
295 docs:
296 @$(MAKE) -C docs || (echo "warning: ignored the failed construction of the manual" 1>&2)
297 @if test "x$(FEATURE_OCAML)" = x1; then \
298 if test -f ./parsing_c/ast_c.cmo -o -f ./parsing_c/ast_c.cmx; then \
299 $(MAKE) -C ocaml doc; \
300 else echo "note: to obtain coccilib documenation, it is required to build 'spatch' first so that ./parsing_c/ast_c.cm* gets build."; \
301 fi fi
302 @echo "finished building manuals"
303
304 clean:: Makefile.config
305 $(MAKE) -C docs clean
306 $(MAKE) -C ocaml cleandoc
307
308 ##############################################################################
309 # Pre-Install (customization of spatch frontend script)
310 ##############################################################################
311
312 preinstall: docs/spatch.1 scripts/spatch scripts/spatch.opt scripts/spatch.byte
313 @echo "generated the wrapper scripts for spatch (the frontends)"
314
315 docs/spatch.1: Makefile.config
316 $(MAKE) -C docs spatch.1
317
318 # user will use spatch to run spatch.opt (native)
319 scripts/spatch: Makefile.config scripts/spatch.sh
320 cp scripts/spatch.sh scripts/spatch
321 chmod +x scripts/spatch
322
323 # user will use spatch to run spatch (bytecode)
324 scripts/spatch.byte: Makefile.config scripts/spatch.sh
325 cp scripts/spatch.sh scripts/spatch.byte
326 chmod +x scripts/spatch.byte
327
328 # user will use spatch.opt to run spatch.opt (native)
329 scripts/spatch.opt: Makefile.config scripts/spatch.sh
330 cp scripts/spatch.sh scripts/spatch.opt
331 chmod +x scripts/spatch.opt
332
333 distclean::
334 rm -f scripts/spatch scripts/spatch.byte scripts/spatch.opt
335
336 ##############################################################################
337 # Install
338 ##############################################################################
339
340 # don't remove DESTDIR, it can be set by package build system like ebuild
341 # for staged installation.
342 install-common:
343 $(MKDIR_P) $(DESTDIR)$(BINDIR)
344 $(MKDIR_P) $(DESTDIR)$(LIBDIR)
345 $(MKDIR_P) $(DESTDIR)$(SHAREDIR)/ocaml
346 $(MKDIR_P) $(DESTDIR)$(SHAREDIR)/commons
347 $(MKDIR_P) $(DESTDIR)$(SHAREDIR)/globals
348 $(MKDIR_P) $(DESTDIR)$(SHAREDIR)/parsing_c
349 $(INSTALL_DATA) standard.h $(DESTDIR)$(SHAREDIR)
350 $(INSTALL_DATA) standard.iso $(DESTDIR)$(SHAREDIR)
351 $(INSTALL_DATA) ocaml/coccilib.cmi $(DESTDIR)$(SHAREDIR)/ocaml/
352 $(INSTALL_DATA) parsing_c/*.cmi $(DESTDIR)$(SHAREDIR)/parsing_c/
353 $(INSTALL_DATA) commons/*.cmi $(DESTDIR)$(SHAREDIR)/commons/
354 $(INSTALL_DATA) globals/iteration.cmi $(DESTDIR)$(SHAREDIR)/globals/
355
356 install-man:
357 @echo "Installing manuals in: ${DESTDIR}${MANDIR}"
358 $(MKDIR_P) $(DESTDIR)$(MANDIR)/man1
359 $(MKDIR_P) $(DESTDIR)$(MANDIR)/man3
360 $(INSTALL_DATA) docs/spatch.1 $(DESTDIR)$(MANDIR)/man1/
361 $(INSTALL_DATA) docs/Coccilib.3cocci $(DESTDIR)$(MANDIR)/man3/
362
363 install-bash:
364 @echo "Installing bash completion in: ${DESTDIR}${BASH_COMPLETION_DIR}"
365 $(MKDIR_P) $(DESTDIR)$(BASH_COMPLETION_DIR)
366 $(INSTALL_DATA) scripts/spatch.bash_completion \
367 $(DESTDIR)$(BASH_COMPLETION_DIR)/spatch
368
369 install-tools:
370 @echo "Installing tools in: ${DESTDIR}${BINDIR}"
371 $(MKDIR_P) $(DESTDIR)$(BINDIR)
372 $(INSTALL_PROGRAM) tools/splitpatch \
373 $(DESTDIR)$(BINDIR)/splitpatch
374 $(INSTALL_PROGRAM) tools/cocci-send-email.perl \
375 $(DESTDIR)$(BINDIR)/cocci-send-email.perl
376
377 install-python:
378 @echo "Installing python support in: ${DESTDIR}${SHAREDIR}/python"
379 $(MKDIR_P) $(DESTDIR)$(SHAREDIR)/python/coccilib/coccigui
380 $(INSTALL_DATA) python/coccilib/*.py \
381 $(DESTDIR)$(SHAREDIR)/python/coccilib
382 $(INSTALL_DATA) python/coccilib/coccigui/*.py \
383 $(DESTDIR)$(SHAREDIR)/python/coccilib/coccigui
384 $(INSTALL_DATA) python/coccilib/coccigui/pygui.glade \
385 $(DESTDIR)$(SHAREDIR)/python/coccilib/coccigui
386 $(INSTALL_DATA) python/coccilib/coccigui/pygui.gladep \
387 $(DESTDIR)$(SHAREDIR)/python/coccilib/coccigui
388
389 install-stubs:
390 $(MKDIR_P) $(DESTDIR)$(SHAREDIR)
391 @if test -f ./bundles/pycaml/dllpycaml_stubs.so; then \
392 cp -fv ./bundles/pycaml/dllpycaml_stubs.so $(DESTDIR)$(SHAREDIR); fi
393 @if test -f ./bundles/pcre/dllpcre_stubs.so; then \
394 cp -fv ./bundles/pcre/dllpcre_stubs.so $(DESTDIR)$(SHAREDIR); fi
395
396 install: install-man install-common install-stubs $(PYTHON_INSTALL_TARGET)
397 rm -f $(DESTDIR)$(SHAREDIR)/spatch
398 rm -f $(DESTDIR)$(SHAREDIR)/spatch.opt
399 @if test -x spatch -o -x spatch.opt; then \
400 $(MAKE) install-def;fi
401 @if test -x spatch ; then \
402 $(MAKE) install-byte; fi
403 @if test -x spatch.opt ; then \
404 $(MAKE) install-opt;fi
405 @if test ! -x spatch -a ! -x spatch.opt ; then \
406 echo -e "\n\n\t==> Run 'make', 'make opt', or both first. <==\n\n";fi
407 @echo ""
408 @echo -e "\tYou can also install spatch by copying the program spatch"
409 @echo -e "\t(available in this directory) anywhere you want and"
410 @echo -e "\tgive it the right options to find its configuration files."
411 @echo ""
412
413 #
414 # Installation of spatch and spatch.opt and their wrappers
415 #
416
417 # user will use spatch to run one of the binaries
418 install-def:
419 $(INSTALL_PROGRAM) scripts/spatch $(DESTDIR)$(BINDIR)/spatch
420
421 # user will use spatch.byte to run spatch (bytecode)
422 install-byte:
423 $(INSTALL_PROGRAM) spatch $(DESTDIR)$(SHAREDIR)
424 $(INSTALL_PROGRAM) scripts/spatch.byte $(DESTDIR)$(BINDIR)/spatch.byte
425
426 # user will use spatch.opt to run spatch.opt (native)
427 install-opt:
428 $(INSTALL_PROGRAM) spatch.opt $(DESTDIR)$(SHAREDIR)
429 $(INSTALL_PROGRAM) scripts/spatch.opt $(DESTDIR)$(BINDIR)/spatch.opt
430
431 uninstall:
432 rm -f $(DESTDIR)$(BINDIR)/spatch
433 rm -f $(DESTDIR)$(BINDIR)/spatch.opt
434 rm -f $(DESTDIR)$(BINDIR)/spatch.byte
435 rm -f $(DESTDIR)$(SHAREDIR)/dllpycaml_stubs.so
436 rm -f $(DESTDIR)$(SHAREDIR)/dllpcre_stubs.so
437 rm -f $(DESTDIR)$(SHAREDIR)/spatch
438 rm -f $(DESTDIR)$(SHAREDIR)/spatch.opt
439 rm -f $(DESTDIR)$(SHAREDIR)/standard.h
440 rm -f $(DESTDIR)$(SHAREDIR)/standard.iso
441 rm -f $(DESTDIR)$(SHAREDIR)/ocaml/coccilib.cmi
442 rm -f $(DESTDIR)$(SHAREDIR)/parsing_c/*.cmi
443 rm -f $(DESTDIR)$(SHAREDIR)/commons/*.cmi
444 rm -f $(DESTDIR)$(SHAREDIR)/globals/*.cmi
445 rm -f $(DESTDIR)$(SHAREDIR)/python/coccilib/coccigui/*
446 rm -f $(DESTDIR)$(SHAREDIR)/python/coccilib/*.py
447 rmdir --ignore-fail-on-non-empty -p \
448 $(DESTDIR)$(SHAREDIR)/python/coccilib/coccigui
449 rmdir $(DESTDIR)$(SHAREDIR)/globals
450 rmdir $(DESTDIR)$(SHAREDIR)/commons
451 rmdir $(DESTDIR)$(SHAREDIR)/parsing_c
452 rmdir $(DESTDIR)$(SHAREDIR)/ocaml
453 rmdir $(DESTDIR)$(SHAREDIR)
454 rm -f $(DESTDIR)$(MANDIR)/man1/spatch.1
455 rm -f $(DESTDIR)$(MANDIR)/man3/Coccilib.3cocci
456
457 uninstall-bash:
458 rm -f $(DESTDIR)$(BASH_COMPLETION_DIR)/spatch
459 rmdir --ignore-fail-on-non-empty -p \
460 $(DESTDIR)$(BASH_COMPLETION_DIR)
461
462 uninstall-tools:
463 rm -f $(DESTDIR)$(BINDIR)/splitpatch
464 rm -f $(DESTDIR)$(BINDIR)/cocci-send-email.perl
465
466 version:
467 @echo "spatch $(VERSION)"
468 @echo "spatch $(PKGVERSION) ($(DISTRIB_ID))"
469 @echo "coccicheck $(CCVERSION)"
470
471
472 ##############################################################################
473 # Deb package (for Ubuntu) and release rules
474 ##############################################################################
475
476 include Makefile.release
477
478 ##############################################################################
479 # Developer rules
480 ##############################################################################
481
482 -include Makefile.dev
483
484 test: $(TARGET)
485 ./$(TARGET) -testall
486
487 testparsing:
488 ./$(TARGET) -D standard.h -parse_c -dir tests/
489
490 # the check target runs:
491 # * some feature tests (depending on what is enabled)
492 # * the test suite
493 check: scripts/spatch
494 @echo "testing if spatch works on hello world..."
495 @COCCINELLE_HOME="$$(pwd)" ./scripts/spatch --sp-file demos/hello/hello-smpl.cocci demos/hello/helloworld.c --very-quiet | grep -q '+ printf("world, hello!");'
496 @echo "testing if spatch works with regexes..."
497 @COCCINELLE_HOME="$$(pwd)" ./scripts/spatch --sp-file demos/hello/hello-regexp.cocci demos/hello/helloworld.c --very-quiet | grep -q '+ printf("world, hello!");'
498 @if test "x${FEATURE_OCAML}" = x1 -a -z "${NO_OCAMLFIND}"; then \
499 echo "testing if spatch works with ocaml scripts..."; \
500 COCCINELLE_HOME="$$(pwd)" ./scripts/spatch --sp-file demos/hello/hello-ocaml.cocci demos/hello/helloworld.c --very-quiet | grep -q 'Hello at: 2'; fi
501 @if test "x${FEATURE_PYTHON}" = x1; then \
502 echo "testing if spatch works with python scripts..."; \
503 COCCINELLE_HOME="$$(pwd)" ./scripts/spatch --sp-file demos/hello/hello-python.cocci demos/hello/helloworld.c --very-quiet | grep -q 'Hello at: 2'; fi
504 @echo running the test suite
505 COCCINELLE_HOME="$$(pwd)" ./scripts/spatch --testall --no-update-score-file
506
507 # -inline 0 to see all the functions in the profile.
508 # Can also use the profile framework in commons/ and run your program
509 # with -profile.
510 forprofiling:
511 $(MAKE) OPTFLAGS="-p -inline 0 ${EXTRA_OCAML_FLAGS}" opt
512
513 clean distclean::
514 rm -f gmon.out ocamlprof.dump
515
516 tags:
517 otags -no-mli-tags -r .
518
519 dependencygraph:
520 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
521 ocamldot -lr /tmp/dependfull.depend > /tmp/dependfull.dot
522 dot -Tps /tmp/dependfull.dot > /tmp/dependfull.ps
523 ps2pdf /tmp/dependfull.ps /tmp/dependfull.pdf
524
525 ##############################################################################
526 # Misc rules
527 ##############################################################################
528
529 # each member of the project can have its own test.ml. this file is
530 # not under CVS.
531 test.ml:
532 echo "let foo_ctl () = failwith \"there is no foo_ctl formula\"" \
533 > test.ml
534
535 ##############################################################################
536 # Generic ocaml rules
537 ##############################################################################
538
539 .SUFFIXES: .ml .mli .cmo .cmi .cmx
540
541 .ml.cmo:
542 $(OCAMLC_CMD) -c $<
543 .mli.cmi:
544 $(OCAMLC_CMD) -c $<
545 .ml.cmx:
546 $(OCAMLOPT_CMD) -c $<
547
548 .ml.mldepend:
549 $(OCAMLC_CMD) -i $<
550
551 clean distclean::
552 rm -f .depend
553 rm -f *.cm[iox] *.o *.annot
554 rm -f *~ .*~ *.exe #*#
555
556 distclean::
557 set -e; for i in $(CLEANSUBDIRS); do $(MAKE) -C $$i $@; done
558 rm -f test.ml
559 rm -f TAGS *.native *.byte *.d.native *.p.byte
560 rm -rf _build _log
561 rm -f tests/SCORE_actual.sexp tests/SCORE_best_of_both.sexp
562 find . -name ".#*1.*" | xargs rm -f
563 rm -f $(EXEC) $(EXEC).opt $(EXEC).top
564
565 # using 'touch' to prevent infinite recursion with 'make depend'
566 .PHONY:: depend
567 .depend: Makefile.config test.ml version
568 @touch .depend
569 @$(MAKE) depend
570
571 depend: Makefile.config test.ml version
572 @echo constructing '.depend'
573 @rm -f .depend
574 @set -e; for i in $(MAKESUBDIRS); do $(MAKE) -C $$i depend; done
575 $(OCAMLDEP_CMD) *.mli *.ml > .depend
576
577 ##############################################################################
578 # configure-related
579 ##############################################################################
580
581 distclean::
582 @echo "cleaning configured files"
583 if test -z "${KEEP_CONFIG}"; then rm -f Makefile.config; fi
584 rm -rf autom4te.cache
585 rm -f config.status
586 rm -f config.log
587 rm -f version.ml
588 rm -f globals/config.ml
589 rm -f globals/regexp.ml python/pycocci.ml ocaml/prepare_ocamlcocci.ml
590 rm -f scripts/spatch.sh
591 rm -f aclocal.m4
592 @echo "run 'configure' again prior to building coccinelle"
593
594
595 # don't include depend for those actions that either don't need
596 # depend or that call 'make .depend' explicitly.
597 # TODO: find a nicer way to express this
598 ifneq ($(MAKECMDGOALS),clean)
599 ifneq ($(MAKECMDGOALS),distclean)
600 ifneq ($(MAKECMDGOALS),configure)
601 ifneq ($(MAKECMDGOALS),prerelease)
602 ifneq ($(MAKECMDGOALS),release)
603 ifneq ($(MAKECMDGOALS),package)
604 ifneq ($(MAKECMDGOALS),all-release)
605 ifneq ($(MAKECMDGOALS),all-dev)
606 ifneq ($(MAKECMDGOALS),all)
607 ifneq ($(MAKECMDGOALS),.depend)
608 ifneq ($(MAKECMDGOALS),depend)
609 -include .depend
610 endif
611 endif
612 endif
613 endif
614 endif
615 endif
616 endif
617 endif
618 endif
619 endif
620 endif
621
622 include Makefile.common