Release coccinelle-0.2.2-rc1
[bpt/coccinelle.git] / Makefile
index fd8a9c5..1a4cad6 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,44 +1,49 @@
-# Copyright 2005-2009, Ecole des Mines de Nantes, University of Copenhagen
-# Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller
+# Copyright 2005-2010, Ecole des Mines de Nantes, University of Copenhagen
+# Yoann Padioleau, Julia Lawall, Rene Rydhof Hansen, Henrik Stuart, Gilles Muller, Nicolas Palix
 # This file is part of Coccinelle.
-# 
+#
 # Coccinelle is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation, according to version 2 of the License.
-# 
+#
 # Coccinelle is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
-# 
+#
 # You should have received a copy of the GNU General Public License
 # along with Coccinelle.  If not, see <http://www.gnu.org/licenses/>.
-# 
+#
 # The authors reserve the right to distribute this or future versions of
 # Coccinelle under other licenses.
 
 
+
 #############################################################################
 # Configuration section
 #############################################################################
 
 -include Makefile.config
+-include /etc/lsb-release
 
-VERSION=$(shell cat globals/config.ml |grep version |perl -p -e 's/.*"(.*)".*/$$1/;')
+VERSION=$(shell cat globals/config.ml.in |grep version |perl -p -e 's/.*"(.*)".*/$$1/;')
+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' )
 
 ##############################################################################
 # Variables
 ##############################################################################
 TARGET=spatch
+PRJNAME=coccinelle
 
 SRC=flag_cocci.ml cocci.ml testing.ml test.ml main.ml
 
-
 ifeq ($(FEATURE_PYTHON),1)
 PYCMA=pycaml/pycaml.cma
 PYDIR=pycaml
 PYLIB=dllpycaml_stubs.so
-# the following is essential for Coccinelle to compile under gentoo (wierd)
+# the following is essential for Coccinelle to compile under gentoo (weird)
 OPTLIBFLAGS=-cclib dllpycaml_stubs.so
 else
 PYCMA=
@@ -47,17 +52,23 @@ PYLIB=
 OPTLIBFLAGS=
 endif
 
+SEXPSYSCMA=bigarray.cma nums.cma
 
-SYSLIBS=str.cma unix.cma
-LIBS=commons/commons.cma globals/globals.cma\
+SYSLIBS=str.cma unix.cma $(SEXPSYSCMA)
+LIBS=commons/commons.cma \
+     ocamlsexp/sexplib1.cma commons/commons_sexp.cma \
+     globals/globals.cma \
      ctl/ctl.cma \
      parsing_cocci/cocci_parser.cma parsing_c/parsing_c.cma \
      engine/cocciengine.cma popl09/popl.cma \
      extra/extra.cma $(PYCMA) python/coccipython.cma
 
-MAKESUBDIRS=commons globals menhirlib $(PYDIR) ctl parsing_cocci parsing_c \
+#used for clean: and depend: and a little for rec & rec.opt
+MAKESUBDIRS=commons ocamlsexp \
+ globals menhirlib $(PYDIR) ctl parsing_cocci parsing_c \
  engine popl09 extra python
-INCLUDEDIRS=commons commons/ocamlextra globals menhirlib $(PYDIR) ctl \
+INCLUDEDIRS=commons commons/ocamlextra ocamlsexp \
+ globals menhirlib $(PYDIR) ctl \
  parsing_cocci parsing_c engine popl09 extra python
 
 ##############################################################################
@@ -75,11 +86,14 @@ EXEC=$(TARGET)
 # Generic ocaml variables
 ##############################################################################
 
-OCAMLCFLAGS= #-g -dtypes # -w A
+OCAMLCFLAGS=
 
 # for profiling add  -p -inline 0
 # 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=
 # the following is essential for Coccinelle to compile under gentoo
 # but is now defined above in this file
@@ -101,25 +115,39 @@ BYTECODE_STATIC=-custom
 ##############################################################################
 # Top rules
 ##############################################################################
