Howto to rebuild Debian packages

http://raphaelhertzog.com/2010/12/15/howto-to-rebuild-debian-packages/

1. apt-get source packagename

2. apt-get build-dep packagename
If you can't use APT for this, enter the directory where the source
package has been unpacked and run dpkg-checkbuilddeps. It will spit
out a list of unmet build dependencies (if there are any, otherwise it
will print nothing and you can go ahead safely). With a bit of copy
and paste and a "apt-get install" invocation, you'll install the
required packages in a few seconds.

3. Do whatever changes you need

I won't detail this step since it depends on your specific goal with
the rebuild. You might have to edit debian/rules, or to apply a patch.

But one thing is sure, if you have made any change or have recompiled
the package in a different environment, you should really change its
version number. You can do this with "dch --local foo" (again from the
devscripts package), replace "foo" by a short name identifying you as
the supplier of the updated version. It will update debian/changelog
and invite you to write a small entry documenting your change.

4. Build the package

The last step is also the simplest one now that everything is in
place. You must be in the directory of the unpacked source package.
Now run either "debuild -us -uc" (recommended, requires the devscripts
package) or directly "dpkg-buildpackage -us -uc". The "-us -uc"
options avoid the signature step in the build process that would
generate a (harmless) failure at the end if you have no GPG key
matching the name entered in the top entry of the Debian changelog.

$ cd publican-2.1
$ debuild -us -uc
dpkg-buildpackage -rfakeroot -D -us -uc
dpkg-buildpackage: export CFLAGS from dpkg-buildflags (origin: vendor): -g -O2
dpkg-buildpackage: export CPPFLAGS from dpkg-buildflags (origin: vendor):
dpkg-buildpackage: export CXXFLAGS from dpkg-buildflags (origin: vendor): -g -O2
dpkg-buildpackage: export FFLAGS from dpkg-buildflags (origin: vendor): -g -O2
dpkg-buildpackage: export LDFLAGS from dpkg-buildflags (origin: vendor):
dpkg-buildpackage: source package publican
dpkg-buildpackage: source version 2.1-2rh1
dpkg-buildpackage: source changed by Raphaël Hertzog
dpkg-source --before-build publican-2.1
dpkg-buildpackage: host architecture i386
[...]
dpkg-deb: building package `publican' in `../publican_2.1-2rh1_all.deb'.
dpkg-genchanges >../publican_2.1-2rh1_i386.changes
dpkg-genchanges: not including original source code in upload

Tips:
Actually you can do something like this with apt-get. Put the snippet
below in /etc/apt/apt.conf.d/local and any package installed by
"apt-get build-dep" will be marked as automatically installed and will
be removed by the next "apt-get autoremove".

APT::Get::Build-Dep-Automatic true;


dpkg-source --after-build publican-2.1
dpkg-buildpackage: binary and diff upload (original source NOT included)
Now running lintian...
Finished running lintian.

The build is over, the updated source and binary packages have been
generated in the parent directory.