fd8a9c50c49878efecd17b964f5fc34eac23934d
[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 |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
37 ifeq ($(FEATURE_PYTHON),1)
38 PYCMA=pycaml/pycaml.cma
39 PYDIR=pycaml
40 PYLIB=dllpycaml_stubs.so
41 # the following is essential for Coccinelle to compile under gentoo (wierd)
42 OPTLIBFLAGS=-cclib dllpycaml_stubs.so
43 else
44 PYCMA=
45 PYDIR=
46 PYLIB=
47 OPTLIBFLAGS=
48 endif
49
50
51 SYSLIBS=str.cma unix.cma
52 LIBS=commons/commons.cma globals/globals.cma\
53 ctl/ctl.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
57
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
62
63 ##############################################################################
64 # Generic variables
65 ##############################################################################
66
67 INCLUDES=$(INCLUDEDIRS:%=-I %)
68
69 OBJS= $(SRC:.ml=.cmo)
70 OPTOBJS= $(SRC:.ml=.cmx)
71
72 EXEC=$(TARGET)
73
74 ##############################################################################
75 # Generic ocaml variables
76 ##############################################################################
77
78 OCAMLCFLAGS= #-g -dtypes # -w A
79
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.
83 OPTFLAGS=
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
87
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)
94
95 # can also be set via 'make static'
96 STATIC= #-ccopt -static
97
98 # can also be unset via 'make purebytecode'
99 BYTECODE_STATIC=-custom
100
101 ##############################################################################
102 # Top rules
103 ##############################################################################
104 .PHONY: all all.opt opt top clean configure
105 .PHONY: $(MAKESUBDIRS) $(MAKESUBDIRS:%=%.opt) subdirs subdirs.opt
106
107 all:
108 $(MAKE) subdirs
109 $(MAKE) $(EXEC)
110
111 opt:
112 $(MAKE) subdirs.opt
113 $(MAKE) $(EXEC).opt
114
115 all.opt: opt
116 top: $(EXEC).top
117
118 subdirs:
119 +for D in $(MAKESUBDIRS); do $(MAKE) $$D ; done
120
121 subdirs.opt:
122 +for D in $(MAKESUBDIRS); do $(MAKE) $$D.opt ; done
123
124 $(MAKESUBDIRS):
125 $(MAKE) -C $@ OCAMLCFLAGS="$(OCAMLCFLAGS)" all
126
127 $(MAKESUBDIRS:%=%.opt):
128 $(MAKE) -C $(@:%.opt=%) OCAMLCFLAGS="$(OCAMLCFLAGS)" all.opt
129
130 # commons:
131 # globals:
132 # menhirlib:
133 # parsing_cocci: commons globals menhirlib
134 # parsing_c:parsing_cocci
135 # ctl:globals commons
136 # engine: parsing_cocci parsing_c ctl
137 # popl09:engine
138 # extra: parsing_cocci parsing_c ctl
139 # pycaml:
140 # python:pycaml parsing_cocci parsing_c
141 #
142 # commons.opt:
143 # globals.opt:
144 # menhirlib.opt:
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
151 # pycaml.opt:
152 # python.opt:pycaml.opt parsing_cocci.opt parsing_c.opt
153
154 clean::
155 set -e; for i in $(MAKESUBDIRS); do $(MAKE) -C $$i clean; done
156
157 configure:
158 ./configure
159
160 $(LIBS): $(MAKESUBDIRS)
161 $(LIBS:.cma=.cmxa): $(MAKESUBDIRS:%=%.opt)
162
163 $(OBJS):$(LIBS)
164 $(OPTOBJS):$(LIBS:.cma=.cmxa)
165
166 $(EXEC): $(LIBS) $(OBJS)
167 $(OCAMLC) $(BYTECODE_STATIC) -o $@ $(SYSLIBS) $^
168
169 $(EXEC).opt: $(LIBS:.cma=.cmxa) $(OPTOBJS)
170 $(OCAMLOPT) $(STATIC) -o $@ $(SYSLIBS:.cma=.cmxa) $(OPTLIBFLAGS) $^
171
172 $(EXEC).top: $(LIBS) $(OBJS)
173 $(OCAMLMKTOP) -custom -o $@ $(SYSLIBS) $^
174
175 clean::
176 rm -f $(TARGET) $(TARGET).opt $(TARGET).top
177
178 clean::
179 rm -f dllpycaml_stubs.so
180
181
182 .PHONY: tools all configure
183
184 tools:
185 $(MAKE) -C tools
186 clean::
187 $(MAKE) -C tools clean
188
189
190 static:
191 rm -f spatch.opt spatch
192 $(MAKE) STATIC="-ccopt -static" spatch.opt
193 cp spatch.opt spatch
194
195 purebytecode:
196 rm -f spatch.opt spatch
197 $(MAKE) BYTECODE_STATIC="" spatch
198
199
200 ##############################################################################
201 # Install
202 ##############################################################################
203
204 # don't remove DESTDIR, it can be set by package build system like ebuild
205 install-common:
206 mkdir -p $(DESTDIR)$(BINDIR)
207 mkdir -p $(DESTDIR)$(LIBDIR)
208 mkdir -p $(DESTDIR)$(SHAREDIR)
209 mkdir -p $(DESTDIR)$(MANDIR)/man1
210 cp standard.h $(DESTDIR)$(SHAREDIR)
211 cp standard.iso $(DESTDIR)$(SHAREDIR)
212 cp docs/spatch.1 $(DESTDIR)$(MANDIR)/man1/
213 mkdir -p $(DESTDIR)$(SHAREDIR)/python
214 cp -a python/coccilib $(DESTDIR)$(SHAREDIR)/python
215 cp -f dllpycaml_stubs.so $(DESTDIR)$(LIBDIR)
216 @echo ""
217 @echo "You can also install spatch by copying the program spatch"
218 @echo "(available in this directory) anywhere you want and"
219 @echo "give it the right options to find its configuration files."
220 @echo ""
221
222 # user will use spatch to run spatch.opt (native)
223 install: all.opt install-common
224 cp spatch.opt $(DESTDIR)$(SHAREDIR)
225 cat scripts/spatch.sh | sed "s|SHAREDIR|$(DESTDIR)$(SHAREDIR)|g" > $(DESTDIR)$(BINDIR)/spatch
226
227 # user will use spatch to run spatch (bytecode)
228 install-byte: all install-common
229 cp spatch $(DESTDIR)$(SHAREDIR)
230 cat scripts/spatch.sh | sed "s|\.opt||" | sed "s|SHAREDIR|$(DESTDIR)$(SHAREDIR)|g" > $(DESTDIR)$(BINDIR)/spatch
231
232 # user will use spatch.opt to run spatch.opt (native)
233 install-opt: all.opt install-common
234 cp spatch.opt $(DESTDIR)$(SHAREDIR)
235 cat scripts/spatch.sh | sed "s|SHAREDIR|$(DESTDIR)$(SHAREDIR)|g" > $(DESTDIR)$(BINDIR)/spatch.opt
236
237 uninstall:
238 rm -f $(DESTDIR)$(BINDIR)/spatch
239 rm -f $(DESTDIR)$(LIBDIR)/dllpycaml_stubs.so
240 rm -f $(DESTDIR)$(SHAREDIR)/standard.h
241 rm -f $(DESTDIR)$(SHAREDIR)/standard.iso
242 rm -rf $(DESTDIR)$(SHAREDIR)/python/coccilib
243 rm -f $(DESTDIR)$(MANDIR)/man1/spatch.1
244
245
246
247 version:
248 @echo $(VERSION)
249
250
251 ##############################################################################
252 # Package rules
253 ##############################################################################
254
255 PACKAGE=coccinelle-$(VERSION)
256
257 BINSRC=spatch env.sh env.csh standard.h standard.iso \
258 *.txt docs/* \
259 demos/foo.* demos/simple.*
260 # $(PYLIB) python/coccilib/ demos/printloc.*
261 BINSRC2=$(BINSRC:%=$(PACKAGE)/%)
262
263 TMP=/tmp
264 OCAMLVERSION=$(shell ocaml -version |perl -p -e 's/.*version (.*)/$$1/;')
265
266 # Procedure to do first time:
267 # cd ~/release
268 # cvs checkout coccinelle
269 # cd coccinelle
270 # cvs update -d -P
271 # touch **/*
272 # make licensify
273 # remember to comment the -g -dtypes in this Makefile
274
275 # Procedure to do each time:
276 # cvs update
277 # make sure that ocaml is the distribution ocaml of /usr/bin, not ~pad/...
278 # modify globals/config.ml
279 # cd globals/; cvs commit -m"new version" (do not commit from the root!)
280 # ./configure --without-python
281 # make package
282 # make website
283 # Check that run an ocaml in /usr/bin
284
285 # To test you can try compile and run spatch from different instances
286 # like my ~/coccinelle, ~/release/coccinelle, and the /tmp/coccinelle-0.X
287 # downloaded from the website.
288
289 # For 'make srctar' it must done from a clean
290 # repo such as ~/release/coccinelle. It must also be a repo where
291 # the scripts/licensify has been run at least once.
292 # For the 'make bintar' I can do it from my original repo.
293
294
295 package:
296 make srctar
297 make bintar
298 make staticbintar
299 make bytecodetar
300
301 # I currently pre-generate the parser so the user does not have to
302 # install menhir on his machine. I also do a few cleanups like 'rm todo_pos'.
303 # You may have first to do a 'make licensify'.
304 srctar:
305 make clean
306 cp -a . $(TMP)/$(PACKAGE)
307 cd $(TMP)/$(PACKAGE); cd parsing_cocci/; make parser_cocci_menhir.ml
308 cd $(TMP)/$(PACKAGE); rm todo_pos
309 cd $(TMP); tar cvfz $(PACKAGE).tgz --exclude-vcs $(PACKAGE)
310 rm -rf $(TMP)/$(PACKAGE)
311
312
313 bintar: all
314 rm -f $(TMP)/$(PACKAGE)
315 ln -s `pwd` $(TMP)/$(PACKAGE)
316 cd $(TMP); tar cvfz $(PACKAGE)-bin-x86.tgz --exclude-vcs $(BINSRC2)
317 rm -f $(TMP)/$(PACKAGE)
318
319 staticbintar: all.opt
320 rm -f $(TMP)/$(PACKAGE)
321 ln -s `pwd` $(TMP)/$(PACKAGE)
322 make static
323 cd $(TMP); tar cvfz $(PACKAGE)-bin-x86-static.tgz --exclude-vcs $(BINSRC2)
324 rm -f $(TMP)/$(PACKAGE)
325
326 # add ocaml version in name ?
327 bytecodetar: all
328 rm -f $(TMP)/$(PACKAGE)
329 ln -s `pwd` $(TMP)/$(PACKAGE)
330 make purebytecode
331 cd $(TMP); tar cvfz $(PACKAGE)-bin-bytecode-$(OCAMLVERSION).tgz --exclude-vcs $(BINSRC2)
332 rm -f $(TMP)/$(PACKAGE)
333
334 clean::
335 rm -f $(PACKAGE)
336 rm -f $(PACKAGE)-bin-x86.tgz
337 rm -f $(PACKAGE)-bin-x86-static.tgz
338 rm -f $(PACKAGE)-bin-bytecode-$(OCAMLVERSION).tgz
339
340
341
342 TOLICENSIFY=ctl engine parsing_cocci popl popl09 python
343 licensify:
344 ocaml tools/licensify.ml
345 set -e; for i in $(TOLICENSIFY); do cd $$i; ocaml ../tools/licensify.ml; cd ..; done
346
347 # When checking out the source from diku sometimes I have some "X in the future"
348 # error messages.
349 fixdates:
350 echo do 'touch **/*.*'
351
352 #fixCVS:
353 # cvs update -d -P
354 # echo do 'rm -rf **/CVS'
355
356 ocamlversion:
357 @echo $(OCAMLVERSION)
358
359
360 ##############################################################################
361 # Pad specific rules
362 ##############################################################################
363
364 #TOP=/home/pad/mobile/project-coccinelle
365 WEBSITE=/home/pad/mobile/homepage/software/project-coccinelle
366
367 website:
368 cp $(TMP)/$(PACKAGE).tgz $(WEBSITE)
369 cp $(TMP)/$(PACKAGE)-bin-x86.tgz $(WEBSITE)
370 cp $(TMP)/$(PACKAGE)-bin-x86-static.tgz $(WEBSITE)
371 cp $(TMP)/$(PACKAGE)-bin-bytecode-$(OCAMLVERSION).tgz $(WEBSITE)
372 rm -f $(WEBSITE)/LATEST* $(WEBSITE)/coccinelle-latest.tgz
373 cd $(WEBSITE); touch LATEST_IS_$(VERSION); ln -s $(PACKAGE).tgz coccinelle-latest.tgz
374
375
376 #TXT=$(wildcard *.txt)
377 syncwiki:
378 # unison ~/public_html/wiki/wiki-LFS/data/pages/ docs/wiki/
379 # set -e; for i in $(TXT); do unison $$i docs/wiki/$$i; done
380
381 darcsweb:
382 # @echo pull from ~/public_html/darcs/c-coccinelle and c-commons and lib-xxx
383
384 DARCSFORESTS=commons \
385 parsing_c parsing_cocci engine
386
387 update_darcs:
388 darcs pull
389 set -e; for i in $(DARCSFORESTS); do cd $$i; darcs pull; cd ..; done
390
391 #darcs diff -u
392 diff_darcs:
393 set -e; for i in $(DARCSFORESTS); do cd $$i; darcs diff -u; cd ..; done
394
395
396 ##############################################################################
397 # Developer rules
398 ##############################################################################
399
400 test: $(TARGET)
401 ./$(TARGET) -testall
402
403 testparsing:
404 ./$(TARGET) -D standard.h -parse_c -dir tests/
405
406
407
408 # -inline 0 to see all the functions in the profile.
409 # Can also use the profile framework in commons/ and run your program
410 # with -profile.
411 forprofiling:
412 $(MAKE) OPTFLAGS="-p -inline 0 " opt
413
414 clean::
415 rm -f gmon.out
416
417 tags:
418 otags -no-mli-tags -r .
419
420 dependencygraph:
421 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
422 ocamldot -lr /tmp/dependfull.depend > /tmp/dependfull.dot
423 dot -Tps /tmp/dependfull.dot > /tmp/dependfull.ps
424 ps2pdf /tmp/dependfull.ps /tmp/dependfull.pdf
425
426 ##############################################################################
427 # Misc rules
428 ##############################################################################
429
430 # each member of the project can have its own test.ml. this file is
431 # not under CVS.
432 test.ml:
433 echo "let foo_ctl () = failwith \"there is no foo_ctl formula\"" \
434 > test.ml
435
436 beforedepend:: test.ml
437
438
439 #INC=$(dir $(shell which ocaml))
440 #INCX=$(INC:/=)
441 #INCY=$(dir $(INCX))
442 #INCZ=$(INCY:/=)/lib/ocaml
443 #
444 #prim.o: prim.c
445 # gcc -c -o prim.o -I $(INCZ) prim.c
446
447
448 ##############################################################################
449 # Generic ocaml rules
450 ##############################################################################
451
452 .SUFFIXES: .ml .mli .cmo .cmi .cmx
453
454 .ml.cmo:
455 $(OCAMLC) -c $<
456 .mli.cmi:
457 $(OCAMLC) -c $<
458 .ml.cmx:
459 $(OCAMLOPT) -c $<
460
461 .ml.mldepend:
462 $(OCAMLC) -i $<
463
464 clean::
465 rm -f *.cm[iox] *.o *.annot
466
467 clean::
468 rm -f *~ .*~ *.exe #*#
469
470 beforedepend::
471
472 depend:: beforedepend
473 $(OCAMLDEP) *.mli *.ml > .depend
474 set -e; for i in $(MAKESUBDIRS); do $(MAKE) -C $$i depend; done
475
476 -include .depend