Skip to contentSkip to conversation

build: honor toolchain related environment vars

PATCH New Roger Pau Monne 1 participant 5 messages Sep 5, 2019

lore
Share & tools
lore
#0 lore raw

v2 cover build: honor toolchain related environment vars

Hello,

Current Xen build system will ignore any toolchain related variables on the environment when building (ie: CC, LD, CXX...), and the only way to set those is to assign them directly on the make command line (ie: make CC=foo CXX=bar ...).

The following series attempts to fix this, by removing the hardcoding of the toolchain variables previously done in StdGNU.mk.

Note that this has the side effect that the build system will no longer prepend CROSS_COMPILE to the toolchain variables if those are already set. So if you are building Xen and setting CROSS_COMPILE make sure toolchain variables are unset, or if set they should contain CROSS_COMPILE. The Travis CI script is updated in patch 3/4 in order to comply with the above.

This is v2 because v1 was missing the first patch, rendering the whole series useless. Apart from that there are no changes from v1.

The series can be found at:

git://xenbits.xen.org/people/royger/xen.git env_tools

Results from Travis and gitlab CI loops are at:

https://travis-ci.org/royger/xen/builds/581139388
https://gitlab.com/xen-project/people/royger/xen/pipelines/80440648

Thanks, Roger.

Roger Pau Monne (4):
build: set HOST{CC/CXX}, clang and gcc in StdGNU.mk
kconfig: include default toolchain values
build: allow picking the env values for compiler variables
build: allow picking the env values for toolchain utilities

 Config.mk                          | 18 ----------
 config/StdGNU.mk                   | 53 ++++++++++++++++++++----------
 scripts/travis-build               |  8 +++++
 xen/Makefile                       |  6 ++--
 xen/tools/kconfig/Makefile.kconfig |  7 ++--
 5 files changed, 50 insertions(+), 42 deletions(-)
Signature · 7 lines
2.22.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#1 lore raw

PATCH v2 1/4 build: set HOST{CC/CXX}, clang and gcc in StdGNU.mk

This is a preparatory change for simplifying the setting of HOST{CC/CXX} and allowing the Xen build system to pick the toolchain variables from the environment.

No functional change intended.

---
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Julien Grall <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Tim Deegan <[email protected]>
Cc: Wei Liu <[email protected]>

---
 Config.mk        | 18 ------------------
 config/StdGNU.mk | 16 ++++++++++++++++
 2 files changed, 16 insertions(+), 18 deletions(-)
Config.mk +0 -18
index 0fa4591379..57a6c934b3 100644
@@ -39,24 +39,6 @@ DESTDIR     ?= /
 # Allow phony attribute to be listed as dependency rather than fake target
 .PHONY: .phony
 
-# If we are not cross-compiling, default HOSTC{C/XX} to C{C/XX}
-ifeq ($(XEN_TARGET_ARCH), $(XEN_COMPILE_ARCH))
-HOSTCC ?= $(CC)
-HOSTCXX ?= $(CXX)
-endif
-
-# Use Clang/LLVM instead of GCC?
-clang ?= n
-ifeq ($(clang),n)
-gcc := y
-HOSTCC ?= gcc
-HOSTCXX ?= g++
-else
-gcc := n
-HOSTCC ?= clang
-HOSTCXX ?= clang++
-endif
-
 DEPS_INCLUDE = $(addsuffix .d2, $(basename $(wildcard $(DEPS))))
 DEPS_RM = $(DEPS) $(DEPS_INCLUDE)
 
config/StdGNU.mk +16 -0
index 039274ea61..7a6159021b 100644
@@ -1,14 +1,30 @@
+# Use Clang/LLVM instead of GCC?
+clang     ?= n
+
+# If we are not cross-compiling, default HOSTC{C/XX} to C{C/XX}
+ifeq ($(XEN_TARGET_ARCH), $(XEN_COMPILE_ARCH))
+HOSTCC    ?= $(CC)
+HOSTCXX   ?= $(CXX)
+endif
+
 AS         = $(CROSS_COMPILE)as
 LD         = $(CROSS_COMPILE)ld
 ifeq ($(clang),y)
+gcc       := n
 CC         = $(CROSS_COMPILE)clang
 CXX        = $(CROSS_COMPILE)clang++
 LD_LTO     = $(CROSS_COMPILE)llvm-ld
+HOSTCC    ?= clang
+HOSTCXX   ?= clang++
 else
+gcc       := y
 CC         = $(CROSS_COMPILE)gcc
 CXX        = $(CROSS_COMPILE)g++
 LD_LTO     = $(CROSS_COMPILE)ld
+HOSTCC    ?= gcc
+HOSTCXX   ?= g++
 endif
+
 CPP        = $(CC) -E
 AR         = $(CROSS_COMPILE)ar
 RANLIB     = $(CROSS_COMPILE)ranlib
