diff options
-rw-r--r-- | Makefile | 63 | ||||
-rw-r--r-- | templates/Makefile.template | 63 |
2 files changed, 62 insertions, 64 deletions
@@ -226,26 +226,44 @@ DEFINES_mutrace = _DEBUG DEBUG prefix ?= /usr/local -PROTOC = protoc -DTRACE = dtrace +PROTOC ?= protoc +DTRACE ?= dtrace CONFIG ?= opt +# 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)) -LDXX = $(LDXX_$(CONFIG)) +endif +LDXX ?= $(LDXX_$(CONFIG)) +ifeq ($(origin AR), default) AR = ar +endif ifeq ($(SYSTEM),Linux) -STRIP = strip --strip-unneeded +STRIP ?= strip --strip-unneeded else ifeq ($(SYSTEM),Darwin) -STRIP = strip -x +STRIP ?= strip -x else -STRIP = strip +STRIP ?= strip endif endif -INSTALL = install -RM = rm -f -PKG_CONFIG = pkg-config +INSTALL ?= install +RM ?= rm -f +PKG_CONFIG ?= pkg-config ifndef VALID_CONFIG_$(CONFIG) $(error Invalid CONFIG value '$(CONFIG)') @@ -266,10 +284,10 @@ HAS_CXX11 = $(shell $(CXX11_CHECK_CMD) 2> /dev/null && echo true || echo false) # cross-compiling, you can override these variables from GNU make's # command line: make CC=cross-gcc HOST_CC=gcc -HOST_CC = $(CC) -HOST_CXX = $(CXX) -HOST_LD = $(LD) -HOST_LDXX = $(LDXX) +HOST_CC ?= $(CC) +HOST_CXX ?= $(CXX) +HOST_LD ?= $(LD) +HOST_LDXX ?= $(LDXX) ifdef EXTRA_DEFINES DEFINES += $(EXTRA_DEFINES) @@ -400,14 +418,6 @@ else IS_GIT_FOLDER = true endif -ifeq ($(SYSTEM),Linux) -OPENSSL_REQUIRES_DL = true -endif - -ifeq ($(SYSTEM),Darwin) -OPENSSL_REQUIRES_DL = true -endif - ifeq ($(HAS_PKG_CONFIG),true) OPENSSL_ALPN_CHECK_CMD = $(PKG_CONFIG) --atleast-version=1.0.2 openssl OPENSSL_NPN_CHECK_CMD = $(PKG_CONFIG) --atleast-version=1.0.1 openssl @@ -426,11 +436,6 @@ OPENSSL_NPN_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/open ZLIB_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/zlib.c -lz $(LDFLAGS) PROTOBUF_CHECK_CMD = $(CXX) $(CXXFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/protobuf.cc -lprotobuf $(LDFLAGS) -ifeq ($(OPENSSL_REQUIRES_DL),true) -OPENSSL_ALPN_CHECK_CMD += -ldl -OPENSSL_NPN_CHECK_CMD += -ldl -endif - endif # HAS_PKG_CONFIG PERFTOOLS_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/perftools.c -lprofiler $(LDFLAGS) @@ -594,9 +599,6 @@ OPENSSL_DEP += $(LIBDIR)/$(CONFIG)/libboringssl.a OPENSSL_MERGE_LIBS += $(LIBDIR)/$(CONFIG)/libboringssl.a # need to prefix these to ensure overriding system libraries CPPFLAGS := -Ithird_party/boringssl/include $(CPPFLAGS) -ifeq ($(OPENSSL_REQUIRES_DL),true) -LIBS_SECURE = dl -endif # OPENSSL_REQUIRES_DL else # EMBED_OPENSSL=false ifeq ($(HAS_PKG_CONFIG),true) OPENSSL_PKG_CONFIG = true @@ -616,10 +618,7 @@ ifeq ($(HAS_SYSTEM_OPENSSL_NPN),true) CPPFLAGS += -DTSI_OPENSSL_ALPN_SUPPORT=0 LIBS_SECURE = $(OPENSSL_LIBS) endif # HAS_SYSTEM_OPENSSL_NPN -ifeq ($(OPENSSL_REQUIRES_DL),true) -LIBS_SECURE += dl PC_LIBS_SECURE = $(addprefix -l, $(LIBS_SECURE)) -endif # OPENSSL_REQUIRES_DL=true endif # EMBED_OPENSSL endif # NO_SECURE diff --git a/templates/Makefile.template b/templates/Makefile.template index 589f724fd1..a4fcf66782 100644 --- a/templates/Makefile.template +++ b/templates/Makefile.template @@ -130,26 +130,44 @@ prefix ?= /usr/local - PROTOC = protoc - DTRACE = dtrace + PROTOC ?= protoc + DTRACE ?= dtrace CONFIG ?= opt + # 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)) - LDXX = $(LDXX_$(CONFIG)) + endif + LDXX ?= $(LDXX_$(CONFIG)) + ifeq ($(origin AR), default) AR = ar + endif ifeq ($(SYSTEM),Linux) - STRIP = strip --strip-unneeded + STRIP ?= strip --strip-unneeded else ifeq ($(SYSTEM),Darwin) - STRIP = strip -x + STRIP ?= strip -x else - STRIP = strip + STRIP ?= strip endif endif - INSTALL = install - RM = rm -f - PKG_CONFIG = pkg-config + INSTALL ?= install + RM ?= rm -f + PKG_CONFIG ?= pkg-config ifndef VALID_CONFIG_$(CONFIG) $(error Invalid CONFIG value '$(CONFIG)') @@ -170,10 +188,10 @@ # cross-compiling, you can override these variables from GNU make's # command line: make CC=cross-gcc HOST_CC=gcc - HOST_CC = $(CC) - HOST_CXX = $(CXX) - HOST_LD = $(LD) - HOST_LDXX = $(LDXX) + HOST_CC ?= $(CC) + HOST_CXX ?= $(CXX) + HOST_LD ?= $(LD) + HOST_LDXX ?= $(LDXX) ifdef EXTRA_DEFINES DEFINES += $(EXTRA_DEFINES) @@ -315,14 +333,6 @@ IS_GIT_FOLDER = true endif - ifeq ($(SYSTEM),Linux) - OPENSSL_REQUIRES_DL = true - endif - - ifeq ($(SYSTEM),Darwin) - OPENSSL_REQUIRES_DL = true - endif - ifeq ($(HAS_PKG_CONFIG),true) OPENSSL_ALPN_CHECK_CMD = $(PKG_CONFIG) --atleast-version=1.0.2 openssl OPENSSL_NPN_CHECK_CMD = $(PKG_CONFIG) --atleast-version=1.0.1 openssl @@ -341,11 +351,6 @@ ZLIB_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/zlib.c -lz $(LDFLAGS) PROTOBUF_CHECK_CMD = $(CXX) $(CXXFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/protobuf.cc -lprotobuf $(LDFLAGS) - ifeq ($(OPENSSL_REQUIRES_DL),true) - OPENSSL_ALPN_CHECK_CMD += -ldl - OPENSSL_NPN_CHECK_CMD += -ldl - endif - endif # HAS_PKG_CONFIG PERFTOOLS_CHECK_CMD = $(CC) $(CFLAGS) $(CPPFLAGS) -o $(TMPOUT) test/build/perftools.c -lprofiler $(LDFLAGS) @@ -509,9 +514,6 @@ OPENSSL_MERGE_LIBS += $(LIBDIR)/$(CONFIG)/libboringssl.a # need to prefix these to ensure overriding system libraries CPPFLAGS := -Ithird_party/boringssl/include $(CPPFLAGS) - ifeq ($(OPENSSL_REQUIRES_DL),true) - LIBS_SECURE = dl - endif # OPENSSL_REQUIRES_DL else # EMBED_OPENSSL=false ifeq ($(HAS_PKG_CONFIG),true) OPENSSL_PKG_CONFIG = true @@ -531,10 +533,7 @@ CPPFLAGS += -DTSI_OPENSSL_ALPN_SUPPORT=0 LIBS_SECURE = $(OPENSSL_LIBS) endif # HAS_SYSTEM_OPENSSL_NPN - ifeq ($(OPENSSL_REQUIRES_DL),true) - LIBS_SECURE += dl PC_LIBS_SECURE = $(addprefix -l, $(LIBS_SECURE)) - endif # OPENSSL_REQUIRES_DL=true endif # EMBED_OPENSSL endif # NO_SECURE |