Release coccinelle-0.1.8
[bpt/coccinelle.git] / Makefile
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.
4 #
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.
8 #
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.
13 #
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/>.
16 #
17 # The authors reserve the right to distribute this or future versions of
18 # Coccinelle under other licenses.
19
20
21 #############################################################################
22 # Configuration section
23 #############################################################################
24
25 -include Makefile.config
26
27 VERSION=$(shell cat globals/config.ml.in |grep version |perl -p -e 's/.*"(.*)".*/$$1/;')
28
29 ##############################################################################
30 # Variables
31 ##############################################################################
32 TARGET=spatch
33
34 SRC=flag_cocci.ml cocci.ml testing.ml test.ml main.ml
35
36 ifeq ($(FEATURE_PYTHON),1)
37 PYCMA=pycaml/pycaml.cma
38 PYDIR=pycaml
39 PYLIB=dllpycaml_stubs.so
40 # the following is essential for Coccinelle to compile under gentoo (weird)
41 OPTLIBFLAGS=-cclib dllpycaml_stubs.so
42 else
43 PYCMA=
44 PYDIR=
45 PYLIB=
46 OPTLIBFLAGS=
47 endif
48
49 SEXPSYSCMA=bigarray.cma nums.cma
50
51 SYSLIBS=str.cma unix.cma $(SEXPSYSCMA)
52 LIBS=commons/commons.cma \
53 ocamlsexp/sexplib1.cma commons/commons_sexp.cma \
54 globals/globals.cma \
55 ctl/ctl.cma \
56 parsing_cocci/cocci_parser.cma parsing_c/parsing_c.cma \
57 engine/cocciengine.cma \
58 extra/extra.cma $(PYCMA) python/coccipython.cma
59
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 \
63 engine extra python
64 INCLUDEDIRS=commons commons/ocamlextra ocamlsexp \
65 globals menhirlib $(PYDIR) ctl \
66 parsing_cocci parsing_c engine extra python
67
68 ##############################################################################
69 # Generic variables
70 ##############################################################################
71
72 INCLUDES=$(INCLUDEDIRS:%=-I %)
73
74 OBJS= $(SRC:.ml=.cmo)
75 OPTOBJS= $(SRC:.ml=.cmx)
76
77 EXEC=$(TARGET)
78
79 ##############################################################################
80 # Generic ocaml variables
81 ##############################################################################
82
83 OCAMLCFLAGS= #-g -dtypes # -w A
84
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
90 # not worth it.
91 OPTFLAGS=
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
95
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)
102
103 # can also be set via 'make static'
104 STATIC= #-ccopt -static
105
106 # can also be unset via 'make purebytecode'
107 BYTECODE_STATIC=-custom
108
109 ##############################################################################
110 # Top rules
111 ##############################################################################
112 .PHONY:: all all.opt byte opt top clean distclean configure
113 .PHONY:: $(MAKESUBDIRS) $(MAKESUBDIRS:%=%.opt) subdirs subdirs.opt
114
115 all: Makefile.config byte preinstall
116
117 opt: all.opt
118 all.opt: opt-compil preinstall
119
120 world: preinstall
121 $(MAKE) byte
122 $(MAKE) opt-compil
123
124 byte: .depend
125 $(MAKE) subdirs
126 $(MAKE) $(EXEC)
127
128 opt-compil: .depend
129 $(MAKE) subdirs.opt
130 $(MAKE) $(EXEC).opt
131
132 top: $(EXEC).top
133
134 subdirs:
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
139
140 subdirs.opt:
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
145
146 $(MAKESUBDIRS):
147 $(MAKE) -C $@ OCAMLCFLAGS="$(OCAMLCFLAGS)" all
148
149 $(MAKESUBDIRS:%=%.opt):
150 $(MAKE) -C $(@:%.opt=%) OCAMLCFLAGS="$(OCAMLCFLAGS)" all.opt
151
152 #dependencies:
153 # commons:
154 # globals:
155 # menhirlib:
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
161 # pycaml:
162 # python:pycaml parsing_cocci parsing_c
163
164 clean::
165 set -e; for i in $(MAKESUBDIRS); do $(MAKE) -C $$i $@; done
166
167 $(LIBS): $(MAKESUBDIRS)
168 $(LIBS:.cma=.cmxa): $(MAKESUBDIRS:%=%.opt)
169
170 $(OBJS):$(LIBS)
171 $(OPTOBJS):$(LIBS:.cma=.cmxa)
172
173 $(EXEC): $(LIBS) $(OBJS)
174 $(OCAMLC) $(BYTECODE_STATIC) -o $@ $(SYSLIBS) $^
175
176 $(EXEC).opt: $(LIBS:.cma=.cmxa) $(OPTOBJS)
177 $(OCAMLOPT) $(STATIC) -o $@ $(SYSLIBS:.cma=.cmxa) $(OPTLIBFLAGS) $^
178
179 $(EXEC).top: $(LIBS) $(OBJS)
180 $(OCAMLMKTOP) -custom -o $@ $(SYSLIBS) $^
181
182 clean::
183 rm -f $(TARGET) $(TARGET).opt $(TARGET).top
184
185 clean::
186 rm -f dllpycaml_stubs.so
187
188
189 .PHONY:: tools configure
190
191 configure:
192 ./configure
193
194 Makefile.config:
195 @echo "Makefile.config is missing. Have you run ./configure?"
196 @exit 1
197
198 tools:
199 $(MAKE) -C tools
200
201 clean::
202 $(MAKE) -C tools clean
203
204 static:
205 rm -f spatch.opt spatch
206 $(MAKE) STATIC="-ccopt -static" spatch.opt
207 cp spatch.opt spatch
208
209 purebytecode:
210 rm -f spatch.opt spatch
211 $(MAKE) BYTECODE_STATIC="" spatch
212
213
214 ##############################################################################
215 # Build documentation
216 ##############################################################################
217 .PHONY:: docs
218
219 docs:
220 make -C docs
221
222 clean::
223 make -C docs clean
224
225 distclean::
226 make -C docs distclean
227
228 ##############################################################################
229 # Pre-Install (customization of spatch frontend script)
230 ##############################################################################
231
232 preinstall: scripts/spatch scripts/spatch.opt scripts/spatch.byte
233
234 # user will use spatch to run spatch.opt (native)
235 scripts/spatch:
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
240
241 # user will use spatch to run spatch (bytecode)
242 scripts/spatch.byte:
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
252
253 # user will use spatch.opt to run spatch.opt (native)
254 scripts/spatch.opt:
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 \
259 > scripts/spatch.opt
260 rm -f scripts/spatch.opt.tmp scripts/spatch.opt.tmp2
261
262 clean::
263 rm -f scripts/spatch scripts/spatch.byte scripts/spatch.opt
264
265 ##############################################################################
266 # Install
267 ##############################################################################
268
269 # don't remove DESTDIR, it can be set by package build system like ebuild
270 # for staged installation.
271 install-common:
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
280
281 install-python:
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)
292
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
302 @echo ""
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."
306 @echo ""
307
308 # user will use spatch to run spatch.opt (native)
309 install-def:
310 $(INSTALL_PROGRAM) spatch.opt $(DESTDIR)$(SHAREDIR)
311 $(INSTALL_PROGRAM) scripts/spatch $(DESTDIR)$(BINDIR)/spatch
312
313 # user will use spatch to run spatch (bytecode)
314 install-byte:
315 $(INSTALL_PROGRAM) spatch $(DESTDIR)$(SHAREDIR)
316 $(INSTALL_PROGRAM) scripts/spatch.byte $(DESTDIR)$(BINDIR)/spatch
317
318 # user will use spatch.opt to run spatch.opt (native)
319 install-opt:
320 $(INSTALL_PROGRAM) spatch.opt $(DESTDIR)$(SHAREDIR)
321 $(INSTALL_PROGRAM) scripts/spatch.opt $(DESTDIR)$(BINDIR)/spatch.opt
322
323 uninstall:
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
331
332 version:
333 @echo $(VERSION)
334
335
336 ##############################################################################
337 # Package rules
338 ##############################################################################
339
340 PACKAGE=coccinelle-$(VERSION)
341
342 BINSRC=spatch env.sh env.csh standard.h standard.iso \
343 *.txt \
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)/%)
349
350 TMP=/tmp
351 OCAMLVERSION=$(shell ocaml -version |perl -p -e 's/.*version (.*)/$$1/;')
352
353 # Procedure to do first time:
354 # cd ~/release
355 # cvs checkout coccinelle
356 # cd coccinelle
357 # cvs update -d -P
358 # touch **/*
359 # make licensify
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/
363
364 # Procedure to do each time:
365 # cvs update
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
370 # make package
371 # make website
372 # Check that run an ocaml in /usr/bin
373
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.
377
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.
382
383
384 package:
385 make srctar
386 ./configure --without-python
387 make docs
388 make bintar
389 make staticbintar
390 make bytecodetar
391
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'.
395 #
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).
399 srctar:
400 make distclean
401 make docs
402 make clean
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)
407
408
409 bintar: all
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)
414
415 staticbintar: all.opt
416 rm -f $(TMP)/$(PACKAGE)
417 ln -s `pwd` $(TMP)/$(PACKAGE)
418 make static
419 cd $(TMP); tar cvfz $(PACKAGE)-bin-x86-static.tgz --exclude-vcs $(BINSRC2)
420 rm -f $(TMP)/$(PACKAGE)
421
422 # add ocaml version in name ?
423 bytecodetar: all
424 rm -f $(TMP)/$(PACKAGE)
425 ln -s `pwd` $(TMP)/$(PACKAGE)
426 make purebytecode
427 cd $(TMP); tar cvfz $(PACKAGE)-bin-bytecode-$(OCAMLVERSION).tgz --exclude-vcs $(BINSRC2)
428 rm -f $(TMP)/$(PACKAGE)
429
430 clean::
431 rm -f $(PACKAGE)
432 rm -f $(PACKAGE)-bin-x86.tgz
433 rm -f $(PACKAGE)-bin-x86-static.tgz
434 rm -f $(PACKAGE)-bin-bytecode-$(OCAMLVERSION).tgz
435
436
437
438 TOLICENSIFY=ctl engine parsing_cocci python
439 licensify:
440 ocaml tools/licensify.ml
441 set -e; for i in $(TOLICENSIFY); do cd $$i; ocaml ../tools/licensify.ml; cd ..; done
442
443 # When checking out the source from diku sometimes I have some "X in the future"
444 # error messages.
445 fixdates:
446 echo do 'touch **/*.*'
447
448 #fixCVS:
449 # cvs update -d -P
450 # echo do 'rm -rf **/CVS'
451
452 ocamlversion:
453 @echo $(OCAMLVERSION)
454
455
456 ##############################################################################
457 # Pad specific rules
458 ##############################################################################
459
460 #TOP=/home/pad/mobile/project-coccinelle
461 WEBSITE=/home/pad/mobile/homepage/software/project-coccinelle
462
463 website:
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)
472
473
474 #TXT=$(wildcard *.txt)
475 syncwiki:
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
478
479 darcsweb:
480 # @echo pull from ~/public_html/darcs/c-coccinelle and c-commons and lib-xxx
481
482 DARCSFORESTS=commons ocamlsexp \
483 parsing_c parsing_cocci engine
484
485 update_darcs:
486 darcs pull
487 set -e; for i in $(DARCSFORESTS); do cd $$i; darcs pull; cd ..; done
488
489 #darcs diff -u
490 diff_darcs:
491 set -e; for i in $(DARCSFORESTS); do cd $$i; darcs diff -u; cd ..; done
492
493 ##############################################################################
494 # Git Developer rules
495 ##############################################################################
496 gitupdate:
497 git cvsimport -d :ext:topps:/var/cvs/cocci coccinelle
498
499 ##############################################################################
500 # Developer rules
501 ##############################################################################
502
503 test: $(TARGET)
504 ./$(TARGET) -testall
505
506 testparsing:
507 ./$(TARGET) -D standard.h -parse_c -dir tests/
508
509
510
511 # -inline 0 to see all the functions in the profile.
512 # Can also use the profile framework in commons/ and run your program
513 # with -profile.
514 forprofiling:
515 $(MAKE) OPTFLAGS="-p -inline 0 " opt
516
517 clean::
518 rm -f gmon.out
519
520 tags:
521 otags -no-mli-tags -r .
522
523 dependencygraph:
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
528
529 ##############################################################################
530 # Misc rules
531 ##############################################################################
532
533 # each member of the project can have its own test.ml. this file is
534 # not under CVS.
535 test.ml:
536 echo "let foo_ctl () = failwith \"there is no foo_ctl formula\"" \
537 > test.ml
538
539 beforedepend:: test.ml
540
541
542 #INC=$(dir $(shell which ocaml))
543 #INCX=$(INC:/=)
544 #INCY=$(dir $(INCX))
545 #INCZ=$(INCY:/=)/lib/ocaml
546 #
547 #prim.o: prim.c
548 # gcc -c -o prim.o -I $(INCZ) prim.c
549
550
551 ##############################################################################
552 # Generic ocaml rules
553 ##############################################################################
554
555 .SUFFIXES: .ml .mli .cmo .cmi .cmx
556
557 .ml.cmo:
558 $(OCAMLC) -c $<
559 .mli.cmi:
560 $(OCAMLC) -c $<
561 .ml.cmx:
562 $(OCAMLOPT) -c $<
563
564 .ml.mldepend:
565 $(OCAMLC) -i $<
566
567 clean::
568 rm -f *.cm[iox] *.o *.annot
569 rm -f *~ .*~ *.exe #*#
570
571 distclean:: clean
572 set -e; for i in $(MAKESUBDIRS); do $(MAKE) -C $$i $@; done
573 rm -f .depend
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
579 rm -f TAGS
580 rm -f tests/SCORE_actual.sexp
581 rm -f tests/SCORE_best_of_both.sexp
582 find -name ".#*1.*" | xargs rm -f
583
584 beforedepend::
585
586 depend:: beforedepend
587 $(OCAMLDEP) *.mli *.ml > .depend
588 set -e; for i in $(MAKESUBDIRS); do $(MAKE) -C $$i $@; done
589
590 .depend::
591 @if [ ! -f .depend ] ; then $(MAKE) depend ; fi
592
593 -include .depend