-.PHONY: all all.opt opt top clean configure
-.PHONY: $(MAKESUBDIRS) $(MAKESUBDIRS:%=%.opt) subdirs subdirs.opt
+.PHONY:: all all.opt byte opt top clean distclean configure
+.PHONY:: $(MAKESUBDIRS) $(MAKESUBDIRS:%=%.opt) subdirs subdirs.opt
+
+all: Makefile.config byte preinstall
+
+opt: all.opt
+all.opt: opt-compil preinstall
 
-all:
+world: preinstall
+       $(MAKE) byte
+       $(MAKE) opt-compil
+
+byte: .depend
        $(MAKE) subdirs
        $(MAKE) $(EXEC)
 
-opt:
+opt-compil: .depend
        $(MAKE) subdirs.opt
        $(MAKE) $(EXEC).opt
 
-all.opt: opt
 top: $(EXEC).top
 
 subdirs:
-       +for D in $(MAKESUBDIRS); do $(MAKE) $$D ; done
+       $(MAKE) -C commons OCAMLCFLAGS="$(OCAMLCFLAGS)"
+       $(MAKE) -C ocamlsexp OCAMLCFLAGS="$(OCAMLCFLAGS)"
+       $(MAKE) -C commons sexp OCAMLCFLAGS="$(OCAMLCFLAGS)"
+       +for D in $(MAKESUBDIRS); do $(MAKE) $$D || exit 1 ; done
 
 subdirs.opt:
-       +for D in $(MAKESUBDIRS); do $(MAKE) $$D.opt ; done
+       $(MAKE) -C commons all.opt OCAMLCFLAGS="$(OCAMLCFLAGS)"
+       $(MAKE) -C ocamlsexp all.opt OCAMLCFLAGS="$(OCAMLCFLAGS)"
+       $(MAKE) -C commons sexp.opt OCAMLCFLAGS="$(OCAMLCFLAGS)"
+       +for D in $(MAKESUBDIRS); do $(MAKE) $$D.opt || exit 1 ; done
 
 $(MAKESUBDIRS):
        $(MAKE) -C $@ OCAMLCFLAGS="$(OCAMLCFLAGS)" all
@@ -127,6 +155,7 @@ $(MAKESUBDIRS):
 $(MAKESUBDIRS:%=%.opt):
        $(MAKE) -C $(@:%.opt=%) OCAMLCFLAGS="$(OCAMLCFLAGS)" all.opt
 
+#dependencies:
 # commons:
 # globals:
 # menhirlib:
@@ -138,24 +167,10 @@ $(MAKESUBDIRS:%=%.opt):
 # extra: parsing_cocci parsing_c ctl
 # pycaml:
 # python:pycaml parsing_cocci parsing_c
-#
-# commons.opt:
-# globals.opt:
-# menhirlib.opt:
-# parsing_cocci.opt: commons.opt globals.opt menhirlib.opt
-# parsing_c.opt:parsing_cocci.opt
-# ctl.opt:globals.opt commons.opt
-# engine.opt: parsing_cocci.opt parsing_c.opt ctl.opt
-# popl09.opt:engine.opt
-# extra.opt: parsing_cocci.opt parsing_c.opt ctl.opt
-# pycaml.opt:
-# python.opt:pycaml.opt parsing_cocci.opt parsing_c.opt
 
 clean::
-       set -e; for i in $(MAKESUBDIRS); do $(MAKE) -C $$i clean; done
-
-configure:
-       ./configure
+       set -e; for i in $(MAKESUBDIRS); do $(MAKE) -C $$i $@; done
+       $(MAKE) -C demos/spp $@
 
 $(LIBS): $(MAKESUBDIRS)
 $(LIBS:.cma=.cmxa): $(MAKESUBDIRS:%=%.opt)
@@ -174,18 +189,22 @@ $(EXEC).top: $(LIBS) $(OBJS)
 
 clean::
        rm -f $(TARGET) $(TARGET).opt $(TARGET).top
-
-clean::
        rm -f dllpycaml_stubs.so
 
+.PHONY:: tools configure
 
-.PHONY: tools all configure
+configure:
+       ./configure
+
+Makefile.config:
+       @echo "Makefile.config is missing. Have you run ./configure?"
+       @exit 1
 
 tools:
        $(MAKE) -C tools
-clean::
-       $(MAKE) -C tools clean
 
