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.
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.
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.
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/>.
21 # The authors reserve the right to distribute this or future versions of
22 # Coccinelle under other licenses.
26 #############################################################################
27 # Configuration section
28 #############################################################################
30 -include Makefile.libs
31 -include Makefile.config
32 -include /etc
/lsb-release
34 VERSION
=$(shell cat .
/version
)
35 CCVERSION
=$(shell cat scripts
/coccicheck
/README |grep
"Coccicheck version" |perl
-p
-e
's/.*version (.*)[ ]*/$$1/;')
36 PKGVERSION
=$(shell dpkg-parsechangelog
-ldebian
/changelog.
$(DISTRIB_CODENAME
) 2> /dev
/null \
37 | sed
-n
's/^Version: \(.*\)/\1/p' )
39 ##############################################################################
41 ##############################################################################
46 SRC
=flag_cocci.ml cocci.ml testing.ml
test.ml
$(LEXER_SOURCES
:.mll
=.ml
) main.ml
48 ifeq ($(FEATURE_PYTHON
),1)
50 # the following is essential for Coccinelle to compile under gentoo (weird)
51 #OPTLIBFLAGS=-cclib dllpycaml_stubs.so
57 ifeq ("$(SEXPDIR)","ocamlsexp")
58 SEXPLIB
=ocamlsexp
/sexplib.cmo
59 OPTSEXPLIB
=sexplib.cmx
62 OPTSEXPLIB
=sexplib.cmxa
65 ifeq ("$(DYNLINK)","no")
78 SEXPSYSCMA
=bigarray.cma nums.cma
80 SYSLIBS
=str.cma unix.cma
$(SEXPSYSCMA
) $(DYNLINK
) $(PCRELIB
) # threads.cma
81 LIBS
=commons
/commons.cma \
82 commons
/commons_sexp.cma \
85 parsing_cocci
/cocci_parser.cma parsing_c
/parsing_c.cma \
86 engine
/cocciengine.cma popl09
/popl.cma \
87 extra
/extra.cma python
/coccipython.cma ocaml
/cocciocaml.cma
89 # Should we use the local version of pycaml
90 ifeq ($(FEATURE_PYTHON
),1)
91 ifeq ("$(PYCAMLDIR)","pycaml")
98 # Should we use the local version of menhirLib
99 ifeq ("$(MENHIRDIR)","menhirlib")
100 LOCALMENHIR
=menhirlib
105 # Should we use the local version of ocamlsexp
106 ifeq ("$(SEXPDIR)","ocamlsexp")
112 # used for depend: and a little for rec & rec.opt
113 MAKESUBDIRS
=$(LOCALSEXP
) commons \
114 globals
$(LOCALMENHIR
) ctl parsing_cocci parsing_c \
115 engine popl09 extra python ocaml \
119 # It is like MAKESUBDIRS but also
120 # force cleaning of local library copies
121 CLEANSUBDIRS
=pycaml ocamlsexp commons \
122 globals menhirlib ctl parsing_cocci parsing_c \
123 engine popl09 extra python ocaml \
126 INCLUDEDIRSDEP
=commons commons
/ocamlextra
$(LOCALSEXP
) \
127 globals
$(LOCALMENHIR
) $(LOCALPYCAML
) ctl \
128 parsing_cocci parsing_c engine popl09 extra python ocaml \
131 INCLUDEDIRS
=$(INCLUDEDIRSDEP
) $(SEXPDIR
) $(MENHIRDIR
) $(PYCAMLDIR
) $(PCREDIR
) $(INCLIBS
)
134 LINKFLAGS
=$(EXTRALINKS
:%=-cclib
-l
%)
136 ##############################################################################
138 ##############################################################################
140 INCLUDES
=$(INCLUDEDIRS
:%=-I
%)
142 OBJS
= $(SRC
:.ml
=.cmo
)
143 OPTOBJS
= $(SRC
:.ml
=.cmx
)
147 ##############################################################################
148 # Generic ocaml variables
149 ##############################################################################
153 # for profiling add -p -inline 0
154 # but 'make forprofiling' below does that for you.
155 # This flag is also used in subdirectories so don't change its name here.
156 # To enable backtrace support for native code, you need to put -g in OPTFLAGS
157 # to also link with -g.
160 OCAMLC
=ocamlc
$(OPTBIN
) $(OCAMLCFLAGS
) $(LINKFLAGS
) $(INCLUDES
)
161 OCAMLOPT
=ocamlopt
$(OPTBIN
) $(OPTFLAGS
) $(LINKFLAGS
) $(INCLUDES
)
162 OCAMLLEX
=ocamllex
#-ml # -ml for debugging lexer, but slightly slower
163 OCAMLYACC
=ocamlyacc
-v
164 OCAMLDEP
=ocamldep
$(INCLUDEDIRSDEP
:%=-I
%)
165 OCAMLMKTOP
=ocamlmktop
-g
-custom
$(INCLUDES
)
167 # can also be set via 'make static'
168 CFLAGS
=-pie
-fPIE
-fpic
-fPIC
-static
169 STATICCFLAGS
=$(CFLAGS
:%=-ccopt
%)
170 STATIC
= # $(STATICCFLAGS)
172 # can also be unset via 'make purebytecode'
173 BYTECODE_STATIC
=-custom
175 ##############################################################################
177 ##############################################################################
178 .PHONY
:: all all.opt byte opt top
clean distclean configure
179 .PHONY
:: $(MAKESUBDIRS
) $(MAKESUBDIRS
:%=%.opt
) subdirs subdirs.opt
181 all: Makefile.config byte preinstall
183 opt
all.opt
: opt-compil preinstall
200 +for D in
$(MAKESUBDIRS
); do
$(MAKE
) $$D || exit
1 ; done
201 $(MAKE
) -C commons sexp OCAMLCFLAGS
="$(OCAMLCFLAGS)"
204 +for D in
$(MAKESUBDIRS
); do
$(MAKE
) $$D.opt || exit
1 ; done
205 $(MAKE
) -C commons sexp.opt OPTFLAGS
="$(OPTFLAGS)"
208 $(MAKE
) -C
$@ OCAMLCFLAGS
="$(OCAMLCFLAGS)" all
210 $(MAKESUBDIRS
:%=%.opt
):
211 $(MAKE
) -C
$(@
:%.opt
=%) OPTFLAGS
="$(OPTFLAGS)" all.opt
217 # parsing_cocci: commons globals menhirlib
218 # parsing_c:parsing_cocci
219 # ctl:globals commons
220 # engine: parsing_cocci parsing_c ctl
222 # extra: parsing_cocci parsing_c ctl
224 # python:pycaml parsing_cocci parsing_c
227 set
-e
; for i in
$(CLEANSUBDIRS
); do
$(MAKE
) -C
$$i $@
; done
228 $(MAKE
) -C demos
/spp
$@
230 $(LIBS
): $(MAKESUBDIRS
)
231 $(LIBS
:.cma
=.cmxa
): $(MAKESUBDIRS
:%=%.opt
)
232 $(LNKLIBS
) : $(MAKESUBDIRS
)
233 $(LNKOPTLIBS
) : $(MAKESUBDIRS
:%=%.opt
)
235 $(OBJS
):$(LIBS
) $(LNKLIBS
)
236 $(OPTOBJS
):$(LIBS
:.cma
=.cmxa
) $(LNKOPTLIBS
)
238 $(EXEC
): $(LIBS
) $(OBJS
)
239 $(OCAMLC
) $(BYTECODE_STATIC
) -o
$@
$(SYSLIBS
) $(SEXPLIB
) $(LNKLIBS
) $^
241 $(EXEC
).opt
: $(LIBS
:.cma
=.cmxa
) $(OPTOBJS
)
242 $(OCAMLOPT
) $(STATIC
) -o
$@
$(SYSLIBS
:.cma
=.cmxa
) $(OPTSEXPLIB
) $(OPTLIBFLAGS
) $(FLAGSLIB
) $(OPTLNKLIBS
) $^
244 $(EXEC
).top
: $(LIBS
) $(OBJS
) $(LNKLIBS
)
245 $(OCAMLMKTOP
) -custom
-o
$@
$(SYSLIBS
) $(SEXPLIB
) $(LNKLIBS
) $^
248 rm -f
$(TARGET
) $(TARGET
).opt
$(TARGET
).top
250 .PHONY
:: tools configure
256 @echo
"Makefile.config is missing. Have you run ./configure?"
259 tools
: $(LIBS
) $(LNKLIBS
)
263 if
[ -d tools
] ; then
$(MAKE
) -C tools
distclean ; fi
266 rm -f spatch.opt spatch
267 $(MAKE
) STATIC
="$(STATICCFLAGS)" spatch.opt
271 rm -f spatch.opt spatch
272 $(MAKE
) BYTECODE_STATIC
="" spatch
273 perl
-p
-i
-e
's/^#!.*/#!\/usr\/bin\/ocamlrun/' spatch
276 ##############################################################################
277 # Build documentation
278 ##############################################################################
283 if
[ -x
"$(TARGET)" -o
-x
"$(TARGET).opt" ]; \
284 then
$(MAKE
) -C ocaml doc
; fi
287 $(MAKE
) -C docs
clean
288 $(MAKE
) -C ocaml cleandoc
291 $(MAKE
) -C docs
distclean
293 ##############################################################################
294 # Pre-Install (customization of spatch frontend script)
295 ##############################################################################
297 preinstall
: docs
/spatch
.1 scripts
/spatch scripts
/spatch.opt scripts
/spatch.byte
299 docs
/spatch
.1: Makefile.config
300 $(MAKE
) -C docs spatch
.1
302 # user will use spatch to run spatch.opt (native)
303 scripts
/spatch
: Makefile.config
304 cp scripts
/spatch.sh scripts
/spatch.tmp2
305 sed
"s|SHAREDIR|$(SHAREDIR)|g" scripts
/spatch.tmp2
> scripts
/spatch.tmp
306 sed
"s|LIBDIR|$(LIBDIR)|g" scripts
/spatch.tmp
> scripts
/spatch
307 rm -f scripts
/spatch.tmp2 scripts
/spatch.tmp
309 # user will use spatch to run spatch (bytecode)
310 scripts
/spatch.byte
: Makefile.config
311 cp scripts
/spatch.sh scripts
/spatch.byte.tmp3
312 sed
"s|\.opt||" scripts
/spatch.byte.tmp3
> scripts
/spatch.byte.tmp2
313 sed
"s|SHAREDIR|$(SHAREDIR)|g" scripts
/spatch.byte.tmp2 \
314 > scripts
/spatch.byte.tmp
315 sed
"s|LIBDIR|$(LIBDIR)|g" scripts
/spatch.byte.tmp \
316 > scripts
/spatch.byte
317 rm -f scripts
/spatch.byte.tmp3 \
318 scripts
/spatch.byte.tmp2 \
319 scripts
/spatch.byte.tmp
321 # user will use spatch.opt to run spatch.opt (native)
322 scripts
/spatch.opt
: Makefile.config
323 cp scripts
/spatch.sh scripts
/spatch.opt.tmp2
324 sed
"s|SHAREDIR|$(SHAREDIR)|g" scripts
/spatch.opt.tmp2 \
325 > scripts
/spatch.opt.tmp
326 sed
"s|LIBDIR|$(LIBDIR)|g" scripts
/spatch.opt.tmp \
328 rm -f scripts
/spatch.opt.tmp scripts
/spatch.opt.tmp2
331 rm -f scripts
/spatch scripts
/spatch.byte scripts
/spatch.opt
333 ##############################################################################
335 ##############################################################################
337 # don't remove DESTDIR, it can be set by package build system like ebuild
338 # for staged installation.
340 mkdir
-p
$(DESTDIR
)$(BINDIR
)
341 mkdir
-p
$(DESTDIR
)$(LIBDIR
)
342 mkdir
-p
$(DESTDIR
)$(SHAREDIR
)/ocaml
343 mkdir
-p
$(DESTDIR
)$(SHAREDIR
)/commons
344 mkdir
-p
$(DESTDIR
)$(SHAREDIR
)/globals
345 mkdir
-p
$(DESTDIR
)$(SHAREDIR
)/parsing_c
346 $(INSTALL_DATA
) standard.h
$(DESTDIR
)$(SHAREDIR
)
347 $(INSTALL_DATA
) standard.iso
$(DESTDIR
)$(SHAREDIR
)
348 $(INSTALL_DATA
) ocaml
/coccilib.cmi
$(DESTDIR
)$(SHAREDIR
)/ocaml
/
349 $(INSTALL_DATA
) parsing_c
/*.cmi
$(DESTDIR
)$(SHAREDIR
)/parsing_c
/
350 $(INSTALL_DATA
) commons
/*.cmi
$(DESTDIR
)$(SHAREDIR
)/commons
/
351 $(INSTALL_DATA
) globals
/iteration.cmi
$(DESTDIR
)$(SHAREDIR
)/globals
/
352 @if
[ $(FEATURE_PYTHON
) -eq
1 ]; then
$(MAKE
) install-python
; fi
355 mkdir
-p
$(DESTDIR
)$(MANDIR
)/man1
356 mkdir
-p
$(DESTDIR
)$(MANDIR
)/man3
357 $(INSTALL_DATA
) docs
/spatch
.1 $(DESTDIR
)$(MANDIR
)/man1
/
358 $(INSTALL_DATA
) docs
/Coccilib
.3cocci
$(DESTDIR
)$(MANDIR
)/man3
/
361 mkdir
-p
$(DESTDIR
)$(BASH_COMPLETION_DIR
)
362 $(INSTALL_DATA
) scripts
/spatch.bash_completion \
363 $(DESTDIR
)$(BASH_COMPLETION_DIR
)/spatch
366 mkdir
-p
$(DESTDIR
)$(BINDIR
)
367 $(INSTALL_PROGRAM
) tools
/splitpatch \
368 $(DESTDIR
)$(BINDIR
)/splitpatch
369 $(INSTALL_PROGRAM
) tools
/cocci-send-email.perl \
370 $(DESTDIR
)$(BINDIR
)/cocci-send-email.perl
373 mkdir
-p
$(DESTDIR
)$(SHAREDIR
)/python
/coccilib
/coccigui
374 $(INSTALL_DATA
) python
/coccilib
/*.py \
375 $(DESTDIR
)$(SHAREDIR
)/python
/coccilib
376 $(INSTALL_DATA
) python
/coccilib
/coccigui
/*.py \
377 $(DESTDIR
)$(SHAREDIR
)/python
/coccilib
/coccigui
378 $(INSTALL_DATA
) python
/coccilib
/coccigui
/pygui.glade \
379 $(DESTDIR
)$(SHAREDIR
)/python
/coccilib
/coccigui
380 $(INSTALL_DATA
) python
/coccilib
/coccigui
/pygui.gladep \
381 $(DESTDIR
)$(SHAREDIR
)/python
/coccilib
/coccigui
382 if
[ -f pycaml
/dllpycaml_stubs.so
]; then \
383 $(INSTALL_LIB
) pycaml
/dllpycaml_stubs.so
$(DESTDIR
)$(LIBDIR
) ; fi
385 install: install-man install-common
386 @if
test -x spatch
-a
! -x spatch.opt
; then \
387 $(MAKE
) install-byte
;fi
388 @if
test ! -x spatch
-a
-x spatch.opt
; then \
389 $(MAKE
) install-def
; $(MAKE
) install-opt
;fi
390 @if
test -x spatch
-a
-x spatch.opt
; then \
391 $(MAKE
) install-byte
; $(MAKE
) install-opt
;fi
392 @if
test ! -x spatch
-a
! -x spatch.opt
; then \
393 echo
"\n\n\t==> Run 'make', 'make opt', or both first. <==\n\n";fi
395 @echo
"\tYou can also install spatch by copying the program spatch"
396 @echo
"\t(available in this directory) anywhere you want and"
397 @echo
"\tgive it the right options to find its configuration files."
400 # user will use spatch to run spatch.opt (native)
402 $(INSTALL_PROGRAM
) spatch.opt
$(DESTDIR
)$(SHAREDIR
)
403 $(INSTALL_PROGRAM
) scripts
/spatch
$(DESTDIR
)$(BINDIR
)/spatch
405 # user will use spatch to run spatch (bytecode)
407 $(INSTALL_PROGRAM
) spatch
$(DESTDIR
)$(SHAREDIR
)
408 $(INSTALL_PROGRAM
) scripts
/spatch.byte
$(DESTDIR
)$(BINDIR
)/spatch
410 # user will use spatch.opt to run spatch.opt (native)
412 $(INSTALL_PROGRAM
) spatch.opt
$(DESTDIR
)$(SHAREDIR
)
413 $(INSTALL_PROGRAM
) scripts
/spatch.opt
$(DESTDIR
)$(BINDIR
)/spatch.opt
416 rm -f
$(DESTDIR
)$(BINDIR
)/spatch
417 rm -f
$(DESTDIR
)$(BINDIR
)/spatch.opt
418 rm -f
$(DESTDIR
)$(LIBDIR
)/dllpycaml_stubs.so
419 rm -f
$(DESTDIR
)$(SHAREDIR
)/spatch
420 rm -f
$(DESTDIR
)$(SHAREDIR
)/spatch.opt
421 rm -f
$(DESTDIR
)$(SHAREDIR
)/standard.h
422 rm -f
$(DESTDIR
)$(SHAREDIR
)/standard.iso
423 rm -f
$(DESTDIR
)$(SHAREDIR
)/ocaml
/coccilib.cmi
424 rm -f
$(DESTDIR
)$(SHAREDIR
)/parsing_c
/*.cmi
425 rm -f
$(DESTDIR
)$(SHAREDIR
)/commons
/*.cmi
426 rm -f
$(DESTDIR
)$(SHAREDIR
)/globals
/*.cmi
427 rm -f
$(DESTDIR
)$(SHAREDIR
)/python
/coccilib
/coccigui
/*
428 rm -f
$(DESTDIR
)$(SHAREDIR
)/python
/coccilib
/*.py
429 rmdir
--ignore-fail-on-non-empty
-p \
430 $(DESTDIR
)$(SHAREDIR
)/python
/coccilib
/coccigui
431 rmdir
$(DESTDIR
)$(SHAREDIR
)/globals
432 rmdir
$(DESTDIR
)$(SHAREDIR
)/commons
433 rmdir
$(DESTDIR
)$(SHAREDIR
)/parsing_c
434 rmdir
$(DESTDIR
)$(SHAREDIR
)/ocaml
435 rmdir
$(DESTDIR
)$(SHAREDIR
)
436 rm -f
$(DESTDIR
)$(MANDIR
)/man1
/spatch
.1
437 rm -f
$(DESTDIR
)$(MANDIR
)/man3
/Coccilib
.3cocci
440 rm -f
$(DESTDIR
)$(BASH_COMPLETION_DIR
)/spatch
441 rmdir
--ignore-fail-on-non-empty
-p \
442 $(DESTDIR
)$(BASH_COMPLETION_DIR
)
445 rm -f
$(DESTDIR
)$(BINDIR
)/splitpatch
446 rm -f
$(DESTDIR
)$(BINDIR
)/cocci-send-email.perl
449 @echo
"spatch $(VERSION)"
450 @echo
"spatch $(PKGVERSION) ($(DISTRIB_ID))"
451 @echo
"coccicheck $(CCVERSION)"
454 ##############################################################################
455 # Deb package (for Ubuntu) and release rules
456 ##############################################################################
458 include Makefile.release
460 ##############################################################################
462 ##############################################################################
464 -include Makefile.dev
470 .
/$(TARGET
) -D standard.h
-parse_c
-dir tests
/
474 # -inline 0 to see all the functions in the profile.
475 # Can also use the profile framework in commons/ and run your program
478 $(MAKE
) OPTFLAGS
="-p -inline 0 " opt
484 otags
-no-mli-tags
-r .
487 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
488 ocamldot
-lr
/tmp
/dependfull.depend
> /tmp
/dependfull.dot
489 dot
-Tps
/tmp
/dependfull.dot
> /tmp
/dependfull.ps
490 ps2pdf
/tmp
/dependfull.ps
/tmp
/dependfull.pdf
492 ##############################################################################
494 ##############################################################################
496 # each member of the project can have its own test.ml. this file is
499 echo
"let foo_ctl () = failwith \"there is no foo_ctl formula\"" \
502 beforedepend
:: test.ml
505 #INC=$(dir $(shell which ocaml))
508 #INCZ=$(INCY:/=)/lib/ocaml
511 # gcc -c -o prim.o -I $(INCZ) prim.c
514 ##############################################################################
515 # Generic ocaml rules
516 ##############################################################################
518 .SUFFIXES
: .ml .mli .cmo .cmi .cmx
530 $(LEXER_SOURCES
:.mll
=.ml
) : $(LEXER_SOURCES
)
531 $(OCAMLLEX
) $(LEXER_SOURCES
)
534 rm -f
*.cm
[iox
] *.o
*.annot
535 rm -f
*~ .
*~
*.exe
#*#
538 set
-e
; for i in
$(MAKESUBDIRS
); do
$(MAKE
) -C
$$i $@
; done
540 rm -f Makefile.config
541 rm -f globals
/config.ml
test.ml
543 rm -f tests
/SCORE_actual.sexp
544 rm -f tests
/SCORE_best_of_both.sexp
545 find .
-name
".#*1.*" | xargs
rm -f
549 depend
:: beforedepend
550 $(OCAMLDEP
) *.mli
*.ml
> .depend
551 set
-e
; for i in
$(MAKESUBDIRS
); do
$(MAKE
) -C
$$i $@
; done
554 @if
[ ! -f .depend
] ; then
$(MAKE
) depend
; fi