Automatically install unmet build dependencies as detected by dpkg-checkbuilddeps

13,997

Solution 1

I use mk-build-deps from the devscripts package for this (you’ll also need equivs).

mk-build-deps

will build a package depending on all the build-dependencies in the debian/control control file; that package can then be installed using apt, which will also install all the missing dependencies.

The advantage of this approach is that uninstalling the dependency package, once you’ve finished with it, will also identify any build-dependencies which could also be uninstalled.

To reduce manual steps, the following command can be used:

mk-build-deps --install --root-cmd sudo --remove

The end result of this is that all the build dependencies are installed, but not the newly-generated build-dependency package itself: it’s installed (--install), along with all its dependencies, and then removed (--remove), but the dependencies are left in place.

Solution 2

Try the following:

dpkg-checkbuilddeps 2>&1 | sed 's/dpkg-checkbuilddeps:\serror:\sUnmet build dependencies: //g' | sed 's/[\(][^)]*[\)] //g'

First of all, dpkg-checkbuilddeps prints out the error to stderr not stdout. So it needs to be redirected to stdout to use pipeline.

Here is how to Redirect stderr and stdout in Bash

You used the regex ([^)]*) on:

sed 's/([^)]*)//g'

But it should be:

sed 's/[\(][^)]*[\)]//g'

Reference: Using sed to delete a string between parentheses

Share:
13,997

Related videos on Youtube

Forivin
Author by

Forivin

Updated on September 18, 2022

Comments

  • Forivin
    Forivin over 1 year

    Is there a command that installs all the unmet build dependencies that dpkg-checkbuilddeps would list?

    I tried to sed the output and give it to apt-get install, but it seems very hacky and for some reason didn't work in some environments.

    sudo apt-get install --yes $(dpkg-checkbuilddeps | sed 's/([^)]*)//g' | sed 's/dpkg-checkbuilddeps:\serror:\sUnmet build dependencies://g')
    

    Is there a better way?

  • Seamus
    Seamus about 2 years
    This was incredibly helpful. It solved the error dpkg-checkbuilddeps: error: Unmet build dependencies: libudev-dev running debuild -b -uc -us on dhcpcd5 on RPi OS 'buster'. But the syntax here is different than in man mk-build-deps, and why does install & remove work? I guess I'm asking for a bit more explanation.
  • Stephen Kitt
    Stephen Kitt about 2 years
    @Seamus I don’t know what version of the man page you’re looking at, but mine explains everything used here: mk-build-deps creates a binary package with all the build dependencies, --install installs it along with the dependencies, --root sudo specifies that sudo should be used whenever root privileges are required (to install and remove packages, in this case), and --remove removes the generated package without removing its dependencies.
  • Seamus
    Seamus about 2 years
    man mk-build-deps: 2019-08-04 for buster; 2021-08-18 for bullseye. Neither really has the --root sudo argument as you've written it, instead it has -s, --root-cmd; Use the specified tool to gain root privileges before installing. Ignored if used without the --install switch.. This is the "Raspberry Pi OS" - a Debian "offspring" AIUI. And in fact, it seems to match the Debian docs. Yet, I used your command verbatim.
  • Stephen Kitt
    Stephen Kitt about 2 years
    Ah right, apologies; I thought you were asking about --install and --remove. --root matches --root-cmdmk-build-deps follows the GNU command-line option practice of matching partial long options as long as they’re still unique. I’ve edited the answer to remove the ambiguity.
  • Seamus
    Seamus about 2 years
    No apologies needed... the enlightenment just keeps on coming :)