+clean::
+       if [ -d tools ] ; then $(MAKE) -C tools clean ; fi
 
 static:
        rm -f spatch.opt spatch
@@ -195,91 +214,176 @@ static:
 purebytecode:
        rm -f spatch.opt spatch
        $(MAKE) BYTECODE_STATIC="" spatch
+       perl -p -i -e 's/^#!.*/#!\/usr\/bin\/ocamlrun/' spatch
 
 
+##############################################################################
+# Build documentation
+##############################################################################
+.PHONY:: docs
+
+docs:
+       make -C docs
+
+clean::
+       make -C docs clean
+
+distclean::
+       make -C docs distclean
+
+##############################################################################
+# Pre-Install (customization of spatch frontend script)
+##############################################################################
+
+preinstall: scripts/spatch scripts/spatch.opt scripts/spatch.byte
+
+# user will use spatch to run spatch.opt (native)
+scripts/spatch:
+       cp scripts/spatch.sh scripts/spatch.tmp2
+       sed "s|SHAREDIR|$(SHAREDIR)|g" scripts/spatch.tmp2 > scripts/spatch.tmp
+       sed "s|LIBDIR|$(LIBDIR)|g" scripts/spatch.tmp > scripts/spatch
+       rm -f scripts/spatch.tmp2 scripts/spatch.tmp
+
+# user will use spatch to run spatch (bytecode)
+scripts/spatch.byte:
+       cp scripts/spatch.sh scripts/spatch.byte.tmp3
+       sed "s|\.opt||" scripts/spatch.byte.tmp3 > scripts/spatch.byte.tmp2
+       sed "s|SHAREDIR|$(SHAREDIR)|g" scripts/spatch.byte.tmp2 \
+               > scripts/spatch.byte.tmp
+       sed "s|LIBDIR|$(LIBDIR)|g" scripts/spatch.byte.tmp \
+               > scripts/spatch.byte
+       rm -f   scripts/spatch.byte.tmp3 \
+               scripts/spatch.byte.tmp2 \
+               scripts/spatch.byte.tmp
+
+# user will use spatch.opt to run spatch.opt (native)
+scripts/spatch.opt:
+       cp scripts/spatch.sh scripts/spatch.opt.tmp2
+       sed "s|SHAREDIR|$(SHAREDIR)|g" scripts/spatch.opt.tmp2 \
+               > scripts/spatch.opt.tmp
+       sed "s|LIBDIR|$(LIBDIR)|g" scripts/spatch.opt.tmp \
+               > scripts/spatch.opt
+       rm -f scripts/spatch.opt.tmp scripts/spatch.opt.tmp2
+
+clean::
+       rm -f scripts/spatch scripts/spatch.byte scripts/spatch.opt
+
 ##############################################################################
 # Install
 ##############################################################################
 
 # don't remove DESTDIR, it can be set by package build system like ebuild
+# for staged installation.
 install-common:
        mkdir -p $(DESTDIR)$(BINDIR)
        mkdir -p $(DESTDIR)$(LIBDIR)
        mkdir -p $(DESTDIR)$(SHAREDIR)
        mkdir -p $(DESTDIR)$(MANDIR)/man1
