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 # the OPTBIN variable is here to allow to use ocamlc.opt instead of
89 # ocaml, when it is available, which speeds up compilation. So
90 # if you want the fast version of the ocaml chain tools, set this var
91 # or setenv it to ".opt" in your startup script.
94 OCAMLC=ocamlc$(OPTBIN) $(OCAMLCFLAGS) $(INCLUDES)
95 OCAMLOPT=ocamlopt$(OPTBIN) $(OPTFLAGS) $(INCLUDES)
96 OCAMLLEX=ocamllex #-ml # -ml for debugging lexer, but slightly slower
97 OCAMLYACC=ocamlyacc -v
98 OCAMLDEP=ocamldep #$(INCLUDES)
99 OCAMLMKTOP=ocamlmktop -g -custom $(INCLUDES)
101 # can also be set via 'make static'
102 STATIC= #-ccopt -static
104 # can also be unset via 'make purebytecode'
105 BYTECODE_STATIC=-custom
107 ##############################################################################
109 ##############################################################################
115 .PHONY: $(MAKESUBDIRS) $(MAKESUBDIRS:%=%.opt)
118 $(MAKE) -C $@ OCAMLCFLAGS="$(OCAMLCFLAGS)" all
120 $(MAKESUBDIRS:%=%.opt):
121 $(MAKE) -C $(@:%.opt=%) OCAMLCFLAGS="$(OCAMLCFLAGS)" all.opt
126 parsing_cocci:globals menhirlib
127 parsing_c:parsing_cocci
129 engine: parsing_cocci parsing_c ctl
131 extra: parsing_cocci parsing_c ctl
133 python:pycaml parsing_cocci parsing_c
138 parsing_cocci.opt:globals.opt menhirlib.opt
139 parsing_c.opt:parsing_cocci.opt
140 ctl.opt:globals.opt commons.opt
141 engine.opt: parsing_cocci.opt parsing_c.opt ctl.opt
142 popl09.opt:engine.opt
143 extra.opt: parsing_cocci.opt parsing_c.opt ctl.opt
145 python.opt:pycaml.opt parsing_cocci.opt parsing_c.opt
147 # set -e; for i in $(MAKESUBDIRS); \
148 # do $(MAKE) -C $$i OCAMLCFLAGS="$(OCAMLCFLAGS)" all; done
151 # set -e; for i in $(MAKESUBDIRS); \
152 # do $(MAKE) -C $$i OCAMLCFLAGS="$(OCAMLCFLAGS)" all.opt; done
154 set -e; for i in $(MAKESUBDIRS); do $(MAKE) -C $$i clean; done
159 $(LIBS): $(MAKESUBDIRS)
160 $(LIBS:.cma=.cmxa): $(MAKESUBDIRS:%=%.opt)
163 echo "$(SRC:.ml=.cmi): $(MAKESUBDIRS)" > .subdirs
167 echo "$(SRC:.ml=.cmi): $(MAKESUBDIRS:%=%.opt)" > .subdirs
173 $(OPTOBJS):$(LIBS:.cma=.cmxa)
175 $(EXEC): $(LIBS) $(OBJS)
176 $(OCAMLC) $(BYTECODE_STATIC) -o $@ $(SYSLIBS) $^
178 $(EXEC).opt: $(LIBS:.cma=.cmxa) $(OPTOBJS)
179 $(OCAMLOPT) $(STATIC) -o $@ $(SYSLIBS:.cma=.cmxa) $(OPTLIBFLAGS) $^
181 $(EXEC).top: $(LIBS) $(OBJS)
182 $(OCAMLMKTOP) -custom -o $@ $(SYSLIBS) $^
185 rm -f $(TARGET) $(TARGET).opt $(TARGET).top
188 rm -f dllpycaml_stubs.so
191 .PHONY: tools all configure
196 $(MAKE) -C tools clean
200 rm -f spatch.opt spatch
201 $(MAKE) STATIC="-ccopt -static" spatch.opt
205 rm -f spatch.opt spatch
206 $(MAKE) BYTECODE_STATIC="" spatch
209 ##############################################################################
211 ##############################################################################
213 # don't remove DESTDIR, it can be set by package build system like ebuild
215 mkdir -p $(DESTDIR)$(BINDIR)
216 mkdir -p $(DESTDIR)$(LIBDIR)
217 mkdir -p $(DESTDIR)$(SHAREDIR)
218 mkdir -p $(DESTDIR)$(MANDIR)/man1
219 cp spatch $(DESTDIR)$(BINDIR)
220 cp standard.h $(DESTDIR)$(SHAREDIR)
221 cp standard.iso $(DESTDIR)$(SHAREDIR)
222 cp docs/spatch.1 $(DESTDIR)$(MANDIR)/man1/
223 mkdir -p $(DESTDIR)$(SHAREDIR)/python
224 cp -a python/coccilib $(DESTDIR)$(SHAREDIR)/python
225 cp -f dllpycaml_stubs.so $(DESTDIR)$(LIBDIR)
227 @echo "You can also install spatch by copying the program spatch"
228 @echo "(available in this directory) anywhere you want and"
229 @echo "give it the right options to find its configuration files."
232 rm -f $(DESTDIR)$(BINDIR)/spatch
233 rm -f $(DESTDIR)$(LIBDIR)/dllpycaml_stubs.so
234 rm -f $(DESTDIR)$(SHAREDIR)/standard.h
235 rm -f $(DESTDIR)$(SHAREDIR)/standard.iso
236 rm -rf $(DESTDIR)$(SHAREDIR)/python/coccilib
237 rm -f $(DESTDIR)$(MANDIR)/man1/spatch.1
245 ##############################################################################
247 ##############################################################################
249 PACKAGE=coccinelle-$(VERSION)
251 BINSRC=spatch env.sh env.csh standard.h standard.iso \
253 demos/foo.* demos/simple.*
254 # $(PYLIB) python/coccilib/ demos/printloc.*
255 BINSRC2=$(BINSRC:%=$(PACKAGE)/%)
258 OCAMLVERSION=$(shell ocaml -version |perl -p -e 's/.*version (.*)/$$1/;')
260 # Procedure to do first time:
262 # cvs checkout coccinelle
267 # remember to comment the -g -dtypes in this Makefile
269 # Procedure to do each time:
271 # ./configure --without-python
274 # Check also that run an ocaml in /usr/bin
276 # To test you can try compile and run spatch from different instances
277 # like my ~/coccinelle, ~/release/coccinelle, and the /tmp/coccinelle-0.X
278 # downloaded from the website.
280 # For 'make srctar' it must done from a clean
281 # repo such as ~/release/coccinelle. It must also be a repo where
282 # the scripts/licensify has been run at least once.
283 # For the 'make bintar' I can do it from my original repo.
292 # I currently pre-generate the parser so the user does not have to
293 # install menhir on his machine. I also do a few cleanups like 'rm todo_pos'.
294 # You may have first to do a 'make licensify'.
297 cp -a . $(TMP)/$(PACKAGE)
298 cd $(TMP)/$(PACKAGE); cd parsing_cocci/; make parser_cocci_menhir.ml
299 cd $(TMP)/$(PACKAGE); rm todo_pos
300 cd $(TMP); tar cvfz $(PACKAGE).tgz --exclude=CVS $(PACKAGE)
301 rm -rf $(TMP)/$(PACKAGE)
305 rm -f $(TMP)/$(PACKAGE)
306 ln -s `pwd` $(TMP)/$(PACKAGE)
307 cd $(TMP); tar cvfz $(PACKAGE)-bin-x86.tgz --exclude=CVS $(BINSRC2)
308 rm -f $(TMP)/$(PACKAGE)
310 staticbintar: all.opt
311 rm -f $(TMP)/$(PACKAGE)
312 ln -s `pwd` $(TMP)/$(PACKAGE)
314 cd $(TMP); tar cvfz $(PACKAGE)-bin-x86-static.tgz --exclude=CVS $(BINSRC2)
315 rm -f $(TMP)/$(PACKAGE)
317 # add ocaml version in name ?
319 rm -f $(TMP)/$(PACKAGE)
320 ln -s `pwd` $(TMP)/$(PACKAGE)
322 cd $(TMP); tar cvfz $(PACKAGE)-bin-bytecode-$(OCAMLVERSION).tgz --exclude=CVS $(BINSRC2)
323 rm -f $(TMP)/$(PACKAGE)
327 rm -f $(PACKAGE)-bin-x86.tgz
328 rm -f $(PACKAGE)-bin-x86-static.tgz
329 rm -f $(PACKAGE)-bin-bytecode-$(OCAMLVERSION).tgz
333 TOLICENSIFY=ctl engine parsing_cocci popl popl09 python
335 ocaml tools/licensify.ml
336 set -e; for i in $(TOLICENSIFY); do cd $$i; ocaml ../tools/licensify.ml; cd ..; done
338 # When checking out the source from diku sometimes I have some "X in the future"
341 echo do 'touch **/*.*'
345 # echo do 'rm -rf **/CVS'
348 @echo $(OCAMLVERSION)
351 ##############################################################################
353 ##############################################################################
355 #TOP=/home/pad/mobile/project-coccinelle
356 WEBSITE=/home/pad/mobile/homepage/software/project-coccinelle
359 cp $(TMP)/$(PACKAGE).tgz $(WEBSITE)
360 cp $(TMP)/$(PACKAGE)-bin-x86.tgz $(WEBSITE)
361 cp $(TMP)/$(PACKAGE)-bin-x86-static.tgz $(WEBSITE)
362 cp $(TMP)/$(PACKAGE)-bin-bytecode-$(OCAMLVERSION).tgz $(WEBSITE)
365 #TXT=$(wildcard *.txt)
367 # unison ~/public_html/wiki/wiki-LFS/data/pages/ docs/wiki/
368 # set -e; for i in $(TXT); do unison $$i docs/wiki/$$i; done
371 # @echo pull from ~/public_html/darcs/c-coccinelle and c-commons and lib-xxx
373 DARCSFORESTS=commons \
374 parsing_c parsing_cocci engine
378 set -e; for i in $(DARCSFORESTS); do cd $$i; darcs pull; cd ..; done
382 set -e; for i in $(DARCSFORESTS); do cd $$i; darcs diff -u; cd ..; done
385 ##############################################################################
387 ##############################################################################
393 ./$(TARGET) -D standard.h -parse_c -dir tests/
397 # -inline 0 to see all the functions in the profile.
398 # Can also use the profile framework in commons/ and run your program
401 $(MAKE) OPTFLAGS="-p -inline 0 " opt
407 otags -no-mli-tags -r .
410 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
411 ocamldot -lr /tmp/dependfull.depend > /tmp/dependfull.dot
412 dot -Tps /tmp/dependfull.dot > /tmp/dependfull.ps
413 ps2pdf /tmp/dependfull.ps /tmp/dependfull.pdf
415 ##############################################################################
417 ##############################################################################
419 # each member of the project can have its own test.ml. this file is
422 echo "let foo_ctl () = failwith \"there is no foo_ctl formula\"" \
425 beforedepend:: test.ml
428 #INC=$(dir $(shell which ocaml))
431 #INCZ=$(INCY:/=)/lib/ocaml
434 # gcc -c -o prim.o -I $(INCZ) prim.c
437 ##############################################################################
438 # Generic ocaml rules
439 ##############################################################################
441 .SUFFIXES: .ml .mli .cmo .cmi .cmx
454 rm -f *.cm[iox] *.o *.annot
457 rm -f *~ .*~ *.exe #*#
461 depend:: beforedepend
462 $(OCAMLDEP) *.mli *.ml > .depend
463 set -e; for i in $(MAKESUBDIRS); do $(MAKE) -C $$i depend; done