Skip to contentSkip to conversation

Makefile: Use CFLAGS in cc-option

PATCH Superseded Andrew Jones 2 participants 3 messages Mar 7, 2025

Subsystems (5)
KVM Kbuild s390 KVM arm64 +1 more subsystems

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Makefile: Use CFLAGS in cc-option

When cross compiling with clang we need to specify the target in CFLAGS and cc-option will fail to recognize target-specific options without it. Add CFLAGS to the CC invocation in cc-option.

---
 Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Makefile +1 -1
index 78352fced9d4..9dc5d2234e2a 100644
@@ -21,7 +21,7 @@ DESTDIR := $(PREFIX)/share/kvm-unit-tests/
 
 # cc-option
 # Usage: OP_CFLAGS+=$(call cc-option, -falign-functions=0, -malign-functions=0)
-cc-option = $(shell if $(CC) -Werror $(1) -S -o /dev/null -xc /dev/null \
+cc-option = $(shell if $(CC) $(CFLAGS) -Werror $(1) -S -o /dev/null -xc /dev/null \
               > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi ;)
 
 libcflat := lib/libcflat.a
Signature · 1 line
2.48.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 14 lines · Andrew Jones

When cross compiling with clang we need to specify the target in CFLAGS and cc-option will fail to recognize target-specific options without it. Add CFLAGS to the CC invocation in cc-option.

---
  Makefile | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
Makefile +0 -0
index 78352fced9d4..9dc5d2234e2a 100644

Makefile DESTDIR := $(PREFIX)/share/kvm-unit-tests/ · line 27

Quoted 8 lines
Makefile +1 -1
@@ -21,7 +21,7 @@ DESTDIR := $(PREFIX)/share/kvm-unit-tests/
 
  # cc-option
  # Usage: OP_CFLAGS+=$(call cc-option, -falign-functions=0, -malign-functions=0)
-cc-option = $(shell if $(CC) -Werror $(1) -S -o /dev/null -xc /dev/null \
+cc-option = $(shell if $(CC) $(CFLAGS) -Werror $(1) -S -o /dev/null -xc /dev/null \
                > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi ;)
 
  libcflat := lib/libcflat.a
#2 lore raw
Quoted 10 lines · Thomas Huth
Quoted 9 lines · Andrew Jones

When cross compiling with clang we need to specify the target in CFLAGS and cc-option will fail to recognize target-specific options without it. Add CFLAGS to the CC invocation in cc-option.

---
  Makefile | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines

Makefile DESTDIR := $(PREFIX)/share/kvm-unit-tests/ · line 25

Quoted 11 lines
Makefile +1 -1
index 78352fced9d4..9dc5d2234e2a 100644
@@ -21,7 +21,7 @@ DESTDIR := $(PREFIX)/share/kvm-unit-tests/
  # cc-option
  # Usage: OP_CFLAGS+=$(call cc-option, -falign-functions=0, -malign-functions=0)
-cc-option = $(shell if $(CC) -Werror $(1) -S -o /dev/null -xc /dev/null \
+cc-option = $(shell if $(CC) $(CFLAGS) -Werror $(1) -S -o /dev/null -xc /dev/null \
                > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi ;)
  libcflat := lib/libcflat.a

Thanks, but I just found out that I was too hasty with this patch. I broke x86,

/builds/jones-drew/kvm-unit-tests/x86/Makefile.common:105: *** Recursive variable 'CFLAGS' references itself (eventually). Stop.

I'll try to sort that out and send a v2.

Thanks,
drew