-       cp standard.h $(DESTDIR)$(SHAREDIR)
-       cp standard.iso $(DESTDIR)$(SHAREDIR)
-       cp docs/spatch.1 $(DESTDIR)$(MANDIR)/man1/
-       mkdir -p $(DESTDIR)$(SHAREDIR)/python
-       cp -a python/coccilib $(DESTDIR)$(SHAREDIR)/python
-       cp -f dllpycaml_stubs.so $(DESTDIR)$(LIBDIR)
+       $(INSTALL_DATA) standard.h $(DESTDIR)$(SHAREDIR)
+       $(INSTALL_DATA) standard.iso $(DESTDIR)$(SHAREDIR)
+       $(INSTALL_DATA) docs/spatch.1 $(DESTDIR)$(MANDIR)/man1/
+       @if [ $(FEATURE_PYTHON) -eq 1 ]; then $(MAKE) install-python; fi
+
+install-python:
+       mkdir -p $(DESTDIR)$(SHAREDIR)/python/coccilib/coccigui
+       $(INSTALL_DATA) python/coccilib/*.py \
+               $(DESTDIR)$(SHAREDIR)/python/coccilib
+       $(INSTALL_DATA) python/coccilib/coccigui/*.py \
+               $(DESTDIR)$(SHAREDIR)/python/coccilib/coccigui
+       $(INSTALL_DATA) python/coccilib/coccigui/pygui.glade \
+               $(DESTDIR)$(SHAREDIR)/python/coccilib/coccigui
+       $(INSTALL_DATA) python/coccilib/coccigui/pygui.gladep \
+               $(DESTDIR)$(SHAREDIR)/python/coccilib/coccigui
+       $(INSTALL_LIB) dllpycaml_stubs.so $(DESTDIR)$(LIBDIR)
+
+install: install-common
+       @if test -x spatch -a ! -x spatch.opt ; then \
+               $(MAKE) install-byte;fi
+       @if test ! -x spatch -a -x spatch.opt ; then \
+               $(MAKE) install-def; $(MAKE) install-opt;fi
+       @if test -x spatch -a -x spatch.opt ; then \
+               $(MAKE) install-byte; $(MAKE) install-opt;fi
+       @if test ! -x spatch -a ! -x spatch.opt ; then \
+               echo "\n\n\t==> Run 'make', 'make opt', or both first. <==\n\n";fi
        @echo ""
-       @echo "You can also install spatch by copying the program spatch"
-       @echo "(available in this directory) anywhere you want and"
-       @echo "give it the right options to find its configuration files."
+       @echo "\tYou can also install spatch by copying the program spatch"
+       @echo "\t(available in this directory) anywhere you want and"
+       @echo "\tgive it the right options to find its configuration files."
        @echo ""
 
 # user will use spatch to run spatch.opt (native)
-install: all.opt install-common
-       cp spatch.opt $(DESTDIR)$(SHAREDIR)
-       cat scripts/spatch.sh | sed "s|SHAREDIR|$(DESTDIR)$(SHAREDIR)|g" > $(DESTDIR)$(BINDIR)/spatch
+install-def:
+       $(INSTALL_PROGRAM) spatch.opt $(DESTDIR)$(SHAREDIR)
+       $(INSTALL_PROGRAM) scripts/spatch $(DESTDIR)$(BINDIR)/spatch
 
 # user will use spatch to run spatch (bytecode)
-install-byte: all install-common
-       cp spatch $(DESTDIR)$(SHAREDIR)
-       cat scripts/spatch.sh | sed "s|\.opt||" | sed "s|SHAREDIR|$(DESTDIR)$(SHAREDIR)|g" > $(DESTDIR)$(BINDIR)/spatch
+install-byte:
+       $(INSTALL_PROGRAM) spatch $(DESTDIR)$(SHAREDIR)
+       $(INSTALL_PROGRAM) scripts/spatch.byte $(DESTDIR)$(BINDIR)/spatch
 
 # user will use spatch.opt to run spatch.opt (native)
-install-opt: all.opt install-common
-       cp spatch.opt $(DESTDIR)$(SHAREDIR)
-       cat scripts/spatch.sh | sed "s|SHAREDIR|$(DESTDIR)$(SHAREDIR)|g" > $(DESTDIR)$(BINDIR)/spatch.opt
+install-opt:
+       $(INSTALL_PROGRAM) spatch.opt $(DESTDIR)$(SHAREDIR)
+       $(INSTALL_PROGRAM) scripts/spatch.opt $(DESTDIR)$(BINDIR)/spatch.opt
 
 uninstall:
        rm -f $(DESTDIR)$(BINDIR)/spatch
+       rm -f $(DESTDIR)$(BINDIR)/spatch.opt
        rm -f $(DESTDIR)$(LIBDIR)/dllpycaml_stubs.so
        rm -f $(DESTDIR)$(SHAREDIR)/standard.h
        rm -f $(DESTDIR)$(SHAREDIR)/standard.iso
        rm -rf $(DESTDIR)$(SHAREDIR)/python/coccilib
        rm -f $(DESTDIR)$(MANDIR)/man1/spatch.1
 
-
-
 version:
-       @echo $(VERSION)
+       @echo "spatch     $(VERSION)"
+       @echo "spatch     $(PKGVERSION) ($(DISTRIB_ID))"
+       @echo "coccicheck $(CCVERSION)"
 
 
 ##############################################################################
 # Package rules
 ##############################################################################
 
-PACKAGE=coccinelle-$(VERSION)
+PACKAGE=$(PRJNAME)-$(VERSION)
+CCPACKAGE=coccicheck-$(CCVERSION)
 
 BINSRC=spatch env.sh env.csh standard.h standard.iso \
-       *.txt docs/* \
-       demos/foo.* demos/simple.*
-#      $(PYLIB) python/coccilib/ demos/printloc.*
+       *.txt \
+       docs/manual/manual.pdf docs/manual/options.pdf docs/manual/main_grammar.pdf docs/spatch.1 \
+       docs/manual/cocci-python.txt \
+       demos/*
+BINSRC-PY=$(BINSRC) $(PYLIB) python/coccilib/
 BINSRC2=$(BINSRC:%=$(PACKAGE)/%)
+BINSRC2-PY=$(BINSRC-PY:%=$(PACKAGE)/%)
 
 TMP=/tmp
 OCAMLVERSION=$(shell ocaml -version |perl -p -e 's/.*version (.*)/$$1/;')
 
 # Procedure to do first time:
 #  cd ~/release
-#  cvs checkout coccinelle
+#  cvs checkout coccinelle -dP
 #  cd coccinelle
-#  cvs update -d -P
-#  touch **/*
-#  make licensify
-#  remember to comment the -g -dtypes in this Makefile
-
+#
 # Procedure to do each time:
-#  cvs update
+#
+#  1) make prepackage # WARN: These will clean your local rep. of pending modifications
+#
+#  UPDATE VERSION number in globals/config.ml.in
+#  and commit it with
+#
+#  2) make release
+#
+#  The project is then automatically licensified.
+#
+#  Remember to comment the -g -dtypes in this Makefile
+#  You can also remove a few things, for instance I removed in this
+#   Makefile things related to popl/ and popl09/
 #  make sure that ocaml is the distribution ocaml of /usr/bin, not ~pad/...
-#  modify globals/config.ml
-#  cd globals/; cvs commit -m"new version"  (do not commit from the root!)
-#  ./configure --without-python
-#  make package
-#  make website
+#
+#  3) make package
+#
+#  if WEBSITE is set properly, you can also run 'make website'
 # Check that run an ocaml in /usr/bin
 
 # To test you can try compile and run spatch from different instances
@@ -291,21 +395,54 @@ OCAMLVERSION=$(shell ocaml -version |perl -p -e 's/.*version (.*)/$$1/;')
 # the scripts/licensify has been run at least once.
 # For the 'make bintar' I can do it from my original repo.
 
+prepackage:
+       cvs up -CdP
+       $(MAKE) distclean
+       sed -i "s|^OCAMLCFLAGS=.*$$|OCAMLCFLAGS=|" Makefile
+
+release:
+       cvs ci -m "Release $(VERSION)" globals/config.ml.in
+       $(MAKE) licensify
 
 package:
-       make srctar
-       make bintar
-       make staticbintar
-       make bytecodetar
+       $(MAKE) package-src
+       $(MAKE) package-nopython
+       $(MAKE) package-python
+
+package-src:
+       $(MAKE) distclean       # Clean project
+       $(MAKE) srctar
+       $(MAKE) coccicheck
+
+package-nopython:
+       $(MAKE) distclean       # Clean project
+       ./configure --without-python
+       $(MAKE) docs
+       $(MAKE) bintar
+       $(MAKE) bytecodetar
+       $(MAKE) staticbintar
+
+package-python:
+       $(MAKE) distclean       # Clean project
+       ./configure             # Reconfigure project with Python support
+       $(MAKE) docs
+       $(MAKE) bintar-python
+       $(MAKE) bytecodetar-python
+
 
 # I currently pre-generate the parser so the user does not have to
-# install menhir on his machine. I also do a few cleanups like 'rm todo_pos'.
+# install menhir on his machine. We could also do a few cleanups.
 # You may have first to do a 'make licensify'.
+#
+# update: make docs generates pdf but also some ugly .log files, so
+# make clean is there to remove them while not removing the pdf
+# (only distclean remove the pdfs).
 srctar:
+       make distclean
+       make docs
        make clean
        cp -a .  $(TMP)/$(PACKAGE)
        cd $(TMP)/$(PACKAGE); cd parsing_cocci/; make parser_cocci_menhir.ml
-       cd $(TMP)/$(PACKAGE); rm todo_pos
        cd $(TMP); tar cvfz $(PACKAGE).tgz --exclude-vcs $(PACKAGE)
        rm -rf  $(TMP)/$(PACKAGE)
 
@@ -331,18 +468,42 @@ bytecodetar: all
        cd $(TMP); tar cvfz $(PACKAGE)-bin-bytecode-$(OCAMLVERSION).tgz --exclude-vcs $(BINSRC2)
        rm -f $(TMP)/$(PACKAGE)
 
-clean::
-       rm -f $(PACKAGE)
-       rm -f $(PACKAGE)-bin-x86.tgz
-       rm -f $(PACKAGE)-bin-x86-static.tgz
-       rm -f $(PACKAGE)-bin-bytecode-$(OCAMLVERSION).tgz
+bintar-python: all
+       rm -f $(TMP)/$(PACKAGE)
+       ln -s `pwd` $(TMP)/$(PACKAGE)
+       cd $(TMP); tar cvfz $(PACKAGE)-bin-x86-python.tgz --exclude-vcs $(BINSRC2-PY)
+       rm -f $(TMP)/$(PACKAGE)
 
+# add ocaml version in name ?
+bytecodetar-python: all
+       rm -f $(TMP)/$(PACKAGE)
+       ln -s `pwd` $(TMP)/$(PACKAGE)
+       make purebytecode
+       cd $(TMP); tar cvfz $(PACKAGE)-bin-bytecode-$(OCAMLVERSION)-python.tgz --exclude-vcs $(BINSRC2-PY)
+       rm -f $(TMP)/$(PACKAGE)
+
+coccicheck:
+       cp -a `pwd`/scripts/coccicheck $(TMP)/$(CCPACKAGE)
+       tar cvfz $(TMP)/$(CCPACKAGE).tgz -C $(TMP) --exclude-vcs $(CCPACKAGE)
+       rm -rf $(TMP)/$(CCPACKAGE)
 
+clean-packages::
+       rm -f $(TMP)/$(PACKAGE).tgz
+       rm -f $(TMP)/$(PACKAGE)-bin-x86.tgz
+       rm -f $(TMP)/$(PACKAGE)-bin-x86-static.tgz
+       rm -f $(TMP)/$(PACKAGE)-bin-bytecode-$(OCAMLVERSION).tgz
+       rm -f $(TMP)/$(PACKAGE)-bin-x86-python.tgz
+       rm -f $(TMP)/$(PACKAGE)-bin-bytecode-$(OCAMLVERSION)-python.tgz
+       rm -f $(TMP)/$(CCPACKAGE).tgz
 
-TOLICENSIFY=ctl engine parsing_cocci popl popl09 python
+#
+# No need to licensify 'demos'. Because these is basic building blocks
+# to use SmPL.
+#
+TOLICENSIFY=ctl engine globals parsing_cocci popl popl09 python scripts tools
 licensify:
-       ocaml tools/licensify.ml
-       set -e; for i in $(TOLICENSIFY); do cd $$i; ocaml ../tools/licensify.ml; cd ..; done
+       ocaml str.cma tools/licensify.ml
+       set -e; for i in $(TOLICENSIFY); do cd $$i; ocaml str.cma ../tools/licensify.ml; cd ..; done
 
 # When checking out the source from diku sometimes I have some "X in the future"
 # error messages.
@@ -358,45 +519,44 @@ ocamlversion:
 
 
 ##############################################################################
-# Pad specific rules
+# Packaging rules -- To build deb packages
 ##############################################################################
