permit multiline comments and strings in macros
[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 pure-byte
125 .PHONY:: copy-stubs install-stubs install install-man install-python install-common
126
127
128 # below follow the main make targets when ocamlbuild is not enabled
129 ifneq ($(FEATURE_OCAMLBUILD),yes)
130
131 # All make targets that are expected to be an entry point have a dependency on
132 # 'Makefile.config' to ensure that if Makefile.config is not present, an error
133 # message is printed first before any other actions are executed.
134 # In addition, the targets that actually build something have a dependency on
135 # '.depend' and 'version.ml'.
136
137 # dispatches to either 'all-dev' or 'all-release'
138 all: Makefile.config
139 @$(MAKE) .depend
140 $(MAKE) $(TARGET_ALL)
141
142 # make "all" comes in three flavours
143 world: Makefile.config version.ml
144 @echo "building both versions of spatch"
145 $(MAKE) .depend
146 $(MAKE) byte
147 $(MAKE) opt-compil
148 $(MAKE) preinstall
149 $(MAKE) docs
150 @echo ""
151 @echo -e "\tcoccinelle can now be installed via 'make install'"
152
153 # note: the 'all-dev' target excludes the documentation
154 all-dev: Makefile.config version.ml
155 @$(MAKE) .depend
156 @echo "building the unoptimized version of spatch"
157 $(MAKE) byte
158 @$(MAKE) preinstall
159 @echo ""
160 @echo -e "\tcoccinelle can now be installed via 'make install'"
161
162 all-release: Makefile.config version.ml
163 @echo building $(TARGET_SPATCH)
164 $(MAKE) .depend
165 $(MAKE) $(TARGET_SPATCH)
166 $(MAKE) preinstall
167 $(MAKE) docs
168 @echo ""
169 @echo -e "\tcoccinelle can now be installed via 'make install'"
170
171 all.opt: Makefile.config
172 @$(MAKE) .depend
173 $(MAKE) opt-only
174 $(MAKE) preinstall
175
176 byte: Makefile.config version.ml
177 @$(MAKE) .depend
178 @$(MAKE) subdirs.all
179 @$(MAKE) $(EXEC)
180 @echo the compilation of $(EXEC) finished
181 @echo $(EXEC) can be installed or used
182
183 opt-compil: Makefile.config version.ml
184 $(MAKE) .depend
185 $(MAKE) subdirs.opt BUILD_OPT=yes
186 $(MAKE) $(EXEC).opt BUILD_OPT=yes
187 @echo the compilation of $(EXEC).opt finished
188 @echo $(EXEC).opt can be installed or used
189
190 top: $(EXEC).top
191
192 # the .cmi file of coccilib
193 ocaml/coccilib/coccilib.cmi: ocaml/coccilib.cmi
194 cp ocaml/coccilib.cmi ocaml/coccilib/coccilib.cmi
195
196 # ocamlbuild version of the main make targets
197 else
198
199 all: Makefile.config
200 $(MAKE) $(TARGET_ALL)
201
202 world: Makefile.config myocamlbuild.ml version.ml prepare-bundles
203 @echo "building both versions of spatch"
204 $(MAKE) byte
205 $(MAKE) opt-compil
206 @$(MAKE) coccilib-cmi
207 $(MAKE) preinstall
208 $(MAKE) docs
209 @echo ""
210 @echo -e "\tcoccinelle can now be installed via 'make install'"
211
212 # note: the 'all-dev' target excludes the documentation and is less noisy
213 all-dev: Makefile.config myocamlbuild.ml version.ml prepare-bundles
214 $(MAKE) byte
215 @$(MAKE) coccilib-cmi
216 @$(MAKE) preinstall
217
218 all-release: Makefile.config myocamlbuild.ml version.ml prepare-bundles
219 @echo building $(TARGET_SPATCH)
220 $(MAKE) $(TARGET_SPATCH)
221 @$(MAKE) coccilib-cmi
222 $(MAKE) preinstall
223 $(MAKE) docs
224 @echo ""
225 @echo -e "\tcoccinelle can now be installed via 'make install'"
226
227 all.opt: Makefile.config myocamlbuild.ml version.ml prepare-bundles
228 $(MAKE) opt-only
229 @$(MAKE) coccilib-cmi
230 $(MAKE) preinstall
231
232 byte: Makefile.config myocamlbuild.ml version.ml prepare-bundles
233 $(OCAMLBUILD) -j 0 main.byte
234 cp _build/main.byte $(EXEC)
235
236 pure-byte: Makefile.config myocamlbuild.ml version.ml prepare-bundles
237 $(OCAMLBUILD) -j 0 -tag nocustom main.byte
238 cp _build/main.byte $(EXEC)
239
240 opt-compil: Makefile.config myocamlbuild.ml version.ml prepare-bundles
241 $(OCAMLBUILD) -j 0 main.native
242 cp _build/main.native $(EXEC).opt
243
244 # the .cmi file of coccilib
245 _build/ocaml/coccilib.cmi:
246 $(OCAMLBUILD) -j 0 ocaml/coccilib.cmi
247 ocaml/coccilib/coccilib.cmi: _build/ocaml/coccilib.cmi
248 cp _build/ocaml/coccilib.cmi ocaml/coccilib/coccilib.cmi
249
250 # end of main build target distinction on ocamlbuild
251 endif
252
253 # aliases for "byte" and "opt-compil"
254 opt opt-only: Makefile.config opt-compil
255 byte-only: Makefile.config byte
256
257
258 # ensures that coccilib.cmi gets build
259 .PHONY:: coccilib-cmi
260 coccilib-cmi: ocaml/coccilib/coccilib.cmi
261 distclean::
262 rm -f ocaml/coccilib/coccilib.cmi
263
264
265 subdirs.all:
266 @+for D in $(MAKESUBDIRS); do $(MAKE) $$D.all || exit 1 ; done
267
268 subdirs.opt:
269 @+for D in $(MAKESUBDIRS); do $(MAKE) $$D.opt || exit 1 ; done
270
271 $(MAKESUBDIRS:%=%.all):
272 @$(MAKE) -C $(@:%.all=%) all
273
274 $(MAKESUBDIRS:%=%.opt):
275 @$(MAKE) -C $(@:%.opt=%) all.opt
276
277 # This make target prepares the bundled software for building.
278 # Note that running 'make' in these subdirectories will
279 # automatically prepare the bundled software.
280 .PHONY:: prepare-bundles
281 prepare-bundles: $(MAKELIBS:%=%/.prepare)
282
283 $(MAKELIBS:%=%/.prepare):
284 echo $@
285 @$(MAKE) -C $(@:%.prepare=%) .prepare
286
287 #dependencies:
288 # commons:
289 # globals:
290 # menhirLib:
291 # parsing_cocci: commons globals menhirLib
292 # parsing_c:parsing_cocci
293 # ctl:globals commonsg
294 # engine: parsing_cocci parsing_c ctl
295 # popl09:engine
296 # extra: parsing_cocci parsing_c ctl
297 # pycaml:
298 # python:pycaml parsing_cocci parsing_c
299
300 clean:: Makefile.config
301 @set -e; for i in $(CLEANSUBDIRS); do $(MAKE) -C $$i $@; done
302 @$(MAKE) -C demos/spp $@
303
304 $(LIBS): $(MAKESUBDIRS:%=%.all)
305 $(LIBS:.cma=.cmxa): $(MAKESUBDIRS:%=%.opt)
306 $(LNKLIBS) : $(MAKESUBDIRS:%=%.all)
307 $(LNKOPTLIBS) : $(MAKESUBDIRS:%=%.opt)
308
309 $(OBJS):$(LIBS)
310 $(OPTOBJS):$(LIBS:.cma=.cmxa)
311
312 $(EXEC): $(LNKLIBS) $(LIBS) $(OBJS)
313 $(OCAMLC_CMD) $(BYTECODE_EXTRA) $(FLAGSLIBS) -o $@ $(SYSLIBS) $^
314
315 $(EXEC).opt: $(OPTLNKLIBS) $(LIBS:.cma=.cmxa) $(OPTOBJS)
316 $(OCAMLOPT_CMD) $(OPTFLAGSLIBS) -o $@ $(SYSLIBS:.cma=.cmxa) $^
317
318 $(EXEC).top: $(LNKLIBS) $(LIBS) $(OBJS)
319 $(OCAMLMKTOP_CMD) -custom -o $@ $(SYSLIBS) $(FLAGSLIBS) $^
320
321 clean distclean::
322 rm -f $(TARGET) $(TARGET).opt $(TARGET).top
323
324 clean::
325 @if test -n "${OCAMLBUILD}" -d _build; then \
326 $(OCAMLBUILD) -clean; fi
327
328 # distclean can run without ocamlbuild configured.
329 distclean::
330 -@if test -d _build; then \
331 ocamlbuild -clean; fi
332 rm -rf _build _log
333
334 .PHONY:: tools configure
335
336 configure:
337 ./configure $(CONFIGURE_FLAGS)
338
339 # the dependencies on Makefile.config should give a hint to the programmer that
340 # configure should be run again
341 Makefile.config: Makefile.config.in configure.ac
342 @echo "Makefile.config needs to be (re)build. Run ./configure $(CONFIGURE_FLAGS) to generate it."
343 @false
344
345 # as above, also for the ocamlbuild plugin
346 myocamlbuild.ml: myocamlbuild.ml.in configure.ac
347
348 tools: $(LIBS) $(LNKLIBS)
349 $(MAKE) -C tools
350
351 distclean::
352 @if [ -d tools ] ; then $(MAKE) -C tools distclean ; fi
353
354 # it seems impossible to pass "-static" unless all dependent
355 # libraries are also available as static archives.
356 # set $(STATIC) to -static if you have such libraries.
357 static:
358 rm -f spatch.opt spatch
359 $(MAKE) $(STATIC) opt-only
360 cp spatch.opt spatch
361
362 # creates a portable version of spatch, which, however, may
363 # be dependent on non-portably dynamic libraries. You
364 # may need the stubs, see 'copy-stubs'.
365 purebytecode:
366 rm -f spatch.opt spatch
367 ifneq ($(FEATURE_OCAMLBUILD),yes)
368 $(MAKE) BYTECODE_EXTRA="" byte-only
369 else
370 @$(MAKE) pure-byte
371 endif
372 sed -i '1 s,^#!.*$$,#!/usr/bin/ocamlrun,g' spatch
373
374 # copies the stubs libraries (if any) to the root directory
375 ifneq ($(FEATURE_OCAMLBUILD),yes)
376 copy-stubs:
377 @if test -f ./bundles/pycaml/dllpycaml_stubs.so; then \
378 cp -fv ./bundles/pycaml/dllpycaml_stubs.so .; fi
379 @if test -f ./bundles/pcre/dllpcre_stubs.so; then \
380 cp -fv ./bundles/pcre/dllpcre_stubs.so .; fi
381 else
382 copy-stubs:
383 @if test -f _build/bundles/pycaml/dllpycaml_stubs.so; then \
384 cp -fv _build/bundles/pycaml/dllpycaml_stubs.so .; fi
385 @if test -f _build/bundles/pcre/dllpcre_stubs.so; then \
386 cp -fv _build/bundles/pcre/dllpcre_stubs.so .; fi
387 endif
388
389 ##############################################################################
390 # Build version information
391 ##############################################################################
392
393 version.ml:
394 @echo "version.ml is missing. Run ./configure to generate it."
395 @false
396
397 ##############################################################################
398 # Build documentation
399 ##############################################################################
400 .PHONY:: docs
401
402 ifneq ($(FEATURE_OCAMLBUILD),yes)
403 docs:
404 else
405 docs: prepare-bundles
406 endif
407 @$(MAKE) -C docs || (echo "warning: ignored the failed construction of the manual" 1>&2)
408 ifneq ($(FEATURE_OCAMLBUILD),yes)
409 @if test "x$(FEATURE_OCAML)" = x1; then \
410 if test -f ./parsing_c/ast_c.cmo -o -f ./parsing_c/ast_c.cmx; then \
411 $(MAKE) -C ocaml doc; \
412 else echo "note: to obtain coccilib documenation, it is required to build 'spatch' first so that ./parsing_c/ast_c.cm* gets build."; \
413 fi fi
414 else
415 @if test "x$(FEATURE_OCAML)" = x1; then \
416 $(MAKE) -C ocaml doc; fi
417 endif
418 @echo "finished building manuals"
419
420 clean:: Makefile.config
421 $(MAKE) -C docs clean
422 $(MAKE) -C ocaml cleandoc
423
424 ##############################################################################
425 # Pre-Install (customization of spatch frontend script)
426 ##############################################################################
427
428 preinstall: docs/spatch.1 scripts/spatch scripts/spatch.opt scripts/spatch.byte
429
430 docs/spatch.1: Makefile.config
431 $(MAKE) -C docs spatch.1
432
433 # user will use spatch to run spatch.opt (native)
434 scripts/spatch: Makefile.config scripts/spatch.sh
435 cp scripts/spatch.sh scripts/spatch
436 chmod +x scripts/spatch
437
438 # user will use spatch to run spatch (bytecode)
439 scripts/spatch.byte: Makefile.config scripts/spatch.sh
440 cp scripts/spatch.sh scripts/spatch.byte
441 chmod +x scripts/spatch.byte
442
443 # user will use spatch.opt to run spatch.opt (native)
444 scripts/spatch.opt: Makefile.config scripts/spatch.sh
445 cp scripts/spatch.sh scripts/spatch.opt
446 chmod +x scripts/spatch.opt
447
448 distclean::
449 rm -f scripts/spatch scripts/spatch.byte scripts/spatch.opt
450
451 ##############################################################################
452 # Install
453 ##############################################################################
454
455 # don't remove DESTDIR, it can be set by package build system like ebuild
456 # for staged installation.
457 install-common: ocaml/coccilib/coccilib.cmi
458 $(MKDIR_P) $(DESTDIR)$(BINDIR)
459 $(MKDIR_P) $(DESTDIR)$(LIBDIR)
460 $(MKDIR_P) $(DESTDIR)$(SHAREDIR)/ocaml
461 # $(MKDIR_P) $(DESTDIR)$(SHAREDIR)/commons
462 # $(MKDIR_P) $(DESTDIR)$(SHAREDIR)/globals
463 # $(MKDIR_P) $(DESTDIR)$(SHAREDIR)/parsing_c
464 $(INSTALL_DATA) standard.h $(DESTDIR)$(SHAREDIR)
465 $(INSTALL_DATA) standard.iso $(DESTDIR)$(SHAREDIR)
466 $(INSTALL_DATA) ocaml/coccilib/coccilib.cmi $(DESTDIR)$(SHAREDIR)/ocaml/
467 # $(INSTALL_DATA) parsing_c/*.cmi $(DESTDIR)$(SHAREDIR)/parsing_c/
468 # $(INSTALL_DATA) commons/*.cmi $(DESTDIR)$(SHAREDIR)/commons/
469 # $(INSTALL_DATA) globals/iteration.cmi $(DESTDIR)$(SHAREDIR)/globals/
470
471 install-man:
472 @echo "Installing manuals in: ${DESTDIR}${MANDIR}"
473 $(MKDIR_P) $(DESTDIR)$(MANDIR)/man1
474 $(MKDIR_P) $(DESTDIR)$(MANDIR)/man3
475 $(INSTALL_DATA) docs/spatch.1 $(DESTDIR)$(MANDIR)/man1/
476 $(INSTALL_DATA) docs/Coccilib.3cocci $(DESTDIR)$(MANDIR)/man3/
477
478 install-bash:
479 @echo "Installing bash completion in: ${DESTDIR}${BASH_COMPLETION_DIR}"
480 $(MKDIR_P) $(DESTDIR)$(BASH_COMPLETION_DIR)
481 $(INSTALL_DATA) scripts/spatch.bash_completion \
482 $(DESTDIR)$(BASH_COMPLETION_DIR)/spatch
483
484 install-tools:
485 @echo "Installing tools in: ${DESTDIR}${BINDIR}"
486 $(MKDIR_P) $(DESTDIR)$(BINDIR)
487 $(INSTALL_PROGRAM) tools/splitpatch \
488 $(DESTDIR)$(BINDIR)/splitpatch
489 $(INSTALL_PROGRAM) tools/cocci-send-email.perl \
490 $(DESTDIR)$(BINDIR)/cocci-send-email.perl
491
492 install-python:
493 @echo "Installing python support in: ${DESTDIR}${SHAREDIR}/python"
494 $(MKDIR_P) $(DESTDIR)$(SHAREDIR)/python/coccilib/coccigui
495 $(INSTALL_DATA) python/coccilib/*.py \
496 $(DESTDIR)$(SHAREDIR)/python/coccilib
497 $(INSTALL_DATA) python/coccilib/coccigui/*.py \
498 $(DESTDIR)$(SHAREDIR)/python/coccilib/coccigui
499 $(INSTALL_DATA) python/coccilib/coccigui/pygui.glade \
500 $(DESTDIR)$(SHAREDIR)/python/coccilib/coccigui
501 $(INSTALL_DATA) python/coccilib/coccigui/pygui.gladep \
502 $(DESTDIR)$(SHAREDIR)/python/coccilib/coccigui
503
504 install-stubs:
505 $(MKDIR_P) $(DESTDIR)$(SHAREDIR)
506 @if test -f ./bundles/pycaml/dllpycaml_stubs.so; then \
507 cp -fv ./bundles/pycaml/dllpycaml_stubs.so $(DESTDIR)$(SHAREDIR); fi
508 @if test -f ./bundles/pcre/dllpcre_stubs.so; then \
509 cp -fv ./bundles/pcre/dllpcre_stubs.so $(DESTDIR)$(SHAREDIR); fi
510
511 install: install-man install-common install-stubs $(PYTHON_INSTALL_TARGET)
512 rm -f $(DESTDIR)$(SHAREDIR)/spatch
513 rm -f $(DESTDIR)$(SHAREDIR)/spatch.opt
514 @if test -x spatch -o -x spatch.opt; then \
515 $(MAKE) install-def;fi
516 @if test -x spatch ; then \
517 $(MAKE) install-byte; fi
518 @if test -x spatch.opt ; then \
519 $(MAKE) install-opt;fi
520 @if test ! -x spatch -a ! -x spatch.opt ; then \
521 echo -e "\n\n\t==> Run 'make', 'make opt', or both first. <==\n\n";fi
522 @echo ""
523 @echo -e "\tYou can also install spatch by copying the program spatch"
524 @echo -e "\t(available in this directory) anywhere you want and"
525 @echo -e "\tgive it the right options to find its configuration files."
526 @echo ""
527
528 #
529 # Installation of spatch and spatch.opt and their wrappers
530 #
531
532 # user will use spatch to run one of the binaries
533 install-def:
534 $(INSTALL_PROGRAM) scripts/spatch $(DESTDIR)$(BINDIR)/spatch
535
536 # user will use spatch.byte to run spatch (bytecode)
537 install-byte:
538 $(INSTALL_PROGRAM) spatch $(DESTDIR)$(SHAREDIR)
539 $(INSTALL_PROGRAM) scripts/spatch.byte $(DESTDIR)$(BINDIR)/spatch.byte
540
541 # user will use spatch.opt to run spatch.opt (native)
542 install-opt:
543 $(INSTALL_PROGRAM) spatch.opt $(DESTDIR)$(SHAREDIR)
544 $(INSTALL_PROGRAM) scripts/spatch.opt $(DESTDIR)$(BINDIR)/spatch.opt
545
546 uninstall:
547 rm -f $(DESTDIR)$(BINDIR)/spatch
548 rm -f $(DESTDIR)$(BINDIR)/spatch.opt
549 rm -f $(DESTDIR)$(BINDIR)/spatch.byte
550 rm -f $(DESTDIR)$(SHAREDIR)/dllpycaml_stubs.so
551 rm -f $(DESTDIR)$(SHAREDIR)/dllpcre_stubs.so
552 rm -f $(DESTDIR)$(SHAREDIR)/spatch
553 rm -f $(DESTDIR)$(SHAREDIR)/spatch.opt
554 rm -f $(DESTDIR)$(SHAREDIR)/standard.h
555 rm -f $(DESTDIR)$(SHAREDIR)/standard.iso
556 rm -f $(DESTDIR)$(SHAREDIR)/ocaml/coccilib.cmi
557 rm -f $(DESTDIR)$(SHAREDIR)/parsing_c/*.cmi
558 rm -f $(DESTDIR)$(SHAREDIR)/commons/*.cmi
559 rm -f $(DESTDIR)$(SHAREDIR)/globals/*.cmi
560 rm -f $(DESTDIR)$(SHAREDIR)/python/coccilib/coccigui/*
561 rm -f $(DESTDIR)$(SHAREDIR)/python/coccilib/*.py
562 rmdir --ignore-fail-on-non-empty -p \
563 $(DESTDIR)$(SHAREDIR)/python/coccilib/coccigui
564 rmdir $(DESTDIR)$(SHAREDIR)/globals
565 rmdir $(DESTDIR)$(SHAREDIR)/commons
566 rmdir $(DESTDIR)$(SHAREDIR)/parsing_c
567 rmdir $(DESTDIR)$(SHAREDIR)/ocaml
568 rmdir $(DESTDIR)$(SHAREDIR)
569 rm -f $(DESTDIR)$(MANDIR)/man1/spatch.1
570 rm -f $(DESTDIR)$(MANDIR)/man3/Coccilib.3cocci
571
572 uninstall-bash:
573 rm -f $(DESTDIR)$(BASH_COMPLETION_DIR)/spatch
574 rmdir --ignore-fail-on-non-empty -p \
575 $(DESTDIR)$(BASH_COMPLETION_DIR)
576
577 uninstall-tools:
578 rm -f $(DESTDIR)$(BINDIR)/splitpatch
579 rm -f $(DESTDIR)$(BINDIR)/cocci-send-email.perl
580
581 version:
582 @echo "spatch $(VERSION)"
583 @echo "spatch $(PKGVERSION) ($(DISTRIB_ID))"
584 @echo "coccicheck $(CCVERSION)"
585
586
587 ##############################################################################
588 # Deb package (for Ubuntu) and release rules
589 ##############################################################################
590
591 include Makefile.release
592
593 ##############################################################################
594 # Developer rules
595 ##############################################################################
596
597 -include Makefile.dev
598
599 test: $(TARGET)
600 ./$(TARGET) -testall
601
602 testparsing:
603 ./$(TARGET) -D standard.h -parse_c -dir tests/
604
605 # the check target runs:
606 # * some feature tests (depending on what is enabled)
607 # * the test suite
608 check: scripts/spatch
609 @echo "testing if spatch works on hello world..."
610 @COCCINELLE_HOME="$$(pwd)" ./scripts/spatch --sp-file demos/hello/hello-smpl.cocci demos/hello/helloworld.c --very-quiet | grep -q '+ printf("world, hello!");'
611 @echo "testing if spatch works with regexes..."
612 @COCCINELLE_HOME="$$(pwd)" ./scripts/spatch --sp-file demos/hello/hello-regexp.cocci demos/hello/helloworld.c --very-quiet | grep -q '+ printf("world, hello!");'
613 @if test "x${FEATURE_OCAML}" = x1 -a -z "${NO_OCAMLFIND}"; then \
614 echo "testing if spatch works with ocaml scripts..."; \
615 COCCINELLE_HOME="$$(pwd)" ./scripts/spatch --sp-file demos/hello/hello-ocaml.cocci demos/hello/helloworld.c --very-quiet | grep -q 'Hello at: 2'; fi
616 @if test "x${FEATURE_PYTHON}" = x1; then \
617 echo "testing if spatch works with python scripts..."; \
618 COCCINELLE_HOME="$$(pwd)" ./scripts/spatch --sp-file demos/hello/hello-python.cocci demos/hello/helloworld.c --very-quiet | grep -q 'Hello at: 2'; fi
619 @echo running the test suite
620 COCCINELLE_HOME="$$(pwd)" ./scripts/spatch --testall --no-update-score-file
621
622 # -inline 0 to see all the functions in the profile.
623 # Can also use the profile framework in commons/ and run your program
624 # with -profile.
625 forprofiling:
626 $(MAKE) OPTFLAGS="-p -inline 0 ${EXTRA_OCAML_FLAGS}" opt
627
628 clean distclean::
629 rm -f gmon.out ocamlprof.dump
630
631 tags:
632 otags -no-mli-tags -r .
633
634 dependencygraph:
635 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
636 ocamldot -lr /tmp/dependfull.depend > /tmp/dependfull.dot
637 dot -Tps /tmp/dependfull.dot > /tmp/dependfull.ps
638 ps2pdf /tmp/dependfull.ps /tmp/dependfull.pdf
639
640 ##############################################################################
641 # Misc rules
642 ##############################################################################
643
644 # each member of the project can have its own test.ml. this file is
645 # not under CVS.
646 test.ml:
647 echo "let foo_ctl () = failwith \"there is no foo_ctl formula\"" \
648 > test.ml
649
650 ##############################################################################
651 # Generic ocaml rules
652 ##############################################################################
653
654 .SUFFIXES: .ml .mli .cmo .cmi .cmx
655
656 .ml.cmo:
657 $(OCAMLC_CMD) -c $<
658 .mli.cmi:
659 $(OCAMLC_CMD) -c $<
660 .ml.cmx:
661 $(OCAMLOPT_CMD) -c $<
662
663 .ml.mldepend:
664 $(OCAMLC_CMD) -i $<
665
666 clean distclean::
667 rm -f .depend
668 rm -f *.cm[iox] *.o *.annot
669 rm -f *~ .*~ *.exe #*#
670
671 distclean::
672 set -e; for i in $(CLEANSUBDIRS); do $(MAKE) -C $$i $@; done
673 rm -f test.ml
674 rm -f TAGS *.native *.byte *.d.native *.p.byte
675 if test -z "${KEEP_GENERATED}"; then \
676 rm -f tests/SCORE_actual.sexp tests/SCORE_best_of_both.sexp; fi
677 find . -name ".#*1.*" | xargs rm -f
678 rm -f $(EXEC) $(EXEC).opt $(EXEC).top
679 rm -f setup/Makefile
680
681 # using 'touch' to prevent infinite recursion with 'make depend'
682 .PHONY:: depend
683 .depend: Makefile.config test.ml version
684 @touch .depend
685 @$(MAKE) depend
686
687 depend: Makefile.config test.ml version
688 @echo constructing '.depend'
689 @rm -f .depend
690 @set -e; for i in $(MAKESUBDIRS); do $(MAKE) -C $$i depend; done
691 $(OCAMLDEP_CMD) *.mli *.ml > .depend
692
693 ##############################################################################
694 # configure-related
695 ##############################################################################
696
697 distclean::
698 @echo "cleaning configured files"
699 if test -z "${KEEP_CONFIG}"; then rm -f Makefile.config; fi
700 rm -rf autom4te.cache
701 rm -f config.status
702 rm -f config.log
703 if test -z "${KEEP_GENERATED}"; then \
704 rm -f version.ml; fi
705 rm -f globals/config.ml
706 rm -f globals/regexp.ml python/pycocci.ml ocaml/prepare_ocamlcocci.ml
707 rm -f scripts/spatch.sh
708 rm -f aclocal.m4
709 @echo "run 'configure' again prior to building coccinelle"
710
711
712 # don't include depend for those actions that either don't need
713 # depend or that call 'make .depend' explicitly.
714 # TODO: find a nicer way to express this
715 ifneq ($(MAKECMDGOALS),clean)
716 ifneq ($(MAKECMDGOALS),distclean)
717 ifneq ($(MAKECMDGOALS),configure)
718 ifneq ($(MAKECMDGOALS),prerelease)
719 ifneq ($(MAKECMDGOALS),release)
720 ifneq ($(MAKECMDGOALS),package)
721 ifneq ($(MAKECMDGOALS),all-release)
722 ifneq ($(MAKECMDGOALS),all-dev)
723 ifneq ($(MAKECMDGOALS),all)
724 ifneq ($(MAKECMDGOALS),.depend)
725 ifneq ($(MAKECMDGOALS),depend)
726 ifneq ($(FEATURE_OCAMLBUILD),yes)
727 -include .depend
728 endif
729 endif
730 endif
731 endif
732 endif
733 endif
734 endif
735 endif
736 endif
737 endif
738 endif
739 endif
740
741 include Makefile.common