I based my build on this set of instructions. These notes are mostly to remind me what I had to do to build this particular package, and the issues I ran into. There maybe omissions, this is mostly from memory.
gromacs itself seems to contain a half working deb package build system, with some missing files. There is a debian package for the current version of gromacs (4.5.5 IIRC), it might be better to take the debian config files from this. The configuration file below also added a suffix to gromacs commands, so both 4.5.5 and 4.0.5 can be installed concurrently.
0. Do not do this on an NFS drive with root squashing, install tries to change the file ownership to root and breaks. Install build-essentials and a bunch of other things (see above URL).
1. Rename the gromacs tarball to gromacs_4.0.5.orig.tar.gz
2. Untar it (tar -xvf gromacs_4.0.5.orig.tar.gz).
3. cd gromacs-4.0.5
4. mkdir debian
5. mkdir debian/source
6. touch debian/copyright
7. Create debian/compat, should contain the single number 8.
8. Use the following to create a changelog:
dch --create -v 4.0.5-1 --package gromacs405
9. Create a file debian/rules with the following contents (this is a makefile, spaces at the start of lines need to be tab characters):
#!/usr/bin/make -f %: dh $@ override_dh_auto_configure: dh_auto_configure -- --program-suffix=405 --prefix=/usr --docdir=/usr/share/gromacs405 --includedir=/usr/include/gromacs405 --htmldir=/usr/share/gromacs405 --datadir=/usr/share/gromacs405 --enable-static=no --libdir=/usr/lib/gromacs405 override_dh_auto_install: $(MAKE) DESTDIR=$$(pwd)/debian/gromacs405 install override_dh_install: sed -i "/dependency_libs/ s/'.*'/''/" `find . -name '*.la'` dh_install
10. Create a file debian/source/format with the following contents:
11. Run this to build everything:
debuild -us -uc
12. Your deb should be built.