The cxx_compiler function should not blindly return clang++ as the C++ compiler if $(CC) contains "clang".
Instead, it should perform a textual replacement of $(CC) from "clang" to "clang++". The same is true
for "llvm-gcc" to "llvm-g++" and for "gcc" to "g++". This way, we keep the path component of the $(CC)
passed in from the user and do not end up with a mixed toolchains with different paths.
Ditto for a newly added function called cxx_linker.
git-svn-id: https://llvm.org/svn/llvm-project/llvdb/trunk@123451 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/test/make/Makefile.rules b/test/make/Makefile.rules
index 524ddec..e048f04 100644
--- a/test/make/Makefile.rules
+++ b/test/make/Makefile.rules
@@ -31,8 +31,11 @@
EXE = a.out
DSYM = $(EXE).dSYM
-# Function that returns the counterpart C++ compiler.
-cxx_compiler = $(if $(findstring clang,$(1)), clang++, $(if $(findstring llvm-gcc,$(1)), llvm-g++, g++))
+# Function that returns the counterpart C++ compiler, given $(CC) as arg.
+cxx_compiler = $(if $(findstring clang,$(1)), $(subst clang,clang++,$(1)), $(if $(findstring llvm-gcc,$(1)), $(subst llvm-gcc,llvm-g++,$(1)), $(subst gcc,g++,$(1))))
+
+# Function that returns the C++ linker, given $(CC) as arg.
+cxx_linker = $(if $(findstring clang,$(1)), $(subst clang,g++,$(1)), $(if $(findstring llvm-gcc,$(1)), $(subst llvm-gcc,g++,$(1)), $(subst gcc,g++,$(1))))
#----------------------------------------------------------------------
# dylib settings
@@ -55,7 +58,7 @@
ifneq "$(strip $(CXX_SOURCES))" ""
OBJECTS +=$(strip $(CXX_SOURCES:.cpp=.o))
CXX = $(call cxx_compiler,$(CC))
- LD = g++
+ LD = $(call cxx_linker,$(CC))
endif
#----------------------------------------------------------------------
@@ -72,7 +75,7 @@
ifneq "$(strip $(OBJCXX_SOURCES))" ""
OBJECTS +=$(strip $(OBJCXX_SOURCES:.mm=.o))
CXX = $(call cxx_compiler,$(CC))
- LD = g++
+ LD = $(call cxx_linker,$(CC))
ifeq $(findstring lobjc,$(LDFLAGS)) ""
LDFLAGS +=-lobjc
endif