Release coccinelle-0.2.0rc1
[bpt/coccinelle.git] / Makefile
1
2 #############################################################################
3 # Configuration section
4 #############################################################################
5
6 -include Makefile.config
7
8 VERSION=$(shell cat globals/config.ml.in |grep version |perl -p -e 's/.*"(.*)".*/$$1/;')
9 CCVERSION=$(shell cat scripts/coccicheck/README |grep "Coccicheck version" |perl -p -e 's/.*version (.*)[ ]*/$$1/;')
10
11 ##############################################################################
12 # Variables
13 ##############################################################################
14 TARGET=spatch
15
16 SRC=flag_cocci.ml cocci.ml testing.ml test.ml main.ml
17
18 ifeq ($(FEATURE_PYTHON),1)
19 PYCMA=pycaml/pycaml.cma
20 PYDIR=pycaml
21 PYLIB=dllpycaml_stubs.so
22 # the following is essential for Coccinelle to compile under gentoo (weird)
23 OPTLIBFLAGS=-cclib dllpycaml_stubs.so
24 else
25 PYCMA=
26 PYDIR=
27 PYLIB=
28 OPTLIBFLAGS=
29 endif
30
31 SEXPSYSCMA=bigarray.cma nums.cma
32
33 SYSLIBS=str.cma unix.cma $(SEXPSYSCMA)
34 LIBS=commons/commons.cma \
35 ocamlsexp/sexplib1.cma commons/commons_sexp.cma \
36 globals/globals.cma \
37 ctl/ctl.cma \
38 parsing_cocci/cocci_parser.cma parsing_c/parsing_c.cma \
39 engine/cocciengine.cma popl09/popl.cma \
40 extra/extra.cma $(PYCMA) python/coccipython.cma
41
42 #used for clean: and depend: and a little for rec & rec.opt
43 MAKESUBDIRS=commons ocamlsexp \
44 globals menhirlib $(PYDIR) ctl parsing_cocci parsing_c \
45 engine popl09 extra python
46 INCLUDEDIRS=commons commons/ocamlextra ocamlsexp \
47 globals menhirlib $(PYDIR) ctl \
48 parsing_cocci parsing_c engine popl09 extra python
49
50 ##############################################################################
51 # Generic variables
52 ##############################################################################
53
54 INCLUDES=$(INCLUDEDIRS:%=-I %)
55
56 OBJS= $(SRC:.ml=.cmo)
57 OPTOBJS= $(SRC:.ml=.cmx)
58
59 EXEC=$(TARGET)
60
61 ##############################################################################
62 # Generic ocaml variables
63 ##############################################################################
64
65 OCAMLCFLAGS=# -g -dtypes # -w A
66
67 # for profiling add -p -inline 0
68 # but 'make forprofiling' below does that for you.
69 # This flag is also used in subdirectories so don't change its name here.
70 # To enable backtrace support for native code, you need to put -g in OPTFLAGS
71 # to also link with -g, but even in 3.11 the backtrace support seems buggy so
72 # not worth it.
73 OPTFLAGS=
74 # the following is essential for Coccinelle to compile under gentoo
75 # but is now defined above in this file
76 #OPTLIBFLAGS=-cclib dllpycaml_stubs.so
77
78 OCAMLC=ocamlc$(OPTBIN) $(OCAMLCFLAGS) $(INCLUDES)
79 OCAMLOPT=ocamlopt$(OPTBIN) $(OPTFLAGS) $(INCLUDES)
80 OCAMLLEX=ocamllex #-ml # -ml for debugging lexer, but slightly slower
81 OCAMLYACC=ocamlyacc -v
82 OCAMLDEP=ocamldep $(INCLUDES)
83 OCAMLMKTOP=ocamlmktop -g -custom $(INCLUDES)
84
85 # can also be set via 'make static'
86 STATIC= #-ccopt -static
87
88 # can also be unset via 'make purebytecode'
89 BYTECODE_STATIC=-custom
90
91 ##############################################################################
92 # Top rules
93 ##############################################################################
94 .PHONY:: all all.opt byte opt top clean distclean configure
95 .PHONY:: $(MAKESUBDIRS) $(MAKESUBDIRS:%=%.opt) subdirs subdirs.opt
96
97 all: Makefile.config byte preinstall
98
99 opt: all.opt
100 all.opt: opt-compil preinstall
101
102 world: preinstall
103 $(MAKE) byte
104 $(MAKE) opt-compil
105
106 byte: .depend
107 $(MAKE) subdirs
108 $(MAKE) $(EXEC)
109
110 opt-compil: .depend
111 $(MAKE) subdirs.opt
112 $(MAKE) $(EXEC).opt
113
114 top: $(EXEC).top
115
116 subdirs:
117 $(MAKE) -C commons OCAMLCFLAGS="$(OCAMLCFLAGS)"
118 $(MAKE) -C ocamlsexp OCAMLCFLAGS="$(OCAMLCFLAGS)"
119 $(MAKE) -C commons sexp OCAMLCFLAGS="$(OCAMLCFLAGS)"
120 +for D in $(MAKESUBDIRS); do $(MAKE) $$D || exit 1 ; done
121
122 subdirs.opt:
123 $(MAKE) -C commons all.opt OCAMLCFLAGS="$(OCAMLCFLAGS)"
124 $(MAKE) -C ocamlsexp all.opt OCAMLCFLAGS="$(OCAMLCFLAGS)"
125 $(MAKE) -C commons sexp.opt OCAMLCFLAGS="$(OCAMLCFLAGS)"
126 +for D in $(MAKESUBDIRS); do $(MAKE) $$D.opt || exit 1 ; done
127
128 $(MAKESUBDIRS):
129 $(MAKE) -C $@ OCAMLCFLAGS="$(OCAMLCFLAGS)" all
130
131 $(MAKESUBDIRS:%=%.opt):
132 $(MAKE) -C $(@:%.opt=%) OCAMLCFLAGS="$(OCAMLCFLAGS)" all.opt
133
134 #dependencies:
135 # commons:
136 # globals:
137 # menhirlib:
138 # parsing_cocci: commons globals menhirlib
139 # parsing_c:parsing_cocci
140 # ctl:globals commons
141 # engine: parsing_cocci parsing_c ctl
142 # popl09:engine
143 # extra: parsing_cocci parsing_c ctl
144 # pycaml:
145 # python:pycaml parsing_cocci parsing_c
146
147 clean::
148 set -e; for i in $(MAKESUBDIRS); do $(MAKE) -C $$i $@; done
149
150 $(LIBS): $(MAKESUBDIRS)
151 $(LIBS:.cma=.cmxa): $(MAKESUBDIRS:%=%.opt)
152
153 $(OBJS):$(LIBS)
154 $(OPTOBJS):$(LIBS:.cma=.cmxa)
155
156 $(EXEC): $(LIBS) $(OBJS)
157 $(OCAMLC) $(BYTECODE_STATIC) -o $@ $(SYSLIBS) $^
158
159 $(EXEC).opt: $(LIBS:.cma=.cmxa) $(OPTOBJS)
160 $(OCAMLOPT) $(STATIC) -o $@ $(SYSLIBS:.cma=.cmxa) $(OPTLIBFLAGS) $^
161
162 $(EXEC).top: $(LIBS) $(OBJS)
163 $(OCAMLMKTOP) -custom -o $@ $(SYSLIBS) $^
164
165 clean::
166 rm -f $(TARGET) $(TARGET).opt $(TARGET).top
167 rm -f dllpycaml_stubs.so
168
169 .PHONY:: tools configure
170
171 configure:
172 ./configure
173
174 Makefile.config:
175 @echo "Makefile.config is missing. Have you run ./configure?"
176 @exit 1
177
178 tools:
179 $(MAKE) -C tools
180
181 clean::
182 $(MAKE) -C tools clean
183
184 static:
185 rm -f spatch.opt spatch
186 $(MAKE) STATIC="-ccopt -static" spatch.opt
187 cp spatch.opt spatch
188
189 purebytecode:
190 rm -f spatch.opt spatch
191 $(MAKE) BYTECODE_STATIC="" spatch
192 perl -p -i -e 's/^#!.*/#!\/usr\/bin\/ocamlrun/' spatch
193
194
195 ##############################################################################
196 # Build documentation
197 ##############################################################################
198 .PHONY:: docs
199
200 docs:
201 make -C docs
202
203 clean::
204 make -C docs clean
205
206 distclean::
207 make -C docs distclean
208
209 ##############################################################################
210 # Pre-Install (customization of spatch frontend script)
211 ##############################################################################
212
213 preinstall: scripts/spatch scripts/spatch.opt scripts/spatch.byte
214
215 # user will use spatch to run spatch.opt (native)
216 scripts/spatch:
217 cp scripts/spatch.sh scripts/spatch.tmp2
218 sed "s|SHAREDIR|$(SHAREDIR)|g" scripts/spatch.tmp2 > scripts/spatch.tmp
219 sed "s|LIBDIR|$(LIBDIR)|g" scripts/spatch.tmp > scripts/spatch
220 rm -f scripts/spatch.tmp2 scripts/spatch.tmp
221
222 # user will use spatch to run spatch (bytecode)
223 scripts/spatch.byte:
224 cp scripts/spatch.sh scripts/spatch.byte.tmp3
225 sed "s|\.opt||" scripts/spatch.byte.tmp3 > scripts/spatch.byte.tmp2
226 sed "s|SHAREDIR|$(SHAREDIR)|g" scripts/spatch.byte.tmp2 \
227 > scripts/spatch.byte.tmp
228 sed "s|LIBDIR|$(LIBDIR)|g" scripts/spatch.byte.tmp \
229 > scripts/spatch.byte
230 rm -f scripts/spatch.byte.tmp3 \
231 scripts/spatch.byte.tmp2 \
232 scripts/spatch.byte.tmp
233
234 # user will use spatch.opt to run spatch.opt (native)
235 scripts/spatch.opt:
236 cp scripts/spatch.sh scripts/spatch.opt.tmp2
237 sed "s|SHAREDIR|$(SHAREDIR)|g" scripts/spatch.opt.tmp2 \
238 > scripts/spatch.opt.tmp
239 sed "s|LIBDIR|$(LIBDIR)|g" scripts/spatch.opt.tmp \
240 > scripts/spatch.opt
241 rm -f scripts/spatch.opt.tmp scripts/spatch.opt.tmp2
242
243 clean::
244 rm -f scripts/spatch scripts/spatch.byte scripts/spatch.opt
245
246 ##############################################################################
247 # Install
248 ##############################################################################
249
250 # don't remove DESTDIR, it can be set by package build system like ebuild
251 # for staged installation.
252 install-common:
253 mkdir -p $(DESTDIR)$(BINDIR)
254 mkdir -p $(DESTDIR)$(LIBDIR)
255 mkdir -p $(DESTDIR)$(SHAREDIR)
256 mkdir -p $(DESTDIR)$(MANDIR)/man1
257 $(INSTALL_DATA) standard.h $(DESTDIR)$(SHAREDIR)
258 $(INSTALL_DATA) standard.iso $(DESTDIR)$(SHAREDIR)
259 $(INSTALL_DATA) docs/spatch.1 $(DESTDIR)$(MANDIR)/man1/
260 @if [ $(FEATURE_PYTHON) -eq 1 ]; then $(MAKE) install-python; fi
261
262 install-python:
263 mkdir -p $(DESTDIR)$(SHAREDIR)/python/coccilib/coccigui
264 $(INSTALL_DATA) python/coccilib/*.py \
265 $(DESTDIR)$(SHAREDIR)/python/coccilib
266 $(INSTALL_DATA) python/coccilib/coccigui/*.py \
267 $(DESTDIR)$(SHAREDIR)/python/coccilib/coccigui
268 $(INSTALL_DATA) python/coccilib/coccigui/pygui.glade \
269 $(DESTDIR)$(SHAREDIR)/python/coccilib/coccigui
270 $(INSTALL_DATA) python/coccilib/coccigui/pygui.gladep \
271 $(DESTDIR)$(SHAREDIR)/python/coccilib/coccigui
272 $(INSTALL_LIB) dllpycaml_stubs.so $(DESTDIR)$(LIBDIR)
273
274 install: install-common
275 @if test -x spatch -a ! -x spatch.opt ; then \
276 $(MAKE) install-byte;fi
277 @if test ! -x spatch -a -x spatch.opt ; then \
278 $(MAKE) install-def; $(MAKE) install-opt;fi
279 @if test -x spatch -a -x spatch.opt ; then \
280 $(MAKE) install-byte; $(MAKE) install-opt;fi
281 @if test ! -x spatch -a ! -x spatch.opt ; then \
282 echo "\n\n\t==> Run 'make', 'make opt', or both first. <==\n\n";fi
283 @echo ""
284 @echo "\tYou can also install spatch by copying the program spatch"
285 @echo "\t(available in this directory) anywhere you want and"
286 @echo "\tgive it the right options to find its configuration files."
287 @echo ""
288
289 # user will use spatch to run spatch.opt (native)
290 install-def:
291 $(INSTALL_PROGRAM) spatch.opt $(DESTDIR)$(SHAREDIR)
292 $(INSTALL_PROGRAM) scripts/spatch $(DESTDIR)$(BINDIR)/spatch
293
294 # user will use spatch to run spatch (bytecode)
295 install-byte:
296 $(INSTALL_PROGRAM) spatch $(DESTDIR)$(SHAREDIR)
297 $(INSTALL_PROGRAM) scripts/spatch.byte $(DESTDIR)$(BINDIR)/spatch
298
299 # user will use spatch.opt to run spatch.opt (native)
300 install-opt:
301 $(INSTALL_PROGRAM) spatch.opt $(DESTDIR)$(SHAREDIR)
302 $(INSTALL_PROGRAM) scripts/spatch.opt $(DESTDIR)$(BINDIR)/spatch.opt
303
304 uninstall:
305 rm -f $(DESTDIR)$(BINDIR)/spatch
306 rm -f $(DESTDIR)$(BINDIR)/spatch.opt
307 rm -f $(DESTDIR)$(LIBDIR)/dllpycaml_stubs.so
308 rm -f $(DESTDIR)$(SHAREDIR)/standard.h
309 rm -f $(DESTDIR)$(SHAREDIR)/standard.iso
310 rm -rf $(DESTDIR)$(SHAREDIR)/python/coccilib
311 rm -f $(DESTDIR)$(MANDIR)/man1/spatch.1
312
313 version:
314 @echo "spatch $(VERSION)"
315 @echo "coccicheck $(CCVERSION)"
316
317
318 ##############################################################################
319 # Package rules
320 ##############################################################################
321
322 PACKAGE=coccinelle-$(VERSION)
323 CCPACKAGE=coccicheck-$(CCVERSION)
324
325 BINSRC=spatch env.sh env.csh standard.h standard.iso \
326 *.txt \
327 docs/manual/manual.pdf docs/manual/options.pdf docs/manual/main_grammar.pdf docs/spatch.1 \
328 docs/manual/cocci-python.txt \
329 demos/foo.* demos/simple.*
330 # $(PYLIB) python/coccilib/ demos/printloc.*
331 BINSRC2=$(BINSRC:%=$(PACKAGE)/%)
332
333 TMP=/tmp
334 OCAMLVERSION=$(shell ocaml -version |perl -p -e 's/.*version (.*)/$$1/;')
335
336 # Procedure to do first time:
337 # cd ~/release
338 # cvs checkout coccinelle -dP
339 # cd coccinelle
340 #
341 # Procedure to do each time:
342 #
343 # 1) make prepackage # WARN: These will clean your local rep. of pending modifications
344 #
345 # UPDATE VERSION number in globals/config.ml.in
346 # and commit it with
347 #
348 # 2) make release
349 #
350 # The project is then automatically licensified.
351 #
352 # Remember to comment the -g -dtypes in this Makefile
353 # You can also remove a few things, for instance I removed in this
354 # Makefile things related to popl/ and popl09/
355 # make sure that ocaml is the distribution ocaml of /usr/bin, not ~pad/...
356 #
357 # 3) make package
358 #
359 # if WEBSITE is set properly, you can also run 'make website'
360 # Check that run an ocaml in /usr/bin
361
362 # To test you can try compile and run spatch from different instances
363 # like my ~/coccinelle, ~/release/coccinelle, and the /tmp/coccinelle-0.X
364 # downloaded from the website.
365
366 # For 'make srctar' it must done from a clean
367 # repo such as ~/release/coccinelle. It must also be a repo where
368 # the scripts/licensify has been run at least once.
369 # For the 'make bintar' I can do it from my original repo.
370
371 prepackage:
372 cvs up -CdP
373 $(MAKE) distclean
374
375 release:
376 cvs ci -m "Release $(VERSION)" globals/config.ml-in
377 $(MAKE) licensify
378
379 package:
380 $(MAKE) distclean # Clean project
381 $(MAKE) srctar
382 ./configure --without-python
383 $(MAKE) docs
384 $(MAKE) bintar
385 $(MAKE) bytecodetar
386 $(MAKE) staticbintar
387 $(MAKE) distclean # Clean project
388 ./configure # Reconfigure project with Python support
389 $(MAKE) docs
390 $(MAKE) bintar-python
391 $(MAKE) bytecodetar-python
392 $(MAKE) coccicheck
393
394
395 # I currently pre-generate the parser so the user does not have to
396 # install menhir on his machine. We could also do a few cleanups.
397 # You may have first to do a 'make licensify'.
398 #
399 # update: make docs generates pdf but also some ugly .log files, so
400 # make clean is there to remove them while not removing the pdf
401 # (only distclean remove the pdfs).
402 srctar:
403 make distclean
404 make docs
405 make clean
406 cp -a . $(TMP)/$(PACKAGE)
407 cd $(TMP)/$(PACKAGE); cd parsing_cocci/; make parser_cocci_menhir.ml
408 cd $(TMP); tar cvfz $(PACKAGE).tgz --exclude-vcs $(PACKAGE)
409 rm -rf $(TMP)/$(PACKAGE)
410
411
412 bintar: all
413 rm -f $(TMP)/$(PACKAGE)
414 ln -s `pwd` $(TMP)/$(PACKAGE)
415 cd $(TMP); tar cvfz $(PACKAGE)-bin-x86.tgz --exclude-vcs $(BINSRC2)
416 rm -f $(TMP)/$(PACKAGE)
417
418 staticbintar: all.opt
419 rm -f $(TMP)/$(PACKAGE)
420 ln -s `pwd` $(TMP)/$(PACKAGE)
421 make static
422 cd $(TMP); tar cvfz $(PACKAGE)-bin-x86-static.tgz --exclude-vcs $(BINSRC2)
423 rm -f $(TMP)/$(PACKAGE)
424
425 # add ocaml version in name ?
426 bytecodetar: all
427 rm -f $(TMP)/$(PACKAGE)
428 ln -s `pwd` $(TMP)/$(PACKAGE)
429 make purebytecode
430 cd $(TMP); tar cvfz $(PACKAGE)-bin-bytecode-$(OCAMLVERSION).tgz --exclude-vcs $(BINSRC2)
431 rm -f $(TMP)/$(PACKAGE)
432
433 bintar-python: all
434 rm -f $(TMP)/$(PACKAGE)
435 ln -s `pwd` $(TMP)/$(PACKAGE)
436 cd $(TMP); tar cvfz $(PACKAGE)-bin-x86-python.tgz --exclude-vcs $(BINSRC2)
437 rm -f $(TMP)/$(PACKAGE)
438
439 # add ocaml version in name ?
440 bytecodetar-python: all
441 rm -f $(TMP)/$(PACKAGE)
442 ln -s `pwd` $(TMP)/$(PACKAGE)
443 make purebytecode
444 cd $(TMP); tar cvfz $(PACKAGE)-bin-bytecode-$(OCAMLVERSION)-python.tgz --exclude-vcs $(BINSRC2)
445 rm -f $(TMP)/$(PACKAGE)
446
447 coccicheck:
448 cp -a `pwd`/scripts/coccicheck $(TMP)/$(CCPACKAGE)
449 tar cvfz $(TMP)/$(CCPACKAGE).tgz -C $(TMP) --exclude-vcs $(CCPACKAGE)
450 rm -rf $(TMP)/$(CCPACKAGE)
451
452 clean-packages::
453 rm -f $(TMP)/$(PACKAGE).tgz
454 rm -f $(TMP)/$(PACKAGE)-bin-x86.tgz
455 rm -f $(TMP)/$(PACKAGE)-bin-x86-static.tgz
456 rm -f $(TMP)/$(PACKAGE)-bin-bytecode-$(OCAMLVERSION).tgz
457 rm -f $(TMP)/$(PACKAGE)-bin-x86-python.tgz
458 rm -f $(TMP)/$(PACKAGE)-bin-bytecode-$(OCAMLVERSION)-python.tgz
459 rm -f $(TMP)/$(CCPACKAGE).tgz
460
461 #
462 # No need to licensify 'demos'. Because these is basic building blocks
463 # to use SmPL.
464 #
465 TOLICENSIFY=ctl engine globals parsing_cocci popl popl09 python scripts tools
466 licensify:
467 ocaml str.cma tools/licensify.ml
468 set -e; for i in $(TOLICENSIFY); do cd $$i; ocaml str.cma ../tools/licensify.ml; cd ..; done
469
470 # When checking out the source from diku sometimes I have some "X in the future"
471 # error messages.
472 fixdates:
473 echo do 'touch **/*.*'
474
475 #fixCVS:
476 # cvs update -d -P
477 # echo do 'rm -rf **/CVS'
478
479 ocamlversion:
480 @echo $(OCAMLVERSION)
481
482 ##############################################################################
483 # Developer rules
484 ##############################################################################
485
486 -include Makefile.dev
487
488 test: $(TARGET)
489 ./$(TARGET) -testall
490
491 testparsing:
492 ./$(TARGET) -D standard.h -parse_c -dir tests/
493
494
495
496 # -inline 0 to see all the functions in the profile.
497 # Can also use the profile framework in commons/ and run your program
498 # with -profile.
499 forprofiling:
500 $(MAKE) OPTFLAGS="-p -inline 0 " opt
501
502 clean::
503 rm -f gmon.out
504
505 tags:
506 otags -no-mli-tags -r .
507
508 dependencygraph:
509 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
510 ocamldot -lr /tmp/dependfull.depend > /tmp/dependfull.dot
511 dot -Tps /tmp/dependfull.dot > /tmp/dependfull.ps
512 ps2pdf /tmp/dependfull.ps /tmp/dependfull.pdf
513
514 ##############################################################################
515 # Misc rules
516 ##############################################################################
517
518 # each member of the project can have its own test.ml. this file is
519 # not under CVS.
520 test.ml:
521 echo "let foo_ctl () = failwith \"there is no foo_ctl formula\"" \
522 > test.ml
523
524 beforedepend:: test.ml
525
526
527 #INC=$(dir $(shell which ocaml))
528 #INCX=$(INC:/=)
529 #INCY=$(dir $(INCX))
530 #INCZ=$(INCY:/=)/lib/ocaml
531 #
532 #prim.o: prim.c
533 # gcc -c -o prim.o -I $(INCZ) prim.c
534
535
536 ##############################################################################
537 # Generic ocaml rules
538 ##############################################################################
539
540 .SUFFIXES: .ml .mli .cmo .cmi .cmx
541
542 .ml.cmo:
543 $(OCAMLC) -c $<
544 .mli.cmi:
545 $(OCAMLC) -c $<
546 .ml.cmx:
547 $(OCAMLOPT) -c $<
548
549 .ml.mldepend:
550 $(OCAMLC) -i $<
551
552 clean::
553 rm -f *.cm[iox] *.o *.annot
554 rm -f *~ .*~ *.exe #*#
555
556 distclean:: clean
557 set -e; for i in $(MAKESUBDIRS); do $(MAKE) -C $$i $@; done
558 rm -f .depend
559 rm -f Makefile.config
560 rm -f python/coccilib/output.py
561 rm -f python/pycocci.ml
562 rm -f python/pycocci_aux.ml
563 rm -f globals/config.ml
564 rm -f TAGS
565 rm -f tests/SCORE_actual.sexp
566 rm -f tests/SCORE_best_of_both.sexp
567 find -name ".#*1.*" | xargs rm -f
568
569 beforedepend::
570
571 depend:: beforedepend
572 $(OCAMLDEP) *.mli *.ml > .depend
573 set -e; for i in $(MAKESUBDIRS); do $(MAKE) -C $$i $@; done
574
575 .depend::
576 @if [ ! -f .depend ] ; then $(MAKE) depend ; fi
577
578 -include .depend