Signature · 7 lines
2.22.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#2 lore raw

PATCH v2 2/4 kconfig: include default toolchain values

In reply to Roger Pau Monne

Include config/$(OS).mk which contains the default values for the toolchain variables. This removes the need to pass HOST{CC/CXX} as parameters from the high level make target or to default them to gcc/g++ if unset.

---
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Julien Grall <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Tim Deegan <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: Doug Goldstein <[email protected]>

---
 xen/Makefile                       | 6 +++---
 xen/tools/kconfig/Makefile.kconfig | 7 +++----
 2 files changed, 6 insertions(+), 7 deletions(-)
xen/Makefile +3 -3
index c80914c31d..e9f700f9e7 100644
@@ -267,14 +267,14 @@ kconfig := silentoldconfig oldconfig config menuconfig defconfig \
 	randconfig $(notdir $(wildcard arch/$(SRCARCH)/configs/*_defconfig))
 .PHONY: $(kconfig)
 $(kconfig):
-	$(MAKE) -f $(BASEDIR)/tools/kconfig/Makefile.kconfig ARCH=$(ARCH) SRCARCH=$(SRCARCH) HOSTCC="$(HOSTCC)" HOSTCXX="$(HOSTCXX)" $@
+	$(MAKE) -f $(BASEDIR)/tools/kconfig/Makefile.kconfig ARCH=$(ARCH) SRCARCH=$(SRCARCH) $@
 
 include/config/%.conf: include/config/auto.conf.cmd $(KCONFIG_CONFIG)
-	$(MAKE) -f $(BASEDIR)/tools/kconfig/Makefile.kconfig ARCH=$(ARCH) SRCARCH=$(SRCARCH) HOSTCC="$(HOSTCC)" HOSTCXX="$(HOSTCXX)" silentoldconfig
+	$(MAKE) -f $(BASEDIR)/tools/kconfig/Makefile.kconfig ARCH=$(ARCH) SRCARCH=$(SRCARCH) silentoldconfig
 
 # Allow people to just run `make` as before and not force them to configure
 $(KCONFIG_CONFIG):
-	$(MAKE) -f $(BASEDIR)/tools/kconfig/Makefile.kconfig ARCH=$(ARCH) SRCARCH=$(SRCARCH) HOSTCC="$(HOSTCC)" HOSTCXX="$(HOSTCXX)" defconfig
+	$(MAKE) -f $(BASEDIR)/tools/kconfig/Makefile.kconfig ARCH=$(ARCH) SRCARCH=$(SRCARCH) defconfig
 
 # Break the dependency chain for the first run
 include/config/auto.conf.cmd: ;
xen/tools/kconfig/Makefile.kconfig +3 -4
index dbd8912015..138bf3f1b7 100644
@@ -35,15 +35,14 @@ KBUILD_DEFCONFIG := $(ARCH)_defconfig
 # provide our shell
 CONFIG_SHELL := $(SHELL)
 
-# provide the host compiler
-HOSTCC ?= gcc
-HOSTCXX ?= g++
-
 # force target
 PHONY += FORCE
 
 FORCE:
 
+# Sets toolchain binaries to use
+include $(XEN_ROOT)/config/$(shell uname -s).mk
+
 # include the original Makefile and Makefile.host from Linux
 include $(src)/Makefile
 include $(src)/Makefile.host
Signature · 7 lines
2.22.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#4 lore raw

PATCH v2 4/4 build: allow picking the env values for toolchain utilities

In reply to Roger Pau Monne

Don't force the usage of the hardcoded toolchain values if those are already set on the environment.

Note that as part of the change the definition of AS and LD is moved after the setting of compiler related variables.

---
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Julien Grall <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Tim Deegan <[email protected]>
Cc: Wei Liu <[email protected]>

---
 config/StdGNU.mk | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)
config/StdGNU.mk +11 -11
index b3072f5b13..cab7369f12 100644
@@ -1,8 +1,6 @@
 # Use Clang/LLVM instead of GCC?
 clang     ?= n
 
-AS         = $(CROSS_COMPILE)as
-LD         = $(CROSS_COMPILE)ld
 ifeq ($(clang),y)
 gcc       := n
 DEF_CC     = clang
@@ -28,19 +26,21 @@ HOSTCC    ?= $(DEF_CC)
 HOSTCXX   ?= $(DEF_CXX)
 endif
 
-CPP        = $(CC) -E
-AR         = $(CROSS_COMPILE)ar
-RANLIB     = $(CROSS_COMPILE)ranlib
-NM         = $(CROSS_COMPILE)nm
-STRIP      = $(CROSS_COMPILE)strip
-OBJCOPY    = $(CROSS_COMPILE)objcopy
-OBJDUMP    = $(CROSS_COMPILE)objdump
-SIZEUTIL   = $(CROSS_COMPILE)size
+AS        ?= $(CROSS_COMPILE)as
+LD        ?= $(CROSS_COMPILE)ld
+CPP       ?= $(CC) -E
+AR        ?= $(CROSS_COMPILE)ar
+RANLIB    ?= $(CROSS_COMPILE)ranlib
+NM        ?= $(CROSS_COMPILE)nm
+STRIP     ?= $(CROSS_COMPILE)strip
+OBJCOPY   ?= $(CROSS_COMPILE)objcopy
+OBJDUMP   ?= $(CROSS_COMPILE)objdump
+SIZEUTIL  ?= $(CROSS_COMPILE)size
 
 # Allow git to be wrappered in the environment
 GIT        ?= git
 
-INSTALL      = install
+INSTALL     ?= install
 INSTALL_DIR  = $(INSTALL) -d -m0755 -p
 INSTALL_DATA = $(INSTALL) -m0644 -p
 INSTALL_PROG = $(INSTALL) -m0755 -p
Signature · 7 lines
2.22.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#3 lore raw

PATCH v2 3/4 build: allow picking the env values for compiler variables

In reply to Roger Pau Monne

Don't force the usage of the hardcoded compiler values if those are already set on the environment. This allows the Xen build system to correctly pick CC/CXX values present on the environment, and fixes the usage of those by the Gitlab CI test system.

Note that without this fix the Xen build system will completely ignore any CC or CXX values set on the environment, and the only way to pass a different CC or CXX is to overwrite it on the make command line.

Due to this change, Travis CI needs to be updated in order to pass a CC and CXX that also contains the CROSS_COMPILE path, since Xen will no longer overwrite the CC or CXX value if those are set on the environment.

---
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Julien Grall <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Tim Deegan <[email protected]>
Cc: Wei Liu <[email protected]>

---
 config/StdGNU.mk     | 35 +++++++++++++++++++----------------
 scripts/travis-build |  8 ++++++++
 2 files changed, 27 insertions(+), 16 deletions(-)
config/StdGNU.mk +19 -16
index 7a6159021b..b3072f5b13 100644
@@ -1,28 +1,31 @@
 # Use Clang/LLVM instead of GCC?
 clang     ?= n
 
-# If we are not cross-compiling, default HOSTC{C/XX} to C{C/XX}
-ifeq ($(XEN_TARGET_ARCH), $(XEN_COMPILE_ARCH))
-HOSTCC    ?= $(CC)
-HOSTCXX   ?= $(CXX)
-endif
-
 AS         = $(CROSS_COMPILE)as
 LD         = $(CROSS_COMPILE)ld
 ifeq ($(clang),y)
 gcc       := n
-CC         = $(CROSS_COMPILE)clang
-CXX        = $(CROSS_COMPILE)clang++
-LD_LTO     = $(CROSS_COMPILE)llvm-ld
-HOSTCC    ?= clang
-HOSTCXX   ?= clang++
+DEF_CC     = clang
+DEF_CXX    = clang++
+LD_LTO    ?= $(CROSS_COMPILE)llvm-ld
 else
 gcc       := y
-CC         = $(CROSS_COMPILE)gcc
-CXX        = $(CROSS_COMPILE)g++
-LD_LTO     = $(CROSS_COMPILE)ld
-HOSTCC    ?= gcc
-HOSTCXX   ?= g++
+DEF_CC     = gcc
+DEF_CXX    = g++
+LD_LTO    ?= $(CROSS_COMPILE)ld
+endif
+
+CC        ?= $(CROSS_COMPILE)$(DEF_CC)
+CXX       ?= $(CROSS_COMPILE)$(DEF_CXX)
+
+# If we are not cross-compiling, default HOSTC{C/XX} to C{C/XX}
+# else use the default values if unset
+ifeq ($(XEN_TARGET_ARCH), $(XEN_COMPILE_ARCH))
+HOSTCC    ?= $(CC)
+HOSTCXX   ?= $(CXX)
+else
+HOSTCC    ?= $(DEF_CC)
+HOSTCXX   ?= $(DEF_CXX)
 endif
 
 CPP        = $(CC) -E
scripts/travis-build +8 -0
index 0cb15a89e4..a264e286b2 100755
@@ -1,6 +1,14 @@
 #!/bin/bash -ex
 
+# Set HOST{CC/CXX} in case we are cross building
+export HOSTCC=${CC}
+export HOSTCXX=${CXX}
+# Prefix environment CC/CXX with CROSS_COMPILE if present
+export CC=${CROSS_COMPILE}${CC}
+export CXX=${CROSS_COMPILE}${CXX}
+
 $CC --version
+[[ "${CC}" != "${HOSTCC}" ]] && $HOSTCC --version
 
 # random config or default config
 if [[ "${RANDCONFIG}" == "y" ]]; then
Signature · 7 lines
2.22.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel