[CRIU] [PATCH] build system: make CC/LD derive from HOSTCC/HOSTLD
Kir Kolyshkin
kir at openvz.org
Thu Oct 27 15:30:02 PDT 2016
On 10/27/2016 03:05 PM, Cyrill Gorcunov wrote:
> On Thu, Oct 27, 2016 at 02:43:46PM -0700, Kir Kolyshkin wrote:
>> 1. Move HOSTCC/HOSTLD to nmk (note there are rules in nmk
>> that make use of these variables already)
>>
>> 2. Make CC/LD derive from HOSTCC/HOSTLD
>>
>> Note that one can still change anything from the command line.
>>
>> Cc: Cyrill Gorcunov <gorcunov at openvz.org>
>> Signed-off-by: Kir Kolyshkin <kir at openvz.org>
>> ---
>> Makefile | 6 ------
>> scripts/nmk/scripts/tools.mk | 8 +++++---
>> 2 files changed, 5 insertions(+), 9 deletions(-)
>>
>> diff --git a/Makefile b/Makefile
>> index 7fbb1db..f704601 100644
>> --- a/Makefile
>> +++ b/Makefile
>> @@ -6,12 +6,6 @@ export __nmk_dir
>> include $(__nmk_dir)include.mk
>> include $(__nmk_dir)macro.mk
>>
>> -#
>> -# To build host helpers.
>> -HOSTCC ?= gcc
>> -HOSTLD ?= ld
>> -export HOSTCC HOSTLD
>> -
>> CFLAGS += $(USERCFLAGS)
>> export CFLAGS
>>
>> diff --git a/scripts/nmk/scripts/tools.mk b/scripts/nmk/scripts/tools.mk
>> index 199a4ba..56dba84 100644
>> --- a/scripts/nmk/scripts/tools.mk
>> +++ b/scripts/nmk/scripts/tools.mk
>> @@ -3,8 +3,10 @@ ifndef ____nmk_defined__tools
>> #
>> # System tools shorthands
>> RM := rm -f
>> -LD := $(CROSS_COMPILE)ld
>> -CC := $(CROSS_COMPILE)gcc
>> +HOSTLD ?= ld
>> +LD := $(CROSS_COMPILE)$(HOSTLD)
> Worth to make it conditional, ie "?="
I'm not sure it makes sense, as you can still override those from the
command line.
More to say, it's impossible to do it right. I tried it a few weeks ago
and failed.
The following is what I remember of it.
The problem is, make has built-ins for variables like CC and LD, so
conditionals
won't work unless you _always_ run make with -R flag. We do run "make -R"
from makefiles (i.e. when we run a sub-make), but from the command line
we can't expect a user to always do that, so ?= won't work in some cases
(like the top-level Makefile).
Now, I tried to play with $(origin ) feature to figure out whether the
value comes
from, in order to only set the value if it's unset or comes from the
built-in rules/vars,
but otherwise leave it as is. This didn't work either, the exact reason
eludes from
my memory.
Resume: ?= is not working for built-in vars, hard to make it work --
let's leave it as is.
More information about the CRIU
mailing list