Release coccinelle-0.2.3rc3
[bpt/coccinelle.git] / Makefile
CommitLineData
90aeb998
C
1# Copyright 2010, INRIA, University of Copenhagen
2# Julia Lawall, Rene Rydhof Hansen, Gilles Muller, Nicolas Palix
3# Copyright 2005-2009, Ecole des Mines de Nantes, University of Copenhagen
9f8e26f4
C
4# Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix
5# This file is part of Coccinelle.
6#
7# Coccinelle is free software: you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation, according to version 2 of the License.
10#
11# Coccinelle is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with Coccinelle. If not, see <http://www.gnu.org/licenses/>.
18#
19# The authors reserve the right to distribute this or future versions of
20# Coccinelle under other licenses.
21
22
951c7801 23
34e49164
C
24#############################################################################
25# Configuration section
26#############################################################################
27
28-include Makefile.config
c3e37e97 29-include /etc/lsb-release
34e49164 30
b1b2de81 31VERSION=$(shell cat globals/config.ml.in |grep version |perl -p -e 's/.*"(.*)".*/$$1/;')
951c7801 32CCVERSION=$(shell cat scripts/coccicheck/README |grep "Coccicheck version" |perl -p -e 's/.*version (.*)[ ]*/$$1/;')
c3e37e97
C
33PKGVERSION=$(shell dpkg-parsechangelog -ldebian/changelog.$(DISTRIB_CODENAME) 2> /dev/null \
34 | sed -n 's/^Version: \(.*\)/\1/p' )
34e49164
C
35
36##############################################################################
37# Variables
38##############################################################################
39TARGET=spatch
c3e37e97 40PRJNAME=coccinelle
34e49164
C
41
42SRC=flag_cocci.ml cocci.ml testing.ml test.ml main.ml
43
34e49164 44ifeq ($(FEATURE_PYTHON),1)
90aeb998 45PYCMA=pycaml.cma
b1b2de81 46# the following is essential for Coccinelle to compile under gentoo (weird)
90aeb998 47#OPTLIBFLAGS=-cclib dllpycaml_stubs.so
34e49164
C
48else
49PYCMA=
90aeb998 50endif
34e49164 51OPTLIBFLAGS=
90aeb998
C
52
53ifeq ("$(SEXPDIR)","ocamlsexp")
54SEXPLIB=sexplib.cmo
55OPTSEXPLIB=sexplib.cmx
56else
57SEXPLIB=sexplib.cma
58OPTSEXPLIB=sexplib.cmxa
34e49164
C
59endif
60
b1b2de81 61SEXPSYSCMA=bigarray.cma nums.cma
34e49164 62
174d1640 63SYSLIBS=str.cma unix.cma $(SEXPSYSCMA) $(PYCMA) dynlink.cma
b1b2de81 64LIBS=commons/commons.cma \
90aeb998 65 commons/commons_sexp.cma \
b1b2de81 66 globals/globals.cma \
34e49164
C
67 ctl/ctl.cma \
68 parsing_cocci/cocci_parser.cma parsing_c/parsing_c.cma \
951c7801 69 engine/cocciengine.cma popl09/popl.cma \
174d1640 70 extra/extra.cma python/coccipython.cma ocaml/cocciocaml.cma
90aeb998
C
71
72# Should we use the local version of pycaml
73ifeq ("$(PYCAMLDIR)","pycaml")
74LOCALPYCAML=pycaml
75else
76LOCALPYCAML=
77endif
78
79# Should we use the local version of menhirLib
174d1640
C
80ifeq ("$(MENHIRDIR)","menhirlib")
81LOCALMENHIR=menhirlib
90aeb998
C
82else
83LOCALMENHIR=
84endif
85
86# Should we use the local version of ocamlsexp
87ifeq ("$(SEXPDIR)","ocamlsexp")
88LOCALSEXP=ocamlsexp
89else
90LOCALSEXP=
91endif
34e49164 92
174d1640 93# used for depend: and a little for rec & rec.opt
90aeb998
C
94MAKESUBDIRS=$(LOCALPYCAML) $(LOCALSEXP) commons \
95 globals $(LOCALMENHIR) ctl parsing_cocci parsing_c \
174d1640
C
96 engine popl09 extra python ocaml
97
98# used for clean:
99# It is like MAKESUBDIRS but also
100# force cleaning of local library copies
101CLEANSUBDIRS=pycaml ocamlsexp commons \
102 globals menhirlib ctl parsing_cocci parsing_c \
103 engine popl09 extra python ocaml
90aeb998
C
104
105INCLUDEDIRSDEP=commons commons/ocamlextra $(LOCALSEXP) \
106 globals $(LOCALMENHIR) $(LOCALPYCAML) ctl \
174d1640 107 parsing_cocci parsing_c engine popl09 extra python ocaml
34e49164 108
90aeb998
C
109INCLUDEDIRS=$(INCLUDEDIRSDEP) $(SEXPDIR) $(MENHIRDIR) $(PYCAMLDIR)
110
34e49164
C
111##############################################################################
112# Generic variables
113##############################################################################
114
115INCLUDES=$(INCLUDEDIRS:%=-I %)
116
117OBJS= $(SRC:.ml=.cmo)
118OPTOBJS= $(SRC:.ml=.cmx)
119
120EXEC=$(TARGET)
121
122##############################################################################
123# Generic ocaml variables
124##############################################################################
125
ae4735db 126OCAMLCFLAGS=
34e49164
C
127
128# for profiling add -p -inline 0
129# but 'make forprofiling' below does that for you.
130# This flag is also used in subdirectories so don't change its name here.
708f4980
C
131# To enable backtrace support for native code, you need to put -g in OPTFLAGS
132# to also link with -g, but even in 3.11 the backtrace support seems buggy so
133# not worth it.
34e49164 134OPTFLAGS=
34e49164 135
34e49164 136OCAMLC=ocamlc$(OPTBIN) $(OCAMLCFLAGS) $(INCLUDES)
faf9a90c 137OCAMLOPT=ocamlopt$(OPTBIN) $(OPTFLAGS) $(INCLUDES)
34e49164
C
138OCAMLLEX=ocamllex #-ml # -ml for debugging lexer, but slightly slower
139OCAMLYACC=ocamlyacc -v
90aeb998 140OCAMLDEP=ocamldep $(INCLUDEDIRSDEP:%=-I %)
34e49164
C
141OCAMLMKTOP=ocamlmktop -g -custom $(INCLUDES)
142
143# can also be set via 'make static'
144STATIC= #-ccopt -static
145
146# can also be unset via 'make purebytecode'
147BYTECODE_STATIC=-custom
148
149##############################################################################
150# Top rules
151##############################################################################
b1b2de81
C
152.PHONY:: all all.opt byte opt top clean distclean configure
153.PHONY:: $(MAKESUBDIRS) $(MAKESUBDIRS:%=%.opt) subdirs subdirs.opt
154
708f4980 155all: Makefile.config byte preinstall
b1b2de81
C
156
157opt: all.opt
708f4980 158all.opt: opt-compil preinstall
faf9a90c 159
708f4980 160world: preinstall
b1b2de81 161 $(MAKE) byte
708f4980 162 $(MAKE) opt-compil
b1b2de81
C
163
164byte: .depend
faf9a90c
C
165 $(MAKE) subdirs
166 $(MAKE) $(EXEC)
167
b1b2de81 168opt-compil: .depend
faf9a90c
C
169 $(MAKE) subdirs.opt
170 $(MAKE) $(EXEC).opt
171
485bce71 172top: $(EXEC).top
34e49164 173
0708f913 174subdirs:
90aeb998
C
175# $(MAKE) -C commons OCAMLCFLAGS="$(OCAMLCFLAGS)"
176# if [ "$(LOCALSEXP)" != "" ]; then \
177# $(MAKE) -C ocamlsexp OCAMLCFLAGS="$(OCAMLCFLAGS)" ; fi
b1b2de81 178 +for D in $(MAKESUBDIRS); do $(MAKE) $$D || exit 1 ; done
90aeb998 179 $(MAKE) -C commons sexp OCAMLCFLAGS="$(OCAMLCFLAGS)"
0708f913
C
180
181subdirs.opt:
90aeb998
C
182# $(MAKE) -C commons all.opt OCAMLCFLAGS="$(OCAMLCFLAGS)"
183# if [ "$(LOCALSEXP)" != "" ]; then \
184# $(MAKE) -C ocamlsexp all.opt OCAMLCFLAGS="$(OCAMLCFLAGS)"; fi
b1b2de81 185 +for D in $(MAKESUBDIRS); do $(MAKE) $$D.opt || exit 1 ; done
90aeb998 186 $(MAKE) -C commons sexp.opt OCAMLCFLAGS="$(OCAMLCFLAGS)"
faf9a90c
C
187
188$(MAKESUBDIRS):
189 $(MAKE) -C $@ OCAMLCFLAGS="$(OCAMLCFLAGS)" all
190
191$(MAKESUBDIRS:%=%.opt):
192 $(MAKE) -C $(@:%.opt=%) OCAMLCFLAGS="$(OCAMLCFLAGS)" all.opt
193
b1b2de81 194#dependencies:
0708f913
C
195# commons:
196# globals:
197# menhirlib:
198# parsing_cocci: commons globals menhirlib
199# parsing_c:parsing_cocci
200# ctl:globals commons
201# engine: parsing_cocci parsing_c ctl
951c7801 202# popl09:engine
0708f913
C
203# extra: parsing_cocci parsing_c ctl
204# pycaml:
205# python:pycaml parsing_cocci parsing_c
faf9a90c 206
34e49164 207clean::
174d1640 208 set -e; for i in $(CLEANSUBDIRS); do $(MAKE) -C $$i $@; done
c3e37e97 209 $(MAKE) -C demos/spp $@
34e49164 210
0708f913
C
211$(LIBS): $(MAKESUBDIRS)
212$(LIBS:.cma=.cmxa): $(MAKESUBDIRS:%=%.opt)
faf9a90c
C
213
214$(OBJS):$(LIBS)
215$(OPTOBJS):$(LIBS:.cma=.cmxa)
216
34e49164 217$(EXEC): $(LIBS) $(OBJS)
90aeb998 218 $(OCAMLC) $(BYTECODE_STATIC) -o $@ $(SYSLIBS) $(SEXPLIB) $^
34e49164 219
faf9a90c 220$(EXEC).opt: $(LIBS:.cma=.cmxa) $(OPTOBJS)
90aeb998 221 $(OCAMLOPT) $(STATIC) -o $@ $(SYSLIBS:.cma=.cmxa) $(OPTSEXPLIB) $(OPTLIBFLAGS) $^
34e49164 222
faf9a90c 223$(EXEC).top: $(LIBS) $(OBJS)
90aeb998 224 $(OCAMLMKTOP) -custom -o $@ $(SYSLIBS) $(SEXPLIB) $^
34e49164
C
225
226clean::
227 rm -f $(TARGET) $(TARGET).opt $(TARGET).top
34e49164 228
b1b2de81
C
229.PHONY:: tools configure
230
231configure:
232 ./configure
34e49164 233
7f004419 234Makefile.config:
708f4980
C
235 @echo "Makefile.config is missing. Have you run ./configure?"
236 @exit 1
237
34e49164
C
238tools:
239 $(MAKE) -C tools
b1b2de81 240
34e49164 241clean::
c3e37e97 242 if [ -d tools ] ; then $(MAKE) -C tools clean ; fi
34e49164 243
34e49164
C
244static:
245 rm -f spatch.opt spatch
246 $(MAKE) STATIC="-ccopt -static" spatch.opt
247 cp spatch.opt spatch
248
249purebytecode:
250 rm -f spatch.opt spatch
251 $(MAKE) BYTECODE_STATIC="" spatch
fc1ad971 252 perl -p -i -e 's/^#!.*/#!\/usr\/bin\/ocamlrun/' spatch
34e49164
C
253
254
b1b2de81
C
255##############################################################################
256# Build documentation
257##############################################################################
258.PHONY:: docs
259
260docs:
261 make -C docs
262
263clean::
264 make -C docs clean
265
266distclean::
267 make -C docs distclean
268
269##############################################################################
270# Pre-Install (customization of spatch frontend script)
271##############################################################################
b1b2de81 272
90aeb998
C
273preinstall: docs/spatch.1 scripts/spatch scripts/spatch.opt scripts/spatch.byte
274
275docs/spatch.1: Makefile.config
276 $(MAKE) -C docs spatch.1
b1b2de81
C
277
278# user will use spatch to run spatch.opt (native)
5636bb2c 279scripts/spatch: Makefile.config
b1b2de81
C
280 cp scripts/spatch.sh scripts/spatch.tmp2
281 sed "s|SHAREDIR|$(SHAREDIR)|g" scripts/spatch.tmp2 > scripts/spatch.tmp
282 sed "s|LIBDIR|$(LIBDIR)|g" scripts/spatch.tmp > scripts/spatch
283 rm -f scripts/spatch.tmp2 scripts/spatch.tmp
284
285# user will use spatch to run spatch (bytecode)
5636bb2c 286scripts/spatch.byte: Makefile.config
708f4980
C
287 cp scripts/spatch.sh scripts/spatch.byte.tmp3
288 sed "s|\.opt||" scripts/spatch.byte.tmp3 > scripts/spatch.byte.tmp2
289 sed "s|SHAREDIR|$(SHAREDIR)|g" scripts/spatch.byte.tmp2 \
290 > scripts/spatch.byte.tmp
291 sed "s|LIBDIR|$(LIBDIR)|g" scripts/spatch.byte.tmp \
292 > scripts/spatch.byte
293 rm -f scripts/spatch.byte.tmp3 \
294 scripts/spatch.byte.tmp2 \
295 scripts/spatch.byte.tmp
b1b2de81
C
296
297# user will use spatch.opt to run spatch.opt (native)
5636bb2c 298scripts/spatch.opt: Makefile.config
b1b2de81 299 cp scripts/spatch.sh scripts/spatch.opt.tmp2
708f4980
C
300 sed "s|SHAREDIR|$(SHAREDIR)|g" scripts/spatch.opt.tmp2 \
301 > scripts/spatch.opt.tmp
302 sed "s|LIBDIR|$(LIBDIR)|g" scripts/spatch.opt.tmp \
303 > scripts/spatch.opt
b1b2de81
C
304 rm -f scripts/spatch.opt.tmp scripts/spatch.opt.tmp2
305
306clean::
307 rm -f scripts/spatch scripts/spatch.byte scripts/spatch.opt
308
34e49164
C
309##############################################################################
310# Install
311##############################################################################
312
313# don't remove DESTDIR, it can be set by package build system like ebuild
8ba84ae2 314# for staged installation.
0708f913 315install-common:
34e49164
C
316 mkdir -p $(DESTDIR)$(BINDIR)
317 mkdir -p $(DESTDIR)$(LIBDIR)
174d1640 318 mkdir -p $(DESTDIR)$(SHAREDIR)/ocaml
faf9a90c 319 mkdir -p $(DESTDIR)$(MANDIR)/man1
8ba84ae2
C
320 $(INSTALL_DATA) standard.h $(DESTDIR)$(SHAREDIR)
321 $(INSTALL_DATA) standard.iso $(DESTDIR)$(SHAREDIR)
174d1640 322 $(INSTALL_DATA) ocaml/coccilib.cmi $(DESTDIR)$(SHAREDIR)/ocaml/
8ba84ae2
C
323 $(INSTALL_DATA) docs/spatch.1 $(DESTDIR)$(MANDIR)/man1/
324 @if [ $(FEATURE_PYTHON) -eq 1 ]; then $(MAKE) install-python; fi
174d1640
C
325 @if [ -d $(BASH_COMPLETION_DIR) ]; then $(MAKE) install-bash; fi
326
327install-bash:
328 mkdir -p $(DESTDIR)$(BASH_COMPLETION_DIR)
329 $(INSTALL_DATA) scripts/spatch.bash_completion \
330 $(DESTDIR)$(BASH_COMPLETION_DIR)/spatch
0708f913 331
8ba84ae2
C
332install-python:
333 mkdir -p $(DESTDIR)$(SHAREDIR)/python/coccilib/coccigui
334 $(INSTALL_DATA) python/coccilib/*.py \
335 $(DESTDIR)$(SHAREDIR)/python/coccilib
336 $(INSTALL_DATA) python/coccilib/coccigui/*.py \
337 $(DESTDIR)$(SHAREDIR)/python/coccilib/coccigui
b1b2de81
C
338 $(INSTALL_DATA) python/coccilib/coccigui/pygui.glade \
339 $(DESTDIR)$(SHAREDIR)/python/coccilib/coccigui
340 $(INSTALL_DATA) python/coccilib/coccigui/pygui.gladep \
341 $(DESTDIR)$(SHAREDIR)/python/coccilib/coccigui
90aeb998
C
342 if [ -f pycaml/dllpycaml_stubs.so ]; then \
343 $(INSTALL_LIB) pycaml/dllpycaml_stubs.so $(DESTDIR)$(LIBDIR) ; fi
8ba84ae2 344
951c7801 345install: install-common
b1b2de81
C
346 @if test -x spatch -a ! -x spatch.opt ; then \
347 $(MAKE) install-byte;fi
348 @if test ! -x spatch -a -x spatch.opt ; then \
349 $(MAKE) install-def; $(MAKE) install-opt;fi
350 @if test -x spatch -a -x spatch.opt ; then \
351 $(MAKE) install-byte; $(MAKE) install-opt;fi
352 @if test ! -x spatch -a ! -x spatch.opt ; then \
353 echo "\n\n\t==> Run 'make', 'make opt', or both first. <==\n\n";fi
708f4980
C
354 @echo ""
355 @echo "\tYou can also install spatch by copying the program spatch"
356 @echo "\t(available in this directory) anywhere you want and"
357 @echo "\tgive it the right options to find its configuration files."
358 @echo ""
b1b2de81 359
0708f913 360# user will use spatch to run spatch.opt (native)
708f4980 361install-def:
8ba84ae2 362 $(INSTALL_PROGRAM) spatch.opt $(DESTDIR)$(SHAREDIR)
b1b2de81 363 $(INSTALL_PROGRAM) scripts/spatch $(DESTDIR)$(BINDIR)/spatch
0708f913
C
364
365# user will use spatch to run spatch (bytecode)
708f4980 366install-byte:
8ba84ae2 367 $(INSTALL_PROGRAM) spatch $(DESTDIR)$(SHAREDIR)
b1b2de81 368 $(INSTALL_PROGRAM) scripts/spatch.byte $(DESTDIR)$(BINDIR)/spatch
0708f913
C
369
370# user will use spatch.opt to run spatch.opt (native)
708f4980 371install-opt:
8ba84ae2 372 $(INSTALL_PROGRAM) spatch.opt $(DESTDIR)$(SHAREDIR)
b1b2de81 373 $(INSTALL_PROGRAM) scripts/spatch.opt $(DESTDIR)$(BINDIR)/spatch.opt
34e49164
C
374
375uninstall:
376 rm -f $(DESTDIR)$(BINDIR)/spatch
8ba84ae2 377 rm -f $(DESTDIR)$(BINDIR)/spatch.opt
34e49164 378 rm -f $(DESTDIR)$(LIBDIR)/dllpycaml_stubs.so
90aeb998
C
379 rm -f $(DESTDIR)$(SHAREDIR)/spatch
380 rm -f $(DESTDIR)$(SHAREDIR)/spatch.opt
34e49164
C
381 rm -f $(DESTDIR)$(SHAREDIR)/standard.h
382 rm -f $(DESTDIR)$(SHAREDIR)/standard.iso
174d1640 383 rm -f $(DESTDIR)$(SHAREDIR)/ocaml/coccilib.cmi
90aeb998
C
384 rm -f $(DESTDIR)$(SHAREDIR)/python/coccilib/coccigui/*
385 rm -f $(DESTDIR)$(SHAREDIR)/python/coccilib/*.py
386 rmdir --ignore-fail-on-non-empty -p \
387 $(DESTDIR)$(SHAREDIR)/python/coccilib/coccigui
faf9a90c 388 rm -f $(DESTDIR)$(MANDIR)/man1/spatch.1
34e49164 389
34e49164 390version:
951c7801 391 @echo "spatch $(VERSION)"
c3e37e97 392 @echo "spatch $(PKGVERSION) ($(DISTRIB_ID))"
951c7801 393 @echo "coccicheck $(CCVERSION)"
34e49164
C
394
395
396##############################################################################
5636bb2c 397# Deb package (for Ubuntu) and release rules
34e49164
C
398##############################################################################
399
5636bb2c 400include Makefile.release
c3e37e97 401
34e49164
C
402##############################################################################
403# Developer rules
404##############################################################################
405
7f004419
C
406-include Makefile.dev
407
34e49164
C
408test: $(TARGET)
409 ./$(TARGET) -testall
410
411testparsing:
412 ./$(TARGET) -D standard.h -parse_c -dir tests/
413
414
415
faf9a90c
C
416# -inline 0 to see all the functions in the profile.
417# Can also use the profile framework in commons/ and run your program
34e49164
C
418# with -profile.
419forprofiling:
420 $(MAKE) OPTFLAGS="-p -inline 0 " opt
421
422clean::
faf9a90c 423 rm -f gmon.out
34e49164
C
424
425tags:
426 otags -no-mli-tags -r .
427
428dependencygraph:
951c7801 429 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 430 ocamldot -lr /tmp/dependfull.depend > /tmp/dependfull.dot
34e49164 431 dot -Tps /tmp/dependfull.dot > /tmp/dependfull.ps
485bce71 432 ps2pdf /tmp/dependfull.ps /tmp/dependfull.pdf
34e49164
C
433
434##############################################################################
435# Misc rules
436##############################################################################
437
faf9a90c 438# each member of the project can have its own test.ml. this file is
34e49164 439# not under CVS.
faf9a90c 440test.ml:
34e49164
C
441 echo "let foo_ctl () = failwith \"there is no foo_ctl formula\"" \
442 > test.ml
443
444beforedepend:: test.ml
445
446
447#INC=$(dir $(shell which ocaml))
448#INCX=$(INC:/=)
449#INCY=$(dir $(INCX))
450#INCZ=$(INCY:/=)/lib/ocaml
451#
452#prim.o: prim.c
453# gcc -c -o prim.o -I $(INCZ) prim.c
454
455
456##############################################################################
457# Generic ocaml rules
458##############################################################################
459
460.SUFFIXES: .ml .mli .cmo .cmi .cmx
461
462.ml.cmo:
463 $(OCAMLC) -c $<
464.mli.cmi:
465 $(OCAMLC) -c $<
466.ml.cmx:
467 $(OCAMLOPT) -c $<
468
faf9a90c 469.ml.mldepend:
34e49164
C
470 $(OCAMLC) -i $<
471
472clean::
473 rm -f *.cm[iox] *.o *.annot
34e49164
C
474 rm -f *~ .*~ *.exe #*#
475
b1b2de81
C
476distclean:: clean
477 set -e; for i in $(MAKESUBDIRS); do $(MAKE) -C $$i $@; done
478 rm -f .depend
479 rm -f Makefile.config
b1b2de81
C
480 rm -f python/pycocci.ml
481 rm -f python/pycocci_aux.ml
482 rm -f globals/config.ml
483 rm -f TAGS
484 rm -f tests/SCORE_actual.sexp
485 rm -f tests/SCORE_best_of_both.sexp
486 find -name ".#*1.*" | xargs rm -f
487
34e49164
C
488beforedepend::
489
490depend:: beforedepend
491 $(OCAMLDEP) *.mli *.ml > .depend
b1b2de81
C
492 set -e; for i in $(MAKESUBDIRS); do $(MAKE) -C $$i $@; done
493
494.depend::
495 @if [ ! -f .depend ] ; then $(MAKE) depend ; fi
34e49164
C
496
497-include .depend