[PATCH] Makefile: Use -j`nproc` by default

473 views
Skip to first unread message

Nadav Har'El

unread,
Nov 11, 2013, 7:36:32 AM11/11/13
to osv...@googlegroups.com, Nadav Har'El
This patch tells make to, by default, run as many parallel jobs as the
compilation machine has CPUs.

This default can be overridden by the user by using the -j option explicitly
in the "make" command line, e.g., "make -j8" or "make -j". Unfortunately,
doing "make -j1" will not be supported, because GNU make doesn't give us
any way to differentiate between "make -j1" and the case of no -j option,
so "make -j1" will use our new default of `nproc` jobs, not one job.

I know that Dor and Avi *don't* like this patch, saying that people should
type the "-j" option themselves. Any other people have opinion about this
issue?

Signed-off-by: Nadav Har'El <n...@cloudius-systems.com>
---
Makefile | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index 85f4e7a..e8f9abf 100644
--- a/Makefile
+++ b/Makefile
@@ -22,7 +22,12 @@ all: $(submake)
$(call quiet, $(silentant) ant -Dmode=$(mode) -Dout=$(abspath $(out)/tests/bench) \
-e -f tests/bench/build.xml $(if $V,,-q), ANT tests/bench)
$(call only-if, $(mgmt), cd mgmt && ./gradlew --daemon :web:jar build)
- $(MAKE) -r -C $(dir $(submake)) $@
+ # By default, use -j `nproc`, to make reasonable use of all the CPUs
+ # available. If the user specified a different -j option, use that
+ # instead. Unfortunately, make gives us no way to differentiate between
+ # the user not giving any -j option at all, or using -j1, so "-j1"
+ # will not correctly use single-threaded make.
+ $(MAKE) $(if $(findstring j,$(MAKEFLAGS)),,-j$(shell nproc)) -r -C $(dir $(submake)) $@

$(submake): Makefile
mkdir -p $(dir $@)
--
1.8.3.1

Pekka Enberg

unread,
Nov 11, 2013, 10:52:07 AM11/11/13
to Nadav Har'El, Osv Dev
On Mon, Nov 11, 2013 at 2:36 PM, Nadav Har'El <n...@cloudius-systems.com> wrote:
> This patch tells make to, by default, run as many parallel jobs as the
> compilation machine has CPUs.
>
> This default can be overridden by the user by using the -j option explicitly
> in the "make" command line, e.g., "make -j8" or "make -j". Unfortunately,
> doing "make -j1" will not be supported, because GNU make doesn't give us
> any way to differentiate between "make -j1" and the case of no -j option,
> so "make -j1" will use our new default of `nproc` jobs, not one job.
>
> I know that Dor and Avi *don't* like this patch, saying that people should
> type the "-j" option themselves. Any other people have opinion about this
> issue?
>
> Signed-off-by: Nadav Har'El <n...@cloudius-systems.com>

I don't see a problem with it but I already have MAKEFLAGS set to
"-j4" so I don't have pressing need for the functionality.

What do other people think?

Pekka
Reply all
Reply to author
Forward
0 new messages