Commit | Line | Data |
---|---|---|
34e49164 C |
1 | # Copyright 2005-2008, 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 globals menhirlib $(PYDIR) ctl parsing_cocci parsing_c \ | |
61 | 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 | ||
111 | all: rec $(EXEC) | |
112 | opt: rec.opt $(EXEC).opt | |
113 | all.opt: opt | |
114 | ||
115 | rec: | |
116 | set -e; for i in $(MAKESUBDIRS); \ | |
117 | do $(MAKE) -C $$i OCAMLCFLAGS="$(OCAMLCFLAGS)" all; done | |
118 | rec.opt: | |
119 | set -e; for i in $(MAKESUBDIRS); do $(MAKE) -C $$i all.opt; done | |
120 | clean:: | |
121 | set -e; for i in $(MAKESUBDIRS); do $(MAKE) -C $$i clean; done | |
122 | ||
123 | ||
124 | $(EXEC): $(LIBS) $(OBJS) | |
125 | $(OCAMLC) $(BYTECODE_STATIC) -o $@ $(SYSLIBS) $^ | |
126 | ||
127 | $(EXEC).opt: $(LIBS:.cma=.cmxa) $(OPTOBJS) | |
128 | $(OCAMLOPT) $(STATIC) -o $@ $(SYSLIBS:.cma=.cmxa) $(OPTLIBFLAGS) $^ | |
129 | ||
130 | $(EXEC).top: $(LIBS) $(OBJS) | |
131 | $(OCAMLMKTOP) -custom -o $@ $(SYSLIBS) $^ | |
132 | ||
133 | clean:: | |
134 | rm -f $(TARGET) $(TARGET).opt $(TARGET).top | |
135 | ||
136 | ||
137 | clean:: | |
138 | rm -f dllpycaml_stubs.so | |
139 | ||
140 | ||
141 | .PHONY: tools | |
142 | ||
143 | tools: | |
144 | $(MAKE) -C tools | |
145 | clean:: | |
146 | $(MAKE) -C tools clean | |
147 | ||
148 | ||
149 | static: | |
150 | rm -f spatch.opt spatch | |
151 | $(MAKE) STATIC="-ccopt -static" spatch.opt | |
152 | cp spatch.opt spatch | |
153 | ||
154 | purebytecode: | |
155 | rm -f spatch.opt spatch | |
156 | $(MAKE) BYTECODE_STATIC="" spatch | |
157 | ||
158 | ||
159 | ############################################################################## | |
160 | # Install | |
161 | ############################################################################## | |
162 | ||
163 | # don't remove DESTDIR, it can be set by package build system like ebuild | |
164 | install: all | |
165 | mkdir -p $(DESTDIR)$(BINDIR) | |
166 | mkdir -p $(DESTDIR)$(LIBDIR) | |
167 | mkdir -p $(DESTDIR)$(SHAREDIR) | |
168 | cp spatch $(DESTDIR)$(BINDIR) | |
169 | cp -f dllpycaml_stubs.so $(DESTDIR)$(LIBDIR) | |
170 | cp standard.h $(DESTDIR)$(SHAREDIR) | |
171 | cp standard.iso $(DESTDIR)$(SHAREDIR) | |
172 | mkdir -p $(DESTDIR)$(SHAREDIR)/python | |
173 | cp -a python/coccilib $(DESTDIR)$(SHAREDIR)/python | |
174 | @echo "" | |
175 | @echo "You can also install spatch by copying the program spatch" | |
176 | @echo "(available in this directory) anywhere you want and" | |
177 | @echo "give it the right options to find its configuration files." | |
178 | ||
179 | uninstall: | |
180 | rm -f $(DESTDIR)$(BINDIR)/spatch | |
181 | rm -f $(DESTDIR)$(LIBDIR)/dllpycaml_stubs.so | |
182 | rm -f $(DESTDIR)$(SHAREDIR)/standard.h | |
183 | rm -f $(DESTDIR)$(SHAREDIR)/standard.iso | |
184 | rm -rf $(DESTDIR)$(SHAREDIR)/python/coccilib | |
185 | ||
186 | ||
187 | ||
188 | version: | |
189 | @echo $(VERSION) | |
190 | ||
191 | ||
192 | ############################################################################## | |
193 | # Package rules | |
194 | ############################################################################## | |
195 | ||
196 | PACKAGE=coccinelle-$(VERSION) | |
197 | ||
198 | BINSRC=spatch env.sh env.csh standard.h standard.iso \ | |
199 | *.txt docs/* \ | |
200 | demos/foo.* demos/simple.* | |
201 | # $(PYLIB) python/coccilib/ demos/printloc.* | |
202 | BINSRC2=$(BINSRC:%=$(PACKAGE)/%) | |
203 | ||
204 | TMP=/tmp | |
205 | OCAMLVERSION=$(shell ocaml -version |perl -p -e 's/.*version (.*)/$$1/;') | |
206 | ||
207 | # Procedure to do first time: | |
208 | # cd ~/release | |
209 | # cvs checkout coccinelle | |
210 | # cd coccinelle | |
211 | # cvs update -d -P | |
212 | # touch **/* | |
213 | # make licensify | |
214 | ||
215 | # Procedure to do each time: | |
216 | # cvs update | |
217 | # ./configure --without-python | |
218 | # make package | |
219 | # make website | |
220 | # Check also that run an ocaml in /usr/bin | |
221 | ||
222 | # To test you can try compile and run spatch from different instances | |
223 | # like my ~/coccinelle, ~/release/coccinelle, and the /tmp/coccinelle-0.X | |
224 | # downloaded from the website. | |
225 | ||
226 | # For 'make srctar' it must done from a clean | |
227 | # repo such as ~/release/coccinelle. It must also be a repo where | |
228 | # the scripts/licensify has been run at least once. | |
229 | # For the 'make bintar' I can do it from my original repo. | |
230 | ||
231 | ||
232 | package: | |
233 | make srctar | |
234 | make bintar | |
235 | make staticbintar | |
236 | make bytecodetar | |
237 | ||
238 | # I currently pre-generate the parser so the user does not have to | |
239 | # install menhir on his machine. I also do a few cleanups like 'rm todo_pos'. | |
240 | # You may have first to do a 'make licensify'. | |
241 | srctar: | |
242 | make clean | |
243 | cp -a . $(TMP)/$(PACKAGE) | |
244 | cd $(TMP)/$(PACKAGE); cd parsing_cocci/; make parser_cocci_menhir.ml | |
245 | cd $(TMP)/$(PACKAGE); rm todo_pos | |
246 | cd $(TMP); tar cvfz $(PACKAGE).tgz --exclude=CVS $(PACKAGE) | |
247 | rm -rf $(TMP)/$(PACKAGE) | |
248 | ||
249 | ||
250 | bintar: all | |
251 | rm -f $(TMP)/$(PACKAGE) | |
252 | ln -s `pwd` $(TMP)/$(PACKAGE) | |
253 | cd $(TMP); tar cvfz $(PACKAGE)-bin-x86.tgz $(BINSRC2) | |
254 | rm -f $(TMP)/$(PACKAGE) | |
255 | ||
256 | staticbintar: all.opt | |
257 | rm -f $(TMP)/$(PACKAGE) | |
258 | ln -s `pwd` $(TMP)/$(PACKAGE) | |
259 | make static | |
260 | cd $(TMP); tar cvfz $(PACKAGE)-bin-x86-static.tgz $(BINSRC2) | |
261 | rm -f $(TMP)/$(PACKAGE) | |
262 | ||
263 | # add ocaml version in name ? | |
264 | bytecodetar: all | |
265 | rm -f $(TMP)/$(PACKAGE) | |
266 | ln -s `pwd` $(TMP)/$(PACKAGE) | |
267 | make purebytecode | |
268 | cd $(TMP); tar cvfz $(PACKAGE)-bin-bytecode-$(OCAMLVERSION).tgz $(BINSRC2) | |
269 | rm -f $(TMP)/$(PACKAGE) | |
270 | ||
271 | clean:: | |
272 | rm -f $(PACKAGE) | |
273 | rm -f $(PACKAGE)-bin-x86.tgz | |
274 | rm -f $(PACKAGE)-bin-x86-static.tgz | |
275 | rm -f $(PACKAGE)-bin-bytecode-$(OCAMLVERSION).tgz | |
276 | ||
277 | ||
278 | ||
279 | TOLICENSIFY=ctl engine parsing_cocci popl popl09 python | |
280 | licensify: | |
281 | ocaml tools/licensify.ml | |
282 | set -e; for i in $(TOLICENSIFY); do cd $$i; ocaml ../tools/licensify.ml; cd ..; done | |
283 | ||
284 | # When checking out the source from diku sometimes I have some "X in the future" | |
285 | # error messages. | |
286 | fixdates: | |
287 | echo do 'touch **/*.*' | |
288 | ||
289 | #fixCVS: | |
290 | # cvs update -d -P | |
291 | # echo do 'rm -rf **/CVS' | |
292 | ||
293 | ocamlversion: | |
294 | @echo $(OCAMLVERSION) | |
295 | ||
296 | ||
297 | ############################################################################## | |
298 | # Pad specific rules | |
299 | ############################################################################## | |
300 | ||
301 | #TOP=/home/pad/mobile/project-coccinelle | |
302 | WEBSITE=/home/pad/mobile/homepage/software/project-coccinelle | |
303 | ||
304 | website: | |
305 | cp $(TMP)/$(PACKAGE).tgz $(WEBSITE) | |
306 | cp $(TMP)/$(PACKAGE)-bin-x86.tgz $(WEBSITE) | |
307 | cp $(TMP)/$(PACKAGE)-bin-x86-static.tgz $(WEBSITE) | |
308 | cp $(TMP)/$(PACKAGE)-bin-bytecode-$(OCAMLVERSION).tgz $(WEBSITE) | |
309 | ||
310 | ||
311 | #TXT=$(wildcard *.txt) | |
312 | syncwiki: | |
313 | # unison ~/public_html/wiki/wiki-LFS/data/pages/ docs/wiki/ | |
314 | # set -e; for i in $(TXT); do unison $$i docs/wiki/$$i; done | |
315 | ||
316 | darcsweb: | |
317 | # @echo pull from ~/public_html/darcs/c-coccinelle and c-commons and lib-xxx | |
318 | ||
319 | ||
320 | ############################################################################## | |
321 | # Developer rules | |
322 | ############################################################################## | |
323 | ||
324 | test: $(TARGET) | |
325 | ./$(TARGET) -testall | |
326 | ||
327 | testparsing: | |
328 | ./$(TARGET) -D standard.h -parse_c -dir tests/ | |
329 | ||
330 | ||
331 | ||
332 | # -inline 0 to see all the functions in the profile. | |
333 | # Can also use the profile framework in commons/ and run your program | |
334 | # with -profile. | |
335 | forprofiling: | |
336 | $(MAKE) OPTFLAGS="-p -inline 0 " opt | |
337 | ||
338 | clean:: | |
339 | rm -f gmon.out | |
340 | ||
341 | tags: | |
342 | otags -no-mli-tags -r . | |
343 | ||
344 | dependencygraph: | |
345 | 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 | |
346 | ocamldot -fullgraph /tmp/dependfull.depend > /tmp/dependfull.dot | |
347 | dot -Tps /tmp/dependfull.dot > /tmp/dependfull.ps | |
348 | ||
349 | ############################################################################## | |
350 | # Misc rules | |
351 | ############################################################################## | |
352 | ||
353 | # each member of the project can have its own test.ml. this file is | |
354 | # not under CVS. | |
355 | test.ml: | |
356 | echo "let foo_ctl () = failwith \"there is no foo_ctl formula\"" \ | |
357 | > test.ml | |
358 | ||
359 | beforedepend:: test.ml | |
360 | ||
361 | ||
362 | #INC=$(dir $(shell which ocaml)) | |
363 | #INCX=$(INC:/=) | |
364 | #INCY=$(dir $(INCX)) | |
365 | #INCZ=$(INCY:/=)/lib/ocaml | |
366 | # | |
367 | #prim.o: prim.c | |
368 | # gcc -c -o prim.o -I $(INCZ) prim.c | |
369 | ||
370 | ||
371 | ############################################################################## | |
372 | # Generic ocaml rules | |
373 | ############################################################################## | |
374 | ||
375 | .SUFFIXES: .ml .mli .cmo .cmi .cmx | |
376 | ||
377 | .ml.cmo: | |
378 | $(OCAMLC) -c $< | |
379 | .mli.cmi: | |
380 | $(OCAMLC) -c $< | |
381 | .ml.cmx: | |
382 | $(OCAMLOPT) -c $< | |
383 | ||
384 | .ml.mldepend: | |
385 | $(OCAMLC) -i $< | |
386 | ||
387 | clean:: | |
388 | rm -f *.cm[iox] *.o *.annot | |
389 | ||
390 | clean:: | |
391 | rm -f *~ .*~ *.exe #*# | |
392 | ||
393 | beforedepend:: | |
394 | ||
395 | depend:: beforedepend | |
396 | $(OCAMLDEP) *.mli *.ml > .depend | |
397 | set -e; for i in $(MAKESUBDIRS); do $(MAKE) -C $$i depend; done | |
398 | ||
399 | -include .depend |