CAB
CAB

Reputation: 1045

How to create a Debian package as part of autotools build?

All of the Debian packaging examples I can find assume the user is re-packaging from an upstream build, so it unpacks a source tarball, configures, rebuilds, and re-packages. I'm trying to build a package for my own library, which is built using autotools. I've tried several different approaches, and my latest attempt looks like this:

DH_PACKAGE_NAME=`echo $(PACKAGE_NAME) | sed s/_/-/g`
dist-hook:
    cd $(distdir) ; \
    export DEBFULLNAME="Some One" ; \
    export DEBEMAIL="[email protected]" ; \
    echo -e "\n" | dh_make --copyright blank --library --native \
        --packagename $(DH_PACKAGE_NAME)
    mv $(distdir)/debian $(distdir)/DEBIAN
    dpkg-deb --build $(distdir)

for which dpkg-deb complains about dh_makes control file. I have an inkling the solution is something far simpler?

Upvotes: 16

Views: 7194

Answers (3)

ptomato
ptomato

Reputation: 57854

Here's an example of how I created a Debian package as part of an autotools build.

In configure.ac, I check that dpkg-buildpackage is installed on the system, however, I don't abort if it's not found.

I require the user to run ./configure --enable-deb when building a Debian package, for various reasons, but in most cases that's not necessary. If --enable-deb is specified but dpkg-buildpackage is not found, then I abort.

https://github.com/ptomato/gnome-inform7/blob/master/configure.ac

Then in the top-level Makefile.am, the code looks like this.

https://github.com/ptomato/gnome-inform7/blob/master/Makefile.am

Note that I call make dist first, then unzip the dist tarball and copy the debian directory into it. This is the best practice according to the Debian packaging guide; they say the debian directory should only be in source control, not in the distribution tarball.

Upvotes: 4

CAB
CAB

Reputation: 1045

Unfortunately, I couldn't make either of the excellent answers here actually work in my environment. The dpkg-buildpackage was just too fickle about building the package from source. I've finally settled on the dpkg-deb --build approach shown here

Upvotes: 6

umläute
umläute

Reputation: 31254

the entire packaging process is streamlined towards wrapping the build-process into the packaging-process. trying to wrap the packaging-process into the build-process is therefore probably not super easy, but i don't see a necessity to not do it the standard way.

so:

  • make your autotools based build-system as if you don't care about debian packages at all.
  • create a simple debian/rules file that will call your build-system and make a deb-package
  • if you (or some other user of your package) want(s) to build the deb, run dpkg-buildpackage
  • if you (or some other user of your package) does not want to build a deb, simply run ./configure && make && make install

this is better practice, as it keeps 2 separate stages (building and packaging) apart. it also allows more easy integration into any Debian-based distribution (should you e.g. decide that it would be great to have your package in "real" Debian), since Debian packaging guidelines are quite strict about keeping those two processes apart (upstream-sources that ship their own debian/ are frowned upon and upstream's debian/ is usually removed)

Upvotes: 6

Related Questions