compile source package with multiple cpu cores in debian, "apt-get -b source"

7,149

I use the command debuild from the devscripts package, which calls dpkg-buildpackage from the dpkg-dev package. This has some advantages over using dpkg-buildpackage directly, for example it creates a build log automatically. Normal usage after running

apt-get source pkgname

is

debuild -uc -us

But instead you can do (for example)

debuild -uc -us -j4

This passes the -j flag to dpkg-buildpackage.

Here is the relevant section from man dpkg-buildpackage.

-jjobs Number of jobs allowed to be run simultaneously, equivalent to the make(1) option of the same name. Will add itself to the MAKEFLAGS environment variable, which should cause all subsequent make invocations to inherit the option. Also adds parallel=jobs to the DEB_BUILD_OPTIONS environment variable which allows debian/rules files to use this information for their own purposes. The parallel=jobs in DEB_BUILD_OPTIONS environment variable will override the -j value if this option is given.

This is of course not guaranteed to work. The build will have to actually use either MAKEFLAGS or DEB_BUILD_OPTIONS in a suitable fashion for this to have an effect.

I have never used apt-get -b source, but you might be able to pass suitable flags via that command line too. However, I would recommend doing this build in two steps. In any case, building directly after a download does not work most of the time. Usually you have to at least install build dependencies first. In situations where you are doing backports or otherwise working with packaging that is not designed for the same release you are trying to build on, you may need to modify the packaging before attempting to build.

Share:
7,149
alireza
Author by

alireza

Updated on September 18, 2022

Comments

  • alireza
    alireza over 1 year

    I use apt-get -b source and this command download and compile source with one core of cpu, Is there any way to compile package in debian with apt package manager with multiple cpu cores ? like -j option in make command : make -jX .

    Thanks.

  • alireza
    alireza over 9 years
    This is good (i will try it), but my question is about "is there any way to use apt-get with multiple cores" ?
  • Alen Milakovic
    Alen Milakovic over 9 years
    The commands I've listed are functionally equivalent to apt-get -b source. That command will also call dpkg-buildpackage.
  • alireza
    alireza about 9 years
    this way not work and this error happened for every program that i try to compile : codepad.org/hXe9HrMI
  • Alen Milakovic
    Alen Milakovic about 9 years
    @alirezaimi First, I notice you are running this command as root. That is a really bad idea. Don't do that. Second, I'm not sure why you are getting this error, but that has nothing to my answer to this question.
  • alireza
    alireza about 9 years
    i want a way to compile source with apt-get -b source with multiple cpu cores and you answer this and this way not work on several app. then my problem is not solved !
  • Alen Milakovic
    Alen Milakovic about 9 years
    @alirezaimi Again, my answer addresses your question. If you have problems building a particular package, ask a separate question.
  • pevik
    pevik over 8 years
    Portable way for -j option: -j`nproc` to detect number of CPUs (or -j`getconf _NPROCESSORS_ONLN` if nproc insn't installed).