Here are some notes I made learning how to use the Debian build system. I needed to build D-Bus packages that could be easily put back to how they were in case stuff broke whilst I was testing, so I used Debian's source package system to get the source, build, and repackage it. I could then upload the packages to the virtual machine I am using for testing things and install them with
dpkg --install foo-1.2.3-1.deb
Note: some of the things I've done below are quite hackish - but then, I only wanted to get some quickly hacked but packaged tools into my test environment, so…
This must be done with apt-get for now - aptitude does not cater for fetching source packages:
apt-get source dbus
This fetches a whole bunch of files including the dbus sources. Let's ignore most of them and move onto doing something useful…
One important one is debian/README.source which will tell you how the package's source is being managed.
To build the package without any changes you'll need to do:
cd dbus-1.2.3.4 dpkg-buildpackage -r -b
If it complains (and it probably will) then just install the stuff it's complaining about with aptitude (or your favourite package manager) and try again. Note that -r is equivalent to -rfakeroot (at time of writing).
If you got it all right, then you'll be rewarded with a bunch of .deb files
OK, so the above will have built you some nice .debs (hopefully), but what if you want to change the sources?
Repeating the above will work if you made no changes, or if none of your changes interfere with any of the patches that Debian's build system tries to apply (dpkg-buildpackage -r -b will try to unapply them and fail), but if you fall foul of this, you may want to try something like this:
dpkg-buildpackage -r -uc -nc
Which means we're not going to sign our changes (fine if we're only doing local hacking) and we're not going to clean the source tree (so we dont end up tediously reconfiguring / rebuilding un-necessarily).
It's good for a quick hack, but this isn't really the right way to go about things, as it goes behind the packaging tool's back, and will probably rapidly get out of control. That is, in other cases, it'll need a prod – like, for example, deleting the build stamp file to force a rebuild (eg. net-tools-1.60). In this case, though, it works.
Debian source format 3.0 apparently applies patches when unpacking things, so it wont suffer from this (IMO) limitation. Not many packages are using this yet though.
So, anyhow, once again, we'll end up with a nice bunch of .deb files in our parent directory, hopefully complete with our modifications.
Ok, so this is all good, but (oh no!) something isn't working right. By default, most packages will get their debug symbols stripped, which makes tools like gdb nearly useless. Lets defeat this when we build:
DEB_BUILD_OPTIONS=nostrip dpkg-buildpackage -rfakeroot -uc -nc
Unfortunately, this only 'half works' for now (at least for dbus) because GDB at the time of writing does not have the ability to debug PIE executables. The only solution I can find for this in the case of dbus-daemon is to simply edit bus/Makefile and nuke the PIE CFLAGS and LDFLAGS. Even this:
DEB_BUILD_OPTIONS=nostrip CFLAGS="-g -O0" dpkg-buildpackage -rfakeroot -uc -nc
didn't help in this instance. Sometimes you just have to tweak the Makefile… Note: in the case of dbus, I also had to delete bus/dbus-daemon in order to get it rebuilt.
Put stuff about using quilt etc. to do things properly here after I've read up about it…