Skip to contentSkip to conversation

make: simplify setting HOST{CC/CXX}

PATCH Jan Beulich 2 participants 4 messages Jun 28, 2019

lore
Share & tools
lore
#0 lore raw

Config.mk DESTDIR ?= / · line 39

Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 26.06.19 at 15:55, <[email protected]> wrote:
Config.mk +0 -0
@@ -39,22 +39,12 @@ DESTDIR     ?= /
 # Allow phony attribute to be listed as dependency rather than fake 

target

Quoted 9 lines
Config.mk +0 -6
 .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?

Config.mk DESTDIR ?= / · line 48

Quoted 10 lines
Config.mk +0 -4
 clang ?= n
 ifeq ($(clang),n)
 gcc := y
-HOSTCC ?= gcc
-HOSTCXX ?= g++
 else
 gcc := n
-HOSTCC ?= clang
-HOSTCXX ?= clang++
 endif

The inclusion point leading to config/StdGNU.mk sits below here afaict, so I don't see how ...

config/StdGNU.mk CC ?= $(CROSS_COMPILE)gcc · line 14

Quoted 9 lines
config/StdGNU.mk +3 -0
@@ -9,6 +9,10 @@ CC        ?= $(CROSS_COMPILE)gcc
 CXX       ?= $(CROSS_COMPILE)g++
 LD_LTO    ?= $(CROSS_COMPILE)ld
 endif
+
+HOSTCC    ?= $(CC)
+HOSTCXX   ?= $(CXX)

... these are every going to take effect - the two variables aren't unset anymore at that point. Furthermore, when CROSS_COMPILE is not empty, this is certainly not what we want.

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

#1 lore raw
Quoted 29 lines · Jan Beulich

Config.mk DESTDIR ?= / · line 39

Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 26.06.19 at 15:55, <[email protected]> wrote:
Config.mk +0 -0
@@ -39,22 +39,12 @@ DESTDIR     ?= /
 # Allow phony attribute to be listed as dependency rather than fake 

target

Quoted 9 lines
Config.mk +0 -6
 .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?

Config.mk DESTDIR ?= / · line 48

Quoted 10 lines
Config.mk +0 -4
 clang ?= n
 ifeq ($(clang),n)
 gcc := y
-HOSTCC ?= gcc
-HOSTCXX ?= g++
 else
 gcc := n
-HOSTCC ?= clang
-HOSTCXX ?= clang++
 endif

The inclusion point leading to config/StdGNU.mk sits below here afaict, so I don't see how ...

Quoted 12 lines

config/StdGNU.mk CC ?= $(CROSS_COMPILE)gcc · line 14

Quoted 9 lines
config/StdGNU.mk +3 -0
@@ -9,6 +9,10 @@ CC        ?= $(CROSS_COMPILE)gcc
 CXX       ?= $(CROSS_COMPILE)g++
 LD_LTO    ?= $(CROSS_COMPILE)ld
 endif
+
+HOSTCC    ?= $(CC)
+HOSTCXX   ?= $(CXX)

... these are every going to take effect - the two variables aren't unset anymore at that point.

I'm not sure I follow, after this change the only place where HOST{CC/CXX} are set is in StdGNU.mk, so those variables would be unset unless they are set in the environment.

Quoted 2 lines

Furthermore, when CROSS_COMPILE
is not empty, this is certainly not what we want.

TBH I would like some guidelines about how CROSS_COMPILE is supposed to be used.

I agree the above is not very nice when CROSS_COMPILE is set. What about something like:

ifeq ($(clang),y)

CC        ?= clang
CXX       ?= clang++
LD_LTO    ?= llvm-ld
HOSTCC    ?= $(CC)
HOSTCXX   ?= $(CXX)
CC         = $(CROSS_COMPILE)$(CC)
CXX        = $(CROSS_COMPILE)$(CXX)
LD_LTO     = $(CROSS_COMPILE)$(LD_LTO)

else
[...]

That would keep the current behaviour of setting CC=gcc CROSS_COMPILE=arm-linux-gnueabi-, which my previous approach didn't.

Thanks, Roger.

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

#2 lore raw
Quoted 40 lines · Roger Pau Monné
Quoted 39 lines · Jan Beulich

Config.mk DESTDIR ?= / · line 39

Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 26.06.19 at 15:55, <[email protected]> wrote:
Config.mk +0 -0
@@ -39,22 +39,12 @@ DESTDIR     ?= /
 # Allow phony attribute to be listed as dependency rather than fake

target

Quoted 9 lines
Config.mk +0 -6
 .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?

Config.mk DESTDIR ?= / · line 48

Quoted 10 lines
Config.mk +0 -4
 clang ?= n
 ifeq ($(clang),n)
 gcc := y
-HOSTCC ?= gcc
-HOSTCXX ?= g++
 else
 gcc := n
-HOSTCC ?= clang
-HOSTCXX ?= clang++
 endif

The inclusion point leading to config/StdGNU.mk sits below here afaict, so I don't see how ...

Quoted 9 lines
config/StdGNU.mk +3 -0
@@ -9,6 +9,10 @@ CC        ?= $(CROSS_COMPILE)gcc
 CXX       ?= $(CROSS_COMPILE)g++
 LD_LTO    ?= $(CROSS_COMPILE)ld
 endif
+
+HOSTCC    ?= $(CC)
+HOSTCXX   ?= $(CXX)
Quoted 6 lines
Quoted 2 lines

