Satya's blog - Making a deb file

Jul 27 2005 15:19 Making a deb file
Debian Linux distributes software in files called deb files (.deb). Most end users don't have to worry about them, as the package manager programs, some of which are pretty (see synaptic), do all the work. Other Linux distributions use other packaging formats, like RPM.

But when you write new software, you should make a deb (or RPM or whatever -- since I use Debian, I'll talk about making a deb) so it's easier for others to install your software. Sure, you can distribute a tar.gz like I've done all this time, but that's not very user-friendly.

How do you make a deb file? It's not simple, because the instructions are opaque. The method I give here is probably completely wrong, but it's worked enough for me to obtain a home-grown for-internal-use-only no-frills deb package.

  1. Grab your tarball and put it somewhere like ~/deb/yourprogram.tar.gz (I just make up the deb directory. It's going to get cluttered later, so make a new directory and call it whatever you want. I use 'deb'.)
  2. Untar it, so you have a directory like ~/deb/yourprogram-1.1, or whatever the version happens to be.
  3. Make a Makefile, if you don't have one already. Here's an example:
    build:
        #whatever commans are needed to compile or configure
    
    install:
        #whatever commands are needed to 
        # install. it should behave as if 
        # $(DESTDIR) is the target of the install
        cp -r home $(DESTDIR)
        cp -r etc $(DESTDIR)
    
    clean:
        # to get a pristine package, without object files etc. 
        # should basically reverse whatever build does.
        -rm -rf $DESTDIR.etc
    
    You can leave one or more blank. The build process runs make and make install on your source. This causes or should case your software to be installed into a skeletal filesystem under debian/yourprogram so that it can then be packed into a deb. The buildprocess then runs a make clean to get rid of that stuff.
  4. Run dh_make. I think it comes from dpkg-dev or something. Find it.
  5. Edit the debian/control file that just appeared in ~/deb/yourprogram-version or you can leave it alone. You can also add preinst, postinst, etc., but I won't tell you anything about them and if you can do that on your own, or even know what the heck I'm on about, you don't need these instructions.
  6. You should now be able to run dpkg-buildpackage -rfakeroot and if it runs without errors you might find a file in ~/deb/ called something like yourprogram_version-1.i386.deb


That is all. If I find out what the heck I'm doing wrong, I'll update this.

Tag: tech debian howto