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