1 # Copyright 2005-2009, Ecole des Mines de Nantes, University of Copenhagen
2 # Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller
3 # This file is part of Coccinelle.
5 # Coccinelle is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, according to version 2 of the License.
9 # Coccinelle is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with Coccinelle. If not, see <http://www.gnu.org/licenses/>.
17 # The authors reserve the right to distribute this or future versions of
18 # Coccinelle under other licenses.
21 #############################################################################
22 # Configuration section
23 #############################################################################
25 -include Makefile.config
27 VERSION
=$(shell cat globals
/config.ml.in |grep version |perl
-p
-e
's/.*"(.*)".*/$$1/;')
29 ##############################################################################
31 ##############################################################################
34 SRC
=flag_cocci.ml cocci.ml testing.ml
test.ml main.ml
36 ifeq ($(FEATURE_PYTHON
),1)
37 PYCMA
=pycaml
/pycaml.cma
39 PYLIB
=dllpycaml_stubs.so
40 # the following is essential for Coccinelle to compile under gentoo (weird)
41 OPTLIBFLAGS
=-cclib dllpycaml_stubs.so
49 SEXPSYSCMA
=bigarray.cma nums.cma
51 SYSLIBS
=str.cma unix.cma
$(SEXPSYSCMA
)
52 LIBS
=commons
/commons.cma \
53 ocamlsexp
/sexplib1.cma commons
/commons_sexp.cma \
56 parsing_cocci
/cocci_parser.cma parsing_c
/parsing_c.cma \
57 engine
/cocciengine.cma \
58 extra
/extra.cma
$(PYCMA
) python
/coccipython.cma
60 #used for clean: and depend: and a little for rec & rec.opt
61 MAKESUBDIRS
=commons ocamlsexp \
62 globals menhirlib
$(PYDIR
) ctl parsing_cocci parsing_c \
64 INCLUDEDIRS
=commons commons
/ocamlextra ocamlsexp \
65 globals menhirlib
$(PYDIR
) ctl \
66 parsing_cocci parsing_c engine extra python
68 ##############################################################################
70 ##############################################################################
72 INCLUDES
=$(INCLUDEDIRS
:%=-I
%)
75 OPTOBJS
= $(SRC
:.ml
=.cmx
)
79 ##############################################################################
80 # Generic ocaml variables
81 ##############################################################################
83 OCAMLCFLAGS
= #-g -dtypes # -w A
85 # for profiling add -p -inline 0
86 # but 'make forprofiling' below does that for you.
87 # This flag is also used in subdirectories so don't change its name here.
88 # To enable backtrace support for native code, you need to put -g in OPTFLAGS
89 # to also link with -g, but even in 3.11 the backtrace support seems buggy so
92 # the following is essential for Coccinelle to compile under gentoo
93 # but is now defined above in this file
94 #OPTLIBFLAGS=-cclib dllpycaml_stubs.so
96 OCAMLC
=ocamlc
$(OPTBIN
) $(OCAMLCFLAGS
) $(INCLUDES
)
97 OCAMLOPT
=ocamlopt
$(OPTBIN
) $(OPTFLAGS
) $(INCLUDES
)
98 OCAMLLEX
=ocamllex
#-ml # -ml for debugging lexer, but slightly slower
99 OCAMLYACC
=ocamlyacc
-v
100 OCAMLDEP
=ocamldep
$(INCLUDES
)
101 OCAMLMKTOP
=ocamlmktop
-g
-custom
$(INCLUDES
)
103 # can also be set via 'make static'
104 STATIC
= #-ccopt -static
106 # can also be unset via 'make purebytecode'
107 BYTECODE_STATIC
=-custom
109 ##############################################################################
111 ##############################################################################
112 .PHONY
:: all all.opt byte opt top
clean distclean configure
113 .PHONY
:: $(MAKESUBDIRS
) $(MAKESUBDIRS
:%=%.opt
) subdirs subdirs.opt
115 all: Makefile.config byte preinstall
118 all.opt
: opt-compil preinstall
135 $(MAKE
) -C commons OCAMLCFLAGS
="$(OCAMLCFLAGS)"
136 $(MAKE
) -C ocamlsexp OCAMLCFLAGS
="$(OCAMLCFLAGS)"
137 $(MAKE
) -C commons sexp OCAMLCFLAGS
="$(OCAMLCFLAGS)"
138 +for D in
$(MAKESUBDIRS
); do
$(MAKE
) $$D || exit
1 ; done
141 $(MAKE
) -C commons
all.opt OCAMLCFLAGS
="$(OCAMLCFLAGS)"
142 $(MAKE
) -C ocamlsexp
all.opt OCAMLCFLAGS
="$(OCAMLCFLAGS)"
143 $(MAKE
) -C commons sexp.opt OCAMLCFLAGS
="$(OCAMLCFLAGS)"
144 +for D in
$(MAKESUBDIRS
); do
$(MAKE
) $$D.opt || exit
1 ; done
147 $(MAKE
) -C
$@ OCAMLCFLAGS
="$(OCAMLCFLAGS)" all
149 $(MAKESUBDIRS
:%=%.opt
):
150 $(MAKE
) -C
$(@
:%.opt
=%) OCAMLCFLAGS
="$(OCAMLCFLAGS)" all.opt
156 # parsing_cocci: commons globals menhirlib
157 # parsing_c:parsing_cocci
158 # ctl:globals commons
159 # engine: parsing_cocci parsing_c ctl
160 # extra: parsing_cocci parsing_c ctl
162 # python:pycaml parsing_cocci parsing_c
165 set
-e
; for i in
$(MAKESUBDIRS
); do
$(MAKE
) -C
$$i $@
; done
167 $(LIBS
): $(MAKESUBDIRS
)
168 $(LIBS
:.cma
=.cmxa
): $(MAKESUBDIRS
:%=%.opt
)
171 $(OPTOBJS
):$(LIBS
:.cma
=.cmxa
)
173 $(EXEC
): $(LIBS
) $(OBJS
)
174 $(OCAMLC
) $(BYTECODE_STATIC
) -o
$@
$(SYSLIBS
) $^
176 $(EXEC
).opt
: $(LIBS
:.cma
=.cmxa
) $(OPTOBJS
)
177 $(OCAMLOPT
) $(STATIC
) -o
$@
$(SYSLIBS
:.cma
=.cmxa
) $(OPTLIBFLAGS
) $^
179 $(EXEC
).top
: $(LIBS
) $(OBJS
)
180 $(OCAMLMKTOP
) -custom
-o
$@
$(SYSLIBS
) $^
183 rm -f
$(TARGET
) $(TARGET
).opt
$(TARGET
).top
186 rm -f dllpycaml_stubs.so
189 .PHONY
:: tools configure
195 @echo
"Makefile.config is missing. Have you run ./configure?"
202 $(MAKE
) -C tools
clean
205 rm -f spatch.opt spatch
206 $(MAKE
) STATIC
="-ccopt -static" spatch.opt
210 rm -f spatch.opt spatch
211 $(MAKE
) BYTECODE_STATIC
="" spatch
214 ##############################################################################
215 # Build documentation
216 ##############################################################################
226 make
-C docs
distclean
228 ##############################################################################
229 # Pre-Install (customization of spatch frontend script)
230 ##############################################################################
232 preinstall
: scripts
/spatch scripts
/spatch.opt scripts
/spatch.byte
234 # user will use spatch to run spatch.opt (native)
236 cp scripts
/spatch.sh scripts
/spatch.tmp2
237 sed
"s|SHAREDIR|$(SHAREDIR)|g" scripts
/spatch.tmp2
> scripts
/spatch.tmp
238 sed
"s|LIBDIR|$(LIBDIR)|g" scripts
/spatch.tmp
> scripts
/spatch
239 rm -f scripts
/spatch.tmp2 scripts
/spatch.tmp
241 # user will use spatch to run spatch (bytecode)
243 cp scripts
/spatch.sh scripts
/spatch.byte.tmp3
244 sed
"s|\.opt||" scripts
/spatch.byte.tmp3
> scripts
/spatch.byte.tmp2
245 sed
"s|SHAREDIR|$(SHAREDIR)|g" scripts
/spatch.byte.tmp2 \
246 > scripts
/spatch.byte.tmp
247 sed
"s|LIBDIR|$(LIBDIR)|g" scripts
/spatch.byte.tmp \
248 > scripts
/spatch.byte
249 rm -f scripts
/spatch.byte.tmp3 \
250 scripts
/spatch.byte.tmp2 \
251 scripts
/spatch.byte.tmp
253 # user will use spatch.opt to run spatch.opt (native)
255 cp scripts
/spatch.sh scripts
/spatch.opt.tmp2
256 sed
"s|SHAREDIR|$(SHAREDIR)|g" scripts
/spatch.opt.tmp2 \
257 > scripts
/spatch.opt.tmp
258 sed
"s|LIBDIR|$(LIBDIR)|g" scripts
/spatch.opt.tmp \
260 rm -f scripts
/spatch.opt.tmp scripts
/spatch.opt.tmp2
263 rm -f scripts
/spatch scripts
/spatch.byte scripts
/spatch.opt
265 ##############################################################################
267 ##############################################################################
269 # don't remove DESTDIR, it can be set by package build system like ebuild
270 # for staged installation.
272 mkdir
-p
$(DESTDIR
)$(BINDIR
)
273 mkdir
-p
$(DESTDIR
)$(LIBDIR
)
274 mkdir
-p
$(DESTDIR
)$(SHAREDIR
)
275 mkdir
-p
$(DESTDIR
)$(MANDIR
)/man1
276 $(INSTALL_DATA
) standard.h
$(DESTDIR
)$(SHAREDIR
)
277 $(INSTALL_DATA
) standard.iso
$(DESTDIR
)$(SHAREDIR
)
278 $(INSTALL_DATA
) docs
/spatch
.1 $(DESTDIR
)$(MANDIR
)/man1
/
279 @if
[ $(FEATURE_PYTHON
) -eq
1 ]; then
$(MAKE
) install-python
; fi
282 mkdir
-p
$(DESTDIR
)$(SHAREDIR
)/python
/coccilib
/coccigui
283 $(INSTALL_DATA
) python
/coccilib
/*.py \
284 $(DESTDIR
)$(SHAREDIR
)/python
/coccilib
285 $(INSTALL_DATA
) python
/coccilib
/coccigui
/*.py \
286 $(DESTDIR
)$(SHAREDIR
)/python
/coccilib
/coccigui
287 $(INSTALL_DATA
) python
/coccilib
/coccigui
/pygui.glade \
288 $(DESTDIR
)$(SHAREDIR
)/python
/coccilib
/coccigui
289 $(INSTALL_DATA
) python
/coccilib
/coccigui
/pygui.gladep \
290 $(DESTDIR
)$(SHAREDIR
)/python
/coccilib
/coccigui
291 $(INSTALL_LIB
) dllpycaml_stubs.so
$(DESTDIR
)$(LIBDIR
)
293 install: install-common
294 @if
test -x spatch
-a
! -x spatch.opt
; then \
295 $(MAKE
) install-byte
;fi
296 @if
test ! -x spatch
-a
-x spatch.opt
; then \
297 $(MAKE
) install-def
; $(MAKE
) install-opt
;fi
298 @if
test -x spatch
-a
-x spatch.opt
; then \
299 $(MAKE
) install-byte
; $(MAKE
) install-opt
;fi
300 @if
test ! -x spatch
-a
! -x spatch.opt
; then \
301 echo
"\n\n\t==> Run 'make', 'make opt', or both first. <==\n\n";fi
303 @echo
"\tYou can also install spatch by copying the program spatch"
304 @echo
"\t(available in this directory) anywhere you want and"
305 @echo
"\tgive it the right options to find its configuration files."
308 # user will use spatch to run spatch.opt (native)
310 $(INSTALL_PROGRAM
) spatch.opt
$(DESTDIR
)$(SHAREDIR
)
311 $(INSTALL_PROGRAM
) scripts
/spatch
$(DESTDIR
)$(BINDIR
)/spatch
313 # user will use spatch to run spatch (bytecode)
315 $(INSTALL_PROGRAM
) spatch
$(DESTDIR
)$(SHAREDIR
)
316 $(INSTALL_PROGRAM
) scripts
/spatch.byte
$(DESTDIR
)$(BINDIR
)/spatch
318 # user will use spatch.opt to run spatch.opt (native)
320 $(INSTALL_PROGRAM
) spatch.opt
$(DESTDIR
)$(SHAREDIR
)
321 $(INSTALL_PROGRAM
) scripts
/spatch.opt
$(DESTDIR
)$(BINDIR
)/spatch.opt
324 rm -f
$(DESTDIR
)$(BINDIR
)/spatch
325 rm -f
$(DESTDIR
)$(BINDIR
)/spatch.opt
326 rm -f
$(DESTDIR
)$(LIBDIR
)/dllpycaml_stubs.so
327 rm -f
$(DESTDIR
)$(SHAREDIR
)/standard.h
328 rm -f
$(DESTDIR
)$(SHAREDIR
)/standard.iso
329 rm -rf
$(DESTDIR
)$(SHAREDIR
)/python
/coccilib
330 rm -f
$(DESTDIR
)$(MANDIR
)/man1
/spatch
.1
336 ##############################################################################
338 ##############################################################################
340 PACKAGE
=coccinelle-
$(VERSION
)
342 BINSRC
=spatch env.sh env.csh standard.h standard.iso \
344 docs
/manual
/options.pdf docs
/manual
/cocci_syntax.pdf docs
/spatch
.1 \
345 docs
/manual
/cocci-python.txt \
346 demos
/foo.
* demos
/simple.
*
347 # $(PYLIB) python/coccilib/ demos/printloc.*
348 BINSRC2
=$(BINSRC
:%=$(PACKAGE
)/%)
351 OCAMLVERSION
=$(shell ocaml
-version |perl
-p
-e
's/.*version (.*)/$$1/;')
353 # Procedure to do first time:
355 # cvs checkout coccinelle
360 # remember to comment the -g -dtypes in this Makefile
361 # You can also remove a few things, for instance I removed in this
362 # Makefile things related to popl/ and popl09/
364 # Procedure to do each time:
366 # make sure that ocaml is the distribution ocaml of /usr/bin, not ~pad/...
367 # modify globals/config.ml.in
368 # cd globals/; cvs commit -m"new version" (do not commit from the root!)
369 # ./configure --without-python
372 # Check that run an ocaml in /usr/bin
374 # To test you can try compile and run spatch from different instances
375 # like my ~/coccinelle, ~/release/coccinelle, and the /tmp/coccinelle-0.X
376 # downloaded from the website.
378 # For 'make srctar' it must done from a clean
379 # repo such as ~/release/coccinelle. It must also be a repo where
380 # the scripts/licensify has been run at least once.
381 # For the 'make bintar' I can do it from my original repo.
386 .
/configure
--without-python
392 # I currently pre-generate the parser so the user does not have to
393 # install menhir on his machine. We could also do a few cleanups.
394 # You may have first to do a 'make licensify'.
396 # update: make docs generates pdf but also some ugly .log files, so
397 # make clean is there to remove them while not removing the pdf
398 # (only distclean remove the pdfs).
403 cp
-a .
$(TMP
)/$(PACKAGE
)
404 cd
$(TMP
)/$(PACKAGE
); cd parsing_cocci
/; make parser_cocci_menhir.ml
405 cd
$(TMP
); tar cvfz
$(PACKAGE
).tgz
--exclude-vcs
$(PACKAGE
)
406 rm -rf
$(TMP
)/$(PACKAGE
)
410 rm -f
$(TMP
)/$(PACKAGE
)
411 ln
-s
`pwd` $(TMP
)/$(PACKAGE
)
412 cd
$(TMP
); tar cvfz
$(PACKAGE
)-bin-x86.tgz
--exclude-vcs
$(BINSRC2
)
413 rm -f
$(TMP
)/$(PACKAGE
)
415 staticbintar
: all.opt
416 rm -f
$(TMP
)/$(PACKAGE
)
417 ln
-s
`pwd` $(TMP
)/$(PACKAGE
)
419 cd
$(TMP
); tar cvfz
$(PACKAGE
)-bin-x86-static.tgz
--exclude-vcs
$(BINSRC2
)
420 rm -f
$(TMP
)/$(PACKAGE
)
422 # add ocaml version in name ?
424 rm -f
$(TMP
)/$(PACKAGE
)
425 ln
-s
`pwd` $(TMP
)/$(PACKAGE
)
427 cd
$(TMP
); tar cvfz
$(PACKAGE
)-bin-bytecode-
$(OCAMLVERSION
).tgz
--exclude-vcs
$(BINSRC2
)
428 rm -f
$(TMP
)/$(PACKAGE
)
432 rm -f
$(PACKAGE
)-bin-x86.tgz
433 rm -f
$(PACKAGE
)-bin-x86-static.tgz
434 rm -f
$(PACKAGE
)-bin-bytecode-
$(OCAMLVERSION
).tgz
438 TOLICENSIFY
=ctl engine parsing_cocci python
440 ocaml tools
/licensify.ml
441 set
-e
; for i in
$(TOLICENSIFY
); do cd
$$i; ocaml ..
/tools
/licensify.ml
; cd ..
; done
443 # When checking out the source from diku sometimes I have some "X in the future"
446 echo do
'touch **/*.*'
450 # echo do 'rm -rf **/CVS'
453 @echo
$(OCAMLVERSION
)
456 ##############################################################################
458 ##############################################################################
460 #TOP=/home/pad/mobile/project-coccinelle
461 WEBSITE
=/home
/pad
/mobile
/homepage
/software
/project-coccinelle
464 cp
$(TMP
)/$(PACKAGE
).tgz
$(WEBSITE
)
465 cp
$(TMP
)/$(PACKAGE
)-bin-x86.tgz
$(WEBSITE
)
466 cp
$(TMP
)/$(PACKAGE
)-bin-x86-static.tgz
$(WEBSITE
)
467 cp
$(TMP
)/$(PACKAGE
)-bin-bytecode-
$(OCAMLVERSION
).tgz
$(WEBSITE
)
468 rm -f
$(WEBSITE
)/LATEST
* $(WEBSITE
)/coccinelle-latest.tgz
469 cp changes.txt
$(WEBSITE
)/changes-
$(VERSION
).txt
470 cd
$(WEBSITE
); touch LATEST_IS_
$(VERSION
); ln
-s
$(PACKAGE
).tgz coccinelle-latest.tgz
471 cp readme.txt
$(WEBSITE
)
474 #TXT=$(wildcard *.txt)
476 # unison ~/public_html/wiki/wiki-LFS/data/pages/ docs/wiki/
477 # set -e; for i in $(TXT); do unison $$i docs/wiki/$$i; done
480 # @echo pull from ~/public_html/darcs/c-coccinelle and c-commons and lib-xxx
482 DARCSFORESTS
=commons ocamlsexp \
483 parsing_c parsing_cocci engine
487 set
-e
; for i in
$(DARCSFORESTS
); do cd
$$i; darcs pull
; cd ..
; done
491 set
-e
; for i in
$(DARCSFORESTS
); do cd
$$i; darcs diff
-u
; cd ..
; done
493 ##############################################################################
494 # Git Developer rules
495 ##############################################################################
497 git cvsimport
-d
:ext
:topps
:/var
/cvs
/cocci coccinelle
499 ##############################################################################
501 ##############################################################################
507 .
/$(TARGET
) -D standard.h
-parse_c
-dir tests
/
511 # -inline 0 to see all the functions in the profile.
512 # Can also use the profile framework in commons/ and run your program
515 $(MAKE
) OPTFLAGS
="-p -inline 0 " opt
521 otags
-no-mli-tags
-r .
524 find
-name
"*.ml" |grep
-v
"scripts" | xargs ocamldep
-I commons
-I globals
-I ctl
-I parsing_cocci
-I parsing_c
-I engine
-I extra
> /tmp
/dependfull.depend
525 ocamldot
-lr
/tmp
/dependfull.depend
> /tmp
/dependfull.dot
526 dot
-Tps
/tmp
/dependfull.dot
> /tmp
/dependfull.ps
527 ps2pdf
/tmp
/dependfull.ps
/tmp
/dependfull.pdf
529 ##############################################################################
531 ##############################################################################
533 # each member of the project can have its own test.ml. this file is
536 echo
"let foo_ctl () = failwith \"there is no foo_ctl formula\"" \
539 beforedepend
:: test.ml
542 #INC=$(dir $(shell which ocaml))
545 #INCZ=$(INCY:/=)/lib/ocaml
548 # gcc -c -o prim.o -I $(INCZ) prim.c
551 ##############################################################################
552 # Generic ocaml rules
553 ##############################################################################
555 .SUFFIXES
: .ml .mli .cmo .cmi .cmx
568 rm -f
*.cm
[iox
] *.o
*.annot
569 rm -f
*~ .
*~
*.exe
#*#
572 set
-e
; for i in
$(MAKESUBDIRS
); do
$(MAKE
) -C
$$i $@
; done
574 rm -f Makefile.config
575 rm -f python
/coccilib
/output.py
576 rm -f python
/pycocci.ml
577 rm -f python
/pycocci_aux.ml
578 rm -f globals
/config.ml
580 rm -f tests
/SCORE_actual.sexp
581 rm -f tests
/SCORE_best_of_both.sexp
582 find
-name
".#*1.*" | xargs
rm -f
586 depend
:: beforedepend
587 $(OCAMLDEP
) *.mli
*.ml
> .depend
588 set
-e
; for i in
$(MAKESUBDIRS
); do
$(MAKE
) -C
$$i $@
; done
591 @if
[ ! -f .depend
] ; then
$(MAKE
) depend
; fi