Author: Denis Pronin <dannftk@yandex.ru>

Description: the patch is required to make the lazarus compile with a compiler 
other than gcc

diff --git a/Makefile b/Makefile
index f03baec4..1db2abb0 100644
--- a/Makefile
+++ b/Makefile
@@ -1262,7 +1262,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -1270,14 +1270,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -1285,7 +1285,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -1293,21 +1293,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -1345,14 +1345,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/components/Makefile b/components/Makefile
index 50f69ed3..3f291362 100644
--- a/components/Makefile
+++ b/components/Makefile
@@ -902,7 +902,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -910,14 +910,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -925,7 +925,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -933,21 +933,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -985,14 +985,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/components/PascalScript/Source/Makefile b/components/PascalScript/Source/Makefile
index 75f46dba..28e2765f 100644
--- a/components/PascalScript/Source/Makefile
+++ b/components/PascalScript/Source/Makefile
@@ -2268,7 +2268,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2276,14 +2276,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -2291,7 +2291,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2299,21 +2299,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -2351,14 +2351,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/components/anchordocking/Makefile b/components/anchordocking/Makefile
index 141ef031..736be8d6 100644
--- a/components/anchordocking/Makefile
+++ b/components/anchordocking/Makefile
@@ -2268,7 +2268,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2276,14 +2276,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -2291,7 +2291,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2299,21 +2299,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -2351,14 +2351,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/components/anchordocking/design/Makefile b/components/anchordocking/design/Makefile
index fe864caa..30922eb0 100644
--- a/components/anchordocking/design/Makefile
+++ b/components/anchordocking/design/Makefile
@@ -2268,7 +2268,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2276,14 +2276,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -2291,7 +2291,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2299,21 +2299,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -2351,14 +2351,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/components/buildintf/Makefile b/components/buildintf/Makefile
index b6828ab4..189f3bd4 100644
--- a/components/buildintf/Makefile
+++ b/components/buildintf/Makefile
@@ -2268,7 +2268,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2276,14 +2276,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -2291,7 +2291,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2299,21 +2299,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -2351,14 +2351,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/components/cairocanvas/Makefile b/components/cairocanvas/Makefile
index a8fb9898..6f6c55f8 100644
--- a/components/cairocanvas/Makefile
+++ b/components/cairocanvas/Makefile
@@ -2268,7 +2268,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2276,14 +2276,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -2291,7 +2291,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2299,21 +2299,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -2351,14 +2351,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/components/charactermap/Makefile b/components/charactermap/Makefile
index dc0a1d1a..4c16ae50 100644
--- a/components/charactermap/Makefile
+++ b/components/charactermap/Makefile
@@ -2268,7 +2268,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2276,14 +2276,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -2291,7 +2291,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2299,21 +2299,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -2351,14 +2351,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/components/charactermap/design/Makefile b/components/charactermap/design/Makefile
index 2d512ad6..b2559b20 100644
--- a/components/charactermap/design/Makefile
+++ b/components/charactermap/design/Makefile
@@ -2268,7 +2268,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2276,14 +2276,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -2291,7 +2291,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2299,21 +2299,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -2351,14 +2351,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/components/chmhelp/lhelp/Makefile b/components/chmhelp/lhelp/Makefile
index 9aac47a2..0d184129 100644
--- a/components/chmhelp/lhelp/Makefile
+++ b/components/chmhelp/lhelp/Makefile
@@ -2605,7 +2605,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2613,14 +2613,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -2628,7 +2628,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2636,21 +2636,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -2688,14 +2688,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/components/chmhelp/packages/help/Makefile b/components/chmhelp/packages/help/Makefile
index ecf10c3d..62e6699e 100644
--- a/components/chmhelp/packages/help/Makefile
+++ b/components/chmhelp/packages/help/Makefile
@@ -2268,7 +2268,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2276,14 +2276,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -2291,7 +2291,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2299,21 +2299,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -2351,14 +2351,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/components/chmhelp/packages/idehelp/Makefile b/components/chmhelp/packages/idehelp/Makefile
index c8b14866..3159eb91 100644
--- a/components/chmhelp/packages/idehelp/Makefile
+++ b/components/chmhelp/packages/idehelp/Makefile
@@ -2268,7 +2268,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2276,14 +2276,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -2291,7 +2291,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2299,21 +2299,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -2351,14 +2351,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/components/codetools/Makefile b/components/codetools/Makefile
index ceaf24a5..59d668d1 100644
--- a/components/codetools/Makefile
+++ b/components/codetools/Makefile
@@ -2268,7 +2268,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2276,14 +2276,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -2291,7 +2291,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2299,21 +2299,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -2351,14 +2351,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/components/codetools/ide/Makefile b/components/codetools/ide/Makefile
index fe4de499..143e9f12 100644
--- a/components/codetools/ide/Makefile
+++ b/components/codetools/ide/Makefile
@@ -2268,7 +2268,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2276,14 +2276,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -2291,7 +2291,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2299,21 +2299,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -2351,14 +2351,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/components/datetimectrls/Makefile b/components/datetimectrls/Makefile
index e8939b6c..5a701f79 100644
--- a/components/datetimectrls/Makefile
+++ b/components/datetimectrls/Makefile
@@ -2268,7 +2268,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2276,14 +2276,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -2291,7 +2291,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2299,21 +2299,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -2351,14 +2351,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/components/datetimectrls/design/Makefile b/components/datetimectrls/design/Makefile
index fcae7596..97112105 100644
--- a/components/datetimectrls/design/Makefile
+++ b/components/datetimectrls/design/Makefile
@@ -2604,7 +2604,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2612,14 +2612,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -2627,7 +2627,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2635,21 +2635,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -2687,14 +2687,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/components/debuggerintf/Makefile b/components/debuggerintf/Makefile
index e6898a21..173c0fa8 100644
--- a/components/debuggerintf/Makefile
+++ b/components/debuggerintf/Makefile
@@ -2268,7 +2268,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2276,14 +2276,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -2291,7 +2291,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2299,21 +2299,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -2351,14 +2351,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/components/exampleswindow/Makefile b/components/exampleswindow/Makefile
index 308c298b..1eed0091 100644
--- a/components/exampleswindow/Makefile
+++ b/components/exampleswindow/Makefile
@@ -2268,7 +2268,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2276,14 +2276,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -2291,7 +2291,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2299,21 +2299,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -2351,14 +2351,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/components/externhelp/Makefile b/components/externhelp/Makefile
index 3ddcfd14..64b49ff3 100644
--- a/components/externhelp/Makefile
+++ b/components/externhelp/Makefile
@@ -2268,7 +2268,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2276,14 +2276,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -2291,7 +2291,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2299,21 +2299,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -2351,14 +2351,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/components/fpcunit/Makefile b/components/fpcunit/Makefile
index 4289e1d8..18073181 100644
--- a/components/fpcunit/Makefile
+++ b/components/fpcunit/Makefile
@@ -2268,7 +2268,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2276,14 +2276,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -2291,7 +2291,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2299,21 +2299,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -2351,14 +2351,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/components/fpcunit/ide/Makefile b/components/fpcunit/ide/Makefile
index 0bae2d78..7ab604b3 100644
--- a/components/fpcunit/ide/Makefile
+++ b/components/fpcunit/ide/Makefile
@@ -2268,7 +2268,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2276,14 +2276,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -2291,7 +2291,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2299,21 +2299,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -2351,14 +2351,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/components/fpdebug/Makefile b/components/fpdebug/Makefile
index 782aa6cb..14808754 100644
--- a/components/fpdebug/Makefile
+++ b/components/fpdebug/Makefile
@@ -2268,7 +2268,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2276,14 +2276,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -2291,7 +2291,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2299,21 +2299,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -2351,14 +2351,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/components/freetype/Makefile b/components/freetype/Makefile
index 65c47269..04d800b7 100644
--- a/components/freetype/Makefile
+++ b/components/freetype/Makefile
@@ -2268,7 +2268,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2276,14 +2276,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -2291,7 +2291,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2299,21 +2299,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -2351,14 +2351,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/components/ideintf/Makefile b/components/ideintf/Makefile
index 511beff1..d2fbba5f 100644
--- a/components/ideintf/Makefile
+++ b/components/ideintf/Makefile
@@ -2604,7 +2604,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2612,14 +2612,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -2627,7 +2627,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2635,21 +2635,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -2687,14 +2687,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/components/instantfpc/Makefile b/components/instantfpc/Makefile
index bc03aa39..5817d608 100644
--- a/components/instantfpc/Makefile
+++ b/components/instantfpc/Makefile
@@ -2268,7 +2268,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2276,14 +2276,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -2291,7 +2291,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2299,21 +2299,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -2351,14 +2351,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/components/jcf2/IdePlugin/lazarus/Makefile b/components/jcf2/IdePlugin/lazarus/Makefile
index d2638769..c6eb3288 100644
--- a/components/jcf2/IdePlugin/lazarus/Makefile
+++ b/components/jcf2/IdePlugin/lazarus/Makefile
@@ -2604,7 +2604,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2612,14 +2612,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -2627,7 +2627,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2635,21 +2635,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -2687,14 +2687,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/components/jcf2/Makefile b/components/jcf2/Makefile
index 08a61f00..4bf2787c 100644
--- a/components/jcf2/Makefile
+++ b/components/jcf2/Makefile
@@ -2604,7 +2604,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2612,14 +2612,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -2627,7 +2627,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2635,21 +2635,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -2687,14 +2687,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/components/lazcontrols/Makefile b/components/lazcontrols/Makefile
index 955f0433..9fcd1ed5 100644
--- a/components/lazcontrols/Makefile
+++ b/components/lazcontrols/Makefile
@@ -2268,7 +2268,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2276,14 +2276,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -2291,7 +2291,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2299,21 +2299,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -2351,14 +2351,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/components/lazcontrols/design/Makefile b/components/lazcontrols/design/Makefile
index 04a70fc3..66bf672b 100644
--- a/components/lazcontrols/design/Makefile
+++ b/components/lazcontrols/design/Makefile
@@ -2268,7 +2268,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2276,14 +2276,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -2291,7 +2291,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2299,21 +2299,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -2351,14 +2351,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/components/lazdebuggergdbmi/Makefile b/components/lazdebuggergdbmi/Makefile
index 3145ce75..84558c17 100644
--- a/components/lazdebuggergdbmi/Makefile
+++ b/components/lazdebuggergdbmi/Makefile
@@ -2268,7 +2268,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2276,14 +2276,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -2291,7 +2291,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2299,21 +2299,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -2351,14 +2351,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/components/lazdebuggers/cmdlinedebuggerbase/Makefile b/components/lazdebuggers/cmdlinedebuggerbase/Makefile
index 58e87789..d12e0b19 100644
--- a/components/lazdebuggers/cmdlinedebuggerbase/Makefile
+++ b/components/lazdebuggers/cmdlinedebuggerbase/Makefile
@@ -2268,7 +2268,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2276,14 +2276,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -2291,7 +2291,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2299,21 +2299,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -2351,14 +2351,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/components/lazdebuggers/lazdebuggerfp/Makefile b/components/lazdebuggers/lazdebuggerfp/Makefile
index efbf9ea7..261b6480 100644
--- a/components/lazdebuggers/lazdebuggerfp/Makefile
+++ b/components/lazdebuggers/lazdebuggerfp/Makefile
@@ -2268,7 +2268,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2276,14 +2276,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -2291,7 +2291,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2299,21 +2299,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -2351,14 +2351,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/components/lazdebuggers/lazdebuggerfplldb/Makefile b/components/lazdebuggers/lazdebuggerfplldb/Makefile
index 7d7dd6d8..389496b7 100644
--- a/components/lazdebuggers/lazdebuggerfplldb/Makefile
+++ b/components/lazdebuggers/lazdebuggerfplldb/Makefile
@@ -2268,7 +2268,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2276,14 +2276,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -2291,7 +2291,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2299,21 +2299,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -2351,14 +2351,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/components/lazdebuggers/lazdebuggerintf/Makefile b/components/lazdebuggers/lazdebuggerintf/Makefile
index 4e083b3b..10f415ad 100644
--- a/components/lazdebuggers/lazdebuggerintf/Makefile
+++ b/components/lazdebuggers/lazdebuggerintf/Makefile
@@ -2268,7 +2268,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2276,14 +2276,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -2291,7 +2291,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2299,21 +2299,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -2351,14 +2351,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/components/lazdebuggers/lazdebuggerlldb/Makefile b/components/lazdebuggers/lazdebuggerlldb/Makefile
index ac9f8dd8..658391a7 100644
--- a/components/lazdebuggers/lazdebuggerlldb/Makefile
+++ b/components/lazdebuggers/lazdebuggerlldb/Makefile
@@ -2268,7 +2268,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2276,14 +2276,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -2291,7 +2291,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2299,21 +2299,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -2351,14 +2351,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/components/lazsvnpkg/Makefile b/components/lazsvnpkg/Makefile
index 1f9f037c..4036087f 100644
--- a/components/lazsvnpkg/Makefile
+++ b/components/lazsvnpkg/Makefile
@@ -2268,7 +2268,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2276,14 +2276,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -2291,7 +2291,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2299,21 +2299,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -2351,14 +2351,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/components/lazutils/Makefile b/components/lazutils/Makefile
index 8ec88bc7..4945dbf4 100644
--- a/components/lazutils/Makefile
+++ b/components/lazutils/Makefile
@@ -2268,7 +2268,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2276,14 +2276,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -2291,7 +2291,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2299,21 +2299,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -2351,14 +2351,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/components/lclextensions/Makefile b/components/lclextensions/Makefile
index c698136f..6397ae8a 100644
--- a/components/lclextensions/Makefile
+++ b/components/lclextensions/Makefile
@@ -2604,7 +2604,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2612,14 +2612,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -2627,7 +2627,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2635,21 +2635,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -2687,14 +2687,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/components/leakview/Makefile b/components/leakview/Makefile
index 64169e90..77472b90 100644
--- a/components/leakview/Makefile
+++ b/components/leakview/Makefile
@@ -2268,7 +2268,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2276,14 +2276,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -2291,7 +2291,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2299,21 +2299,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -2351,14 +2351,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/components/macfiles/Makefile b/components/macfiles/Makefile
index 7d8be769..fe5a77fc 100644
--- a/components/macfiles/Makefile
+++ b/components/macfiles/Makefile
@@ -2268,7 +2268,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2276,14 +2276,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -2291,7 +2291,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2299,21 +2299,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -2351,14 +2351,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/components/macroscript/Makefile b/components/macroscript/Makefile
index 4c04970e..afe0d5ab 100644
--- a/components/macroscript/Makefile
+++ b/components/macroscript/Makefile
@@ -2268,7 +2268,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2276,14 +2276,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -2291,7 +2291,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2299,21 +2299,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -2351,14 +2351,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/components/memds/Makefile b/components/memds/Makefile
index eef1ac01..2e5bf7cd 100644
--- a/components/memds/Makefile
+++ b/components/memds/Makefile
@@ -2268,7 +2268,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2276,14 +2276,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -2291,7 +2291,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2299,21 +2299,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -2351,14 +2351,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/components/mouseandkeyinput/Makefile b/components/mouseandkeyinput/Makefile
index 9fbf35c1..bfe65cfb 100644
--- a/components/mouseandkeyinput/Makefile
+++ b/components/mouseandkeyinput/Makefile
@@ -2268,7 +2268,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2276,14 +2276,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -2291,7 +2291,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2299,21 +2299,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -2351,14 +2351,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/components/onlinepackagemanager/Makefile b/components/onlinepackagemanager/Makefile
index d8344184..84904e56 100644
--- a/components/onlinepackagemanager/Makefile
+++ b/components/onlinepackagemanager/Makefile
@@ -2604,7 +2604,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2612,14 +2612,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -2627,7 +2627,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2635,21 +2635,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -2687,14 +2687,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/components/pas2js/Makefile b/components/pas2js/Makefile
index 6540004a..fb7dfdd3 100644
--- a/components/pas2js/Makefile
+++ b/components/pas2js/Makefile
@@ -2268,7 +2268,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2276,14 +2276,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -2291,7 +2291,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2299,21 +2299,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -2351,14 +2351,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/components/printers/Makefile b/components/printers/Makefile
index 772a764d..cf70d822 100644
--- a/components/printers/Makefile
+++ b/components/printers/Makefile
@@ -2604,7 +2604,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2612,14 +2612,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -2627,7 +2627,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2635,21 +2635,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -2687,14 +2687,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/components/printers/design/Makefile b/components/printers/design/Makefile
index c390390d..af51af89 100644
--- a/components/printers/design/Makefile
+++ b/components/printers/design/Makefile
@@ -2268,7 +2268,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2276,14 +2276,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -2291,7 +2291,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2299,21 +2299,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -2351,14 +2351,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/components/projectgroups/Makefile b/components/projectgroups/Makefile
index 24e264c7..46c28f86 100644
--- a/components/projectgroups/Makefile
+++ b/components/projectgroups/Makefile
@@ -2268,7 +2268,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2276,14 +2276,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -2291,7 +2291,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2299,21 +2299,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -2351,14 +2351,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/components/projecttemplates/Makefile b/components/projecttemplates/Makefile
index 7e4375d6..bf2daa49 100644
--- a/components/projecttemplates/Makefile
+++ b/components/projecttemplates/Makefile
@@ -2268,7 +2268,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2276,14 +2276,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -2291,7 +2291,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2299,21 +2299,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -2351,14 +2351,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/components/rtticontrols/Makefile b/components/rtticontrols/Makefile
index 28276b16..97cab1cf 100644
--- a/components/rtticontrols/Makefile
+++ b/components/rtticontrols/Makefile
@@ -2268,7 +2268,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2276,14 +2276,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -2291,7 +2291,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2299,21 +2299,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -2351,14 +2351,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/components/sdf/Makefile b/components/sdf/Makefile
index 71ac50ea..5c3cfb50 100644
--- a/components/sdf/Makefile
+++ b/components/sdf/Makefile
@@ -2268,7 +2268,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2276,14 +2276,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -2291,7 +2291,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2299,21 +2299,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -2351,14 +2351,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/components/simplewebservergui/Makefile b/components/simplewebservergui/Makefile
index ee46dc5e..9821c800 100644
--- a/components/simplewebservergui/Makefile
+++ b/components/simplewebservergui/Makefile
@@ -2268,7 +2268,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2276,14 +2276,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -2291,7 +2291,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2299,21 +2299,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -2351,14 +2351,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/components/sqldb/Makefile b/components/sqldb/Makefile
index 51cb3811..b47521cf 100644
--- a/components/sqldb/Makefile
+++ b/components/sqldb/Makefile
@@ -2268,7 +2268,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2276,14 +2276,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -2291,7 +2291,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2299,21 +2299,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -2351,14 +2351,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/components/synedit/Makefile b/components/synedit/Makefile
index a0fdccb4..bbdf0484 100644
--- a/components/synedit/Makefile
+++ b/components/synedit/Makefile
@@ -2268,7 +2268,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2276,14 +2276,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -2291,7 +2291,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2299,21 +2299,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -2351,14 +2351,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/components/synedit/design/Makefile b/components/synedit/design/Makefile
index beba4711..5b8dbef3 100644
--- a/components/synedit/design/Makefile
+++ b/components/synedit/design/Makefile
@@ -2268,7 +2268,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2276,14 +2276,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -2291,7 +2291,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2299,21 +2299,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -2351,14 +2351,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/components/tachart/Makefile b/components/tachart/Makefile
index 2137ea2c..8bebd0d2 100644
--- a/components/tachart/Makefile
+++ b/components/tachart/Makefile
@@ -2268,7 +2268,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2276,14 +2276,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -2291,7 +2291,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2299,21 +2299,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -2351,14 +2351,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/components/tdbf/Makefile b/components/tdbf/Makefile
index 135ba209..7cbe0089 100644
--- a/components/tdbf/Makefile
+++ b/components/tdbf/Makefile
@@ -2268,7 +2268,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2276,14 +2276,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -2291,7 +2291,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2299,21 +2299,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -2351,14 +2351,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/components/todolist/Makefile b/components/todolist/Makefile
index 5dbc5eb6..2211bdb6 100644
--- a/components/todolist/Makefile
+++ b/components/todolist/Makefile
@@ -2268,7 +2268,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2276,14 +2276,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -2291,7 +2291,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2299,21 +2299,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -2351,14 +2351,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/components/turbopower_ipro/Makefile b/components/turbopower_ipro/Makefile
index 56db2fa8..34b39323 100644
--- a/components/turbopower_ipro/Makefile
+++ b/components/turbopower_ipro/Makefile
@@ -2268,7 +2268,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2276,14 +2276,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -2291,7 +2291,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2299,21 +2299,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -2351,14 +2351,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/components/turbopower_ipro/design/Makefile b/components/turbopower_ipro/design/Makefile
index 4f9860c1..2d015dcf 100644
--- a/components/turbopower_ipro/design/Makefile
+++ b/components/turbopower_ipro/design/Makefile
@@ -2268,7 +2268,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2276,14 +2276,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -2291,7 +2291,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2299,21 +2299,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -2351,14 +2351,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/components/virtualtreeview/Makefile b/components/virtualtreeview/Makefile
index 2bc4d4ed..5e02697a 100644
--- a/components/virtualtreeview/Makefile
+++ b/components/virtualtreeview/Makefile
@@ -2604,7 +2604,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2612,14 +2612,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -2627,7 +2627,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2635,21 +2635,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -2687,14 +2687,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/ide/Makefile b/ide/Makefile
index 6377f228..0f099898 100644
--- a/ide/Makefile
+++ b/ide/Makefile
@@ -3008,7 +3008,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -3016,14 +3016,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -3031,7 +3031,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -3039,21 +3039,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -3091,14 +3091,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/ide/packages/ideconfig/Makefile b/ide/packages/ideconfig/Makefile
index 42ebac8c..2203c53c 100644
--- a/ide/packages/ideconfig/Makefile
+++ b/ide/packages/ideconfig/Makefile
@@ -2604,7 +2604,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2612,14 +2612,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -2627,7 +2627,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2635,21 +2635,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -2687,14 +2687,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/ide/packages/idedebugger/Makefile b/ide/packages/idedebugger/Makefile
index 2c7a5385..f90cf0be 100644
--- a/ide/packages/idedebugger/Makefile
+++ b/ide/packages/idedebugger/Makefile
@@ -2268,7 +2268,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2276,14 +2276,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -2291,7 +2291,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2299,21 +2299,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -2351,14 +2351,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/lcl/Makefile b/lcl/Makefile
index a766d2cf..83d51811 100644
--- a/lcl/Makefile
+++ b/lcl/Makefile
@@ -3580,7 +3580,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -3588,14 +3588,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -3603,7 +3603,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -3611,21 +3611,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -3663,14 +3663,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/lcl/interfaces/Makefile b/lcl/interfaces/Makefile
index 6ea27549..1fee25c7 100644
--- a/lcl/interfaces/Makefile
+++ b/lcl/interfaces/Makefile
@@ -925,7 +925,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -933,14 +933,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -948,7 +948,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -956,21 +956,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -1008,14 +1008,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/lcl/interfaces/cocoa/Makefile b/lcl/interfaces/cocoa/Makefile
index ddf4ab2d..449b9c93 100644
--- a/lcl/interfaces/cocoa/Makefile
+++ b/lcl/interfaces/cocoa/Makefile
@@ -2233,7 +2233,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2241,14 +2241,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -2256,7 +2256,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2264,21 +2264,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -2316,14 +2316,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/lcl/interfaces/customdrawn/Makefile b/lcl/interfaces/customdrawn/Makefile
index 083d97eb..d7f62501 100644
--- a/lcl/interfaces/customdrawn/Makefile
+++ b/lcl/interfaces/customdrawn/Makefile
@@ -2238,7 +2238,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2246,14 +2246,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -2261,7 +2261,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2269,21 +2269,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -2321,14 +2321,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/lcl/interfaces/fpgui/Makefile b/lcl/interfaces/fpgui/Makefile
index 81da4912..cace5ce3 100644
--- a/lcl/interfaces/fpgui/Makefile
+++ b/lcl/interfaces/fpgui/Makefile
@@ -2578,7 +2578,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2586,14 +2586,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -2601,7 +2601,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2609,21 +2609,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -2661,14 +2661,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/lcl/interfaces/gtk2/Makefile b/lcl/interfaces/gtk2/Makefile
index 5fc13c97..4d9a0219 100644
--- a/lcl/interfaces/gtk2/Makefile
+++ b/lcl/interfaces/gtk2/Makefile
@@ -2903,7 +2903,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2911,14 +2911,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -2926,7 +2926,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2934,21 +2934,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -2986,14 +2986,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/lcl/interfaces/gtk3/Makefile b/lcl/interfaces/gtk3/Makefile
index 82872981..69ef0e58 100644
--- a/lcl/interfaces/gtk3/Makefile
+++ b/lcl/interfaces/gtk3/Makefile
@@ -2570,7 +2570,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2578,14 +2578,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -2593,7 +2593,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2601,21 +2601,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -2653,14 +2653,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/lcl/interfaces/mui/Makefile b/lcl/interfaces/mui/Makefile
index 470746ab..0b926c4c 100644
--- a/lcl/interfaces/mui/Makefile
+++ b/lcl/interfaces/mui/Makefile
@@ -2233,7 +2233,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2241,14 +2241,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -2256,7 +2256,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2264,21 +2264,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -2316,14 +2316,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/lcl/interfaces/nogui/Makefile b/lcl/interfaces/nogui/Makefile
index 0f980d4c..497e00f9 100644
--- a/lcl/interfaces/nogui/Makefile
+++ b/lcl/interfaces/nogui/Makefile
@@ -2237,7 +2237,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2245,14 +2245,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -2260,7 +2260,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2268,21 +2268,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -2320,14 +2320,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/lcl/interfaces/qt/Makefile b/lcl/interfaces/qt/Makefile
index a37bc22b..d160adaa 100644
--- a/lcl/interfaces/qt/Makefile
+++ b/lcl/interfaces/qt/Makefile
@@ -2237,7 +2237,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2245,14 +2245,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -2260,7 +2260,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2268,21 +2268,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -2320,14 +2320,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/lcl/interfaces/qt5/Makefile b/lcl/interfaces/qt5/Makefile
index 402bf99f..83ca6d82 100644
--- a/lcl/interfaces/qt5/Makefile
+++ b/lcl/interfaces/qt5/Makefile
@@ -2237,7 +2237,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2245,14 +2245,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -2260,7 +2260,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2268,21 +2268,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -2320,14 +2320,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/lcl/interfaces/qt6/Makefile b/lcl/interfaces/qt6/Makefile
index ae93b2bc..d99446e7 100644
--- a/lcl/interfaces/qt6/Makefile
+++ b/lcl/interfaces/qt6/Makefile
@@ -2237,7 +2237,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2245,14 +2245,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -2260,7 +2260,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2268,21 +2268,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -2320,14 +2320,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/lcl/interfaces/win32/Makefile b/lcl/interfaces/win32/Makefile
index ff4d7ce9..7e682a3d 100644
--- a/lcl/interfaces/win32/Makefile
+++ b/lcl/interfaces/win32/Makefile
@@ -2233,7 +2233,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2241,14 +2241,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -2256,7 +2256,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2264,21 +2264,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -2316,14 +2316,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/lcl/interfaces/wince/Makefile b/lcl/interfaces/wince/Makefile
index e029c85f..e8137e51 100644
--- a/lcl/interfaces/wince/Makefile
+++ b/lcl/interfaces/wince/Makefile
@@ -2233,7 +2233,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2241,14 +2241,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -2256,7 +2256,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2264,21 +2264,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -2316,14 +2316,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/packager/registration/Makefile b/packager/registration/Makefile
index e762e8c2..e2ea0585 100644
--- a/packager/registration/Makefile
+++ b/packager/registration/Makefile
@@ -2268,7 +2268,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2276,14 +2276,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -2291,7 +2291,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2299,21 +2299,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -2351,14 +2351,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
diff --git a/tools/Makefile b/tools/Makefile
index a3b90a4d..7b4fa680 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -2253,7 +2253,7 @@ ifndef GCCLIBDIR
 ifeq ($(CPU_TARGET),i386)
 ifneq ($(filter x86_64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2261,14 +2261,14 @@ endif
 endif
 ifeq ($(CPU_TARGET),powerpc)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
 endif
 ifeq ($(CPU_TARGET),powerpc64)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m64
 endif
@@ -2276,7 +2276,7 @@ endif
 ifeq ($(CPU_TARGET),sparc)
 ifneq ($(filter sparc64,$(shell uname -a)),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -m32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -m32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-m32
 endif
@@ -2284,21 +2284,21 @@ endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips64 mipsel64),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=64 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=64 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=64
 endif
 endif
 ifneq ($(filter $(CPU_TARGET),mips mipsel),)
 ifeq ($(BINUTILSPREFIX),)
-GCCLIBDIR:=$(shell dirname `gcc -mabi=32 -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -mabi=32 -print-libgcc-file-name`)
 else
 CROSSGCCOPT=-mabi=32
 endif
 endif
 ifeq ($(BINUTILSPREFIX),)
 ifeq ($(GCCLIBDIR),)
-GCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+GCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 else
 ifeq ($(CROSSGCCOPT),)
@@ -2336,14 +2336,14 @@ endif
 endif
 endif
 endif
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} $(FPCMAKE_CROSSGCCOPT) -print-libgcc-file-name`)
 endif
 endif
 ifndef FPCMAKEGCCLIBDIR
-FPCMAKEGCCLIBDIR:=$(shell dirname `gcc -print-libgcc-file-name`)
+FPCMAKEGCCLIBDIR:=$(shell dirname `${CC} -print-libgcc-file-name`)
 endif
 ifndef GCCLIBDIR
-CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)gcc$(SRCEXEEXT),$(SEARCHPATH))))
+CROSSGCC=$(strip $(wildcard $(addsuffix /$(BINUTILSPREFIX)${CC}$(SRCEXEEXT),$(SEARCHPATH))))
 ifneq ($(CROSSGCC),)
 GCCLIBDIR:=$(shell dirname `$(CROSSGCC) $(CROSSGCCOPT) -print-libgcc-file-name`)
 endif
