diff --git a/share/mk/bsd.sys.mk b/share/mk/bsd.sys.mk --- a/share/mk/bsd.sys.mk +++ b/share/mk/bsd.sys.mk @@ -273,7 +273,14 @@ # Only allow .TARGET when not using PROGS as it has the same syntax # per PROG which is ambiguous with this syntax. This is only needed # for PROG_VARS vars. -.if !defined(_RECURSING_PROGS) +# +# Some directories (currently just clang) also need to disable this since +# CFLAGS.${COMPILER_TYPE}, CFLAGS.${.IMPSRC:T} and CFLAGS.${.TARGET:T} all live +# in the same namespace, meaning that, for example, GCC builds of clang pick up +# CFLAGS.clang via CFLAGS.${.TARGET:T} and thus try to pass Clang-specific +# flags. Ideally the different sources of CFLAGS would be namespaced to avoid +# collisions. +.if !defined(_RECURSING_PROGS) && !defined(NO_TARGET_FLAGS) .if ${MK_WARNS} != "no" CFLAGS+= ${CWARNFLAGS.${.TARGET:T}} .endif diff --git a/usr.bin/clang/clang/Makefile b/usr.bin/clang/clang/Makefile --- a/usr.bin/clang/clang/Makefile +++ b/usr.bin/clang/clang/Makefile @@ -34,4 +34,7 @@ LIBADD+= z +# Ensure we don't add CFLAGS.clang when using GCC +NO_TARGET_FLAGS= + .include "../clang.prog.mk"