Creating a Debian package

cd to the package's top-level directory

Ensure that a Makefile exists, even if it is empty. It must contain the targets: all, build, binary, binary-arch, binary-indep, clean, distclean, install.

Ensure that debian/ exists.

    dh_make -[is] -a --createorig -p $packageName

Build with

    debuild -rfakeroot --no-tgz-check -i -us -uc -b 
This will invoke at least the clean, build and install targets in the makefile.

The 'build' make target

Use this to compile your code and create binaries and libraries as normal. Most of the packaging work will be done in 'install'.

The 'install' make target

This is where you do the Debian-specific stuff.

PACKAGE=my-package
INSTALLDIR=usr		# Note: no leading /
install: ${FILES_TO_INSTALL}
        mkdir -p ${DESTDIR}/${INSTALLDIR}
        rm -f debian/${PACKAGE}.install
        for i in ${FILES_TO_INSTALL} do \
            mkdir -p ${DESTDIR}/${INSTALLDIR}/`dirname $$i`;\
            cp $$i  ${DESTDIR}/${INSTALLDIR}/`dirname $$i`;\
            echo $$i  ${INSTALLDIR}/`dirname $$i` >> debian/${PACKAGE}.install;\
        done    
	# Choose where you want to put your cron files.
        cp some-arbitrary-file-name debian/${PACKAGE}.cron.{d,hourly,daily,weekly,monthly}

Other helper scripts

The most likely scripts that you will want are debian/postinst and debian/prerm. Use the example scripts that dh_make created for you and modify them to suit.

Building serveral packages from one source tree

In debian/control create a paragraph for each package.

Source: YourSystem
Section: unknown 
Priority: extra
Maintainer: Your Name 
Build-Depends: debhelper (>= 8.0.0)
Standards-Version: 3.9.3

Package: package-p1
Architecture: all
Depends: 
Description: P1 description
 More description for p1 ...

Package: package-p2
Architecture: all
Depends: 
Description: P2 description
 More description for p2 ...

In the Makefile's 'build' target build everything just as for a non-Debian system. In the 'install' target create a ${PACKAGE}.install for each package, each one referring to just the files for that package. dh_install will deal with disentangling things and creating the right .deb files.

You may find it simpler to create separate 'install' targets for each package, e.g. install-p1, install-p2, and then have a master 'install' that depends on them:

   install: install-p1 install-p2 ...

Similarly, the postinst, prerm etc scripts should be named ${PACKAGE}.postinst etc. so that they are specific to each package. Of course if you want the same postinst to be used for all the generated packages ...