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.
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.
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.
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/>.
19 # The authors reserve the right to distribute this or future versions of
20 # Coccinelle under other licenses.
24 #############################################################################
25 # Configuration section
26 #############################################################################
28 -include Makefile.config
29 -include /etc
/lsb-release
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' )
36 ##############################################################################
38 ##############################################################################
43 SRC
=flag_cocci.ml cocci.ml testing.ml
test.ml
$(LEXER_SOURCES
:.mll
=.ml
) main.ml
45 ifeq ($(FEATURE_PYTHON
),1)
47 # the following is essential for Coccinelle to compile under gentoo (weird)
48 #OPTLIBFLAGS=-cclib dllpycaml_stubs.so
54 ifeq ("$(SEXPDIR)","ocamlsexp")
56 OPTSEXPLIB
=sexplib.cmx
59 OPTSEXPLIB
=sexplib.cmxa
62 ifeq ("$(DYNLINK)","no")
75 SEXPSYSCMA
=bigarray.cma nums.cma
77 SYSLIBS
=str.cma unix.cma
$(SEXPSYSCMA
) $(PYCMA
) $(DYNLINK
) $(PCRELIB
) # threads.cma
78 LIBS
=commons
/commons.cma \
79 commons
/commons_sexp.cma \
82 parsing_cocci
/cocci_parser.cma parsing_c
/parsing_c.cma \
83 engine
/cocciengine.cma popl09
/popl.cma \
84 extra
/extra.cma python
/coccipython.cma ocaml
/cocciocaml.cma
86 # Should we use the local version of pycaml
87 ifeq ($(FEATURE_PYTHON
),1)
88 ifeq ("$(PYCAMLDIR)","pycaml")
95 # Should we use the local version of menhirLib
96 ifeq ("$(MENHIRDIR)","menhirlib")
102 # Should we use the local version of ocamlsexp
103 ifeq ("$(SEXPDIR)","ocamlsexp")
109 # used for depend: and a little for rec & rec.opt
110 MAKESUBDIRS
=$(LOCALPYCAML
) $(LOCALSEXP
) commons \
111 globals
$(LOCALMENHIR
) ctl parsing_cocci parsing_c \
112 engine popl09 extra python ocaml
115 # It is like MAKESUBDIRS but also
116 # force cleaning of local library copies
117 CLEANSUBDIRS
=pycaml ocamlsexp commons \
118 globals menhirlib ctl parsing_cocci parsing_c \
119 engine popl09 extra python ocaml
121 INCLUDEDIRSDEP
=commons commons
/ocamlextra
$(LOCALSEXP
) \
122 globals
$(LOCALMENHIR
) $(LOCALPYCAML
) ctl \
123 parsing_cocci parsing_c engine popl09 extra python ocaml
125 INCLUDEDIRS
=$(INCLUDEDIRSDEP
) $(SEXPDIR
) $(MENHIRDIR
) $(PYCAMLDIR
) $(PCREDIR
)
127 ##############################################################################
129 ##############################################################################
131 INCLUDES
=$(INCLUDEDIRS
:%=-I
%)
133 OBJS
= $(SRC
:.ml
=.cmo
)
134 OPTOBJS
= $(SRC
:.ml
=.cmx
)
138 ##############################################################################
139 # Generic ocaml variables
140 ##############################################################################
144 # for profiling add -p -inline 0
145 # but 'make forprofiling' below does that for you.
146 # This flag is also used in subdirectories so don't change its name here.
147 # To enable backtrace support for native code, you need to put -g in OPTFLAGS
148 # to also link with -g.
151 OCAMLC
=ocamlc
$(OPTBIN
) $(OCAMLCFLAGS
) $(INCLUDES
)
152 OCAMLOPT
=ocamlopt
$(OPTBIN
) $(OPTFLAGS
) $(INCLUDES
)
153 OCAMLLEX
=ocamllex
#-ml # -ml for debugging lexer, but slightly slower
154 OCAMLYACC
=ocamlyacc
-v
155 OCAMLDEP
=ocamldep
$(INCLUDEDIRSDEP
:%=-I
%)
156 OCAMLMKTOP
=ocamlmktop
-g
-custom
$(INCLUDES
)
158 # can also be set via 'make static'
159 CFLAGS
=-pie
-fPIE
-fpic
-fPIC
-static
160 STATICCFLAGS
=$(CFLAGS
:%=-ccopt
%)
161 STATIC
= # $(STATICCFLAGS)
163 # can also be unset via 'make purebytecode'
164 BYTECODE_STATIC
=-custom
166 ##############################################################################
168 ##############################################################################
169 .PHONY
:: all all.opt byte opt top
clean distclean configure
170 .PHONY
:: $(MAKESUBDIRS
) $(MAKESUBDIRS
:%=%.opt
) subdirs subdirs.opt
172 all: Makefile.config byte preinstall
174 opt
all.opt
: opt-compil preinstall
191 +for D in
$(MAKESUBDIRS
); do
$(MAKE
) $$D || exit
1 ; done
192 $(MAKE
) -C commons sexp OCAMLCFLAGS
="$(OCAMLCFLAGS)"
195 +for D in
$(MAKESUBDIRS
); do
$(MAKE
) $$D.opt || exit
1 ; done
196 $(MAKE
) -C commons sexp.opt OPTFLAGS
="$(OPTFLAGS)"
199 $(MAKE
) -C
$@ OCAMLCFLAGS
="$(OCAMLCFLAGS)" all
201 $(MAKESUBDIRS
:%=%.opt
):
202 $(MAKE
) -C
$(@
:%.opt
=%) OPTFLAGS
="$(OPTFLAGS)" all.opt
208 # parsing_cocci: commons globals menhirlib
209 # parsing_c:parsing_cocci
210 # ctl:globals commons
211 # engine: parsing_cocci parsing_c ctl
213 # extra: parsing_cocci parsing_c ctl
215 # python:pycaml parsing_cocci parsing_c
218 set
-e
; for i in
$(CLEANSUBDIRS
); do
$(MAKE
) -C
$$i $@
; done
219 $(MAKE
) -C demos
/spp
$@
221 $(LIBS
): $(MAKESUBDIRS
)
222 $(LIBS
:.cma
=.cmxa
): $(MAKESUBDIRS
:%=%.opt
)
225 $(OPTOBJS
):$(LIBS
:.cma
=.cmxa
)
227 $(EXEC
): $(LIBS
) $(OBJS
)
228 $(OCAMLC
) $(BYTECODE_STATIC
) -o
$@
$(SYSLIBS
) $(SEXPLIB
) $^
230 $(EXEC
).opt
: $(LIBS
:.cma
=.cmxa
) $(OPTOBJS
)
231 $(OCAMLOPT
) $(STATIC
) -o
$@
$(SYSLIBS
:.cma
=.cmxa
) $(OPTSEXPLIB
) $(OPTLIBFLAGS
) $^
233 $(EXEC
).top
: $(LIBS
) $(OBJS
)
234 $(OCAMLMKTOP
) -custom
-o
$@
$(SYSLIBS
) $(SEXPLIB
) $^
237 rm -f
$(TARGET
) $(TARGET
).opt
$(TARGET
).top
239 .PHONY
:: tools configure
245 @echo
"Makefile.config is missing. Have you run ./configure?"
252 if
[ -d tools
] ; then
$(MAKE
) -C tools
distclean ; fi
255 rm -f spatch.opt spatch
256 $(MAKE
) STATIC
="$(STATICCFLAGS)" spatch.opt
260 rm -f spatch.opt spatch
261 $(MAKE
) BYTECODE_STATIC
="" spatch
262 perl
-p
-i
-e
's/^#!.*/#!\/usr\/bin\/ocamlrun/' spatch
265 ##############################################################################
266 # Build documentation
267 ##############################################################################
272 if
[ -x
"$(TARGET)" -o
-x
"$(TARGET).opt" ]; \
273 then
$(MAKE
) -C ocaml doc
; fi
276 $(MAKE
) -C docs
clean
277 $(MAKE
) -C ocaml cleandoc
280 $(MAKE
) -C docs
distclean
282 ##############################################################################
283 # Pre-Install (customization of spatch frontend script)
284 ##############################################################################
286 preinstall
: docs
/spatch
.1 scripts
/spatch scripts
/spatch.opt scripts
/spatch.byte
288 docs
/spatch
.1: Makefile.config
289 $(MAKE
) -C docs spatch
.1
291 # user will use spatch to run spatch.opt (native)
292 scripts
/spatch
: Makefile.config
293 cp scripts
/spatch.sh scripts
/spatch.tmp2
294 sed
"s|SHAREDIR|$(SHAREDIR)|g" scripts
/spatch.tmp2
> scripts
/spatch.tmp
295 sed
"s|LIBDIR|$(LIBDIR)|g" scripts
/spatch.tmp
> scripts
/spatch
296 rm -f scripts
/spatch.tmp2 scripts
/spatch.tmp
298 # user will use spatch to run spatch (bytecode)
299 scripts
/spatch.byte
: Makefile.config
300 cp scripts
/spatch.sh scripts
/spatch.byte.tmp3
301 sed
"s|\.opt||" scripts
/spatch.byte.tmp3
> scripts
/spatch.byte.tmp2
302 sed
"s|SHAREDIR|$(SHAREDIR)|g" scripts
/spatch.byte.tmp2 \
303 > scripts
/spatch.byte.tmp
304 sed
"s|LIBDIR|$(LIBDIR)|g" scripts
/spatch.byte.tmp \
305 > scripts
/spatch.byte
306 rm -f scripts
/spatch.byte.tmp3 \
307 scripts
/spatch.byte.tmp2 \
308 scripts
/spatch.byte.tmp
310 # user will use spatch.opt to run spatch.opt (native)
311 scripts
/spatch.opt
: Makefile.config
312 cp scripts
/spatch.sh scripts
/spatch.opt.tmp2
313 sed
"s|SHAREDIR|$(SHAREDIR)|g" scripts
/spatch.opt.tmp2 \
314 > scripts
/spatch.opt.tmp
315 sed
"s|LIBDIR|$(LIBDIR)|g" scripts
/spatch.opt.tmp \
317 rm -f scripts
/spatch.opt.tmp scripts
/spatch.opt.tmp2
320 rm -f scripts
/spatch scripts
/spatch.byte scripts
/spatch.opt
322 ##############################################################################
324 ##############################################################################
326 # don't remove DESTDIR, it can be set by package build system like ebuild
327 # for staged installation.
329 mkdir
-p
$(DESTDIR
)$(BINDIR
)
330 mkdir
-p
$(DESTDIR
)$(LIBDIR
)
331 mkdir
-p
$(DESTDIR
)$(SHAREDIR
)/ocaml
332 mkdir
-p
$(DESTDIR
)$(SHAREDIR
)/commons
333 mkdir
-p
$(DESTDIR
)$(SHAREDIR
)/globals
334 mkdir
-p
$(DESTDIR
)$(SHAREDIR
)/parsing_c
335 $(INSTALL_DATA
) standard.h
$(DESTDIR
)$(SHAREDIR
)
336 $(INSTALL_DATA
) standard.iso
$(DESTDIR
)$(SHAREDIR
)
337 $(INSTALL_DATA
) ocaml
/coccilib.cmi
$(DESTDIR
)$(SHAREDIR
)/ocaml
/
338 $(INSTALL_DATA
) parsing_c
/*.cmi
$(DESTDIR
)$(SHAREDIR
)/parsing_c
/
339 $(INSTALL_DATA
) commons
/*.cmi
$(DESTDIR
)$(SHAREDIR
)/commons
/
340 $(INSTALL_DATA
) globals
/iteration.cmi
$(DESTDIR
)$(SHAREDIR
)/globals
/
341 @if
[ $(FEATURE_PYTHON
) -eq
1 ]; then
$(MAKE
) install-python
; fi
344 mkdir
-p
$(DESTDIR
)$(MANDIR
)/man1
345 mkdir
-p
$(DESTDIR
)$(MANDIR
)/man3
346 $(INSTALL_DATA
) docs
/spatch
.1 $(DESTDIR
)$(MANDIR
)/man1
/
347 $(INSTALL_DATA
) docs
/Coccilib
.3cocci
$(DESTDIR
)$(MANDIR
)/man3
/
350 mkdir
-p
$(DESTDIR
)$(BASH_COMPLETION_DIR
)
351 $(INSTALL_DATA
) scripts
/spatch.bash_completion \
352 $(DESTDIR
)$(BASH_COMPLETION_DIR
)/spatch
355 mkdir
-p
$(DESTDIR
)$(BINDIR
)
356 $(INSTALL_PROGRAM
) tools
/splitpatch \
357 $(DESTDIR
)$(BINDIR
)/splitpatch
358 $(INSTALL_PROGRAM
) tools
/cocci-send-email.perl \
359 $(DESTDIR
)$(BINDIR
)/cocci-send-email.perl
362 mkdir
-p
$(DESTDIR
)$(SHAREDIR
)/python
/coccilib
/coccigui
363 $(INSTALL_DATA
) python
/coccilib
/*.py \
364 $(DESTDIR
)$(SHAREDIR
)/python
/coccilib
365 $(INSTALL_DATA
) python
/coccilib
/coccigui
/*.py \
366 $(DESTDIR
)$(SHAREDIR
)/python
/coccilib
/coccigui
367 $(INSTALL_DATA
) python
/coccilib
/coccigui
/pygui.glade \
368 $(DESTDIR
)$(SHAREDIR
)/python
/coccilib
/coccigui
369 $(INSTALL_DATA
) python
/coccilib
/coccigui
/pygui.gladep \
370 $(DESTDIR
)$(SHAREDIR
)/python
/coccilib
/coccigui
371 if
[ -f pycaml
/dllpycaml_stubs.so
]; then \
372 $(INSTALL_LIB
) pycaml
/dllpycaml_stubs.so
$(DESTDIR
)$(LIBDIR
) ; fi
374 install: install-man install-common
375 @if
test -x spatch
-a
! -x spatch.opt
; then \
376 $(MAKE
) install-byte
;fi
377 @if
test ! -x spatch
-a
-x spatch.opt
; then \
378 $(MAKE
) install-def
; $(MAKE
) install-opt
;fi
379 @if
test -x spatch
-a
-x spatch.opt
; then \
380 $(MAKE
) install-byte
; $(MAKE
) install-opt
;fi
381 @if
test ! -x spatch
-a
! -x spatch.opt
; then \
382 echo
"\n\n\t==> Run 'make', 'make opt', or both first. <==\n\n";fi
384 @echo
"\tYou can also install spatch by copying the program spatch"
385 @echo
"\t(available in this directory) anywhere you want and"
386 @echo
"\tgive it the right options to find its configuration files."
389 # user will use spatch to run spatch.opt (native)
391 $(INSTALL_PROGRAM
) spatch.opt
$(DESTDIR
)$(SHAREDIR
)
392 $(INSTALL_PROGRAM
) scripts
/spatch
$(DESTDIR
)$(BINDIR
)/spatch
394 # user will use spatch to run spatch (bytecode)
396 $(INSTALL_PROGRAM
) spatch
$(DESTDIR
)$(SHAREDIR
)
397 $(INSTALL_PROGRAM
) scripts
/spatch.byte
$(DESTDIR
)$(BINDIR
)/spatch
399 # user will use spatch.opt to run spatch.opt (native)
401 $(INSTALL_PROGRAM
) spatch.opt
$(DESTDIR
)$(SHAREDIR
)
402 $(INSTALL_PROGRAM
) scripts
/spatch.opt
$(DESTDIR
)$(BINDIR
)/spatch.opt
405 rm -f
$(DESTDIR
)$(BINDIR
)/spatch
406 rm -f
$(DESTDIR
)$(BINDIR
)/spatch.opt
407 rm -f
$(DESTDIR
)$(LIBDIR
)/dllpycaml_stubs.so
408 rm -f
$(DESTDIR
)$(SHAREDIR
)/spatch
409 rm -f
$(DESTDIR
)$(SHAREDIR
)/spatch.opt
410 rm -f
$(DESTDIR
)$(SHAREDIR
)/standard.h
411 rm -f
$(DESTDIR
)$(SHAREDIR
)/standard.iso
412 rm -f
$(DESTDIR
)$(SHAREDIR
)/ocaml
/coccilib.cmi
413 rm -f
$(DESTDIR
)$(SHAREDIR
)/parsing_c
/*.cmi
414 rm -f
$(DESTDIR
)$(SHAREDIR
)/commons
/*.cmi
415 rm -f
$(DESTDIR
)$(SHAREDIR
)/globals
/*.cmi
416 rm -f
$(DESTDIR
)$(SHAREDIR
)/python
/coccilib
/coccigui
/*
417 rm -f
$(DESTDIR
)$(SHAREDIR
)/python
/coccilib
/*.py
418 rmdir
--ignore-fail-on-non-empty
-p \
419 $(DESTDIR
)$(SHAREDIR
)/python
/coccilib
/coccigui
420 rmdir
$(DESTDIR
)$(SHAREDIR
)/globals
421 rmdir
$(DESTDIR
)$(SHAREDIR
)/commons
422 rmdir
$(DESTDIR
)$(SHAREDIR
)/parsing_c
423 rmdir
$(DESTDIR
)$(SHAREDIR
)/ocaml
424 rmdir
$(DESTDIR
)$(SHAREDIR
)
425 rm -f
$(DESTDIR
)$(MANDIR
)/man1
/spatch
.1
426 rm -f
$(DESTDIR
)$(MANDIR
)/man3
/Coccilib
.3cocci
429 rm -f
$(DESTDIR
)$(BASH_COMPLETION_DIR
)/spatch
430 rmdir
--ignore-fail-on-non-empty
-p \
431 $(DESTDIR
)$(BASH_COMPLETION_DIR
)
434 rm -f
$(DESTDIR
)$(BINDIR
)/splitpatch
435 rm -f
$(DESTDIR
)$(BINDIR
)/cocci-send-email.perl
438 @echo
"spatch $(VERSION)"
439 @echo
"spatch $(PKGVERSION) ($(DISTRIB_ID))"
440 @echo
"coccicheck $(CCVERSION)"
443 ##############################################################################
444 # Deb package (for Ubuntu) and release rules
445 ##############################################################################
447 include Makefile.release
449 ##############################################################################
451 ##############################################################################
453 -include Makefile.dev
459 .
/$(TARGET
) -D standard.h
-parse_c
-dir tests
/
463 # -inline 0 to see all the functions in the profile.
464 # Can also use the profile framework in commons/ and run your program
467 $(MAKE
) OPTFLAGS
="-p -inline 0 " opt
473 otags
-no-mli-tags
-r .
476 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
477 ocamldot
-lr
/tmp
/dependfull.depend
> /tmp
/dependfull.dot
478 dot
-Tps
/tmp
/dependfull.dot
> /tmp
/dependfull.ps
479 ps2pdf
/tmp
/dependfull.ps
/tmp
/dependfull.pdf
481 ##############################################################################
483 ##############################################################################
485 # each member of the project can have its own test.ml. this file is
488 echo
"let foo_ctl () = failwith \"there is no foo_ctl formula\"" \
491 beforedepend
:: test.ml
494 #INC=$(dir $(shell which ocaml))
497 #INCZ=$(INCY:/=)/lib/ocaml
500 # gcc -c -o prim.o -I $(INCZ) prim.c
503 ##############################################################################
504 # Generic ocaml rules
505 ##############################################################################
507 .SUFFIXES
: .ml .mli .cmo .cmi .cmx
519 $(LEXER_SOURCES
:.mll
=.ml
) : $(LEXER_SOURCES
)
520 $(OCAMLLEX
) $(LEXER_SOURCES
)
523 rm -f
*.cm
[iox
] *.o
*.annot
524 rm -f
*~ .
*~
*.exe
#*#
527 set
-e
; for i in
$(MAKESUBDIRS
); do
$(MAKE
) -C
$$i $@
; done
529 rm -f Makefile.config
530 rm -f globals
/config.ml
test.ml
532 rm -f tests
/SCORE_actual.sexp
533 rm -f tests
/SCORE_best_of_both.sexp
534 find
-name
".#*1.*" | xargs
rm -f
538 depend
:: beforedepend
539 $(OCAMLDEP
) *.mli
*.ml
> .depend
540 set
-e
; for i in
$(MAKESUBDIRS
); do
$(MAKE
) -C
$$i $@
; done
543 @if
[ ! -f .depend
] ; then
$(MAKE
) depend
; fi