views:

7048

answers:

6

I have the source of a program (taken from cvs/svn/git/...) and I'd like to build a Debian/Ubuntu package for it. The package is present in the repositories, but:

  • It is an older version (lacking features I need)
  • I need slightly different compile options than the default.

What is the easiest way of doing it? I am concerned about a couple of things

  • How can I check if I have listed all the dependencies correctly? (I can get some hints by looking on what the older version depended, but new dependencies may have been added.)
  • How I can I prevent the update system installing the older version in the repo on an update?
  • How I can prevent the system installing a newer version (when its out), overwriting my custom package?
+1  A: 

I believe this is the Debian package 'bible'.

Well, it's the Debian new maintainer's guide, so a lot of it won't be applicable, but they do cover what goes where.

Bernard
+1  A: 

Here is a tutorial for building a Debian package.

Basically, you need to:

  1. Set up your folder structure
  2. Create a control file
  3. Optionally create postinst or prerm scripts
  4. Run dpkg-deb

I usually do all of this in my Makefile so I can just type make to spit out the binary and package it in one go.

Adam Pierce
+4  A: 

First, the title question: Assuming the debian directory is already there, be in the source directory (the directory containing the debian directory) and invoke dpkg-buildpackage. I like to run it with these options:

dpkg-buildpackage -us -uc -nc

which mean don't sign the result and don't clean.

How can I check if I have listed all the dependencies correctly?

Getting the dependencies is a black art. The "official" way is to check build depends is if the package builds with only the base system, the "build-essential" packages, and the build dependencies you have specified. Don't know a general answer for regular Dependencies, just wade in :)

How I can I prevent the update system installing the older version in the repo on an update? How I can prevent the system installing a newer version (when its out), overwriting my custom package?

My knowledge might be out of date on this one, but to address both: Use dpkg --set-selections. Assuming nullidentd was the package you wanted to stay put, run as root

echo 'nullidentd hold' | dpkg --set-selections

Alternately, since you are building from source, you can use an epoch to set the version number artificially high and never be bothered again. To use an epoch, add a new entry to the debian/changelog file, and put a 99: in front of the version number. Given my nullidentd example, the first line of your updated changelog would read:

nullidentd (99:1.0-4) unstable; urgency=low

Bernard's link is good, especially if you have to create the debian directory yourself - also helpful are the developers reference and the general resource page. Adam's link also looks good but I'm not familiar with it.

Daniel Bungert
"dpkg --set-selections" still works, but a better method these days would be "aptitude hold nullidentd".
Mark Baker
+3  A: 

For what you want to do, you probably want to use the debian source diff, so your package is similar to the official one apart from the upstream version used. You can download the source diff from packages.debian.org, or can get it along with the .dsc and the original source archive by using "apt-get source".

Then you unpack your new version of the upstream source, change into that directory, and apply the diff you downloaded by doing

zcat ~/downloaded.diff.gz | patch -p1
chmod +x debian/rules

Then make the changes you wanted to compile options, and build the package by doing

dpkg-buildpackage -rfakeroot -us -uc
Mark Baker
You mean `apt-src`?
Ryszard Szopa
No, I meant apt-get source - fixed.
Mark Baker
+2  A: 

you can use the special package "checkinstall" for all packages which are not even in debian/ubuntu yet.

You can use "uupdate" to build a package from source with existing debian sources:

Example for libdrm2:

apt-get build-dep libdrm2
apt-get source libdrm2
cd libdrm-2.3.1
uupdate ~/Downloads/libdrm-2.4.1.tar.gz
cd ../libdrm-2.4.1
dpkg-buildpackage -us -uc -nc
Thanks! I have just used this to port Subversion 1.6.6 to an Ubuntu install that only has 1.6.5 as its latest available version, and it worked flawlessly. Saved me quite a few hours of tinkering! :)
Carlos Villela
+1  A: 
  • put "debian" directory from original package to your source directory
  • use "dch" to update version of package
  • use "debuild" to build the package
zowers