Tuesday, July 17, 2007

Create Debian package for a Python program

Note: You will need root access for the process.

  1. Install dh-make if it's not available in the system.
    apt-get dh-make

  2. Create a directory as <package>-<version>. Note that the package name must be all lower-case.
    eg: - mypackage-1.0

  3. Go inside that folder. Copy all your files into that. (including the setup.py)

  4. Create a Makefile with following contents.
    The reason is that unlike others, Debian uses the Makefile to read package information. We will create this file to be an intermediate between the Debian packager and out good old setup.py

    #### contents of Makefile ####

    all:
    python setup.py build
    clean:
    python setup.py clean --all
    install:
    python setup.py install --root $(DESTDIR)

    For more info about Makefile(s) see http://www.gnu.org/software/make/manual/

  5. Call the dh_make program.

    dh_make --single --createorig --copyright gpl --email my@email.com

    This tells the program to:

    1. Create a single class package.
    2. Create the original archive.
      (dh_make by default tries to convert the original archive of file to a .deb package. Here we ask it to create the original archive as well)
    3. State the copyrights of the package.
    4. email of the package maintainer. (Name of the maintainer is the username you have logged-in)

  6. It will create a folder called debian inside you current folder. Edit the control file inside the debian folder to reflect the dependencies and descriptions you want. Also edit the copyright file and fill in the missing info.

  7. Run the
    dpkg-buildpackage
    command as root.

  8. The root directory (not your package-version directory) will now have the .deb file

No comments: