فهرست منبع

Finally fixing the issue with CC, CX, LD, and AR not being overridable from the environment.

Nicolas "Pixel" Noble 10 سال پیش
والد
کامیت
fba36bc4b8
2فایلهای تغییر یافته به همراه44 افزوده شده و 8 حذف شده
  1. 22 4
      Makefile
  2. 22 4
      templates/Makefile.template

+ 22 - 4
Makefile

@@ -229,11 +229,29 @@ prefix ?= /usr/local
 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

+ 22 - 4
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