Coccinelle release-1.0.0-rc11
[bpt/coccinelle.git] / Makefile
index eae58c8..df350ea 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,6 @@
-# Copyright 2010, INRIA, University of Copenhagen
+# Copyright 2012, INRIA
+# Julia Lawall, Gilles Muller
+# Copyright 2010-2011, INRIA, University of Copenhagen
 # Julia Lawall, Rene Rydhof Hansen, Gilles Muller, Nicolas Palix
 # Copyright 2005-2009, Ecole des Mines de Nantes, University of Copenhagen
 # Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix
 # Configuration section
 #############################################################################
 
+-include Makefile.libs
 -include Makefile.config
 -include /etc/lsb-release
 
-VERSION=$(shell cat globals/config.ml.in |grep version |perl -p -e 's/.*"(.*)".*/$$1/;')
+VERSION=$(shell cat ./version)
 CCVERSION=$(shell cat scripts/coccicheck/README |grep "Coccicheck version" |perl -p -e 's/.*version (.*)[ ]*/$$1/;')
 PKGVERSION=$(shell dpkg-parsechangelog -ldebian/changelog.$(DISTRIB_CODENAME) 2> /dev/null \
         | sed -n 's/^Version: \(.*\)/\1/p' )
@@ -39,7 +42,8 @@ PKGVERSION=$(shell dpkg-parsechangelog -ldebian/changelog.$(DISTRIB_CODENAME) 2>
 TARGET=spatch
 PRJNAME=coccinelle
 
-SRC=flag_cocci.ml cocci.ml testing.ml test.ml main.ml
+LEXER_SOURCES =
+SRC=flag_cocci.ml cocci.ml testing.ml test.ml $(LEXER_SOURCES:.mll=.ml) main.ml
 
 ifeq ($(FEATURE_PYTHON),1)
 PYCMA=pycaml.cma
@@ -51,7 +55,7 @@ endif
 OPTLIBFLAGS=
 
 ifeq ("$(SEXPDIR)","ocamlsexp")
-SEXPLIB=sexplib.cmo
+SEXPLIB=ocamlsexp/sexplib.cmo
 OPTSEXPLIB=sexplib.cmx
 else
 SEXPLIB=sexplib.cma
@@ -64,9 +68,16 @@ else
 DYNLINK=dynlink.cma
 endif
 
+ifdef PCREDIR
+PCRELIB=pcre.cma
+else
+PCRELIB=
+PCREDIR=
+endif
+
 SEXPSYSCMA=bigarray.cma nums.cma
 
-SYSLIBS=str.cma unix.cma $(SEXPSYSCMA) $(PYCMA) $(DYNLINK) # threads.cma
+SYSLIBS=str.cma unix.cma $(SEXPSYSCMA) $(DYNLINK) $(PCRELIB) # threads.cma
 LIBS=commons/commons.cma \
      commons/commons_sexp.cma \
      globals/globals.cma \
@@ -76,11 +87,13 @@ LIBS=commons/commons.cma \
      extra/extra.cma python/coccipython.cma ocaml/cocciocaml.cma
 
 # Should we use the local version of pycaml
+ifeq ($(FEATURE_PYTHON),1)
 ifeq ("$(PYCAMLDIR)","pycaml")
 LOCALPYCAML=pycaml
 else
 LOCALPYCAML=
 endif
+endif
 
 # Should we use the local version of menhirLib
 ifeq ("$(MENHIRDIR)","menhirlib")
@@ -97,22 +110,28 @@ LOCALSEXP=
 endif
 
 # used for depend: and a little for rec & rec.opt
-MAKESUBDIRS=$(LOCALPYCAML) $(LOCALSEXP) commons \
+MAKESUBDIRS=$(LOCALSEXP) commons \
  globals $(LOCALMENHIR) ctl parsing_cocci parsing_c \
- engine popl09 extra python ocaml
+ engine popl09 extra python ocaml \
+ $(MAKELIBS)
 
 # used for clean:
 # It is like MAKESUBDIRS but also
 # force cleaning of local library copies
 CLEANSUBDIRS=pycaml ocamlsexp commons \
  globals menhirlib ctl parsing_cocci parsing_c \
- engine popl09 extra python ocaml
+ engine popl09 extra python ocaml \
+ $(CLEANLIBS)
 
 INCLUDEDIRSDEP=commons commons/ocamlextra $(LOCALSEXP) \
  globals $(LOCALMENHIR) $(LOCALPYCAML) ctl \
- parsing_cocci parsing_c engine popl09 extra python ocaml
+ parsing_cocci parsing_c engine popl09 extra python ocaml \
+ $(DEPLIBS)
 
-INCLUDEDIRS=$(INCLUDEDIRSDEP) $(SEXPDIR) $(MENHIRDIR) $(PYCAMLDIR)
+INCLUDEDIRS=$(INCLUDEDIRSDEP) $(SEXPDIR) $(MENHIRDIR) $(PYCAMLDIR) $(PCREDIR) $(INCLIBS)
+
+EXTRALINKS=
+LINKFLAGS=$(EXTRALINKS:%=-cclib -l%)
 
 ##############################################################################
 # Generic variables
@@ -135,19 +154,20 @@ OCAMLCFLAGS=
 # but 'make forprofiling' below does that for you.
 # This flag is also used in subdirectories so don't change its name here.
 # To enable backtrace support for native code, you need to put -g in OPTFLAGS
-# to also link with -g, but even in 3.11 the backtrace support seems buggy so
-# not worth it.
-OPTFLAGS=
+# to also link with -g.
+OPTFLAGS= -g
 
-OCAMLC=ocamlc$(OPTBIN) $(OCAMLCFLAGS)  $(INCLUDES)
-OCAMLOPT=ocamlopt$(OPTBIN) $(OPTFLAGS) $(INCLUDES)
+OCAMLC=ocamlc$(OPTBIN) $(OCAMLCFLAGS) $(LINKFLAGS) $(INCLUDES)
+OCAMLOPT=ocamlopt$(OPTBIN) $(OPTFLAGS) $(LINKFLAGS) $(INCLUDES)
 OCAMLLEX=ocamllex #-ml # -ml for debugging lexer, but slightly slower
 OCAMLYACC=ocamlyacc -v
 OCAMLDEP=ocamldep $(INCLUDEDIRSDEP:%=-I %)
 OCAMLMKTOP=ocamlmktop -g -custom $(INCLUDES)
 
 # can also be set via 'make static'
-STATIC= #-ccopt -static
+CFLAGS=-pie -fPIE -fpic -fPIC -static
+STATICCFLAGS=$(CFLAGS:%=-ccopt %)
+STATIC= # $(STATICCFLAGS)
 
 # can also be unset via 'make purebytecode'
 BYTECODE_STATIC=-custom
@@ -160,8 +180,7 @@ BYTECODE_STATIC=-custom
 
 all: Makefile.config byte preinstall
 
-opt: all.opt
-all.opt: opt-compil preinstall
+opt all.opt: opt-compil preinstall
 
 world: preinstall
        $(MAKE) byte
@@ -210,18 +229,20 @@ clean::
 
 $(LIBS): $(MAKESUBDIRS)
 $(LIBS:.cma=.cmxa): $(MAKESUBDIRS:%=%.opt)
+$(LNKLIBS) : $(MAKESUBDIRS)
+$(LNKOPTLIBS) : $(MAKESUBDIRS:%=%.opt)
 
-$(OBJS):$(LIBS)
-$(OPTOBJS):$(LIBS:.cma=.cmxa)
+$(OBJS):$(LIBS) $(LNKLIBS)
+$(OPTOBJS):$(LIBS:.cma=.cmxa) $(LNKOPTLIBS)
 
 $(EXEC): $(LIBS) $(OBJS)
-       $(OCAMLC) $(BYTECODE_STATIC) -o $@ $(SYSLIBS) $(SEXPLIB) $^
+       $(OCAMLC) $(BYTECODE_STATIC) -o $@ $(SYSLIBS) $(SEXPLIB) $(LNKLIBS) $^
 
 $(EXEC).opt: $(LIBS:.cma=.cmxa) $(OPTOBJS)
-       $(OCAMLOPT) $(STATIC) -o $@ $(SYSLIBS:.cma=.cmxa) $(OPTSEXPLIB) $(OPTLIBFLAGS)  $^
+       $(OCAMLOPT) $(STATIC) -o $@ $(SYSLIBS:.cma=.cmxa) $(OPTSEXPLIB) $(OPTLIBFLAGS) $(FLAGSLIB) $(OPTLNKLIBS) $^
 
-$(EXEC).top: $(LIBS) $(OBJS)
-       $(OCAMLMKTOP) -custom -o $@ $(SYSLIBS) $(SEXPLIB) $^
+$(EXEC).top: $(LIBS) $(OBJS) $(LNKLIBS)
+       $(OCAMLMKTOP) -custom -o $@ $(SYSLIBS) $(SEXPLIB) $(LNKLIBS) $^
 
 clean::
        rm -f $(TARGET) $(TARGET).opt $(TARGET).top
@@ -235,15 +256,15 @@ Makefile.config:
        @echo "Makefile.config is missing. Have you run ./configure?"
        @exit 1
 
-tools:
+tools: $(LIBS) $(LNKLIBS)
        $(MAKE) -C tools
 
-clean::
-       if [ -d tools ] ; then $(MAKE) -C tools clean ; fi
+distclean::
+       if [ -d tools ] ; then $(MAKE) -C tools distclean ; fi
 
 static:
        rm -f spatch.opt spatch
-       $(MAKE) STATIC="-ccopt -static" spatch.opt
+       $(MAKE) STATIC="$(STATICCFLAGS)" spatch.opt
        cp spatch.opt spatch
 
 purebytecode:
@@ -258,13 +279,16 @@ purebytecode:
 .PHONY:: docs
 
 docs:
-       make -C docs
+       $(MAKE) -C docs
+       if [ -x "$(TARGET)" -o -x "$(TARGET).opt" ]; \
+               then $(MAKE) -C ocaml doc; fi
 
 clean::
-       make -C docs clean
+       $(MAKE) -C docs clean
+       $(MAKE) -C ocaml cleandoc
 
 distclean::
-       make -C docs distclean
+       $(MAKE) -C docs distclean
 
 ##############################################################################
 # Pre-Install (customization of spatch frontend script)
@@ -317,21 +341,34 @@ install-common:
        mkdir -p $(DESTDIR)$(LIBDIR)
        mkdir -p $(DESTDIR)$(SHAREDIR)/ocaml
        mkdir -p $(DESTDIR)$(SHAREDIR)/commons
+       mkdir -p $(DESTDIR)$(SHAREDIR)/globals
        mkdir -p $(DESTDIR)$(SHAREDIR)/parsing_c
-       mkdir -p $(DESTDIR)$(MANDIR)/man1
        $(INSTALL_DATA) standard.h $(DESTDIR)$(SHAREDIR)
        $(INSTALL_DATA) standard.iso $(DESTDIR)$(SHAREDIR)
        $(INSTALL_DATA) ocaml/coccilib.cmi $(DESTDIR)$(SHAREDIR)/ocaml/
        $(INSTALL_DATA) parsing_c/*.cmi $(DESTDIR)$(SHAREDIR)/parsing_c/
        $(INSTALL_DATA) commons/*.cmi $(DESTDIR)$(SHAREDIR)/commons/
-       $(INSTALL_DATA) docs/spatch.1 $(DESTDIR)$(MANDIR)/man1/
+       $(INSTALL_DATA) globals/iteration.cmi $(DESTDIR)$(SHAREDIR)/globals/
        @if [ $(FEATURE_PYTHON) -eq 1 ]; then $(MAKE) install-python; fi
 
+install-man:
+       mkdir -p $(DESTDIR)$(MANDIR)/man1
+       mkdir -p $(DESTDIR)$(MANDIR)/man3
+       $(INSTALL_DATA) docs/spatch.1 $(DESTDIR)$(MANDIR)/man1/
+       $(INSTALL_DATA) docs/Coccilib.3cocci $(DESTDIR)$(MANDIR)/man3/
+
 install-bash:
        mkdir -p $(DESTDIR)$(BASH_COMPLETION_DIR)
        $(INSTALL_DATA) scripts/spatch.bash_completion \
                $(DESTDIR)$(BASH_COMPLETION_DIR)/spatch
 
+install-tools:
+       mkdir -p $(DESTDIR)$(BINDIR)
+       $(INSTALL_PROGRAM) tools/splitpatch \
+               $(DESTDIR)$(BINDIR)/splitpatch
+       $(INSTALL_PROGRAM) tools/cocci-send-email.perl \
+               $(DESTDIR)$(BINDIR)/cocci-send-email.perl
+
 install-python:
        mkdir -p $(DESTDIR)$(SHAREDIR)/python/coccilib/coccigui
        $(INSTALL_DATA) python/coccilib/*.py \
@@ -345,7 +382,7 @@ install-python:
        if [ -f pycaml/dllpycaml_stubs.so ]; then \
                $(INSTALL_LIB) pycaml/dllpycaml_stubs.so $(DESTDIR)$(LIBDIR) ; fi
 
-install: install-common
+install: install-man install-common
        @if test -x spatch -a ! -x spatch.opt ; then \
                $(MAKE) install-byte;fi
        @if test ! -x spatch -a -x spatch.opt ; then \
@@ -385,18 +422,29 @@ uninstall:
        rm -f $(DESTDIR)$(SHAREDIR)/standard.iso
        rm -f $(DESTDIR)$(SHAREDIR)/ocaml/coccilib.cmi
        rm -f $(DESTDIR)$(SHAREDIR)/parsing_c/*.cmi
-       rm -f $(DESTDIR)$(SHAREDIR)/commons*.cmi
+       rm -f $(DESTDIR)$(SHAREDIR)/commons/*.cmi
+       rm -f $(DESTDIR)$(SHAREDIR)/globals/*.cmi
        rm -f $(DESTDIR)$(SHAREDIR)/python/coccilib/coccigui/*
        rm -f $(DESTDIR)$(SHAREDIR)/python/coccilib/*.py
        rmdir --ignore-fail-on-non-empty -p \
                $(DESTDIR)$(SHAREDIR)/python/coccilib/coccigui
+       rmdir $(DESTDIR)$(SHAREDIR)/globals
+       rmdir $(DESTDIR)$(SHAREDIR)/commons
+       rmdir $(DESTDIR)$(SHAREDIR)/parsing_c
+       rmdir $(DESTDIR)$(SHAREDIR)/ocaml
+       rmdir $(DESTDIR)$(SHAREDIR)
        rm -f $(DESTDIR)$(MANDIR)/man1/spatch.1
+       rm -f $(DESTDIR)$(MANDIR)/man3/Coccilib.3cocci
 
 uninstall-bash:
        rm -f $(DESTDIR)$(BASH_COMPLETION_DIR)/spatch
        rmdir --ignore-fail-on-non-empty -p \
                $(DESTDIR)$(BASH_COMPLETION_DIR)
 
+uninstall-tools:
+       rm -f $(DESTDIR)$(BINDIR)/splitpatch
+       rm -f $(DESTDIR)$(BINDIR)/cocci-send-email.perl
+
 version:
        @echo "spatch     $(VERSION)"
        @echo "spatch     $(PKGVERSION) ($(DISTRIB_ID))"
@@ -436,7 +484,7 @@ tags:
        otags -no-mli-tags -r  .
 
 dependencygraph:
-       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
+       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
        ocamldot -lr /tmp/dependfull.depend > /tmp/dependfull.dot
        dot -Tps /tmp/dependfull.dot > /tmp/dependfull.ps
        ps2pdf /tmp/dependfull.ps /tmp/dependfull.pdf
@@ -479,6 +527,9 @@ beforedepend:: test.ml
 .ml.mldepend:
        $(OCAMLC) -i $<
 
+$(LEXER_SOURCES:.mll=.ml) :    $(LEXER_SOURCES)
+       $(OCAMLLEX) $(LEXER_SOURCES)
+
 clean::
        rm -f *.cm[iox] *.o *.annot
        rm -f *~ .*~ *.exe #*#
@@ -487,13 +538,11 @@ distclean:: clean
        set -e; for i in $(MAKESUBDIRS); do $(MAKE) -C $$i $@; done
        rm -f .depend
        rm -f Makefile.config
-       rm -f python/pycocci.ml
-       rm -f python/pycocci_aux.ml
-       rm -f globals/config.ml
+       rm -f globals/config.ml test.ml
        rm -f TAGS
        rm -f tests/SCORE_actual.sexp
        rm -f tests/SCORE_best_of_both.sexp
-       find -name ".#*1.*" | xargs rm -f
+       find -name ".#*1.*" | xargs rm -f
 
 beforedepend::