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