Mesa (master): gallium/targets: use c++ compiler for linking

Marcin Åšlusarz mslusarz at kemper.freedesktop.org
Mon Oct 17 13:58:03 PDT 2011


Module: Mesa
Branch: master
Commit: 757390491cfa3b861fab76940a8c6e508d1f1a25
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=757390491cfa3b861fab76940a8c6e508d1f1a25

Author: Marcin Slusarz <marcin.slusarz at gmail.com>
Date:   Thu Oct 13 21:45:45 2011 +0200

gallium/targets: use c++ compiler for linking

As pointed out by Michel Dänzer, gcc -lstdc++ doesn't work on all systems,
because it may require other libraries which are only pulled in implicitly
by g++. And libstdc++ is available only with GNU compiler.

Use c++ compiler for linking and remove redundant LDFLAGS += -lstdc++
all over the tree.

---

 configure.ac                              |    2 +-
 src/gallium/targets/Makefile.dri          |    2 -
 src/gallium/targets/Makefile.va           |    9 ++++++-
 src/gallium/targets/Makefile.vdpau        |    9 ++++++-
 src/gallium/targets/Makefile.xorg         |   11 ++++++---
 src/gallium/targets/Makefile.xvmc         |   10 ++++++--
 src/gallium/targets/gbm/Makefile          |   34 ++++++++++++++++++++--------
 src/gallium/targets/xa-vmwgfx/Makefile    |    9 ++++++-
 src/gallium/targets/xorg-nouveau/Makefile |    2 +
 src/gallium/targets/xvmc-nouveau/Makefile |    2 +
 10 files changed, 64 insertions(+), 26 deletions(-)

diff --git a/configure.ac b/configure.ac
index 3f951ec..0864b55 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1748,7 +1748,7 @@ if test "x$enable_gallium_llvm" = xyes; then
     if test "x$LLVM_CONFIG" != xno; then
 	LLVM_VERSION=`$LLVM_CONFIG --version`
 	LLVM_CFLAGS=`$LLVM_CONFIG --cppflags|sed 's/-DNDEBUG\>//g'`
-	LLVM_LIBS="`$LLVM_CONFIG --libs` -lstdc++"
+	LLVM_LIBS="`$LLVM_CONFIG --libs`"
 
 	LLVM_LDFLAGS=`$LLVM_CONFIG --ldflags`
 	DEFINES="$DEFINES -D__STDC_CONSTANT_MACROS"
diff --git a/src/gallium/targets/Makefile.dri b/src/gallium/targets/Makefile.dri
index 857ebfe..a26b3ee 100644
--- a/src/gallium/targets/Makefile.dri
+++ b/src/gallium/targets/Makefile.dri
@@ -4,8 +4,6 @@
 ifeq ($(MESA_LLVM),1)
 LDFLAGS += $(LLVM_LDFLAGS)
 DRIVER_EXTRAS = $(LLVM_LIBS)
-else
-LDFLAGS += -lstdc++
 endif
 
 MESA_MODULES = \
diff --git a/src/gallium/targets/Makefile.va b/src/gallium/targets/Makefile.va
index 7ced430..920f130 100644
--- a/src/gallium/targets/Makefile.va
+++ b/src/gallium/targets/Makefile.va
@@ -17,8 +17,13 @@ STATE_TRACKER_LIB = $(TOP)/src/gallium/state_trackers/va/libvatracker.a
 ifeq ($(MESA_LLVM),1)
 LDFLAGS += $(LLVM_LDFLAGS)
 DRIVER_EXTRAS = $(LLVM_LIBS)
+LD=$(CXX)
 else
-LDFLAGS += -lstdc++
+  ifeq ($(LINK_WITH_CXX),1)
+    LD=$(CXX)
+  else
+    LD=$(CC)
+  endif
 endif
 
 # XXX: Hack, VA public funcs aren't exported