-
-#TOP=/home/pad/mobile/project-coccinelle
-WEBSITE=/home/pad/mobile/homepage/software/project-coccinelle
-
-website:
-       cp $(TMP)/$(PACKAGE).tgz                $(WEBSITE)
-       cp $(TMP)/$(PACKAGE)-bin-x86.tgz        $(WEBSITE)
-       cp $(TMP)/$(PACKAGE)-bin-x86-static.tgz $(WEBSITE)
-       cp $(TMP)/$(PACKAGE)-bin-bytecode-$(OCAMLVERSION).tgz   $(WEBSITE)
-       rm -f $(WEBSITE)/LATEST* $(WEBSITE)/coccinelle-latest.tgz
-       cd $(WEBSITE); touch LATEST_IS_$(VERSION); ln -s $(PACKAGE).tgz coccinelle-latest.tgz
-
-
-#TXT=$(wildcard *.txt)
-syncwiki:
-#      unison ~/public_html/wiki/wiki-LFS/data/pages/ docs/wiki/
-#      set -e; for i in $(TXT); do unison $$i docs/wiki/$$i; done
-
-darcsweb:
-#      @echo pull from ~/public_html/darcs/c-coccinelle and c-commons and lib-xxx
-
-DARCSFORESTS=commons \
- parsing_c parsing_cocci engine
-
-update_darcs:
-       darcs pull
-       set -e; for i in $(DARCSFORESTS); do cd $$i; darcs pull; cd ..; done
-
-#darcs diff -u
-diff_darcs:
-       set -e; for i in $(DARCSFORESTS); do cd $$i; darcs diff -u; cd ..; done
-
+EXCL_SYNC=--exclude ".git"          \
+       --exclude ".gitignore"      \
+       --exclude ".cvsignore"      \
+       --exclude "tests"           \
+       --exclude "TODO"            \
+       --cvs-exclude
+
+prepack:
+       rsync -a $(EXCL_SYNC) . $(TMP)/$(PACKAGE)
+       $(MAKE) -C $(TMP)/$(PACKAGE) licensify
+       rm -rf $(TMP)/$(PACKAGE)/tools
+
+packsrc: prepack
+#      $(MAKE) -C $(TMP)/$(PACKAGE)/debian lucid
+       $(MAKE) -C $(TMP)/$(PACKAGE)/debian karmic
+       $(MAKE) push
+       rm -rf  $(TMP)/$(PACKAGE)/
+
+push:
+       cd $(TMP)/ && for p in `ls $(PRJNAME)_$(VERSION).deb*_source.changes`; do dput $(PRJNAME) $$p ; done
+       rm -rf $(TMP)/$(PRJNAME)_$(VERSION).deb*_source.changes
+       rm -rf $(TMP)/$(PRJNAME)_$(VERSION).deb*_source.$(PRJNAME).upload
+       rm -rf $(TMP)/$(PRJNAME)_$(VERSION).deb*.dsc
+       rm -rf $(TMP)/$(PRJNAME)_$(VERSION).deb*.tar.gz
+
+packbin: prepack
+       $(MAKE) -C $(TMP)/$(PACKAGE)/debian binary
+       rm -rf  $(TMP)/$(PACKAGE)/
+       rm -rf $(TMP)/$(PRJNAME)_$(VERSION).deb*_source.build
 
 ##############################################################################
 # Developer rules
 ##############################################################################
 
+-include Makefile.dev
+
 test: $(TARGET)
        ./$(TARGET) -testall
 
@@ -463,14 +623,27 @@ beforedepend:: test.ml
 
 clean::
        rm -f *.cm[iox] *.o *.annot
-
-clean::
        rm -f *~ .*~ *.exe #*#
 
+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 TAGS
+       rm -f tests/SCORE_actual.sexp
+       rm -f tests/SCORE_best_of_both.sexp
+       find -name ".#*1.*" | xargs rm -f
+
 beforedepend::
 
 depend:: beforedepend
        $(OCAMLDEP) *.mli *.ml > .depend
-       set -e; for i in $(MAKESUBDIRS); do $(MAKE) -C $$i depend; done
+       set -e; for i in $(MAKESUBDIRS); do $(MAKE) -C $$i $@; done
+
+.depend::
+       @if [ ! -f .depend ] ; then $(MAKE) depend ; fi
 
 -include .depend