Re: [PATCH] kbuild: deb-pkg: support DEB_BUILD_OPTIONS=parallel=N in debian/rules

From: Masahiro Yamada
Date: Sun Aug 20 2023 - 17:09:01 EST


On Mon, Aug 21, 2023 at 1:20 AM Masahiro Yamada <masahiroy@xxxxxxxxxx> wrote:
>
> 'make srcdeb-pkg' generates a source package, which you can build
> later by using dpkg-buildpackage.
>
> In older dpkg versions, 'dpkg-buildpackage -j N' sets not only
> DEB_BUILD_OPTIONS but also MAKEFLAGS. Hence, passing -j (--jobs)
> to dpkg-buildpackage was enough to run parallel building.
>
> The behavior was changed by commit 1d0ea9b2ba3f ("dpkg-buildpackage:
> Change -j, --jobs semantics to non-force mode") of dpkg project. [1]
>
> Since then, 'dpkg-buildpackage -j N' sets only DEB_BUILD_OPTIONS,
> which is not parsed by the current debian/rules. You cannot build it
> in parallel unless you pass --jobs-force instead or set the MAKEFLAGS
> environment variable.
>
> Debian policy [2] suggests the following code snippet for debian/rules.
>
> ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
> NUMJOBS = $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
> MAKEFLAGS += -j$(NUMJOBS)
> endif
>
> I added slightly different code to debian/rules so 'make -j N deb-pkg'
> works as before. In this case, the '-j N' should not be specified in
> debian/rules again. 'make deb-pkg' without the -j option must explicitly
> pass -j1 to dpkb-buildpackage because otherwise DEB_BUILD_OPTIONS
> contains parallel=<nproc> by default.
>
> This should work with almost all Make versions Kbuild supports.
>
> Only the corner case I found not working is 'make-3.82 -j deb-pkg',
> which results in single thread building. It is not a big deal because
> -j without an argument, which does not limit the number of jobs, is
> rarely used.
>
> As far as I tested, the MAKEFLAGS format varies by Make versions.
>
> command line option $(MAKEFLAGS) in recipe
> Make 3.82 -j j
> -j1 <none>
> -j2 -j
> Make 4.0/4.1 -j -j
> -j1 <none>
> -j2 -j
> Make 4.2+ -j -j
> -j1 -j1
> -j2 -j2



On second thought, this is not a good idea.

I will send v2 with a different solution.





--
Best Regards
Masahiro Yamada