From 340e651d97f0a9e4b02386919085bd27b110c6be Mon Sep 17 00:00:00 2001 From: Julian Oes Date: Mon, 25 May 2020 17:25:00 +0200 Subject: [PATCH] Build: properly read -j argument The previous check for the -j argument was not actually working. Therefore, the build always used 4 cores, unless when building with ninja when presumably the ninja default was used. --- Makefile | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 0cb2fc2232..1fae70c4a1 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ ############################################################################ # -# Copyright (c) 2015 - 2019 PX4 Development Team. All rights reserved. +# Copyright (c) 2015 - 2020 PX4 Development Team. All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions @@ -69,7 +69,13 @@ space := $(subst ,, ) # by cmake in the subdirectory FIRST_ARG := $(firstword $(MAKECMDGOALS)) ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS)) -j ?= 4 + +# Get -j or --jobs argument as suggested in: +# https://stackoverflow.com/a/33616144/8548472 +MAKE_PID := $(shell echo $$PPID) +j := $(shell ps T | sed -n 's/.*$(MAKE_PID).*$(MAKE).* \(-j\|--jobs\) *\([0-9][0-9]*\).*/\2/p') +# Default to 4 +j := $(or $(j),4) NINJA_BIN := ninja ifndef NO_NINJA_BUILD