@@ -39,7 +44,7 @@ OBJECTS = $(C_SOURCES:.c=.o) \
 default: depend symlinks $(TOP)/$(LIB_DIR)/gallium/$(LIBNAME)
 
 $(TOP)/$(LIB_DIR)/gallium/$(LIBNAME): $(OBJECTS) $(PIPE_DRIVERS) $(STATE_TRACKER_LIB) $(TOP)/$(LIB_DIR)/gallium Makefile
-	$(MKLIB) -o $(LIBBASENAME) -linker '$(CC)' -ldflags '$(LDFLAGS)' \
+	$(MKLIB) -o $(LIBBASENAME) -linker '$(LD)' -ldflags '$(LDFLAGS)' \
 		-major $(VA_MAJOR) -minor $(VA_MINOR) $(MKLIB_OPTIONS) \
 		-install $(TOP)/$(LIB_DIR)/gallium \
 		$(OBJECTS) $(STATE_TRACKER_LIB) $(PIPE_DRIVERS) $(LIBS) $(DRIVER_EXTRAS)
diff --git a/src/gallium/targets/Makefile.vdpau b/src/gallium/targets/Makefile.vdpau
index c634915..39984e2 100644
--- a/src/gallium/targets/Makefile.vdpau
+++ b/src/gallium/targets/Makefile.vdpau
@@ -17,8 +17,13 @@ STATE_TRACKER_LIB = $(TOP)/src/gallium/state_trackers/vdpau/libvdpautracker.a
 ifeq ($(MESA_LLVM),1)
 LDFLAGS += $(LLVM_LDFLAGS)
 DRIVER_EXTRAS = $(LLVM_LIBS)
+LD=$(CXX)
 else
-LDFLAGS += -lstdc++
+  ifeq ($(LINK_WITH_CXX),1)
+    LD=$(CXX)
+  else
+    LD=$(CC)
+  endif
 endif
 
 # XXX: Hack, VDPAU public funcs aren't exported if we link to libvdpautracker.a :(
@@ -39,7 +44,7 @@ OBJECTS = $(C_SOURCES:.c=.o) \
 default: depend symlinks $(TOP)/$(LIB_DIR)/gallium/$(LIBNAME)
 
 $(TOP)/$(LIB_DIR)/gallium/$(LIBNAME): $(OBJECTS) $(PIPE_DRIVERS) $(STATE_TRACKER_LIB) $(TOP)/$(LIB_DIR)/gallium Makefile
-	$(MKLIB) -o $(LIBBASENAME) -linker '$(CC)' -ldflags '$(LDFLAGS)' \
+	$(MKLIB) -o $(LIBBASENAME) -linker '$(LD)' -ldflags '$(LDFLAGS)' \
 		-major $(VDPAU_MAJOR) -minor $(VDPAU_MINOR) $(MKLIB_OPTIONS) \
 		-install $(TOP)/$(LIB_DIR)/gallium \
 		$(OBJECTS) $(STATE_TRACKER_LIB) $(PIPE_DRIVERS) $(LIBS) $(DRIVER_EXTRAS)
diff --git a/src/gallium/targets/Makefile.xorg b/src/gallium/targets/Makefile.xorg
index c96eded..d1231ca 100644
--- a/src/gallium/targets/Makefile.xorg
+++ b/src/gallium/targets/Makefile.xorg
@@ -29,12 +29,15 @@ INCLUDES = \
 LIBNAME_STAGING = $(TOP)/$(LIB_DIR)/gallium/$(TARGET)
 
 ifeq ($(MESA_LLVM),1)
-LD = $(CXX)
 LDFLAGS += $(LLVM_LDFLAGS)
-USE_CXX=1
 DRIVER_LINKS += $(LLVM_LIBS) -lm -ldl
+LD=$(CXX)
 else
-LDFLAGS += -lstdc++
+  ifeq ($(LINK_WITH_CXX),1)
+    LD=$(CXX)
+  else
+    LD=$(CC)
+  endif
 endif
 
 
