[CRIU] [PATCH 6/6] make: keep HOSTCFLAGS clean from target cflags

Dmitry Safonov dsafonov at virtuozzo.com
Mon Apr 24 11:37:19 PDT 2017


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 at openvz.org>
Reported-by: "Brinkmann, Harald" <Harald.Brinkmann at bst-international.com>
Signed-off-by: Dmitry Safonov <dsafonov at virtuozzo.com>
---
 Makefile | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/Makefile b/Makefile
index 40bf4c01d16b..fecd648e2250 100644
--- a/Makefile
+++ b/Makefile
@@ -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
-- 
2.12.2



More information about the CRIU mailing list