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