@@ -102,15 +102,33 @@ endif
102102# If you change the defaults of CC, be sure to also change it in the file
103103# test/builders/builder_base.py, which provides a Python way to return the
104104# value of the make variable CC -- getCompiler().
105- #
106- # See also these functions:
107- # o cxx_compiler
108- # o cxx_linker
109105#----------------------------------------------------------------------
110106ifeq "$(CC)" ""
111107$(error "C compiler is not specified. Please run tests through lldb-dotest or lit")
112108endif
113109
110+ # Remove all " and ' characters from the path. Also remove surrounding space chars.
111+ cstrip = $(strip $(subst ",,$(subst ',,$(1))))
112+ override CC := $(call cstrip,$(CC))
113+ override CCC := $(call cstrip,$(CCC))
114+ override CXX := $(call cstrip,$(CXX))
115+ # Always override the linker. Assign already normalized CC.
116+ override LD := $(call cstrip,$(CC))
117+ # A kind of linker. It always gets retrieved from CC.
118+ override LDC := $(call cstrip,$(CCC))
119+ override OBJCOPY := $(call cstrip,$(OBJCOPY))
120+ override STRIP := $(call cstrip,$(STRIP))
121+ override ARCHIVER := $(call cstrip,$(ARCHIVER))
122+ override AR := $(call cstrip,$(AR))
123+ override DWP := $(call cstrip,$(DWP))
124+ override LLVM_AR := $(call cstrip,$(LLVM_AR))
125+
126+ ifeq "$(HOST_OS)" "Windows_NT"
127+ # This function enframes the full path with the platform specific quotes. This is necessary to run the c++ executable
128+ # properly under 'sh' on Windows host (prevent the path breakage because of Windows style path separators).
129+ override CXX := $(QUOTE)$(CXX)$(QUOTE)
130+ endif
131+
114132#----------------------------------------------------------------------
115133# Handle SDKROOT for the cross platform builds.
116134#----------------------------------------------------------------------
@@ -147,10 +165,8 @@ ifeq "$(OS)" "Darwin"
147165 DS := $(DSYMUTIL)
148166 DSFLAGS := $(DSFLAGS_EXTRAS)
149167 DSYM = $(EXE).dSYM
150- AR := $(CROSS_COMPILE)libtool
151168 ARFLAGS := -static -o
152169else
153- AR := $(CROSS_COMPILE)ar
154170 # On non-Apple platforms, -arch becomes -m
155171 ARCHFLAG := -m
156172
@@ -213,7 +229,7 @@ endif
213229LIMIT_DEBUG_INFO_FLAGS =
214230NO_LIMIT_DEBUG_INFO_FLAGS =
215231MODULE_DEBUG_INFO_FLAGS =
216- ifneq (,$(findstring clang,$(CC)) )
232+ ifeq ($(CCC), clang)
217233 LIMIT_DEBUG_INFO_FLAGS += -flimit-debug-info
218234 NO_LIMIT_DEBUG_INFO_FLAGS += -fno-limit-debug-info
219235 MODULE_DEBUG_INFO_FLAGS += -gmodules
@@ -279,7 +295,6 @@ endif
279295
280296CFLAGS += $(CFLAGS_EXTRAS)
281297CXXFLAGS += -std=c++11 $(CFLAGS) $(ARCH_CXXFLAGS)
282- LD = $(CC)
283298# Copy common options to the linker flags (dwarf, arch. & etc).
284299# Note: we get some 'garbage' options for linker here (such as -I, --isystem & etc).
285300LDFLAGS += $(CFLAGS)
@@ -312,61 +327,6 @@ ifneq "$(DYLIB_NAME)" ""
312327 endif
313328endif
314329
315- # Function that returns the counterpart C++ compiler, given $(CC) as arg.
316- cxx_compiler_notdir = $(if $(findstring icc,$(1)), \
317- $(subst icc,icpc,$(1)), \
318- $(if $(findstring llvm-gcc,$(1)), \
319- $(subst llvm-gcc,llvm-g++,$(1)), \
320- $(if $(findstring gcc,$(1)), \
321- $(subst gcc,g++,$(1)), \
322- $(subst cc,c++,$(1)))))
323- cxx_compiler = $(if $(findstring /,$(1)),$(join $(dir $(1)), $(call cxx_compiler_notdir,$(notdir $(1)))),$(call cxx_compiler_notdir,$(1)))
324-
325- # Function that returns the C++ linker, given $(CC) as arg.
326- cxx_linker_notdir = $(if $(findstring icc,$(1)), \
327- $(subst icc,icpc,$(1)), \
328- $(if $(findstring llvm-gcc,$(1)), \
329- $(subst llvm-gcc,llvm-g++,$(1)), \
330- $(if $(findstring gcc,$(1)), \
331- $(subst gcc,g++,$(1)), \
332- $(subst cc,c++,$(1)))))
333- cxx_linker = $(if $(findstring /,$(1)),$(join $(dir $(1)), $(call cxx_linker_notdir,$(notdir $(1)))),$(call cxx_linker_notdir,$(1)))
334-
335- ifneq "$(OS)" "Darwin"
336- CLANG_OR_GCC := $(strip $(if $(findstring clang,$(CC)), \
337- $(findstring clang,$(CC)), \
338- $(if $(findstring gcc,$(CC)), \
339- $(findstring gcc,$(CC)), \
340- cc)))
341-
342- CC_LASTWORD := $(strip $(lastword $(subst -, ,$(CC))))
343-
344- replace_with = $(strip $(if $(findstring $(3),$(CC_LASTWORD)), \
345- $(subst $(3),$(1),$(2)), \
346- $(subst $(3),$(1),$(subst -$(CC_LASTWORD),,$(2)))))
347-
348- ifeq "$(notdir $(CC))" "$(CC)"
349- replace_cc_with = $(call replace_with,$(1),$(CC),$(CLANG_OR_GCC))
350- else
351- replace_cc_with = $(join $(dir $(CC)),$(call replace_with,$(1),$(notdir $(CC)),$(CLANG_OR_GCC)))
352- endif
353-
354- OBJCOPY ?= $(call replace_cc_with,objcopy)
355- ARCHIVER ?= $(call replace_cc_with,ar)
356- # Look for llvm-dwp or gnu dwp
357- DWP ?= $(call replace_cc_with,llvm-dwp)
358- ifeq ($(wildcard $(DWP)),)
359- DWP = $(call replace_cc_with,dwp)
360- ifeq ($(wildcard $(DWP)),)
361- DWP = $(shell command -v llvm-dwp 2> /dev/null)
362- ifeq ($(wildcard $(DWP)),)
363- DWP = $(shell command -v dwp 2> /dev/null)
364- endif
365- endif
366- endif
367- override AR = $(ARCHIVER)
368- endif
369-
370330ifdef PIE
371331 LDFLAGS += -pie
372332endif
@@ -375,7 +335,7 @@ endif
375335# Windows specific options
376336#----------------------------------------------------------------------
377337ifeq "$(OS)" "Windows_NT"
378- ifneq (,$(findstring clang,$(CC)) )
338+ ifeq ($(CCC), clang)
379339 # Clang for Windows doesn't support C++ Exceptions
380340 CXXFLAGS += -fno-exceptions
381341 CXXFLAGS += -D_HAS_EXCEPTIONS=0
@@ -420,7 +380,7 @@ endif
420380
421381ifeq (1,$(USE_LIBSTDCPP))
422382 # Clang requires an extra flag: -stdlib=libstdc++
423- ifneq (,$(findstring clang,$(CC)) )
383+ ifeq ($(CCC), clang)
424384 # Force clang looking for the gcc's headers at specific rootfs folder.
425385 CXXFLAGS += -stdlib=libstdc++ $(GCC_TOOLCHAIN_FLAGS)
426386 LDFLAGS += -stdlib=libstdc++ $(GCC_TOOLCHAIN_FLAGS)
@@ -458,7 +418,7 @@ ifeq (1, $(USE_SYSTEM_STDLIB))
458418 CXXFLAGS += -nostdlib++ -nostdinc++ -cxx-isystem $(SDKROOT)/usr/include/c++/v1
459419 LDFLAGS += -L$(SDKROOT)/usr/lib -Wl,-rpath,$(SDKROOT)/usr/lib -lc++
460420 else
461- ifneq (,$(findstring clang,$(CC)) )
421+ ifeq ($(CCC), clang)
462422 # Force clang looking for the gcc's headers at specific rootfs folder.
463423 CXXFLAGS += $(GCC_TOOLCHAIN_FLAGS)
464424 LDFLAGS += $(GCC_TOOLCHAIN_FLAGS)
@@ -485,8 +445,6 @@ DYLIB_OBJECTS +=$(strip $(DYLIB_C_SOURCES:.c=.o))
485445DYLIB_OBJECTS +=$(strip $(DYLIB_OBJC_SOURCES:.m=.o))
486446ifneq "$(strip $(DYLIB_CXX_SOURCES))" ""
487447 DYLIB_OBJECTS +=$(strip $(patsubst %.mm, %.o, $(DYLIB_CXX_SOURCES:.cpp=.o)))
488- CXX = $(call cxx_compiler,$(CC))
489- LD = $(call cxx_linker,$(CC))
490448endif
491449
492450#----------------------------------------------------------------------
@@ -509,8 +467,6 @@ endif
509467#----------------------------------------------------------------------
510468ifneq "$(strip $(CXX_SOURCES))" ""
511469 OBJECTS +=$(strip $(CXX_SOURCES:.cpp=.o))
512- CXX = $(call cxx_compiler,$(CC))
513- LD = $(call cxx_linker,$(CC))
514470endif
515471
516472#----------------------------------------------------------------------
@@ -526,19 +482,18 @@ endif
526482#----------------------------------------------------------------------
527483ifneq "$(strip $(OBJCXX_SOURCES))" ""
528484 OBJECTS +=$(strip $(OBJCXX_SOURCES:.mm=.o))
529- CXX = $(call cxx_compiler,$(CC))
530- LD = $(call cxx_linker,$(CC))
531485 ifeq "$(findstring lobjc,$(LDFLAGS))" ""
532486 LDFLAGS +=-lobjc
533487 endif
534488endif
535489
536- ifeq ($(findstring clang, $(CXX) ), clang)
490+ ifeq ($(CCC ), clang)
537491 CXXFLAGS += --driver-mode=g++
538492endif
539493
540494ifneq "$(CXX)" ""
541- ifeq ($(findstring clang, $(LD)), clang)
495+ # Specify the driver mode parameter if we use clang as the linker.
496+ ifeq ($(LDC), clang)
542497 LDFLAGS += --driver-mode=g++
543498 endif
544499endif
0 commit comments