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 |grep version |perl
-p
-e
's/.*"(.*)".*/$$1/;')
29 ##############################################################################
31 ##############################################################################
34 SRC
=flag_cocci.ml cocci.ml testing.ml
test.ml main.ml
37 ifeq ($(FEATURE_PYTHON
),1)
38 PYCMA
=pycaml
/pycaml.cma
40 PYLIB
=dllpycaml_stubs.so
41 # the following is essential for Coccinelle to compile under gentoo (wierd)
42 OPTLIBFLAGS
=-cclib dllpycaml_stubs.so
51 SYSLIBS
=str.cma unix.cma
52 LIBS
=commons
/commons.cma globals
/globals.cma\
54 parsing_cocci
/cocci_parser.cma parsing_c
/parsing_c.cma \
55 engine
/cocciengine.cma popl09
/popl.cma \
56 extra
/extra.cma
$(PYCMA
) python
/coccipython.cma
58 MAKESUBDIRS
=commons globals menhirlib
$(PYDIR
) ctl parsing_cocci parsing_c \
59 engine popl09 extra python
60 INCLUDEDIRS
=commons commons
/ocamlextra globals menhirlib
$(PYDIR
) ctl \
61 parsing_cocci parsing_c engine popl09 extra python
63 ##############################################################################
65 ##############################################################################
67 INCLUDES
=$(INCLUDEDIRS
:%=-I
%)
70 OPTOBJS
= $(SRC
:.ml
=.cmx
)
74 ##############################################################################
75 # Generic ocaml variables
76 ##############################################################################
78 OCAMLCFLAGS
= #-g -dtypes # -w A
80 # for profiling add -p -inline 0
81 # but 'make forprofiling' below does that for you.
82 # This flag is also used in subdirectories so don't change its name here.
84 # the following is essential for Coccinelle to compile under gentoo
85 # but is now defined above in this file
86 #OPTLIBFLAGS=-cclib dllpycaml_stubs.so
88 OCAMLC
=ocamlc
$(OPTBIN
) $(OCAMLCFLAGS
) $(INCLUDES
)
89 OCAMLOPT
=ocamlopt
$(OPTBIN
) $(OPTFLAGS
) $(INCLUDES
)
90 OCAMLLEX
=ocamllex
#-ml # -ml for debugging lexer, but slightly slower
91 OCAMLYACC
=ocamlyacc
-v
92 OCAMLDEP
=ocamldep
$(INCLUDES
)
93 OCAMLMKTOP
=ocamlmktop
-g
-custom
$(INCLUDES
)
95 # can also be set via 'make static'
96 STATIC
= #-ccopt -static
98 # can also be unset via 'make purebytecode'
99 BYTECODE_STATIC
=-custom
101 ##############################################################################
103 ##############################################################################
104 .PHONY
: all all.opt opt top
clean configure
105 .PHONY
: $(MAKESUBDIRS
) $(MAKESUBDIRS
:%=%.opt
) subdirs subdirs.opt
119 +for D in
$(MAKESUBDIRS
); do
$(MAKE
) $$D ; done
122 +for D in
$(MAKESUBDIRS
); do
$(MAKE
) $$D.opt
; done
125 $(MAKE
) -C
$@ OCAMLCFLAGS
="$(OCAMLCFLAGS)" all
127 $(MAKESUBDIRS
:%=%.opt
):
128 $(MAKE
) -C
$(@
:%.opt
=%) OCAMLCFLAGS
="$(OCAMLCFLAGS)" all.opt
133 # parsing_cocci: commons globals menhirlib
134 # parsing_c:parsing_cocci
135 # ctl:globals commons
136 # engine: parsing_cocci parsing_c ctl
138 # extra: parsing_cocci parsing_c ctl
140 # python:pycaml parsing_cocci parsing_c
145 # parsing_cocci.opt: commons.opt globals.opt menhirlib.opt
146 # parsing_c.opt:parsing_cocci.opt
147 # ctl.opt:globals.opt commons.opt
148 # engine.opt: parsing_cocci.opt parsing_c.opt ctl.opt
149 # popl09.opt:engine.opt
150 # extra.opt: parsing_cocci.opt parsing_c.opt ctl.opt
152 # python.opt:pycaml.opt parsing_cocci.opt parsing_c.opt
155 set
-e
; for i in
$(MAKESUBDIRS
); do
$(MAKE
) -C
$$i clean; done
160 $(LIBS
): $(MAKESUBDIRS
)
161 $(LIBS
:.cma
=.cmxa
): $(MAKESUBDIRS
:%=%.opt
)
164 $(OPTOBJS
):$(LIBS
:.cma
=.cmxa
)
166 $(EXEC
): $(LIBS
) $(OBJS
)
167 $(OCAMLC
) $(BYTECODE_STATIC
) -o
$@
$(SYSLIBS
) $^
169 $(EXEC
).opt
: $(LIBS
:.cma
=.cmxa
) $(OPTOBJS
)
170 $(OCAMLOPT
) $(STATIC
) -o
$@
$(SYSLIBS
:.cma
=.cmxa
) $(OPTLIBFLAGS
) $^
172 $(EXEC
).top
: $(LIBS
) $(OBJS
)
173 $(OCAMLMKTOP
) -custom
-o
$@
$(SYSLIBS
) $^
176 rm -f
$(TARGET
) $(TARGET
).opt
$(TARGET
).top
179 rm -f dllpycaml_stubs.so
182 .PHONY
: tools
all configure
187 $(MAKE
) -C tools
clean
191 rm -f spatch.opt spatch
192 $(MAKE
) STATIC
="-ccopt -static" spatch.opt
196 rm -f spatch.opt spatch
197 $(MAKE
) BYTECODE_STATIC
="" spatch
200 ##############################################################################
202 ##############################################################################
204 # don't remove DESTDIR, it can be set by package build system like ebuild
205 # for staged installation.
207 mkdir
-p
$(DESTDIR
)$(BINDIR
)
208 mkdir
-p
$(DESTDIR
)$(LIBDIR
)
209 mkdir
-p
$(DESTDIR
)$(SHAREDIR
)
210 mkdir
-p
$(DESTDIR
)$(MANDIR
)/man1
211 $(INSTALL_DATA
) standard.h
$(DESTDIR
)$(SHAREDIR
)
212 $(INSTALL_DATA
) standard.iso
$(DESTDIR
)$(SHAREDIR
)
213 $(INSTALL_DATA
) docs
/spatch
.1 $(DESTDIR
)$(MANDIR
)/man1
/
214 @if
[ $(FEATURE_PYTHON
) -eq
1 ]; then
$(MAKE
) install-python
; fi
216 @echo
"You can also install spatch by copying the program spatch"
217 @echo
"(available in this directory) anywhere you want and"
218 @echo
"give it the right options to find its configuration files."
222 mkdir
-p
$(DESTDIR
)$(SHAREDIR
)/python
/coccilib
/coccigui
223 $(INSTALL_DATA
) python
/coccilib
/*.py \
224 $(DESTDIR
)$(SHAREDIR
)/python
/coccilib
225 $(INSTALL_DATA
) python
/coccilib
/coccigui
/*.py \
226 $(DESTDIR
)$(SHAREDIR
)/python
/coccilib
/coccigui
227 $(INSTALL_LIB
) dllpycaml_stubs.so
$(DESTDIR
)$(LIBDIR
)
229 # user will use spatch to run spatch.opt (native)
230 install: all.opt install-common
231 $(INSTALL_PROGRAM
) spatch.opt
$(DESTDIR
)$(SHAREDIR
)
232 cat scripts
/spatch.sh | sed
"s|SHAREDIR|$(SHAREDIR)|g" > $(DESTDIR
)$(BINDIR
)/spatch
233 chmod
755 $(DESTDIR
)$(BINDIR
)/spatch
235 # user will use spatch to run spatch (bytecode)
236 install-byte
: all install-common
237 $(INSTALL_PROGRAM
) spatch
$(DESTDIR
)$(SHAREDIR
)
238 cat scripts
/spatch.sh | sed
"s|\.opt||" | sed
"s|SHAREDIR|$(SHAREDIR)|g" > $(DESTDIR
)$(BINDIR
)/spatch
239 chmod
755 $(DESTDIR
)$(BINDIR
)/spatch
241 # user will use spatch.opt to run spatch.opt (native)
242 install-opt
: all.opt install-common
243 $(INSTALL_PROGRAM
) spatch.opt
$(DESTDIR
)$(SHAREDIR
)
244 cat scripts
/spatch.sh | sed
"s|SHAREDIR|$(SHAREDIR)|g" > $(DESTDIR
)$(BINDIR
)/spatch.opt
245 chmod
755 $(DESTDIR
)$(BINDIR
)/spatch.opt
248 rm -f
$(DESTDIR
)$(BINDIR
)/spatch
249 rm -f
$(DESTDIR
)$(BINDIR
)/spatch.opt
250 rm -f
$(DESTDIR
)$(LIBDIR
)/dllpycaml_stubs.so
251 rm -f
$(DESTDIR
)$(SHAREDIR
)/standard.h
252 rm -f
$(DESTDIR
)$(SHAREDIR
)/standard.iso
253 rm -rf
$(DESTDIR
)$(SHAREDIR
)/python
/coccilib
254 rm -f
$(DESTDIR
)$(MANDIR
)/man1
/spatch
.1
262 ##############################################################################
264 ##############################################################################
266 PACKAGE
=coccinelle-
$(VERSION
)
268 BINSRC
=spatch env.sh env.csh standard.h standard.iso \
270 demos
/foo.
* demos
/simple.
*
271 # $(PYLIB) python/coccilib/ demos/printloc.*
272 BINSRC2
=$(BINSRC
:%=$(PACKAGE
)/%)
275 OCAMLVERSION
=$(shell ocaml
-version |perl
-p
-e
's/.*version (.*)/$$1/;')
277 # Procedure to do first time:
279 # cvs checkout coccinelle
284 # remember to comment the -g -dtypes in this Makefile
286 # Procedure to do each time:
288 # make sure that ocaml is the distribution ocaml of /usr/bin, not ~pad/...
289 # modify globals/config.ml
290 # cd globals/; cvs commit -m"new version" (do not commit from the root!)
291 # ./configure --without-python
294 # Check that run an ocaml in /usr/bin
296 # To test you can try compile and run spatch from different instances
297 # like my ~/coccinelle, ~/release/coccinelle, and the /tmp/coccinelle-0.X
298 # downloaded from the website.
300 # For 'make srctar' it must done from a clean
301 # repo such as ~/release/coccinelle. It must also be a repo where
302 # the scripts/licensify has been run at least once.
303 # For the 'make bintar' I can do it from my original repo.
312 # I currently pre-generate the parser so the user does not have to
313 # install menhir on his machine. I also do a few cleanups like 'rm todo_pos'.
314 # You may have first to do a 'make licensify'.
317 cp
-a .
$(TMP
)/$(PACKAGE
)
318 cd
$(TMP
)/$(PACKAGE
); cd parsing_cocci
/; make parser_cocci_menhir.ml
319 cd
$(TMP
)/$(PACKAGE
); rm -f todo_pos
320 cd
$(TMP
); tar cvfz
$(PACKAGE
).tgz
--exclude-vcs
$(PACKAGE
)
321 rm -rf
$(TMP
)/$(PACKAGE
)
325 rm -f
$(TMP
)/$(PACKAGE
)
326 ln
-s
`pwd` $(TMP
)/$(PACKAGE
)
327 cd
$(TMP
); tar cvfz
$(PACKAGE
)-bin-x86.tgz
--exclude-vcs
$(BINSRC2
)
328 rm -f
$(TMP
)/$(PACKAGE
)
330 staticbintar
: all.opt
331 rm -f
$(TMP
)/$(PACKAGE
)
332 ln
-s
`pwd` $(TMP
)/$(PACKAGE
)
334 cd
$(TMP
); tar cvfz
$(PACKAGE
)-bin-x86-static.tgz
--exclude-vcs
$(BINSRC2
)
335 rm -f
$(TMP
)/$(PACKAGE
)
337 # add ocaml version in name ?
339 rm -f
$(TMP
)/$(PACKAGE
)
340 ln
-s
`pwd` $(TMP
)/$(PACKAGE
)
342 cd
$(TMP
); tar cvfz
$(PACKAGE
)-bin-bytecode-
$(OCAMLVERSION
).tgz
--exclude-vcs
$(BINSRC2
)
343 rm -f
$(TMP
)/$(PACKAGE
)
347 rm -f
$(PACKAGE
)-bin-x86.tgz
348 rm -f
$(PACKAGE
)-bin-x86-static.tgz
349 rm -f
$(PACKAGE
)-bin-bytecode-
$(OCAMLVERSION
).tgz
353 TOLICENSIFY
=ctl engine parsing_cocci popl popl09 python
355 ocaml tools
/licensify.ml
356 set
-e
; for i in
$(TOLICENSIFY
); do cd
$$i; ocaml ..
/tools
/licensify.ml
; cd ..
; done
358 # When checking out the source from diku sometimes I have some "X in the future"
361 echo do
'touch **/*.*'
365 # echo do 'rm -rf **/CVS'
368 @echo
$(OCAMLVERSION
)
371 ##############################################################################
373 ##############################################################################
375 #TOP=/home/pad/mobile/project-coccinelle
376 WEBSITE
=/home
/pad
/mobile
/homepage
/software
/project-coccinelle
379 cp
$(TMP
)/$(PACKAGE
).tgz
$(WEBSITE
)
380 cp
$(TMP
)/$(PACKAGE
)-bin-x86.tgz
$(WEBSITE
)
381 cp
$(TMP
)/$(PACKAGE
)-bin-x86-static.tgz
$(WEBSITE
)
382 cp
$(TMP
)/$(PACKAGE
)-bin-bytecode-
$(OCAMLVERSION
).tgz
$(WEBSITE
)
383 rm -f
$(WEBSITE
)/LATEST
* $(WEBSITE
)/coccinelle-latest.tgz
384 cd
$(WEBSITE
); touch LATEST_IS_
$(VERSION
); ln
-s
$(PACKAGE
).tgz coccinelle-latest.tgz
387 #TXT=$(wildcard *.txt)
389 # unison ~/public_html/wiki/wiki-LFS/data/pages/ docs/wiki/
390 # set -e; for i in $(TXT); do unison $$i docs/wiki/$$i; done
393 # @echo pull from ~/public_html/darcs/c-coccinelle and c-commons and lib-xxx
395 DARCSFORESTS
=commons \
396 parsing_c parsing_cocci engine
400 set
-e
; for i in
$(DARCSFORESTS
); do cd
$$i; darcs pull
; cd ..
; done
404 set
-e
; for i in
$(DARCSFORESTS
); do cd
$$i; darcs diff
-u
; cd ..
; done
407 ##############################################################################
409 ##############################################################################
415 .
/$(TARGET
) -D standard.h
-parse_c
-dir tests
/
419 # -inline 0 to see all the functions in the profile.
420 # Can also use the profile framework in commons/ and run your program
423 $(MAKE
) OPTFLAGS
="-p -inline 0 " opt
429 otags
-no-mli-tags
-r .
432 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
433 ocamldot
-lr
/tmp
/dependfull.depend
> /tmp
/dependfull.dot
434 dot
-Tps
/tmp
/dependfull.dot
> /tmp
/dependfull.ps
435 ps2pdf
/tmp
/dependfull.ps
/tmp
/dependfull.pdf
437 ##############################################################################
439 ##############################################################################
441 # each member of the project can have its own test.ml. this file is
444 echo
"let foo_ctl () = failwith \"there is no foo_ctl formula\"" \
447 beforedepend
:: test.ml
450 #INC=$(dir $(shell which ocaml))
453 #INCZ=$(INCY:/=)/lib/ocaml
456 # gcc -c -o prim.o -I $(INCZ) prim.c
459 ##############################################################################
460 # Generic ocaml rules
461 ##############################################################################
463 .SUFFIXES
: .ml .mli .cmo .cmi .cmx
476 rm -f
*.cm
[iox
] *.o
*.annot
479 rm -f
*~ .
*~
*.exe
#*#
483 depend
:: beforedepend
484 $(OCAMLDEP
) *.mli
*.ml
> .depend
485 set
-e
; for i in
$(MAKESUBDIRS
); do
$(MAKE
) -C
$$i depend
; done