8

If I have a debian/control file with Build-Depends and Depends entries.

How do I install both sets of dependencies?

At the moment I'm using the following command to create a stub package that depends on the Build-Depends but not the Depends.

$ mk-build-deps --build-dep \
&& dpkg -i *.deb \
|| apt-get update && apt-get install --fix-broken --yes \
jshbrntt
  • 5,134
  • 6
  • 31
  • 60

1 Answers1

6

Assuming this is a standard package in your apt repositories, you should be able to simply run

apt-get build-dep PACKAGE [PACKAGE…]

Generally speaking, the best solution is to find a package with the same dependencies (better yet, an identical yet different version of the same package) and just build-dep it. This solves 99+% of these issues in my experience.


I don't know mk-build-deps at all, but you can run this to see what dependencies are called out in the debian/control file in package "PACKAGE":

echo $(awk '
  /^(Build-)?Depends:/ || /^ / && deps {
    sub(/^[^ ]+: /, "")
    deps = 1
    dep_str = dep_str ", " $0
    next
  }
  { deps=0 }
  END {
    split(dep_str, dep_array, /, */)
    for (d in dep_array) {
      dep = dep_array[d]
      gsub(/[^a-z0-9_.-].*$/, "", dep)
      if (dep && !seen[dep]++) print dep
    }
  }' PACKAGE/debian/control)

(This examines the Debian control file for Build-Depends and Depends lines and presents just the dependencies that are listed, excluding any variables (which I believe are already included in other hits from the file).

AWK code walkthrough: If it is a Build-Depends or Depends line, or it's a whitespace-indended line following such a line, remove the line label, note we're in a dependency line (dep = 1), and save it into dep_str. On other lines, remove the marker saying we're continuing a dependency line. After parsing the input, split the dependency string dep_str into an array delimited by commas and optional trailing whitespace, then iterate through that array. Scrub invalid characters from the end of the dependency name (these are version info) and if anything remains and hasn't been seen (here) before, print it on its own line.

Replace echo with apt-get install if you like, but you might need to prune out the items you're looking to customize and/or manually install first.

After that, you should have an easier time with dpkg -i *.deb. Feel free to try apt-get install --fix-broken at any time if you're stuck.

Adam Katz
  • 14,455
  • 5
  • 68
  • 83
  • I assume I cannot use `apt-get build-dep` on a `debian/control` file? The package would already have to exist? – jshbrntt Dec 16 '17 at 17:51
  • `apt-get build-dep PACKAGE` will install the build dependencies for the latest (including unstable) version of PACKAGE as held in any of your repositories, not locally. It doesn't require having PACKAGE installed itself. If you need to parse the `debian/control` file because you can't find a similar enough package in your repositories, use the second half of my answer. – Adam Katz Dec 16 '17 at 22:59
  • That `sed` does not appear to work it prints a blank line. – jshbrntt May 26 '18 at 08:31
  • 1
    @JoshuaBarnett – Yeah, I found an example it doesn't work on. I've altered my tight ~2line sed into the more reliable (yet giant) three stanza awk code you see now. – Adam Katz May 29 '18 at 19:10
  • Hi, I'm solving something similar and wanted to know how to install dependency packages in the control file without having a user do it. Where exactly should I do this: apt-get build-dep PACKAGE, in a control file or should it be in a post/preinit file? – mgr Mar 04 '19 at 14:29
  • @mgr – `apt-get build-dep PACKAGENAME` should be run on the command line. – Adam Katz Mar 04 '19 at 15:02
  • Hi Adam, thanks, I understand. I'm trying to package an installer that'll be run by someone else and I don't want them to separately run apt-get. I want to make it part of the .deb installer. Is that possible? – mgr Mar 04 '19 at 17:19
  • @mgr – You should list them as dependencies and instruct users to install your package either through APT or else something like [gdebi](https://launchpad.net/gdebi). Since you are the package developer, you can do it properly (edit the `Depends` line in your package's `debian/control` file). This question is quite different. – Adam Katz Mar 04 '19 at 19:57