Commit 04b0a0bd authored by Dmitry Safonov's avatar Dmitry Safonov Committed by Andrei Vagin

make: keep HOSTCFLAGS clean from target cflags

HOSTCFLAGS are populated with CFLAGS if they are set from environment:
    CFLAGS=-O1 make

But it turns out that =? operator, which sets variable iff it was unset
previously - is recursive expanded operator.
Which means that value of HOSTCFLAGS is evaluated every time it's used.

Which is wrong with the current flaw in Makefile:
    1. it assigns HOSTCFLAGS with CFLAGS from environment as recursive
    2. it assigns target-related options to CFLAGS such as -march.
    3. HOSTCFLAGS are used (with the current code - here they are expanded
       from CFLAGS).

Which results in target-related options supplied to host objects building,
which breaks cross-compilation.
Fix by omitting recursive expansion for HOSTCFLAGS.
Still we need to keep $(WARNINGS) and $(DEFINES) in HOSTCFLAGS.

Link: https://lists.openvz.org/pipermail/criu/2017-April/037109.html
Cc: Cyrill Gorcunov <gorcunov@openvz.org>
Reported-by: 's avatar"Brinkmann, Harald" <Harald.Brinkmann@bst-international.com>
Reviewed-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: 's avatarDmitry Safonov <dsafonov@virtuozzo.com>
Signed-off-by: 's avatarAndrei Vagin <avagin@virtuozzo.com>
parent 578d57fb
......@@ -13,11 +13,9 @@ $(__nmk_dir)%.mk: ;
include $(__nmk_dir)include.mk
include $(__nmk_dir)macro.mk
CFLAGS += $(USERCFLAGS)
export CFLAGS
HOSTCFLAGS ?= $(CFLAGS)
export HOSTCFLAGS
ifeq ($(origin HOSTCFLAGS), undefined)
HOSTCFLAGS := $(CFLAGS) $(USERCFLAGS)
endif
UNAME-M := $(shell uname -m)
......@@ -69,15 +67,13 @@ endif
LDARCH ?= $(SRCARCH)
export LDARCH VDSO
export PROTOUFIX DEFINES USERCFLAGS
export PROTOUFIX DEFINES
#
# Independent options for all tools.
DEFINES += -D_FILE_OFFSET_BITS=64
DEFINES += -D_GNU_SOURCE
CFLAGS += $(USERCFLAGS)
WARNINGS := -Wall -Wformat-security
CFLAGS-GCOV := --coverage -fno-exceptions -fno-inline
......@@ -111,7 +107,9 @@ ifeq ($(GMON),1)
export GMON GMONLDOPT
endif
CFLAGS += $(WARNINGS) $(DEFINES) -iquote include/
CFLAGS += $(USERCFLAGS) $(WARNINGS) $(DEFINES) -iquote include/
HOSTCFLAGS += $(WARNINGS) $(DEFINES) -iquote include/
export CFLAGS USERCLFAGS HOSTCFLAGS
# Default target
all: criu lib
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment