15

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="someone@foo.com" ; \
    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?

tshepang
  • 12,111
  • 21
  • 91
  • 136
CAB
  • 1,015
  • 1
  • 14
  • 24
  • 2
    I would recommend not building the package in a dist-hook, but instead making separate targets: `make rpm`, `make pkg`, `make deb`, etc. Do not set DEBFULLNAME/DEBEMAIL, but require the user to set them (probably in shell .rcs). Have the entire debian/ control directory built during configure. – William Pursell Oct 11 '12 at 16:22

3 Answers3

6

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)

umläute
  • 28,885
  • 9
  • 68
  • 122
  • 1
    Some examples of how to use that `dpkg-buildpackage` along with its rules would really help. – Hi-Angel Dec 21 '20 at 14:22
  • 1
    …anyway, looking [at docs](https://www.debian.org/doc/manuals/debmake-doc/ch04.en.html), I can tell in runs multiple stages, requires writing some templates, and ultimately looks overlcomplicated. The [other answer here](https://stackoverflow.com/a/19255087/2388257) that suggests using `dpkg-deb` instead is way simpler: you just create a `deb/debian/` dir, put there a `control` file that describes the package, then run `DESTDIR=$(pwd)/deb make install` *(or `ninja install`, whatever, it supports `DESTDIR` too)*, and finally you execute `dpkg-deb --build deb/`. – Hi-Angel Dec 21 '20 at 14:38
6

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

CAB
  • 1,015
  • 1
  • 14
  • 24
4

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.

Ahresse
  • 497
  • 4
  • 17
ptomato
  • 56,175
  • 13
  • 112
  • 165
  • I notice you're not using dh_make to get the debain directory and control file. perhaps dh_make only makes sense for deb_helper? Can you post a copy of your control file as well? Thanks. – CAB Oct 10 '12 at 14:21
  • The control file and debian directory are there in the same repository, just browse to them... ;-) – ptomato Oct 10 '12 at 19:14
  • 1
    Note that I no longer recommend doing this in configure.ac and Makefile.am, as it often requires reconfiguring your build directory. Instead, I'd recommend having a separate script that does all the packaging operations. – ptomato Aug 08 '20 at 17:32