@@ -43,7 +46,7 @@ endif
 default: depend $(TOP)/$(LIB_DIR)/gallium $(LIBNAME) $(LIBNAME_STAGING)
 
 $(LIBNAME): $(OBJECTS) Makefile ../Makefile.xorg $(LIBS) $(DRIVER_PIPES) $(GALLIUM_AUXILIARIES)
-	$(MKLIB) -linker '$(CC)' -noprefix -o $@ $(LDFLAGS) $(OBJECTS) $(DRIVER_PIPES) $(GALLIUM_AUXILIARIES) $(DRIVER_LINKS)
+	$(MKLIB) -linker '$(LD)' -noprefix -o $@ $(LDFLAGS) $(OBJECTS) $(DRIVER_PIPES) $(GALLIUM_AUXILIARIES) $(DRIVER_LINKS)
 
 depend: $(C_SOURCES) $(CPP_SOURCES) $(ASM_SOURCES) $(SYMLINKS) $(GENERATED_SOURCES)
 	rm -f depend
diff --git a/src/gallium/targets/Makefile.xvmc b/src/gallium/targets/Makefile.xvmc
index 7182356..cb35d3c 100644
--- a/src/gallium/targets/Makefile.xvmc
+++ b/src/gallium/targets/Makefile.xvmc
@@ -17,11 +17,15 @@ STATE_TRACKER_LIB = $(TOP)/src/gallium/state_trackers/xorg/xvmc/libxvmctracker.a
 ifeq ($(MESA_LLVM),1)
 LDFLAGS += $(LLVM_LDFLAGS)
 DRIVER_EXTRAS = $(LLVM_LIBS)
+LD=$(CXX)
 else
-LDFLAGS += -lstdc++
+  ifeq ($(LINK_WITH_CXX),1)
+    LD=$(CXX)
+  else
+    LD=$(CC)
+  endif
 endif
 
-
 # XXX: Hack, XvMC public funcs aren't exported if we link to libxvmctracker.a :(
 OBJECTS = $(C_SOURCES:.c=.o) \
 	  $(ASM_SOURCES:.S=.o) \
@@ -40,7 +44,7 @@ OBJECTS = $(C_SOURCES:.c=.o) \
 default: depend symlinks $(TOP)/$(LIB_DIR)/gallium/$(LIBNAME)
 
 $(TOP)/$(LIB_DIR)/gallium/$(LIBNAME): $(OBJECTS) $(PIPE_DRIVERS) $(STATE_TRACKER_LIB) $(TOP)/$(LIB_DIR)/gallium Makefile
-	$(MKLIB) -o $(LIBBASENAME) -linker '$(CC)' -ldflags '$(LDFLAGS)' \
+	$(MKLIB) -o $(LIBBASENAME) -linker '$(LD)' -ldflags '$(LDFLAGS)' \
 		-major $(XVMC_MAJOR) -minor $(XVMC_MINOR) $(MKLIB_OPTIONS) \
 		-install $(TOP)/$(LIB_DIR)/gallium \
 		$(OBJECTS) $(STATE_TRACKER_LIB) $(PIPE_DRIVERS) $(LIBS) $(DRIVER_EXTRAS)
diff --git a/src/gallium/targets/gbm/Makefile b/src/gallium/targets/gbm/Makefile
index 3f52aae..15618a6 100644
--- a/src/gallium/targets/gbm/Makefile
+++ b/src/gallium/targets/gbm/Makefile
@@ -103,48 +103,55 @@ pipe_LIBS += $(TOP)/src/gallium/drivers/llvmpipe/libllvmpipe.a
 endif
 
 # determine the targets/sources
-pipe_TARGETS =
+_pipe_TARGETS_CC =
+_pipe_TARGETS_CXX =
 pipe_SOURCES =
 
 ifneq ($(findstring i915/drm,$(GALLIUM_WINSYS_DIRS)),)