... these are every going to take effect - the two variables aren't unset anymore at that point.

I'm not sure I follow, after this change the only place where HOST{CC/CXX} are set is in StdGNU.mk, so those variables would be unset unless they are set in the environment.

Oh, I'm sorry - the first pair being a removal of lines I took it that the 2nd and 3rd pairs would be additions, when clearly they're removals too. I'm sorry for the noise here.

Quoted 5 lines
Quoted 2 lines

Furthermore, when CROSS_COMPILE
is not empty, this is certainly not what we want.

TBH I would like some guidelines about how CROSS_COMPILE is supposed to be used.

It never having been spelled out, I guess it's down to the various flavors people might be using. For me personally CROSS_COMPILE isn't flexible enough anyway, so I have to further alter it in a local patch I carry (to accommodate for suffixes on the command names alongside prefixes).

Quoted 12 lines

I agree the above is not very nice when CROSS_COMPILE is set. What about something like:

ifeq ($(clang),y)

CC        ?= clang
CXX       ?= clang++
LD_LTO    ?= llvm-ld
HOSTCC    ?= $(CC)
HOSTCXX   ?= $(CXX)
CC         = $(CROSS_COMPILE)$(CC)
CXX        = $(CROSS_COMPILE)$(CXX)
LD_LTO     = $(CROSS_COMPILE)$(LD_LTO)
Quoted 5 lines

else
[...]

That would keep the current behaviour of setting CC=gcc CROSS_COMPILE=arm-linux-gnueabi-, which my previous approach didn't.

Hmm, yes, this might work for many cases. (The CC/CXX/LD_LTO lines then wouldn't need to be inside the ifeq() anymore, though.)

However, consider this invocation, which I use for pre-push build checks on a 32-bit host:

make -sC build/xen/$v {XEN_TARGET_ARCH,t}=x86_64 CC=gccx LD=ldx OBJCOPY=objcopyx NM=nmx -j32 xen

The "t" environment variable is used by gccx (which is a shell script). That same shell script would then get invoked for uses of $(HOSTCC), and wrongly try to build a 64-bit object/binary. I'm afraid it is wrong in general to derive HOSTCC from CC.

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

#3 lore raw
Quoted 26 lines · Jan Beulich
Quoted 4 lines · Roger Pau Monné
Quoted 1 line · Jan Beulich
Quoted 1 line
Quoted 1 line
Quoted 1 line · On 26.06.19 at 15:55, <[email protected]> wrote:

TBH I would like some guidelines about how CROSS_COMPILE is supposed to be used.

It never having been spelled out, I guess it's down to the various flavors people might be using. For me personally CROSS_COMPILE isn't flexible enough anyway, so I have to further alter it in a local patch I carry (to accommodate for suffixes on the command names alongside prefixes).

Quoted 15 lines

I agree the above is not very nice when CROSS_COMPILE is set. What about something like:

ifeq ($(clang),y)

CC        ?= clang
CXX       ?= clang++
LD_LTO    ?= llvm-ld
HOSTCC    ?= $(CC)
HOSTCXX   ?= $(CXX)
CC         = $(CROSS_COMPILE)$(CC)
CXX        = $(CROSS_COMPILE)$(CXX)
LD_LTO     = $(CROSS_COMPILE)$(LD_LTO)

else
[...]

Quoted 5 lines
Quoted 2 lines

That would keep the current behaviour of setting CC=gcc CROSS_COMPILE=arm-linux-gnueabi-, which my previous approach didn't.

Hmm, yes, this might work for many cases. (The CC/CXX/LD_LTO lines then wouldn't need to be inside the ifeq() anymore, though.)

Oh, right.

Quoted 9 lines

However, consider this invocation, which I use for pre-push build checks on a 32-bit host:

make -sC build/xen/$v {XEN_TARGET_ARCH,t}=x86_64 CC=gccx LD=ldx OBJCOPY=objcopyx NM=nmx -j32 xen

The "t" environment variable is used by gccx (which is a shell script). That same shell script would then get invoked for uses of $(HOSTCC), and wrongly try to build a 64-bit object/binary. I'm afraid it is wrong in general to derive HOSTCC from CC.

OK, so then we should just set HOST{CC/CXX} to clang/gcc if unset, like we do for CC/CXX. I think this would be fine for your use case.

Note that currently HOST{CC/CXX} is derived from CC/CXX if XEN_COMPILE_ARCH matches XEN_TARGET_ARCH (see Config.mk):

# 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

So what about:

ifeq ($(clang),y)

DEF_CC        = clang
DEF_CXX       = clang++
DEF_LD_LTO    = llvm-ld
else
DEF_CC        = gcc
DEF_CXX       = g++
DEF_LD_LTO    = ld

endif

ifeq ($(XEN_TARGET_ARCH), $(XEN_COMPILE_ARCH))
HOSTCC ?= $(DEF_CC)
HOSTCXX ?= $(DEF_CXX)
endif

CC        ?= $(DEF_CC)
CXX       ?= $(DEF_CXX)
LD_LTO    ?= $(DEF_LD_LTO)
CC         = $(CROSS_COMPILE)$(CC)
CXX        = $(CROSS_COMPILE)$(CXX)
LD_LTO     = $(CROSS_COMPILE)$(LD_LTO)

Thanks, Roger.

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