Source code for free software is typically distributed in compressed tar archives called tarballs.
When invoked to create a source package, dpkg-buildpackage calls the maintainer's rules to clean the source tree of any intermediate files, does various sanity checks, and finally, signs the dsc file with the packager's key using the debsign utility.
The reverse process — producing the unpacked source tree from a source package — is accomplished using the dpkg-source utility, which extracts the original tarball to a subdirectory, extracts the debian.tar tarball inside it, and applies any quilt patches present.
This is a unified diff that contains the debian directory and any changes to the upstream source that aren't managed by a patch system.
The build tools only process the top entry, which is used to determine the package version, urgency (which is only of relevance to Debian itself), and bugs in the distribution that this release fixes.
This file is a script that is invoked by dpkg-buildpackage with a single argument that specifies the action to take (clean, build, install, binary).
Apart from invoking the upstream build system, most instructions in debian/rules are highly repetitive and ubiquitous, and thus, virtually all debian/rules files wrap this functionality in debhelper scripts.
For example, automatically determining the dependencies based on shared libraries used is a very common action, and thus, instead of including the code necessary to do it, the debian/rules file simply calls dh_shlibdeps.
Sometimes a user may want to look at differences between two source packages — for example, to generate a proposed patch against the version currently in the repository for inclusion in the distribution's bug tracking system.
Here are example lintian outputs: Source packages are intended to be buildable on any installation of the target distribution version, provided that build dependencies are met.
The Launchpad service provides similar build daemons for Ubuntu, both the official distribution and personal package archives (PPAs).
debian
subdirectory added there by the package maintainer.