-pipe_TARGETS += $(PIPE_PREFIX)i915.so
+_pipe_TARGETS_CC += $(PIPE_PREFIX)i915.so
 pipe_SOURCES += pipe_i915.c
 endif
 
 ifneq ($(findstring i965/drm,$(GALLIUM_WINSYS_DIRS)),)
-pipe_TARGETS += $(PIPE_PREFIX)i965.so
+_pipe_TARGETS_CC += $(PIPE_PREFIX)i965.so
 pipe_SOURCES += pipe_i965.c
 endif
 
 ifneq ($(findstring nouveau/drm,$(GALLIUM_WINSYS_DIRS)),)
-LDFLAGS += -lstdc++
-pipe_TARGETS += $(PIPE_PREFIX)nouveau.so
+_pipe_TARGETS_CXX += $(PIPE_PREFIX)nouveau.so
 pipe_SOURCES += pipe_nouveau.c
 endif
 
 ifneq ($(findstring radeon/drm,$(GALLIUM_WINSYS_DIRS)),)
 ifneq ($(findstring r300,$(GALLIUM_DRIVERS_DIRS)),)
-pipe_TARGETS += $(PIPE_PREFIX)r300.so
+_pipe_TARGETS_CC += $(PIPE_PREFIX)r300.so
 pipe_SOURCES += pipe_r300.c
 endif
 endif
 
 ifneq ($(findstring radeon/drm,$(GALLIUM_WINSYS_DIRS)),)
 ifneq ($(findstring r600,$(GALLIUM_DRIVERS_DIRS)),)
-pipe_TARGETS += $(PIPE_PREFIX)r600.so
+_pipe_TARGETS_CC += $(PIPE_PREFIX)r600.so
 pipe_SOURCES += pipe_r600.c
 endif
 endif
 
 ifneq ($(findstring svga/drm,$(GALLIUM_WINSYS_DIRS)),)
-pipe_TARGETS += $(PIPE_PREFIX)vmwgfx.so
+_pipe_TARGETS_CC += $(PIPE_PREFIX)vmwgfx.so
 pipe_SOURCES += pipe_vmwgfx.c
 endif
 
 pipe_OBJECTS = $(pipe_SOURCES:.c=.o)
 
+ifeq ($(MESA_LLVM),1)
+pipe_TARGETS_CXX = $(_pipe_TARGETS_CXX) $(_pipe_TARGETS_CC)
+pipe_TARGETS_CC =
+else
+pipe_TARGETS_CXX = $(_pipe_TARGETS_CXX)
+pipe_TARGETS_CC = $(_pipe_TARGETS_CC)
+endif
 
-GBM_EXTRA_TARGETS = $(addprefix $(TOP)/$(LIB_DIR)/gbm/, $(pipe_TARGETS))
+GBM_EXTRA_TARGETS = $(addprefix $(TOP)/$(LIB_DIR)/gbm/, $(pipe_TARGETS_CC)) $(addprefix $(TOP)/$(LIB_DIR)/gbm/, $(pipe_TARGETS_CXX))
 GBM_EXTRA_INSTALL = install-pipes
 GBM_EXTRA_CLEAN = clean-pipes
 GBM_EXTRA_SOURCES = $(pipe_SOURCES)
@@ -156,13 +163,20 @@ $(GBM_EXTRA_TARGETS): $(TOP)/$(LIB_DIR)/gbm/%: %
 	@$(INSTALL) -d $(dir $@)
 	$(INSTALL) $< $(dir $@)
 
-$(pipe_TARGETS): $(PIPE_PREFIX)%.so: pipe_%.o $(pipe_LIBS) $($*_LIBS)
+$(pipe_TARGETS_CC): $(PIPE_PREFIX)%.so: pipe_%.o $(pipe_LIBS) $($*_LIBS)
 	$(MKLIB) -o $@ -noprefix -linker '$(CC)' \
 		-ldflags '-L$(TOP)/$(LIB_DIR) $(pipe_LDFLAGS) $(LDFLAGS)' \
 		$(MKLIB_OPTIONS) $< \
 		-Wl,--start-group $(pipe_LIBS) $($*_LIBS) -Wl,--end-group \
 		$(pipe_SYS) $($*_SYS)
 
