From d6e7a8bf0f28cdb7156b891ff565d5406047914a Mon Sep 17 00:00:00 2001 From: Steven Luo Date: Sun, 21 Feb 2010 22:29:32 -0800 Subject: [PATCH] Link binaries with -Wl,--as-needed to reduce library dependencies Using pkg-config --libs to get library link lines has the disadvantage of bringing in many more library dependencies than actually necessary, since that assumes that dependencies of libraries need to be specified explicitly at link time (even when the library is itself linked against those dependencies). Using GNU ld's --as-needed option causes these unnecessary dependencies to be omitted from the binary. --as-needed needs to be specified after all the objects to be linked into the binary and before the libraries, so some reordering of the link command line is needed. --- Makefile | 4 ++-- config-ui/Makefile | 13 +++++++------ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 15c8199..65bb61e 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ CC = gcc CFLAGS = -Wall -Os $(EXTRA_CFLAGS) CPPFLAGS = `pkg-config --cflags dbus-glib-1` $(EXTRA_CPPFLAGS) -LDFLAGS = `pkg-config --libs dbus-glib-1` $(EXTRA_LDFLAGS) +LDFLAGS = -Wl,--as-needed `pkg-config --libs dbus-glib-1` $(EXTRA_LDFLAGS) PREFIX = /usr APP = browser-switchboard @@ -19,7 +19,7 @@ fremantle: $(APP): dbus-server-glue.h $(obj) - $(CC) $(CFLAGS) $(LDFLAGS) -o $(APP) $(obj) + $(CC) $(CFLAGS) -o $(APP) $(obj) $(LDFLAGS) dbus-server-glue.h: dbus-binding-tool --mode=glib-server --prefix="osso_browser" \ diff --git a/config-ui/Makefile b/config-ui/Makefile index d41444f..8bc3749 100644 --- a/config-ui/Makefile +++ b/config-ui/Makefile @@ -5,7 +5,7 @@ CPPFLAGS = -I../ `pkg-config --cflags gtk+-2.0` $(EXTRA_CPPFLAGS) CPPFLAGS_HILDON = -DHILDON `pkg-config --cflags hildon-1` CPPFLAGS_PLUGIN = $(CPPFLAGS_HILDON) -DHILDON_CP_APPLET \ `pkg-config --cflags libosso` `pkg-config --cflags hildon-control-panel` -LDFLAGS = `pkg-config --libs gtk+-2.0` $(EXTRA_LDFLAGS) +LDFLAGS = -Wl,--as-needed `pkg-config --libs gtk+-2.0` $(EXTRA_LDFLAGS) LDFLAGS_HILDON = `pkg-config --libs hildon-1` LDFLAGS_PLUGIN = -shared $(LDFLAGS_HILDON) \ `pkg-config --libs libosso` `pkg-config --libs hildon-control-panel` @@ -36,21 +36,22 @@ fremantle-plugin: @$(MAKE) EXTRA_CPPFLAGS='-DFREMANTLE $(EXTRA_CPPFLAGS)' $(PLUGIN) $(APP): $(app_obj) - $(CC) $(CFLAGS) $(LDFLAGS) -o $(APP) $(app_obj) + $(CC) $(CFLAGS) -o $(APP) $(app_obj) $(LDFLAGS) %.app.o: %.c $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $< $(HILDON_APP): $(happ_obj) - $(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_HILDON) \ - -o $(HILDON_APP) $(happ_obj) + $(CC) $(CFLAGS) -o $(HILDON_APP) $(happ_obj) \ + $(LDFLAGS) $(LDFLAGS_HILDON) %.happ.o: %.c $(CC) $(CFLAGS) $(CPPFLAGS) $(CPPFLAGS_HILDON) -c -o $@ $< $(PLUGIN): $(plugin_obj) - $(CC) $(CFLAGS) $(CFLAGS_PLUGIN) $(LDFLAGS) $(LDFLAGS_PLUGIN) \ - -o $(PLUGIN) $(plugin_obj) + $(CC) $(CFLAGS) $(CFLAGS_PLUGIN) -o $(PLUGIN) $(plugin_obj) \ + $(LDFLAGS) $(LDFLAGS_PLUGIN) + %.plugin.o: %.c $(CC) $(CFLAGS) $(CFLAGS_PLUGIN) $(CPPFLAGS) $(CPPFLAGS_PLUGIN) \ -- 1.7.9.5