1 # Copyright 2005-2009, Ecole des Mines de Nantes, University of Copenhagen
2 # Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix
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.
22 #############################################################################
23 # Configuration section
24 #############################################################################
26 -include Makefile.config
28 VERSION
=$(shell cat globals
/config.ml.in |grep version |perl
-p
-e
's/.*"(.*)".*/$$1/;')
29 CCVERSION
=$(shell cat scripts
/coccicheck
/README |grep
"Coccicheck version" |perl
-p
-e
's/.*version (.*)[ ]*/$$1/;')
31 ##############################################################################
33 ##############################################################################
36 SRC
=flag_cocci.ml cocci.ml testing.ml
test.ml main.ml
38 ifeq ($(FEATURE_PYTHON
),1)
39 PYCMA
=pycaml
/pycaml.cma
41 PYLIB
=dllpycaml_stubs.so
42 # the following is essential for Coccinelle to compile under gentoo (weird)
43 OPTLIBFLAGS
=-cclib dllpycaml_stubs.so
51 SEXPSYSCMA
=bigarray.cma nums.cma
53 SYSLIBS
=str.cma unix.cma
$(SEXPSYSCMA
)
54 LIBS
=commons
/commons.cma \
55 ocamlsexp
/sexplib1.cma commons
/commons_sexp.cma \
58 parsing_cocci
/cocci_parser.cma parsing_c
/parsing_c.cma \
59 engine
/cocciengine.cma popl09
/popl.cma \
60 extra
/extra.cma
$(PYCMA
) python
/coccipython.cma
62 #used for clean: and depend: and a little for rec & rec.opt
63 MAKESUBDIRS
=commons ocamlsexp \
64 globals menhirlib
$(PYDIR
) ctl parsing_cocci parsing_c \
65 engine popl09 extra python
66 INCLUDEDIRS
=commons commons
/ocamlextra ocamlsexp \
67 globals menhirlib
$(PYDIR
) ctl \
68 parsing_cocci parsing_c engine popl09 extra python
70 ##############################################################################
72 ##############################################################################
74 INCLUDES
=$(INCLUDEDIRS
:%=-I
%)
77 OPTOBJS
= $(SRC
:.ml
=.cmx
)
81 ##############################################################################
82 # Generic ocaml variables
83 ##############################################################################
85 OCAMLCFLAGS
=# -g -dtypes # -w A
87 # for profiling add -p -inline 0
88 # but 'make forprofiling' below does that for you.
89 # This flag is also used in subdirectories so don't change its name here.
90 # To enable backtrace support for native code, you need to put -g in OPTFLAGS
91 # to also link with -g, but even in 3.11 the backtrace support seems buggy so
94 # the following is essential for Coccinelle to compile under gentoo
95 # but is now defined above in this file
96 #OPTLIBFLAGS=-cclib dllpycaml_stubs.so
98 OCAMLC
=ocamlc
$(OPTBIN
) $(OCAMLCFLAGS
) $(INCLUDES
)
99 OCAMLOPT
=ocamlopt
$(OPTBIN
) $(OPTFLAGS
) $(INCLUDES
)
100 OCAMLLEX
=ocamllex
#-ml # -ml for debugging lexer, but slightly slower
101 OCAMLYACC
=ocamlyacc
-v
102 OCAMLDEP
=ocamldep
$(INCLUDES
)
103 OCAMLMKTOP
=ocamlmktop
-g
-custom
$(INCLUDES
)
105 # can also be set via 'make static'
106 STATIC
= #-ccopt -static
108 # can also be unset via 'make purebytecode'
109 BYTECODE_STATIC
=-custom
111 ##############################################################################
113 ##############################################################################
114 .PHONY
:: all all.opt byte opt top
clean distclean configure
115 .PHONY
:: $(MAKESUBDIRS
) $(MAKESUBDIRS
:%=%.opt
) subdirs subdirs.opt
117 all: Makefile.config byte preinstall
120 all.opt
: opt-compil preinstall
137 $(MAKE
) -C commons OCAMLCFLAGS
="$(OCAMLCFLAGS)"
138 $(MAKE
) -C ocamlsexp OCAMLCFLAGS
="$(OCAMLCFLAGS)"
139 $(MAKE
) -C commons sexp OCAMLCFLAGS
="$(OCAMLCFLAGS)"
140 +for D in
$(MAKESUBDIRS
); do
$(MAKE
) $$D || exit
1 ; done
143 $(MAKE
) -C commons
all.opt OCAMLCFLAGS
="$(OCAMLCFLAGS)"
144 $(MAKE
) -C ocamlsexp
all.opt OCAMLCFLAGS
="$(OCAMLCFLAGS)"
145 $(MAKE
) -C commons sexp.opt OCAMLCFLAGS
="$(OCAMLCFLAGS)"
146 +for D in
$(MAKESUBDIRS
); do
$(MAKE
) $$D.opt || exit
1 ; done
149 $(MAKE
) -C
$@ OCAMLCFLAGS
="$(OCAMLCFLAGS)" all
151 $(MAKESUBDIRS
:%=%.opt
):
152 $(MAKE
) -C
$(@
:%.opt
=%) OCAMLCFLAGS
="$(OCAMLCFLAGS)" all.opt
158 # parsing_cocci: commons globals menhirlib
159 # parsing_c:parsing_cocci
160 # ctl:globals commons
161 # engine: parsing_cocci parsing_c ctl
163 # extra: parsing_cocci parsing_c ctl
165 # python:pycaml parsing_cocci parsing_c
168 set
-e
; for i in
$(MAKESUBDIRS
); do
$(MAKE
) -C
$$i $@
; done
170 $(LIBS
): $(MAKESUBDIRS
)
171 $(LIBS
:.cma
=.cmxa
): $(MAKESUBDIRS
:%=%.opt
)
174 $(OPTOBJS
):$(LIBS
:.cma
=.cmxa
)
176 $(EXEC
): $(LIBS
) $(OBJS
)
177 $(OCAMLC
) $(BYTECODE_STATIC
) -o
$@
$(SYSLIBS
) $^
179 $(EXEC
).opt
: $(LIBS
:.cma
=.cmxa
) $(OPTOBJS
)
180 $(OCAMLOPT
) $(STATIC
) -o
$@
$(SYSLIBS
:.cma
=.cmxa
) $(OPTLIBFLAGS
) $^
182 $(EXEC
).top
: $(LIBS
) $(OBJS
)
183 $(OCAMLMKTOP
) -custom
-o
$@
$(SYSLIBS
) $^
186 rm -f
$(TARGET
) $(TARGET
).opt
$(TARGET
).top
187 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
212 perl
-p
-i
-e
's/^#!.*/#!\/usr\/bin\/ocamlrun/' spatch
215 ##############################################################################
216 # Build documentation
217 ##############################################################################
227 make
-C docs
distclean
229 ##############################################################################
230 # Pre-Install (customization of spatch frontend script)
231 ##############################################################################
233 preinstall
: scripts
/spatch scripts
/spatch.opt scripts
/spatch.byte
235 # user will use spatch to run spatch.opt (native)
237 cp scripts
/spatch.sh scripts
/spatch.tmp2
238 sed
"s|SHAREDIR|$(SHAREDIR)|g" scripts
/spatch.tmp2
> scripts
/spatch.tmp
239 sed
"s|LIBDIR|$(LIBDIR)|g" scripts
/spatch.tmp
> scripts
/spatch
240 rm -f scripts
/spatch.tmp2 scripts
/spatch.tmp
242 # user will use spatch to run spatch (bytecode)
244 cp scripts
/spatch.sh scripts
/spatch.byte.tmp3
245 sed
"s|\.opt||" scripts
/spatch.byte.tmp3
> scripts
/spatch.byte.tmp2
246 sed
"s|SHAREDIR|$(SHAREDIR)|g" scripts
/spatch.byte.tmp2 \
247 > scripts
/spatch.byte.tmp
248 sed
"s|LIBDIR|$(LIBDIR)|g" scripts
/spatch.byte.tmp \
249 > scripts
/spatch.byte
250 rm -f scripts
/spatch.byte.tmp3 \
251 scripts
/spatch.byte.tmp2 \
252 scripts
/spatch.byte.tmp
254 # user will use spatch.opt to run spatch.opt (native)
256 cp scripts
/spatch.sh scripts
/spatch.opt.tmp2
257 sed
"s|SHAREDIR|$(SHAREDIR)|g" scripts
/spatch.opt.tmp2 \
258 > scripts
/spatch.opt.tmp
259 sed
"s|LIBDIR|$(LIBDIR)|g" scripts
/spatch.opt.tmp \
261 rm -f scripts
/spatch.opt.tmp scripts
/spatch.opt.tmp2
264 rm -f scripts
/spatch scripts
/spatch.byte scripts
/spatch.opt
266 ##############################################################################
268 ##############################################################################
270 # don't remove DESTDIR, it can be set by package build system like ebuild
271 # for staged installation.
273 mkdir
-p
$(DESTDIR
)$(BINDIR
)
274 mkdir
-p
$(DESTDIR
)$(LIBDIR
)
275 mkdir
-p
$(DESTDIR
)$(SHAREDIR
)
276 mkdir
-p
$(DESTDIR
)$(MANDIR
)/man1
277 $(INSTALL_DATA
) standard.h
$(DESTDIR
)$(SHAREDIR
)
278 $(INSTALL_DATA
) standard.iso
$(DESTDIR
)$(SHAREDIR
)
279 $(INSTALL_DATA
) docs
/spatch
.1 $(DESTDIR
)$(MANDIR
)/man1
/
280 @if
[ $(FEATURE_PYTHON
) -eq
1 ]; then
$(MAKE
) install-python
; fi
283 mkdir
-p
$(DESTDIR
)$(SHAREDIR
)/python
/coccilib
/coccigui
284 $(INSTALL_DATA
) python
/coccilib
/*.py \
285 $(DESTDIR
)$(SHAREDIR
)/python
/coccilib
286 $(INSTALL_DATA
) python
/coccilib
/coccigui
/*.py \
287 $(DESTDIR
)$(SHAREDIR
)/python
/coccilib
/coccigui
288 $(INSTALL_DATA
) python
/coccilib
/coccigui
/pygui.glade \
289 $(DESTDIR
)$(SHAREDIR
)/python
/coccilib
/coccigui
290 $(INSTALL_DATA
) python
/coccilib
/coccigui
/pygui.gladep \
291 $(DESTDIR
)$(SHAREDIR
)/python
/coccilib
/coccigui
292 $(INSTALL_LIB
) dllpycaml_stubs.so
$(DESTDIR
)$(LIBDIR
)
294 install: install-common
295 @if
test -x spatch
-a
! -x spatch.opt
; then \
296 $(MAKE
) install-byte
;fi
297 @if
test ! -x spatch
-a
-x spatch.opt
; then \
298 $(MAKE
) install-def
; $(MAKE
) install-opt
;fi
299 @if
test -x spatch
-a
-x spatch.opt
; then \
300 $(MAKE
) install-byte
; $(MAKE
) install-opt
;fi
301 @if
test ! -x spatch
-a
! -x spatch.opt
; then \
302 echo
"\n\n\t==> Run 'make', 'make opt', or both first. <==\n\n";fi
304 @echo
"\tYou can also install spatch by copying the program spatch"
305 @echo
"\t(available in this directory) anywhere you want and"
306 @echo
"\tgive it the right options to find its configuration files."
309 # user will use spatch to run spatch.opt (native)
311 $(INSTALL_PROGRAM
) spatch.opt
$(DESTDIR
)$(SHAREDIR
)
312 $(INSTALL_PROGRAM
) scripts
/spatch
$(DESTDIR
)$(BINDIR
)/spatch
314 # user will use spatch to run spatch (bytecode)
316 $(INSTALL_PROGRAM
) spatch
$(DESTDIR
)$(SHAREDIR
)
317 $(INSTALL_PROGRAM
) scripts
/spatch.byte
$(DESTDIR
)$(BINDIR
)/spatch
319 # user will use spatch.opt to run spatch.opt (native)
321 $(INSTALL_PROGRAM
) spatch.opt
$(DESTDIR
)$(SHAREDIR
)
322 $(INSTALL_PROGRAM
) scripts
/spatch.opt
$(DESTDIR
)$(BINDIR
)/spatch.opt
325 rm -f
$(DESTDIR
)$(BINDIR
)/spatch
326 rm -f
$(DESTDIR
)$(BINDIR
)/spatch.opt
327 rm -f
$(DESTDIR
)$(LIBDIR
)/dllpycaml_stubs.so
328 rm -f
$(DESTDIR
)$(SHAREDIR
)/standard.h
329 rm -f
$(DESTDIR
)$(SHAREDIR
)/standard.iso
330 rm -rf
$(DESTDIR
)$(SHAREDIR
)/python
/coccilib
331 rm -f
$(DESTDIR
)$(MANDIR
)/man1
/spatch
.1
334 @echo
"spatch $(VERSION)"
335 @echo
"coccicheck $(CCVERSION)"
338 ##############################################################################
340 ##############################################################################
342 PACKAGE
=coccinelle-
$(VERSION
)
343 CCPACKAGE
=coccicheck-
$(CCVERSION
)
345 BINSRC
=spatch env.sh env.csh standard.h standard.iso \
347 docs
/manual
/manual.pdf docs
/manual
/options.pdf docs
/manual
/main_grammar.pdf docs
/spatch
.1 \
348 docs
/manual
/cocci-python.txt \
349 demos
/foo.
* demos
/simple.
*
350 # $(PYLIB) python/coccilib/ demos/printloc.*
351 BINSRC2
=$(BINSRC
:%=$(PACKAGE
)/%)
354 OCAMLVERSION
=$(shell ocaml
-version |perl
-p
-e
's/.*version (.*)/$$1/;')
356 # Procedure to do first time:
358 # cvs checkout coccinelle -dP
361 # Procedure to do each time:
363 # 1) make prepackage # WARN: These will clean your local rep. of pending modifications
365 # UPDATE VERSION number in globals/config.ml.in
370 # The project is then automatically licensified.
372 # Remember to comment the -g -dtypes in this Makefile
373 # You can also remove a few things, for instance I removed in this
374 # Makefile things related to popl/ and popl09/
375 # make sure that ocaml is the distribution ocaml of /usr/bin, not ~pad/...
379 # if WEBSITE is set properly, you can also run 'make website'
380 # Check that run an ocaml in /usr/bin
382 # To test you can try compile and run spatch from different instances
383 # like my ~/coccinelle, ~/release/coccinelle, and the /tmp/coccinelle-0.X
384 # downloaded from the website.
386 # For 'make srctar' it must done from a clean
387 # repo such as ~/release/coccinelle. It must also be a repo where
388 # the scripts/licensify has been run at least once.
389 # For the 'make bintar' I can do it from my original repo.
396 cvs ci
-m
"Release $(VERSION)" globals
/config.ml.in
400 $(MAKE
) distclean # Clean project
402 .
/configure
--without-python
407 $(MAKE
) distclean # Clean project
408 .
/configure
# Reconfigure project with Python support
410 $(MAKE
) bintar-python
411 $(MAKE
) bytecodetar-python
415 # I currently pre-generate the parser so the user does not have to
416 # install menhir on his machine. We could also do a few cleanups.
417 # You may have first to do a 'make licensify'.
419 # update: make docs generates pdf but also some ugly .log files, so
420 # make clean is there to remove them while not removing the pdf
421 # (only distclean remove the pdfs).
426 cp
-a .
$(TMP
)/$(PACKAGE
)
427 cd
$(TMP
)/$(PACKAGE
); cd parsing_cocci
/; make parser_cocci_menhir.ml
428 cd
$(TMP
); tar cvfz
$(PACKAGE
).tgz
--exclude-vcs
$(PACKAGE
)
429 rm -rf
$(TMP
)/$(PACKAGE
)
433 rm -f
$(TMP
)/$(PACKAGE
)
434 ln
-s
`pwd` $(TMP
)/$(PACKAGE
)
435 cd
$(TMP
); tar cvfz
$(PACKAGE
)-bin-x86.tgz
--exclude-vcs
$(BINSRC2
)
436 rm -f
$(TMP
)/$(PACKAGE
)
438 staticbintar
: all.opt
439 rm -f
$(TMP
)/$(PACKAGE
)
440 ln
-s
`pwd` $(TMP
)/$(PACKAGE
)
442 cd
$(TMP
); tar cvfz
$(PACKAGE
)-bin-x86-static.tgz
--exclude-vcs
$(BINSRC2
)
443 rm -f
$(TMP
)/$(PACKAGE
)
445 # add ocaml version in name ?
447 rm -f
$(TMP
)/$(PACKAGE
)
448 ln
-s
`pwd` $(TMP
)/$(PACKAGE
)
450 cd
$(TMP
); tar cvfz
$(PACKAGE
)-bin-bytecode-
$(OCAMLVERSION
).tgz
--exclude-vcs
$(BINSRC2
)
451 rm -f
$(TMP
)/$(PACKAGE
)
454 rm -f
$(TMP
)/$(PACKAGE
)
455 ln
-s
`pwd` $(TMP
)/$(PACKAGE
)
456 cd
$(TMP
); tar cvfz
$(PACKAGE
)-bin-x86-python.tgz
--exclude-vcs
$(BINSRC2
)
457 rm -f
$(TMP
)/$(PACKAGE
)
459 # add ocaml version in name ?
460 bytecodetar-python
: all
461 rm -f
$(TMP
)/$(PACKAGE
)
462 ln
-s
`pwd` $(TMP
)/$(PACKAGE
)
464 cd
$(TMP
); tar cvfz
$(PACKAGE
)-bin-bytecode-
$(OCAMLVERSION
)-python.tgz
--exclude-vcs
$(BINSRC2
)
465 rm -f
$(TMP
)/$(PACKAGE
)
468 cp
-a
`pwd`/scripts
/coccicheck
$(TMP
)/$(CCPACKAGE
)
469 tar cvfz
$(TMP
)/$(CCPACKAGE
).tgz
-C
$(TMP
) --exclude-vcs
$(CCPACKAGE
)
470 rm -rf
$(TMP
)/$(CCPACKAGE
)
473 rm -f
$(TMP
)/$(PACKAGE
).tgz
474 rm -f
$(TMP
)/$(PACKAGE
)-bin-x86.tgz
475 rm -f
$(TMP
)/$(PACKAGE
)-bin-x86-static.tgz
476 rm -f
$(TMP
)/$(PACKAGE
)-bin-bytecode-
$(OCAMLVERSION
).tgz
477 rm -f
$(TMP
)/$(PACKAGE
)-bin-x86-python.tgz
478 rm -f
$(TMP
)/$(PACKAGE
)-bin-bytecode-
$(OCAMLVERSION
)-python.tgz
479 rm -f
$(TMP
)/$(CCPACKAGE
).tgz
482 # No need to licensify 'demos'. Because these is basic building blocks
485 TOLICENSIFY
=ctl engine globals parsing_cocci popl popl09 python scripts tools
487 ocaml str.cma tools
/licensify.ml
488 set
-e
; for i in
$(TOLICENSIFY
); do cd
$$i; ocaml str.cma ..
/tools
/licensify.ml
; cd ..
; done
490 # When checking out the source from diku sometimes I have some "X in the future"
493 echo do
'touch **/*.*'
497 # echo do 'rm -rf **/CVS'
500 @echo
$(OCAMLVERSION
)
502 ##############################################################################
504 ##############################################################################
506 -include Makefile.dev
512 .
/$(TARGET
) -D standard.h
-parse_c
-dir tests
/
516 # -inline 0 to see all the functions in the profile.
517 # Can also use the profile framework in commons/ and run your program
520 $(MAKE
) OPTFLAGS
="-p -inline 0 " opt
526 otags
-no-mli-tags
-r .
529 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
530 ocamldot
-lr
/tmp
/dependfull.depend
> /tmp
/dependfull.dot
531 dot
-Tps
/tmp
/dependfull.dot
> /tmp
/dependfull.ps
532 ps2pdf
/tmp
/dependfull.ps
/tmp
/dependfull.pdf
534 ##############################################################################
536 ##############################################################################
538 # each member of the project can have its own test.ml. this file is
541 echo
"let foo_ctl () = failwith \"there is no foo_ctl formula\"" \
544 beforedepend
:: test.ml
547 #INC=$(dir $(shell which ocaml))
550 #INCZ=$(INCY:/=)/lib/ocaml
553 # gcc -c -o prim.o -I $(INCZ) prim.c
556 ##############################################################################
557 # Generic ocaml rules
558 ##############################################################################
560 .SUFFIXES
: .ml .mli .cmo .cmi .cmx
573 rm -f
*.cm
[iox
] *.o
*.annot
574 rm -f
*~ .
*~
*.exe
#*#
577 set
-e
; for i in
$(MAKESUBDIRS
); do
$(MAKE
) -C
$$i $@
; done
579 rm -f Makefile.config
580 rm -f python
/coccilib
/output.py
581 rm -f python
/pycocci.ml
582 rm -f python
/pycocci_aux.ml
583 rm -f globals
/config.ml
585 rm -f tests
/SCORE_actual.sexp
586 rm -f tests
/SCORE_best_of_both.sexp
587 find
-name
".#*1.*" | xargs
rm -f
591 depend
:: beforedepend
592 $(OCAMLDEP
) *.mli
*.ml
> .depend
593 set
-e
; for i in
$(MAKESUBDIRS
); do
$(MAKE
) -C
$$i $@
; done
596 @if
[ ! -f .depend
] ; then
$(MAKE
) depend
; fi