There is no single-command solution to do this, but the tools definitely exist to make it relatively painless:
debootstrap can create a pristine, minimal Ubuntu installation in a self-contained directory
schroot allows you to manage multiple chroots, keeping them clean for later use
mk-schroot can be used to automate the schroot setup and management
- Given a .dsc file (generated with
sbuild will chroot into your pristine chroot, install any dependent packages, and build your sources.
this is basically what the launchpad build servers use to build source packages and put them in the Ubuntu archive.
In general, using a pristine chroot is good practice, as it ensures that the package does not depend on any customised setup on your build machine.
The setup process would involve creating a new schroot for each Ubuntu version you'd like to target. This is fairly straightforward: use
mk-sbuild to build yourself a new chroot. Something like this is what you want:
mk-sbuild --arch=amd64 --name=lucid lucid
This will guide you to create a chroot called 'lucid-amd64', and prints out the following helpful information when it's done:
Done building lucid-amd64.
To CHANGE the golden image: sudo schroot -c lucid-amd64-source -u root
To ENTER an image snapshot: schroot -c lucid-amd64
To BUILD within a snapshot: sbuild -A -d lucid-amd64 PACKAGE*.dsc
So, once your chroots are setup, the build process would be:
- From your source pacakge's top-level directory,
debuild -S to create a source package, including
- Run the build:
sbuild -A -d lucid-amd64 ../<package>_<version>.dsc
For more info, the manpages for
debuild are quite comprehensive. https://wiki.ubuntu.com/DebootstrapChroot has some good info about building and configuring the chroots. Also, there's #ubuntu-devel on irc.freenode.net if you need a hand.