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 ##############################################################################
42 SRC
=flag_cocci.ml cocci.ml testing.ml
test.ml main.ml
44 ifeq ($(FEATURE_PYTHON
),1)
46 # the following is essential for Coccinelle to compile under gentoo (weird)
47 #OPTLIBFLAGS=-cclib dllpycaml_stubs.so
53 ifeq ("$(SEXPDIR)","ocamlsexp")
55 OPTSEXPLIB
=sexplib.cmx
58 OPTSEXPLIB
=sexplib.cmxa
61 ifeq ("$(DYNLINK)","no")
67 SEXPSYSCMA
=bigarray.cma nums.cma
69 SYSLIBS
=str.cma unix.cma
$(SEXPSYSCMA
) $(PYCMA
) $(DYNLINK
) # threads.cma
70 LIBS
=commons
/commons.cma \
71 commons
/commons_sexp.cma \
74 parsing_cocci
/cocci_parser.cma parsing_c
/parsing_c.cma \
75 engine
/cocciengine.cma popl09
/popl.cma \
76 extra
/extra.cma python
/coccipython.cma ocaml
/cocciocaml.cma
78 # Should we use the local version of pycaml
79 ifeq ("$(PYCAMLDIR)","pycaml")
85 # Should we use the local version of menhirLib
86 ifeq ("$(MENHIRDIR)","menhirlib")
92 # Should we use the local version of ocamlsexp
93 ifeq ("$(SEXPDIR)","ocamlsexp")
99 # used for depend: and a little for rec & rec.opt
100 MAKESUBDIRS
=$(LOCALPYCAML
) $(LOCALSEXP
) commons \
101 globals
$(LOCALMENHIR
) ctl parsing_cocci parsing_c \
102 engine popl09 extra python ocaml
105 # It is like MAKESUBDIRS but also
106 # force cleaning of local library copies
107 CLEANSUBDIRS
=pycaml ocamlsexp commons \
108 globals menhirlib ctl parsing_cocci parsing_c \
109 engine popl09 extra python ocaml
111 INCLUDEDIRSDEP
=commons commons
/ocamlextra
$(LOCALSEXP
) \
112 globals
$(LOCALMENHIR
) $(LOCALPYCAML
) ctl \
113 parsing_cocci parsing_c engine popl09 extra python ocaml
115 INCLUDEDIRS
=$(INCLUDEDIRSDEP
) $(SEXPDIR
) $(MENHIRDIR
) $(PYCAMLDIR
)
117 ##############################################################################
119 ##############################################################################
121 INCLUDES
=$(INCLUDEDIRS
:%=-I
%)
123 OBJS
= $(SRC
:.ml
=.cmo
)
124 OPTOBJS
= $(SRC
:.ml
=.cmx
)
128 ##############################################################################
129 # Generic ocaml variables
130 ##############################################################################
134 # for profiling add -p -inline 0
135 # but 'make forprofiling' below does that for you.
136 # This flag is also used in subdirectories so don't change its name here.
137 # To enable backtrace support for native code, you need to put -g in OPTFLAGS
138 # to also link with -g.
141 OCAMLC
=ocamlc
$(OPTBIN
) $(OCAMLCFLAGS
) $(INCLUDES
)
142 OCAMLOPT
=ocamlopt
$(OPTBIN
) $(OPTFLAGS
) $(INCLUDES
)
143 OCAMLLEX
=ocamllex
#-ml # -ml for debugging lexer, but slightly slower
144 OCAMLYACC
=ocamlyacc
-v
145 OCAMLDEP
=ocamldep
$(INCLUDEDIRSDEP
:%=-I
%)
146 OCAMLMKTOP
=ocamlmktop
-g
-custom
$(INCLUDES
)
148 # can also be set via 'make static'
149 STATIC
= #-ccopt -static
151 # can also be unset via 'make purebytecode'
152 BYTECODE_STATIC
=-custom
154 ##############################################################################
156 ##############################################################################
157 .PHONY
:: all all.opt byte opt top
clean distclean configure
158 .PHONY
:: $(MAKESUBDIRS
) $(MAKESUBDIRS
:%=%.opt
) subdirs subdirs.opt
160 all: Makefile.config byte preinstall
163 all.opt
: opt-compil preinstall
180 +for D in
$(MAKESUBDIRS
); do
$(MAKE
) $$D || exit
1 ; done
181 $(MAKE
) -C commons sexp OCAMLCFLAGS
="$(OCAMLCFLAGS)"
184 +for D in
$(MAKESUBDIRS
); do
$(MAKE
) $$D.opt || exit
1 ; done
185 $(MAKE
) -C commons sexp.opt OPTFLAGS
="$(OPTFLAGS)"
188 $(MAKE
) -C
$@ OCAMLCFLAGS
="$(OCAMLCFLAGS)" all
190 $(MAKESUBDIRS
:%=%.opt
):
191 $(MAKE
) -C
$(@
:%.opt
=%) OPTFLAGS
="$(OPTFLAGS)" all.opt
197 # parsing_cocci: commons globals menhirlib
198 # parsing_c:parsing_cocci
199 # ctl:globals commons
200 # engine: parsing_cocci parsing_c ctl
202 # extra: parsing_cocci parsing_c ctl
204 # python:pycaml parsing_cocci parsing_c
207 set
-e
; for i in
$(CLEANSUBDIRS
); do
$(MAKE
) -C
$$i $@
; done
208 $(MAKE
) -C demos
/spp
$@
210 $(LIBS
): $(MAKESUBDIRS
)
211 $(LIBS
:.cma
=.cmxa
): $(MAKESUBDIRS
:%=%.opt
)
214 $(OPTOBJS
):$(LIBS
:.cma
=.cmxa
)
216 $(EXEC
): $(LIBS
) $(OBJS
)
217 $(OCAMLC
) $(BYTECODE_STATIC
) -o
$@
$(SYSLIBS
) $(SEXPLIB
) $^
219 $(EXEC
).opt
: $(LIBS
:.cma
=.cmxa
) $(OPTOBJS
)
220 $(OCAMLOPT
) $(STATIC
) -o
$@
$(SYSLIBS
:.cma
=.cmxa
) $(OPTSEXPLIB
) $(OPTLIBFLAGS
) $^
222 $(EXEC
).top
: $(LIBS
) $(OBJS
)
223 $(OCAMLMKTOP
) -custom
-o
$@
$(SYSLIBS
) $(SEXPLIB
) $^
226 rm -f
$(TARGET
) $(TARGET
).opt
$(TARGET
).top
228 .PHONY
:: tools configure
234 @echo
"Makefile.config is missing. Have you run ./configure?"
241 if
[ -d tools
] ; then
$(MAKE
) -C tools
distclean ; fi
244 rm -f spatch.opt spatch
245 $(MAKE
) STATIC
="-ccopt -static" spatch.opt
249 rm -f spatch.opt spatch
250 $(MAKE
) BYTECODE_STATIC
="" spatch
251 perl
-p
-i
-e
's/^#!.*/#!\/usr\/bin\/ocamlrun/' spatch
254 ##############################################################################
255 # Build documentation
256 ##############################################################################
266 make
-C docs
distclean
268 ##############################################################################
269 # Pre-Install (customization of spatch frontend script)
270 ##############################################################################
272 preinstall
: docs
/spatch
.1 scripts
/spatch scripts
/spatch.opt scripts
/spatch.byte
274 docs
/spatch
.1: Makefile.config
275 $(MAKE
) -C docs spatch
.1
277 # user will use spatch to run spatch.opt (native)
278 scripts
/spatch
: Makefile.config
279 cp scripts
/spatch.sh scripts
/spatch.tmp2
280 sed
"s|SHAREDIR|$(SHAREDIR)|g" scripts
/spatch.tmp2
> scripts
/spatch.tmp
281 sed
"s|LIBDIR|$(LIBDIR)|g" scripts
/spatch.tmp
> scripts
/spatch
282 rm -f scripts
/spatch.tmp2 scripts
/spatch.tmp
284 # user will use spatch to run spatch (bytecode)
285 scripts
/spatch.byte
: Makefile.config
286 cp scripts
/spatch.sh scripts
/spatch.byte.tmp3
287 sed
"s|\.opt||" scripts
/spatch.byte.tmp3
> scripts
/spatch.byte.tmp2
288 sed
"s|SHAREDIR|$(SHAREDIR)|g" scripts
/spatch.byte.tmp2 \
289 > scripts
/spatch.byte.tmp
290 sed
"s|LIBDIR|$(LIBDIR)|g" scripts
/spatch.byte.tmp \
291 > scripts
/spatch.byte
292 rm -f scripts
/spatch.byte.tmp3 \
293 scripts
/spatch.byte.tmp2 \
294 scripts
/spatch.byte.tmp
296 # user will use spatch.opt to run spatch.opt (native)
297 scripts
/spatch.opt
: Makefile.config
298 cp scripts
/spatch.sh scripts
/spatch.opt.tmp2
299 sed
"s|SHAREDIR|$(SHAREDIR)|g" scripts
/spatch.opt.tmp2 \
300 > scripts
/spatch.opt.tmp
301 sed
"s|LIBDIR|$(LIBDIR)|g" scripts
/spatch.opt.tmp \
303 rm -f scripts
/spatch.opt.tmp scripts
/spatch.opt.tmp2
306 rm -f scripts
/spatch scripts
/spatch.byte scripts
/spatch.opt
308 ##############################################################################
310 ##############################################################################
312 # don't remove DESTDIR, it can be set by package build system like ebuild
313 # for staged installation.
315 mkdir
-p
$(DESTDIR
)$(BINDIR
)
316 mkdir
-p
$(DESTDIR
)$(LIBDIR
)
317 mkdir
-p
$(DESTDIR
)$(SHAREDIR
)/ocaml
318 mkdir
-p
$(DESTDIR
)$(SHAREDIR
)/commons
319 mkdir
-p
$(DESTDIR
)$(SHAREDIR
)/globals
320 mkdir
-p
$(DESTDIR
)$(SHAREDIR
)/parsing_c
321 mkdir
-p
$(DESTDIR
)$(MANDIR
)/man1
322 $(INSTALL_DATA
) standard.h
$(DESTDIR
)$(SHAREDIR
)
323 $(INSTALL_DATA
) standard.iso
$(DESTDIR
)$(SHAREDIR
)
324 $(INSTALL_DATA
) ocaml
/coccilib.cmi
$(DESTDIR
)$(SHAREDIR
)/ocaml
/
325 $(INSTALL_DATA
) parsing_c
/*.cmi
$(DESTDIR
)$(SHAREDIR
)/parsing_c
/
326 $(INSTALL_DATA
) commons
/*.cmi
$(DESTDIR
)$(SHAREDIR
)/commons
/
327 $(INSTALL_DATA
) globals
/iteration.cmi
$(DESTDIR
)$(SHAREDIR
)/globals
/
328 $(INSTALL_DATA
) docs
/spatch
.1 $(DESTDIR
)$(MANDIR
)/man1
/
329 @if
[ $(FEATURE_PYTHON
) -eq
1 ]; then
$(MAKE
) install-python
; fi
332 mkdir
-p
$(DESTDIR
)$(BASH_COMPLETION_DIR
)
333 $(INSTALL_DATA
) scripts
/spatch.bash_completion \
334 $(DESTDIR
)$(BASH_COMPLETION_DIR
)/spatch
337 mkdir
-p
$(DESTDIR
)$(BINDIR
)
338 $(INSTALL_PROGRAM
) tools
/splitpatch \
339 $(DESTDIR
)$(BINDIR
)/splitpatch
340 $(INSTALL_PROGRAM
) tools
/cocci-send-email.perl \
341 $(DESTDIR
)$(BINDIR
)/cocci-send-email.perl
344 mkdir
-p
$(DESTDIR
)$(SHAREDIR
)/python
/coccilib
/coccigui
345 $(INSTALL_DATA
) python
/coccilib
/*.py \
346 $(DESTDIR
)$(SHAREDIR
)/python
/coccilib
347 $(INSTALL_DATA
) python
/coccilib
/coccigui
/*.py \
348 $(DESTDIR
)$(SHAREDIR
)/python
/coccilib
/coccigui
349 $(INSTALL_DATA
) python
/coccilib
/coccigui
/pygui.glade \
350 $(DESTDIR
)$(SHAREDIR
)/python
/coccilib
/coccigui
351 $(INSTALL_DATA
) python
/coccilib
/coccigui
/pygui.gladep \
352 $(DESTDIR
)$(SHAREDIR
)/python
/coccilib
/coccigui
353 if
[ -f pycaml
/dllpycaml_stubs.so
]; then \
354 $(INSTALL_LIB
) pycaml
/dllpycaml_stubs.so
$(DESTDIR
)$(LIBDIR
) ; fi
356 install: install-common
357 @if
test -x spatch
-a
! -x spatch.opt
; then \
358 $(MAKE
) install-byte
;fi
359 @if
test ! -x spatch
-a
-x spatch.opt
; then \
360 $(MAKE
) install-def
; $(MAKE
) install-opt
;fi
361 @if
test -x spatch
-a
-x spatch.opt
; then \
362 $(MAKE
) install-byte
; $(MAKE
) install-opt
;fi
363 @if
test ! -x spatch
-a
! -x spatch.opt
; then \
364 echo
"\n\n\t==> Run 'make', 'make opt', or both first. <==\n\n";fi
366 @echo
"\tYou can also install spatch by copying the program spatch"
367 @echo
"\t(available in this directory) anywhere you want and"
368 @echo
"\tgive it the right options to find its configuration files."
371 # user will use spatch to run spatch.opt (native)
373 $(INSTALL_PROGRAM
) spatch.opt
$(DESTDIR
)$(SHAREDIR
)
374 $(INSTALL_PROGRAM
) scripts
/spatch
$(DESTDIR
)$(BINDIR
)/spatch
376 # user will use spatch to run spatch (bytecode)
378 $(INSTALL_PROGRAM
) spatch
$(DESTDIR
)$(SHAREDIR
)
379 $(INSTALL_PROGRAM
) scripts
/spatch.byte
$(DESTDIR
)$(BINDIR
)/spatch
381 # user will use spatch.opt to run spatch.opt (native)
383 $(INSTALL_PROGRAM
) spatch.opt
$(DESTDIR
)$(SHAREDIR
)
384 $(INSTALL_PROGRAM
) scripts
/spatch.opt
$(DESTDIR
)$(BINDIR
)/spatch.opt
387 rm -f
$(DESTDIR
)$(BINDIR
)/spatch
388 rm -f
$(DESTDIR
)$(BINDIR
)/spatch.opt
389 rm -f
$(DESTDIR
)$(LIBDIR
)/dllpycaml_stubs.so
390 rm -f
$(DESTDIR
)$(SHAREDIR
)/spatch
391 rm -f
$(DESTDIR
)$(SHAREDIR
)/spatch.opt
392 rm -f
$(DESTDIR
)$(SHAREDIR
)/standard.h
393 rm -f
$(DESTDIR
)$(SHAREDIR
)/standard.iso
394 rm -f
$(DESTDIR
)$(SHAREDIR
)/ocaml
/coccilib.cmi
395 rm -f
$(DESTDIR
)$(SHAREDIR
)/parsing_c
/*.cmi
396 rm -f
$(DESTDIR
)$(SHAREDIR
)/commons
/*.cmi
397 rm -f
$(DESTDIR
)$(SHAREDIR
)/globals
/*.cmi
398 rm -f
$(DESTDIR
)$(SHAREDIR
)/python
/coccilib
/coccigui
/*
399 rm -f
$(DESTDIR
)$(SHAREDIR
)/python
/coccilib
/*.py
400 rmdir
--ignore-fail-on-non-empty
-p \
401 $(DESTDIR
)$(SHAREDIR
)/python
/coccilib
/coccigui
402 rmdir
$(DESTDIR
)$(SHAREDIR
)/globals
403 rmdir
$(DESTDIR
)$(SHAREDIR
)/commons
404 rmdir
$(DESTDIR
)$(SHAREDIR
)/parsing_c
405 rmdir
$(DESTDIR
)$(SHAREDIR
)/ocaml
406 rmdir
$(DESTDIR
)$(SHAREDIR
)
407 rm -f
$(DESTDIR
)$(MANDIR
)/man1
/spatch
.1
410 rm -f
$(DESTDIR
)$(BASH_COMPLETION_DIR
)/spatch
411 rmdir
--ignore-fail-on-non-empty
-p \
412 $(DESTDIR
)$(BASH_COMPLETION_DIR
)
415 rm -f
$(DESTDIR
)$(BINDIR
)/splitpatch
416 rm -f
$(DESTDIR
)$(BINDIR
)/cocci-send-email.perl
419 @echo
"spatch $(VERSION)"
420 @echo
"spatch $(PKGVERSION) ($(DISTRIB_ID))"
421 @echo
"coccicheck $(CCVERSION)"
424 ##############################################################################
425 # Deb package (for Ubuntu) and release rules
426 ##############################################################################
428 include Makefile.release
430 ##############################################################################
432 ##############################################################################
434 -include Makefile.dev
440 .
/$(TARGET
) -D standard.h
-parse_c
-dir tests
/
444 # -inline 0 to see all the functions in the profile.
445 # Can also use the profile framework in commons/ and run your program
448 $(MAKE
) OPTFLAGS
="-p -inline 0 " opt
454 otags
-no-mli-tags
-r .
457 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
458 ocamldot
-lr
/tmp
/dependfull.depend
> /tmp
/dependfull.dot
459 dot
-Tps
/tmp
/dependfull.dot
> /tmp
/dependfull.ps
460 ps2pdf
/tmp
/dependfull.ps
/tmp
/dependfull.pdf
462 ##############################################################################
464 ##############################################################################
466 # each member of the project can have its own test.ml. this file is
469 echo
"let foo_ctl () = failwith \"there is no foo_ctl formula\"" \
472 beforedepend
:: test.ml
475 #INC=$(dir $(shell which ocaml))
478 #INCZ=$(INCY:/=)/lib/ocaml
481 # gcc -c -o prim.o -I $(INCZ) prim.c
484 ##############################################################################
485 # Generic ocaml rules
486 ##############################################################################
488 .SUFFIXES
: .ml .mli .cmo .cmi .cmx
501 rm -f
*.cm
[iox
] *.o
*.annot
502 rm -f
*~ .
*~
*.exe
#*#
505 set
-e
; for i in
$(MAKESUBDIRS
); do
$(MAKE
) -C
$$i $@
; done
507 rm -f Makefile.config
508 rm -f globals
/config.ml
510 rm -f tests
/SCORE_actual.sexp
511 rm -f tests
/SCORE_best_of_both.sexp
512 find
-name
".#*1.*" | xargs
rm -f
516 depend
:: beforedepend
517 $(OCAMLDEP
) *.mli
*.ml
> .depend
518 set
-e
; for i in
$(MAKESUBDIRS
); do
$(MAKE
) -C
$$i $@
; done
521 @if
[ ! -f .depend
] ; then
$(MAKE
) depend
; fi