Finally fixing the issue with CC, CX, LD, and AR not being overridable from the environment.
diff --git a/Makefile b/Makefile
index c55b0ac..5c60f89 100644
--- a/Makefile
+++ b/Makefile
@@ -229,11 +229,29 @@
PROTOC ?= protoc
DTRACE ?= dtrace
CONFIG ?= opt
-CC ?= $(CC_$(CONFIG))
-CXX ?= $(CXX_$(CONFIG))
-LD ?= $(LD_$(CONFIG))
+# Doing X ?= Y is the same as:
+# ifeq ($(origin X), undefined)
+# X = Y
+# endif
+# but some variables, such as CC, CXX, LD or AR, have defaults.
+# So instead of using ?= on them, we need to check their origin.
+# See:
+# https://www.gnu.org/software/make/manual/html_node/Implicit-Variables.html
+# https://www.gnu.org/software/make/manual/html_node/Flavors.html#index-_003f_003d
+# https://www.gnu.org/software/make/manual/html_node/Origin-Function.html
+ifeq ($(origin CC), default)
+CC = $(CC_$(CONFIG))
+endif
+ifeq ($(origin CXX), default)
+CXX = $(CXX_$(CONFIG))
+endif
+ifeq ($(origin LD), default)
+LD = $(LD_$(CONFIG))
+endif
LDXX ?= $(LDXX_$(CONFIG))
-AR ?= ar
+ifeq ($(origin AR), default)
+AR = ar
+endif
ifeq ($(SYSTEM),Linux)
STRIP ?= strip --strip-unneeded
else
diff --git a/templates/Makefile.template b/templates/Makefile.template
index 351d5ec..a4fcf66 100644
--- a/templates/Makefile.template
+++ b/templates/Makefile.template
@@ -133,11 +133,29 @@
PROTOC ?= protoc
DTRACE ?= dtrace
CONFIG ?= opt
- CC ?= $(CC_$(CONFIG))
- CXX ?= $(CXX_$(CONFIG))
- LD ?= $(LD_$(CONFIG))
+ # Doing X ?= Y is the same as:
+ # ifeq ($(origin X), undefined)
+ # X = Y
+ # endif
+ # but some variables, such as CC, CXX, LD or AR, have defaults.
+ # So instead of using ?= on them, we need to check their origin.
+ # See:
+ # https://www.gnu.org/software/make/manual/html_node/Implicit-Variables.html
+ # https://www.gnu.org/software/make/manual/html_node/Flavors.html#index-_003f_003d
+ # https://www.gnu.org/software/make/manual/html_node/Origin-Function.html
+ ifeq ($(origin CC), default)
+ CC = $(CC_$(CONFIG))
+ endif
+ ifeq ($(origin CXX), default)
+ CXX = $(CXX_$(CONFIG))
+ endif
+ ifeq ($(origin LD), default)
+ LD = $(LD_$(CONFIG))
+ endif
LDXX ?= $(LDXX_$(CONFIG))
- AR ?= ar
+ ifeq ($(origin AR), default)
+ AR = ar
+ endif
ifeq ($(SYSTEM),Linux)
STRIP ?= strip --strip-unneeded
else