1
# Copyright 2005-2010, Ecole des Mines de Nantes, University of Copenhagen
2
# Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix
3
# This file is part of Coccinelle.
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.
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.
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/>.
17
# The authors reserve the right to distribute this or future versions of
18
# Coccinelle under other licenses.
22
#############################################################################
23
# Configuration section
24
#############################################################################
26
-include Makefile.config
27
-include /etc/lsb-release
29
VERSION=$(shell cat globals/config.ml.in |grep version |perl -p -e 's/.*"(.*)".*/$$1/;')
30
CCVERSION=$(shell cat scripts/coccicheck/README |grep "Coccicheck version" |perl -p -e 's/.*version (.*)[ ]*/$$1/;')
31
PKGVERSION=$(shell dpkg-parsechangelog -ldebian/changelog.$(DISTRIB_CODENAME) 2> /dev/null \
32
| sed -n 's/^Version: \(.*\)/\1/p' )
34
##############################################################################
36
##############################################################################
40
SRC=flag_cocci.ml cocci.ml testing.ml test.ml main.ml
42
ifeq ($(FEATURE_PYTHON),1)
43
PYCMA=pycaml/pycaml.cma
45
PYLIB=dllpycaml_stubs.so
46
# the following is essential for Coccinelle to compile under gentoo (weird)
47
OPTLIBFLAGS=-cclib dllpycaml_stubs.so
55
SEXPSYSCMA=bigarray.cma nums.cma
57
SYSLIBS=str.cma unix.cma $(SEXPSYSCMA)
58
LIBS=commons/commons.cma \
59
ocamlsexp/sexplib1.cma commons/commons_sexp.cma \
62
parsing_cocci/cocci_parser.cma parsing_c/parsing_c.cma \
63
engine/cocciengine.cma popl09/popl.cma \
64
extra/extra.cma $(PYCMA) python/coccipython.cma
66
#used for clean: and depend: and a little for rec & rec.opt
67
MAKESUBDIRS=commons ocamlsexp \
68
globals menhirlib $(PYDIR) ctl parsing_cocci parsing_c \
69
engine popl09 extra python
70
INCLUDEDIRS=commons commons/ocamlextra ocamlsexp \
71
globals menhirlib $(PYDIR) ctl \
72
parsing_cocci parsing_c engine popl09 extra python
74
##############################################################################
76
##############################################################################
78
INCLUDES=$(INCLUDEDIRS:%=-I %)
81
OPTOBJS= $(SRC:.ml=.cmx)
85
##############################################################################
86
# Generic ocaml variables
87
##############################################################################
91
# for profiling add -p -inline 0
92
# but 'make forprofiling' below does that for you.
93
# This flag is also used in subdirectories so don't change its name here.
94
# To enable backtrace support for native code, you need to put -g in OPTFLAGS
95
# to also link with -g, but even in 3.11 the backtrace support seems buggy so
98
# the following is essential for Coccinelle to compile under gentoo
99
# but is now defined above in this file
100
#OPTLIBFLAGS=-cclib dllpycaml_stubs.so
102
OCAMLC=ocamlc$(OPTBIN) $(OCAMLCFLAGS) $(INCLUDES)
103
OCAMLOPT=ocamlopt$(OPTBIN) $(OPTFLAGS) $(INCLUDES)
104
OCAMLLEX=ocamllex #-ml # -ml for debugging lexer, but slightly slower
105
OCAMLYACC=ocamlyacc -v
106
OCAMLDEP=ocamldep $(INCLUDES)
107
OCAMLMKTOP=ocamlmktop -g -custom $(INCLUDES)
109
# can also be set via 'make static'
110
STATIC= #-ccopt -static
112
# can also be unset via 'make purebytecode'
113
BYTECODE_STATIC=-custom
115
##############################################################################
117
##############################################################################
118
.PHONY:: all all.opt byte opt top clean distclean configure
119
.PHONY:: $(MAKESUBDIRS) $(MAKESUBDIRS:%=%.opt) subdirs subdirs.opt
121
all: Makefile.config byte preinstall
124
all.opt: opt-compil preinstall
141
$(MAKE) -C commons OCAMLCFLAGS="$(OCAMLCFLAGS)"
142
$(MAKE) -C ocamlsexp OCAMLCFLAGS="$(OCAMLCFLAGS)"
143
$(MAKE) -C commons sexp OCAMLCFLAGS="$(OCAMLCFLAGS)"
144
+for D in $(MAKESUBDIRS); do $(MAKE) $$D || exit 1 ; done
147
$(MAKE) -C commons all.opt OCAMLCFLAGS="$(OCAMLCFLAGS)"
148
$(MAKE) -C ocamlsexp all.opt OCAMLCFLAGS="$(OCAMLCFLAGS)"
149
$(MAKE) -C commons sexp.opt OCAMLCFLAGS="$(OCAMLCFLAGS)"
150
+for D in $(MAKESUBDIRS); do $(MAKE) $$D.opt || exit 1 ; done
153
$(MAKE) -C $@ OCAMLCFLAGS="$(OCAMLCFLAGS)" all
155
$(MAKESUBDIRS:%=%.opt):
156
$(MAKE) -C $(@:%.opt=%) OCAMLCFLAGS="$(OCAMLCFLAGS)" all.opt
162
# parsing_cocci: commons globals menhirlib
163
# parsing_c:parsing_cocci
164
# ctl:globals commons
165
# engine: parsing_cocci parsing_c ctl
167
# extra: parsing_cocci parsing_c ctl
169
# python:pycaml parsing_cocci parsing_c
172
set -e; for i in $(MAKESUBDIRS); do $(MAKE) -C $$i $@; done
173
$(MAKE) -C demos/spp $@
175
$(LIBS): $(MAKESUBDIRS)
176
$(LIBS:.cma=.cmxa): $(MAKESUBDIRS:%=%.opt)
179
$(OPTOBJS):$(LIBS:.cma=.cmxa)
181
$(EXEC): $(LIBS) $(OBJS)
182
$(OCAMLC) $(BYTECODE_STATIC) -o $@ $(SYSLIBS) $^
184
$(EXEC).opt: $(LIBS:.cma=.cmxa) $(OPTOBJS)
185
$(OCAMLOPT) $(STATIC) -o $@ $(SYSLIBS:.cma=.cmxa) $(OPTLIBFLAGS) $^
187
$(EXEC).top: $(LIBS) $(OBJS)
188
$(OCAMLMKTOP) -custom -o $@ $(SYSLIBS) $^
191
rm -f $(TARGET) $(TARGET).opt $(TARGET).top
192
rm -f dllpycaml_stubs.so
194
.PHONY:: tools configure
200
@echo "Makefile.config is missing. Have you run ./configure?"
207
if [ -d tools ] ; then $(MAKE) -C tools clean ; fi
210
rm -f spatch.opt spatch
211
$(MAKE) STATIC="-ccopt -static" spatch.opt
215
rm -f spatch.opt spatch
216
$(MAKE) BYTECODE_STATIC="" spatch
217
perl -p -i -e 's/^#!.*/#!\/usr\/bin\/ocamlrun/' spatch
220
##############################################################################
221
# Build documentation
222
##############################################################################
232
make -C docs distclean
234
##############################################################################
235
# Pre-Install (customization of spatch frontend script)
236
##############################################################################
238
preinstall: scripts/spatch scripts/spatch.opt scripts/spatch.byte
240
# user will use spatch to run spatch.opt (native)
242
cp scripts/spatch.sh scripts/spatch.tmp2
243
sed "s|SHAREDIR|$(SHAREDIR)|g" scripts/spatch.tmp2 > scripts/spatch.tmp
244
sed "s|LIBDIR|$(LIBDIR)|g" scripts/spatch.tmp > scripts/spatch
245
rm -f scripts/spatch.tmp2 scripts/spatch.tmp
247
# user will use spatch to run spatch (bytecode)
249
cp scripts/spatch.sh scripts/spatch.byte.tmp3
250
sed "s|\.opt||" scripts/spatch.byte.tmp3 > scripts/spatch.byte.tmp2
251
sed "s|SHAREDIR|$(SHAREDIR)|g" scripts/spatch.byte.tmp2 \
252
> scripts/spatch.byte.tmp
253
sed "s|LIBDIR|$(LIBDIR)|g" scripts/spatch.byte.tmp \
254
> scripts/spatch.byte
255
rm -f scripts/spatch.byte.tmp3 \
256
scripts/spatch.byte.tmp2 \
257
scripts/spatch.byte.tmp
259
# user will use spatch.opt to run spatch.opt (native)
261
cp scripts/spatch.sh scripts/spatch.opt.tmp2
262
sed "s|SHAREDIR|$(SHAREDIR)|g" scripts/spatch.opt.tmp2 \
263
> scripts/spatch.opt.tmp
264
sed "s|LIBDIR|$(LIBDIR)|g" scripts/spatch.opt.tmp \
266
rm -f scripts/spatch.opt.tmp scripts/spatch.opt.tmp2
269
rm -f scripts/spatch scripts/spatch.byte scripts/spatch.opt
271
##############################################################################
273
##############################################################################
275
# don't remove DESTDIR, it can be set by package build system like ebuild
276
# for staged installation.
278
mkdir -p $(DESTDIR)$(BINDIR)
279
mkdir -p $(DESTDIR)$(LIBDIR)
280
mkdir -p $(DESTDIR)$(SHAREDIR)
281
mkdir -p $(DESTDIR)$(MANDIR)/man1
282
$(INSTALL_DATA) standard.h $(DESTDIR)$(SHAREDIR)
283
$(INSTALL_DATA) standard.iso $(DESTDIR)$(SHAREDIR)
284
$(INSTALL_DATA) docs/spatch.1 $(DESTDIR)$(MANDIR)/man1/
285
@if [ $(FEATURE_PYTHON) -eq 1 ]; then $(MAKE) install-python; fi
288
mkdir -p $(DESTDIR)$(SHAREDIR)/python/coccilib/coccigui
289
$(INSTALL_DATA) python/coccilib/*.py \
290
$(DESTDIR)$(SHAREDIR)/python/coccilib
291
$(INSTALL_DATA) python/coccilib/coccigui/*.py \
292
$(DESTDIR)$(SHAREDIR)/python/coccilib/coccigui
293
$(INSTALL_DATA) python/coccilib/coccigui/pygui.glade \
294
$(DESTDIR)$(SHAREDIR)/python/coccilib/coccigui
295
$(INSTALL_DATA) python/coccilib/coccigui/pygui.gladep \
296
$(DESTDIR)$(SHAREDIR)/python/coccilib/coccigui
297
$(INSTALL_LIB) dllpycaml_stubs.so $(DESTDIR)$(LIBDIR)
299
install: install-common
300
@if test -x spatch -a ! -x spatch.opt ; then \
301
$(MAKE) install-byte;fi
302
@if test ! -x spatch -a -x spatch.opt ; then \
303
$(MAKE) install-def; $(MAKE) install-opt;fi
304
@if test -x spatch -a -x spatch.opt ; then \
305
$(MAKE) install-byte; $(MAKE) install-opt;fi
306
@if test ! -x spatch -a ! -x spatch.opt ; then \
307
echo "\n\n\t==> Run 'make', 'make opt', or both first. <==\n\n";fi
309
@echo "\tYou can also install spatch by copying the program spatch"
310
@echo "\t(available in this directory) anywhere you want and"
311
@echo "\tgive it the right options to find its configuration files."
314
# user will use spatch to run spatch.opt (native)
316
$(INSTALL_PROGRAM) spatch.opt $(DESTDIR)$(SHAREDIR)
317
$(INSTALL_PROGRAM) scripts/spatch $(DESTDIR)$(BINDIR)/spatch
319
# user will use spatch to run spatch (bytecode)
321
$(INSTALL_PROGRAM) spatch $(DESTDIR)$(SHAREDIR)
322
$(INSTALL_PROGRAM) scripts/spatch.byte $(DESTDIR)$(BINDIR)/spatch
324
# user will use spatch.opt to run spatch.opt (native)
326
$(INSTALL_PROGRAM) spatch.opt $(DESTDIR)$(SHAREDIR)
327
$(INSTALL_PROGRAM) scripts/spatch.opt $(DESTDIR)$(BINDIR)/spatch.opt
330
rm -f $(DESTDIR)$(BINDIR)/spatch
331
rm -f $(DESTDIR)$(BINDIR)/spatch.opt
332
rm -f $(DESTDIR)$(LIBDIR)/dllpycaml_stubs.so
333
rm -f $(DESTDIR)$(SHAREDIR)/standard.h
334
rm -f $(DESTDIR)$(SHAREDIR)/standard.iso
335
rm -rf $(DESTDIR)$(SHAREDIR)/python/coccilib
336
rm -f $(DESTDIR)$(MANDIR)/man1/spatch.1
339
@echo "spatch $(VERSION)"
340
@echo "spatch $(PKGVERSION) ($(DISTRIB_ID))"
341
@echo "coccicheck $(CCVERSION)"
344
##############################################################################
346
##############################################################################
348
PACKAGE=$(PRJNAME)-$(VERSION)
349
CCPACKAGE=coccicheck-$(CCVERSION)
351
BINSRC=spatch env.sh env.csh standard.h standard.iso \
353
docs/manual/manual.pdf docs/manual/options.pdf docs/manual/main_grammar.pdf docs/spatch.1 \
354
docs/manual/cocci-python.txt \
356
BINSRC-PY=$(BINSRC) $(PYLIB) python/coccilib/
357
BINSRC2=$(BINSRC:%=$(PACKAGE)/%)
358
BINSRC2-PY=$(BINSRC-PY:%=$(PACKAGE)/%)
361
OCAMLVERSION=$(shell ocaml -version |perl -p -e 's/.*version (.*)/$$1/;')
363
# Procedure to do first time:
365
# cvs checkout coccinelle -dP
368
# Procedure to do each time:
370
# 1) make prepackage # WARN: These will clean your local rep. of pending modifications
372
# UPDATE VERSION number in globals/config.ml.in
377
# The project is then automatically licensified.
379
# Remember to comment the -g -dtypes in this Makefile
380
# You can also remove a few things, for instance I removed in this
381
# Makefile things related to popl/ and popl09/
382
# make sure that ocaml is the distribution ocaml of /usr/bin, not ~pad/...
386
# if WEBSITE is set properly, you can also run 'make website'
387
# Check that run an ocaml in /usr/bin
389
# To test you can try compile and run spatch from different instances
390
# like my ~/coccinelle, ~/release/coccinelle, and the /tmp/coccinelle-0.X
391
# downloaded from the website.
393
# For 'make srctar' it must done from a clean
394
# repo such as ~/release/coccinelle. It must also be a repo where
395
# the scripts/licensify has been run at least once.
396
# For the 'make bintar' I can do it from my original repo.
401
sed -i "s|^OCAMLCFLAGS=.*$$|OCAMLCFLAGS=|" Makefile
404
cvs ci -m "Release $(VERSION)" globals/config.ml.in
409
$(MAKE) package-nopython
410
$(MAKE) package-python
413
$(MAKE) distclean # Clean project
418
$(MAKE) distclean # Clean project
419
./configure --without-python
426
$(MAKE) distclean # Clean project
427
./configure # Reconfigure project with Python support
429
$(MAKE) bintar-python
430
$(MAKE) bytecodetar-python
433
# I currently pre-generate the parser so the user does not have to
434
# install menhir on his machine. We could also do a few cleanups.
435
# You may have first to do a 'make licensify'.
437
# update: make docs generates pdf but also some ugly .log files, so
438
# make clean is there to remove them while not removing the pdf
439
# (only distclean remove the pdfs).
444
cp -a . $(TMP)/$(PACKAGE)
445
cd $(TMP)/$(PACKAGE); cd parsing_cocci/; make parser_cocci_menhir.ml
446
cd $(TMP); tar cvfz $(PACKAGE).tgz --exclude-vcs $(PACKAGE)
447
rm -rf $(TMP)/$(PACKAGE)
451
rm -f $(TMP)/$(PACKAGE)
452
ln -s `pwd` $(TMP)/$(PACKAGE)
453
cd $(TMP); tar cvfz $(PACKAGE)-bin-x86.tgz --exclude-vcs $(BINSRC2)
454
rm -f $(TMP)/$(PACKAGE)
456
staticbintar: all.opt
457
rm -f $(TMP)/$(PACKAGE)
458
ln -s `pwd` $(TMP)/$(PACKAGE)
460
cd $(TMP); tar cvfz $(PACKAGE)-bin-x86-static.tgz --exclude-vcs $(BINSRC2)
461
rm -f $(TMP)/$(PACKAGE)
463
# add ocaml version in name ?
465
rm -f $(TMP)/$(PACKAGE)
466
ln -s `pwd` $(TMP)/$(PACKAGE)
468
cd $(TMP); tar cvfz $(PACKAGE)-bin-bytecode-$(OCAMLVERSION).tgz --exclude-vcs $(BINSRC2)
469
rm -f $(TMP)/$(PACKAGE)
472
rm -f $(TMP)/$(PACKAGE)
473
ln -s `pwd` $(TMP)/$(PACKAGE)
474
cd $(TMP); tar cvfz $(PACKAGE)-bin-x86-python.tgz --exclude-vcs $(BINSRC2-PY)
475
rm -f $(TMP)/$(PACKAGE)
477
# add ocaml version in name ?
478
bytecodetar-python: all
479
rm -f $(TMP)/$(PACKAGE)
480
ln -s `pwd` $(TMP)/$(PACKAGE)
482
cd $(TMP); tar cvfz $(PACKAGE)-bin-bytecode-$(OCAMLVERSION)-python.tgz --exclude-vcs $(BINSRC2-PY)
483
rm -f $(TMP)/$(PACKAGE)
486
cp -a `pwd`/scripts/coccicheck $(TMP)/$(CCPACKAGE)
487
tar cvfz $(TMP)/$(CCPACKAGE).tgz -C $(TMP) --exclude-vcs $(CCPACKAGE)
488
rm -rf $(TMP)/$(CCPACKAGE)
491
rm -f $(TMP)/$(PACKAGE).tgz
492
rm -f $(TMP)/$(PACKAGE)-bin-x86.tgz
493
rm -f $(TMP)/$(PACKAGE)-bin-x86-static.tgz
494
rm -f $(TMP)/$(PACKAGE)-bin-bytecode-$(OCAMLVERSION).tgz
495
rm -f $(TMP)/$(PACKAGE)-bin-x86-python.tgz
496
rm -f $(TMP)/$(PACKAGE)-bin-bytecode-$(OCAMLVERSION)-python.tgz
497
rm -f $(TMP)/$(CCPACKAGE).tgz
500
# No need to licensify 'demos'. Because these is basic building blocks
503
TOLICENSIFY=ctl engine globals parsing_cocci popl popl09 python scripts tools
505
ocaml str.cma tools/licensify.ml
506
set -e; for i in $(TOLICENSIFY); do cd $$i; ocaml str.cma ../tools/licensify.ml; cd ..; done
508
# When checking out the source from diku sometimes I have some "X in the future"
511
echo do 'touch **/*.*'
515
# echo do 'rm -rf **/CVS'
518
@echo $(OCAMLVERSION)
521
##############################################################################
522
# Packaging rules -- To build deb packages
523
##############################################################################
524
EXCL_SYNC=--exclude ".git" \
525
--exclude ".gitignore" \
526
--exclude ".cvsignore" \
532
rsync -a $(EXCL_SYNC) . $(TMP)/$(PACKAGE)
533
$(MAKE) -C $(TMP)/$(PACKAGE) licensify
534
rm -rf $(TMP)/$(PACKAGE)/tools
537
# $(MAKE) -C $(TMP)/$(PACKAGE)/debian lucid
538
$(MAKE) -C $(TMP)/$(PACKAGE)/debian karmic
540
rm -rf $(TMP)/$(PACKAGE)/
543
cd $(TMP)/ && for p in `ls $(PRJNAME)_$(VERSION).deb*_source.changes`; do dput $(PRJNAME) $$p ; done
544
rm -rf $(TMP)/$(PRJNAME)_$(VERSION).deb*_source.changes
545
rm -rf $(TMP)/$(PRJNAME)_$(VERSION).deb*_source.$(PRJNAME).upload
546
rm -rf $(TMP)/$(PRJNAME)_$(VERSION).deb*.dsc
547
rm -rf $(TMP)/$(PRJNAME)_$(VERSION).deb*.tar.gz
550
$(MAKE) -C $(TMP)/$(PACKAGE)/debian binary
551
rm -rf $(TMP)/$(PACKAGE)/
552
rm -rf $(TMP)/$(PRJNAME)_$(VERSION).deb*_source.build
554
##############################################################################
556
##############################################################################
558
-include Makefile.dev
564
./$(TARGET) -D standard.h -parse_c -dir tests/
568
# -inline 0 to see all the functions in the profile.
569
# Can also use the profile framework in commons/ and run your program
572
$(MAKE) OPTFLAGS="-p -inline 0 " opt
578
otags -no-mli-tags -r .
581
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
582
ocamldot -lr /tmp/dependfull.depend > /tmp/dependfull.dot
583
dot -Tps /tmp/dependfull.dot > /tmp/dependfull.ps
584
ps2pdf /tmp/dependfull.ps /tmp/dependfull.pdf
586
##############################################################################
588
##############################################################################
590
# each member of the project can have its own test.ml. this file is
593
echo "let foo_ctl () = failwith \"there is no foo_ctl formula\"" \
596
beforedepend:: test.ml
599
#INC=$(dir $(shell which ocaml))
602
#INCZ=$(INCY:/=)/lib/ocaml
605
# gcc -c -o prim.o -I $(INCZ) prim.c
608
##############################################################################
609
# Generic ocaml rules
610
##############################################################################
612
.SUFFIXES: .ml .mli .cmo .cmi .cmx
625
rm -f *.cm[iox] *.o *.annot
626
rm -f *~ .*~ *.exe #*#
629
set -e; for i in $(MAKESUBDIRS); do $(MAKE) -C $$i $@; done
631
rm -f Makefile.config
632
rm -f python/pycocci.ml
633
rm -f python/pycocci_aux.ml
634
rm -f globals/config.ml
636
rm -f tests/SCORE_actual.sexp
637
rm -f tests/SCORE_best_of_both.sexp
638
find -name ".#*1.*" | xargs rm -f
642
depend:: beforedepend
643
$(OCAMLDEP) *.mli *.ml > .depend
644
set -e; for i in $(MAKESUBDIRS); do $(MAKE) -C $$i $@; done
647
@if [ ! -f .depend ] ; then $(MAKE) depend ; fi