As with most things Debian building a package from source is generally quite easy but this, of course, is only the case if you know how to do it. This guide will show you how to get the source for a package and build it on your local machine.
Generally speaking there is no reason to build a package locally - the speed improvements that you can achieve are almost always minimal and generally non-existant. You might want to pass in a few different flag but most configuration can normally also be done with the compiled package. In fact one of the few reasons to build your own package is so that you can use a package that is currently stalled entering unstable because it doesn't compile on one platform. In my case I know that Eclipse compiles on my platform but for some reason it is failing in the auto-builder which is stopping the latest release from entering unstable.
Update Your Sources List
The first thing you need to do is update your sources list so that it includes a deb-src entry. Generally it is best to just copy your main deb entry and make it deb-src instead. You will need to run an atp-get update after adding the source entry.
Install Commonly Required Package Building Tools
Most (perhaps all) packages will require the following packages to be installed in order for the build to succeed (note if the build includes compiling code you will also need the relevent compiler and tools): dpkg-dev,build-essential, fakeroot.
Get the Package Source
Get the source for the package you want to build with apt-get source package-name where package-name is the name of the package. This will get three files: the latest version of the source for the given package (which might not match the version of the binary package in the binary repository) which will end in orig.tar.gz, a file containing diffs (ending in .diff.gz) and a Debian rules file (ending in .dsc). If save these files in the current directory and unpack the source. To keep things neat and tidy it's best to perform this procedure in an empty build directory - simply create one if you don't already have one.
Note: diff.gz might not be included if the file is native to Debian.
Most packages rely on other packages to function and sometimes build correctly. To make the process of gathering and installing dependencies easier apt-get has a build-dep function. Simply run "apt-get build-dep package-name" to get all the required build dependencies for the given package.
Build the Package
cd into the package source directory and run "debian/rules binary" or if you aren't root "fakeroot debian/rules binary". Sit back and wait for the package to be built - this can take a very long time for a big package.