[fix] translate g++ whole archive to force load for clang++ compilation
authorEvan Shelhamer <shelhamer@imaginarynumber.net>
Wed, 1 Oct 2014 18:50:42 +0000 (11:50 -0700)
committerEvan Shelhamer <shelhamer@imaginarynumber.net>
Fri, 3 Oct 2014 20:19:35 +0000 (13:19 -0700)
To build with the layer registry clang++ requires `-force_load` as
g++ requires `--whole-archive`.

Makefile

index b0b2515..aac8205 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -20,7 +20,6 @@ endif
 LIB_BUILD_DIR := $(BUILD_DIR)/lib
 STATIC_NAME := $(LIB_BUILD_DIR)/lib$(PROJECT).a
 DYNAMIC_NAME := $(LIB_BUILD_DIR)/lib$(PROJECT).so
-STATIC_LINK_COMMAND := -Wl,--whole-archive $(STATIC_NAME) -Wl,--no-whole-archive
 
 ##############################
 # Get all source files
@@ -228,6 +227,7 @@ else ifeq ($(UNAME), Darwin)
        OSX := 1
 endif
 
+# Linux
 ifeq ($(LINUX), 1)
        CXX ?= /usr/bin/g++
        GCCVERSION := $(shell $(CXX) -dumpversion | cut -f1,2 -d.)
@@ -259,6 +259,15 @@ ifdef CUSTOM_CXX
        CXX := $(CUSTOM_CXX)
 endif
 
+# Static linking
+ifneq (,$(findstring clang++,$(CXX)))
+       STATIC_LINK_COMMAND := -Wl,-force_load $(STATIC_NAME)
+else ifneq (,$(findstring g++,$(CXX)))
+       STATIC_LINK_COMMAND := -Wl,--whole-archive $(STATIC_NAME) -Wl,--no-whole-archive
+else
+       $(error Cannot static link with the $(CXX) compiler.)
+endif
+
 # Debugging
 ifeq ($(DEBUG), 1)
        COMMON_FLAGS += -DDEBUG -g -O0