+$(pipe_TARGETS_CXX): $(PIPE_PREFIX)%.so: pipe_%.o $(pipe_LIBS) $($*_LIBS)
+	$(MKLIB) -o $@ -noprefix -linker '$(CXX)' \
+		-ldflags '-L$(TOP)/$(LIB_DIR) $(pipe_LDFLAGS) $(LDFLAGS)' \
+		$(MKLIB_OPTIONS) $< \
+		-Wl,--start-group $(pipe_LIBS) $($*_LIBS) -Wl,--end-group \
+		$(pipe_SYS) $($*_SYS)
+
 $(pipe_OBJECTS): %.o: %.c
 	$(CC) -c -o $@ $< $(pipe_INCLUDES) $(pipe_CFLAGS) $(CFLAGS)
 
diff --git a/src/gallium/targets/xa-vmwgfx/Makefile b/src/gallium/targets/xa-vmwgfx/Makefile
index fecdba6..5eebc50 100644
--- a/src/gallium/targets/xa-vmwgfx/Makefile
+++ b/src/gallium/targets/xa-vmwgfx/Makefile
@@ -33,8 +33,13 @@ OBJECTS = $(SOURCES:.c=.o)
 ifeq ($(MESA_LLVM),1)
 LDFLAGS += $(LLVM_LDFLAGS)
 GALLIUM_AUXILIARIES += $(LLVM_LIBS)
+LD=$(CXX)
 else
-LDFLAGS += -lstdc++
+  ifeq ($(LINK_WITH_CXX),1)
+    LD=$(CXX)
+  else
+    LD=$(CC)
+  endif
 endif
 
 ##### RULES #####
@@ -50,7 +55,7 @@ default: $(TOP)/$(LIB_DIR)/gallium/$(XA_LIB_NAME)
 
 # Make the library
 $(TOP)/$(LIB_DIR)/gallium/$(XA_LIB_NAME): depend $(OBJECTS) $(XA_LIB_DEPS)
-	$(MKLIB) -o $(XA_LIB) -linker $(CC) -ldflags '$(LDFLAGS)' \
+	$(MKLIB) -o $(XA_LIB) -linker $(LD) -ldflags '$(LDFLAGS)' \
 		-major $(XA_MAJOR) -minor $(XA_MINOR) -patch $(XA_TINY) \
 		$(MKLIB_OPTIONS) \
 		-exports $(TOP)/src/gallium/state_trackers/xa/xa_symbols\
diff --git a/src/gallium/targets/xorg-nouveau/Makefile b/src/gallium/targets/xorg-nouveau/Makefile
index cb4ae49..72899db 100644
--- a/src/gallium/targets/xorg-nouveau/Makefile
+++ b/src/gallium/targets/xorg-nouveau/Makefile
@@ -26,4 +26,6 @@ DRIVER_LINKS = \
 DRIVER_INCLUDES = \
 	$(shell $(PKG_CONFIG) --cflags-only-I libdrm libdrm_nouveau xf86driproto)
 
+LINK_WITH_CXX=1
+
 include ../Makefile.xorg
diff --git a/src/gallium/targets/xvmc-nouveau/Makefile b/src/gallium/targets/xvmc-nouveau/Makefile
index cc18864..67036ee 100644
--- a/src/gallium/targets/xvmc-nouveau/Makefile
+++ b/src/gallium/targets/xvmc-nouveau/Makefile
@@ -21,6 +21,8 @@ C_SOURCES = \
 
 DRIVER_LIBS = $(shell $(PKG_CONFIG) libdrm_nouveau --libs) -lXfixes
 
+LINK_WITH_CXX=1
+
 include ../Makefile.xvmc
 
 symlinks:



More information about the mesa-commit mailing list