diff mbox

Statically link libbfd reloaded

Message ID 4E3BFF4F.7020308@canonical.com
State New
Headers show

Commit Message

Stefan Bader Aug. 5, 2011, 2:33 p.m. UTC
getting that done seems to be a major PITA. I _think_ this would be doing the
right thing when running "make LDFLAGS=-static". However, I guess for upstream,
a fix should do what the description says. Which is to produce a static binary,
which I still fail to achieve. Best case was a failure which tells me something
I understand as recompile libc...

-Stefan
diff mbox

Patch

diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index 56d62d3..208157a 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -96,7 +96,11 @@  ifndef PERF_DEBUG
 endif
 
 CFLAGS = -fno-omit-frame-pointer -ggdb3 -Wall -Wextra -std=gnu99 -Werror $(CFLAGS_OPTIMIZE) -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS)
-EXTLIBS = -lpthread -lrt -lelf -lm
+ifeq ($(findstring -static,$(LDFLAGS)),-static)
+	EXTLIBS = -Wl,-Bdynamic -lpthread -lrt -lelf -lm
+else
+	EXTLIBS = -lpthread -lrt -lelf -lm
+endif
 ALL_CFLAGS = $(CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
 ALL_LDFLAGS = $(LDFLAGS)
 STRIP ?= strip
@@ -569,20 +573,25 @@  else
 		EXTLIBS += -liberty
 		BASIC_CFLAGS += -DHAVE_CPLUS_DEMANGLE
         else
-		FLAGS_BFD=$(ALL_CFLAGS) $(ALL_LDFLAGS) $(EXTLIBS) -lbfd
+		ifeq ($(findstring -static,$(LDFLAGS)),-static)
+			LDFLAGS_BFD = -Wl,-Bstatic -lbfd -Wl,-Bdynamic -ldl
+		else
+			LDFLAGS_BFD = -lbfd
+		endif
+		FLAGS_BFD=$(ALL_CFLAGS) $(ALL_LDFLAGS) $(EXTLIBS) $(LDFLAGS_BFD)
 		has_bfd := $(call try-cc,$(SOURCE_BFD),$(FLAGS_BFD))
 		ifeq ($(has_bfd),y)
-			EXTLIBS += -lbfd
+			EXTLIBS += $(LDGLAGS_BFD)
 		else
-			FLAGS_BFD_IBERTY=$(FLAGS_BFD) -liberty
+			FLAGS_BFD_IBERTY=$(LDFLAGS_BFD) -liberty
 			has_bfd_iberty := $(call try-cc,$(SOURCE_BFD),$(FLAGS_BFD_IBERTY))
 			ifeq ($(has_bfd_iberty),y)
-				EXTLIBS += -lbfd -liberty
+				EXTLIBS += $(LDFLAGS_BFD) -liberty
 			else
 				FLAGS_BFD_IBERTY_Z=$(FLAGS_BFD_IBERTY) -lz
 				has_bfd_iberty_z := $(call try-cc,$(SOURCE_BFD),$(FLAGS_BFD_IBERTY_Z))
 				ifeq ($(has_bfd_iberty_z),y)
-					EXTLIBS += -lbfd -liberty -lz
+					EXTLIBS += $(LDFLAGS_BFD) -liberty -lz
 				else
 					FLAGS_CPLUS_DEMANGLE=$(ALL_CFLAGS) $(ALL_LDFLAGS) $(EXTLIBS) -liberty
 					has_cplus_demangle := $(call try-cc,$(SOURCE_CPLUS_DEMANGLE),$(FLAGS_CPLUS_DEMANGLE))
@@ -638,6 +647,9 @@  prefix_SQ = $(subst ','\'',$(prefix))
 
 SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH))
 
+ifeq ($(findstring -static,$(LDFLAGS)),-static)
+	EXTLIBS += -lbz2 -llzma
+endif
 LIBS = -Wl,--whole-archive $(PERFLIBS) -Wl,--no-whole-archive -Wl,--start-group $(EXTLIBS) -Wl,--end-group
 
 ALL_CFLAGS += $(BASIC_CFLAGS)