Creating a Debian Package from source
Debian makes it very easy to build its packages from source code:
- Enter "deb-src" lines in your /etc/apt/sources.list file, to make these just duplicate the deb lines with deb-src in front instead. Then update your apt package listing with "apt-get update".
- Install the following packages: dpkg-dev, build-essential,fakeroot.
#apt-get install dpkg-dev build-essential fakeroot
- Get the source package using "apt-get source packagename" where "packagename" is the name of your source package or any of the binary packages it produces. This will download the orig.tar.gz, diff.gz and dsc source files for your package, and unpack and patch the source code in a new source directory.
- Check the Build-Depends list in the dsc file, and make sure you have all of those packages installed. Also, make sure you do not have any of the packages in the Build-Conflicts list, if there is one.
- cd to the source directory and type (as root) "debian/rules binary" (or as non-root) "fakeroot debian/rules binary". This will automatically go through all of the steps necessary to build your package.
Optimization for Debian Package
You can often increase the performance of an application considerably by building it with optimization, which is done by setting compiler flags. An aggressive optimization setting is "-O6 -mcpu=whatever" where "whatever" is your target processor, but beware such aggressive optimization can lead to errors! See the gcc man page for details. The debian/rules file is usually where you want to set the optimization flags, typically using the CFLAGS variable in the configure line, e.g. "CFLAGS='-O6 -mcpu=ev56' ./configure <configure flags>", this is done between steps 3 and 5 above.
Reference Links
http://www.debian.org/doc/FAQ/ch-pkg_basics.en.html
http://checkinstall.izto.org/
http://www-jcsu.jesus.cam.ac.uk/jcn/documentation/html-only/packaging.html