Don't build directory libraries unless we're building an applet that needs it.
Cherry-picked from Devin Bayer's big MacOS X patch.
diff --git a/archival/Makefile.in b/archival/Makefile.in
index d62507e..ee284ad 100644
--- a/archival/Makefile.in
+++ b/archival/Makefile.in
@@ -26,7 +26,9 @@
ARCHIVAL-$(CONFIG_UNCOMPRESS) += uncompress.o
ARCHIVAL-$(CONFIG_UNZIP) += unzip.o
+ifneq ($(strip $(ARCHIVAL-y)),)
libraries-y+=$(ARCHIVAL_DIR)$(ARCHIVAL_AR)
+endif
ARCHIVAL_SRC-y:=$(patsubst %.o,$(srcdir)/%.c,$(ARCHIVAL-y))
ARCHIVAL_SRC-a:=$(wildcard $(srcdir)/*.c)
diff --git a/console-tools/Makefile.in b/console-tools/Makefile.in
index 42fc590..f14e338 100644
--- a/console-tools/Makefile.in
+++ b/console-tools/Makefile.in
@@ -22,7 +22,9 @@
CONSOLETOOLS-$(CONFIG_RESET) += reset.o
CONSOLETOOLS-$(CONFIG_SETKEYCODES) += setkeycodes.o
+ifneq ($(strip $(CONSOLETOOLS-y)),)
libraries-y+=$(CONSOLETOOLS_DIR)$(CONSOLETOOLS_AR)
+endif
CONSOLETOOLS_SRC-y:=$(patsubst %.o,$(srcdir)/%.c,$(CONSOLETOOLS-y))
CONSOLETOOLS_SRC-a:=$(wildcard $(srcdir)/*.c)
APPLET_SRC-y+=$(CONSOLETOOLS_SRC-y)
diff --git a/coreutils/Makefile.in b/coreutils/Makefile.in
index 4e7b7bd..2ab256c 100644
--- a/coreutils/Makefile.in
+++ b/coreutils/Makefile.in
@@ -82,7 +82,11 @@
COREUTILS-$(CONFIG_YES) += yes.o
COREUTILS-y:=$(sort $(COREUTILS-y))
+
+ifneq ($(strip $(COREUTILS-y)),)
libraries-y+=$(COREUTILS_DIR)$(COREUTILS_AR)
+endif
+
COREUTILS_SRC-y:=$(patsubst %.o,$(srcdir)/%.c,$(COREUTILS-y))
COREUTILS_SRC-a:=$(wildcard $(srcdir)/*.c)
APPLET_SRC-y+=$(COREUTILS_SRC-y)
diff --git a/debianutils/Makefile.in b/debianutils/Makefile.in
index 2fc3dfd..2983565 100644
--- a/debianutils/Makefile.in
+++ b/debianutils/Makefile.in
@@ -18,7 +18,9 @@
DEBIANUTILS-$(CONFIG_START_STOP_DAEMON) += start_stop_daemon.o
DEBIANUTILS-$(CONFIG_WHICH) += which.o
+ifneq ($(strip $(DEBIANUTILS-y)),)
libraries-y+=$(DEBIANUTILS_DIR)$(DEBIANUTILS_AR)
+endif
DEBIANUTILS_SRC-y:=$(patsubst %.o,$(srcdir)/%.c,$(DEBIANUTILS-y))
DEBIANUTILS_SRC-a:=$(wildcard $(srcdir)/*.c)
APPLET_SRC-y+=$(DEBIANUTILS_SRC-y)
diff --git a/e2fsprogs/Makefile.in b/e2fsprogs/Makefile.in
index 28e0e4d..e4cfdf5 100644
--- a/e2fsprogs/Makefile.in
+++ b/e2fsprogs/Makefile.in
@@ -64,7 +64,10 @@
E2FSPROGS-y:=$(sort $(E2FSPROGS-y))
+ifneq ($(strip $(E2FSPROGS-y)),)
libraries-y+=$(E2FSPROGS_DIR)/$(E2FSPROGS_AR)
+endif
+
E2FSPROGS_SRC-y:=$(patsubst %.o,$(E2FSPROGS_SRC)/%.c,$(E2FSPROGS-y))
E2FSPROGS_SRC-a:=$(wildcard $(E2FSPROGS_SRC)/*.c) $(patsubst %,$(E2FSPROGS_SRC)/%,$(BLKID_SRCS) $(E2P_SRCS) $(EXT2FS_SRCS) $(UUID_SRCS))
APPLET_SRC-y+=$(E2FSPROGS_CFLAGS) $(E2FSPROGS_SRC-y)
diff --git a/editors/Makefile.in b/editors/Makefile.in
index 83e1392..805017d 100644
--- a/editors/Makefile.in
+++ b/editors/Makefile.in
@@ -16,7 +16,9 @@
EDITOR-$(CONFIG_SED) += sed.o
EDITOR-$(CONFIG_VI) += vi.o
+ifneq ($(strip $(EDITOR-y)),)
libraries-y+=$(EDITOR_DIR)$(EDITOR_AR)
+endif
EDITOR_SRC-y:=$(patsubst %.o,$(srcdir)/%.c,$(EDITOR-y))
EDITOR_SRC-a:=$(wildcard $(srcdir)/*.c)
diff --git a/findutils/Makefile.in b/findutils/Makefile.in
index e43260d..25a2d38 100644
--- a/findutils/Makefile.in
+++ b/findutils/Makefile.in
@@ -15,7 +15,9 @@
FINDUTILS-$(CONFIG_GREP) += grep.o
FINDUTILS-$(CONFIG_XARGS) += xargs.o
+ifneq ($(strip $(FINDUTILS-y)),)
libraries-y+=$(FINDUTILS_DIR)$(FINDUTILS_AR)
+endif
FINDUTILS_SRC-y:=$(patsubst %.o,$(srcdir)/%.c,$(FINDUTILS-y))
FINDUTILS_SRC-a:=$(wildcard $(srcdir)/*.c)
diff --git a/init/Makefile.in b/init/Makefile.in
index dc63f9b..a48ead4 100644
--- a/init/Makefile.in
+++ b/init/Makefile.in
@@ -27,7 +27,9 @@
INIT-$(CONFIG_INIT_SHARED) += init_shared.o
+ifneq ($(strip $(INIT-y)),)
libraries-y+=$(INIT_DIR)$(INIT_AR)
+endif
INIT_SRC-y:=$(patsubst %.o,$(srcdir)/%.c,$(INIT-y))
INIT_SRC-a:=$(wildcard $(srcdir)/*.c)
diff --git a/loginutils/Makefile.in b/loginutils/Makefile.in
index 30085b3..c11bbfc 100644
--- a/loginutils/Makefile.in
+++ b/loginutils/Makefile.in
@@ -22,7 +22,9 @@
LOGINUTILS-$(CONFIG_DELUSER) += deluser.o
LOGINUTILS-$(CONFIG_DELGROUP) += delgroup.o
+ifneq ($(strip $(LOGINUTILS-y)),)
libraries-y+=$(LOGINUTILS_DIR)$(LOGINUTILS_AR)
+endif
LOGINUTILS_SRC-y:=$(patsubst %.o,$(srcdir)/%.c,$(LOGINUTILS-y))
LOGINUTILS_SRC-a:=$(wildcard $(srcdir)/*.c)
diff --git a/miscutils/Makefile.in b/miscutils/Makefile.in
index 9a45b2f..2c651d3 100644
--- a/miscutils/Makefile.in
+++ b/miscutils/Makefile.in
@@ -31,7 +31,9 @@
MISCUTILS-$(CONFIG_TIME) += time.o
MISCUTILS-$(CONFIG_WATCHDOG) += watchdog.o
+ifneq ($(strip $(MISCUTILS-y)),)
libraries-y+=$(MISCUTILS_DIR)$(MISCUTILS_AR)
+endif
MISCUTILS_SRC-y:=$(patsubst %.o,$(srcdir)/%.c,$(MISCUTILS-y))
MISCUTILS_SRC-a:=$(wildcard $(srcdir)/*.c)
diff --git a/modutils/Makefile.in b/modutils/Makefile.in
index 73c257a..5c7c923 100644
--- a/modutils/Makefile.in
+++ b/modutils/Makefile.in
@@ -16,7 +16,9 @@
MODUTILS-$(CONFIG_MODPROBE) += modprobe.o
MODUTILS-$(CONFIG_RMMOD) += rmmod.o
+ifneq ($(strip $(MODUTILS-y)),)
libraries-y+=$(MODUTILS_DIR)$(MODUTILS_AR)
+endif
MODUTILS_SRC-y:=$(patsubst %.o,$(srcdir)/%.c,$(MODUTILS-y))
MODUTILS_SRC-a:=$(wildcard $(srcdir)/*.c)
diff --git a/networking/Makefile.in b/networking/Makefile.in
index a07af7a..650fc1a 100644
--- a/networking/Makefile.in
+++ b/networking/Makefile.in
@@ -44,7 +44,9 @@
NETWORKING-$(CONFIG_ZCIP) += zcip.o
NETWORKING-y:=$(sort $(NETWORKING-y))
+ifneq ($(strip $(NETWORKING-y)),)
libraries-y+=$(NETWORKING_DIR)$(NETWORKING_AR)
+endif
NETWORKING_SRC-y:=$(patsubst %.o,$(srcdir)/%.c,$(NETWORKING-y))
NETWORKING_SRC-a:=$(wildcard $(srcdir)/*.c)
diff --git a/networking/udhcp/Makefile.in b/networking/udhcp/Makefile.in
index c9e0f5b..df32247 100644
--- a/networking/udhcp/Makefile.in
+++ b/networking/udhcp/Makefile.in
@@ -32,7 +32,9 @@
UDHCP-$(CONFIG_DUMPLEASES) += dumpleases.c
UDHCP_OBJS:=$(patsubst %.c,$(UDHCP_DIR)%.o, $(UDHCP-y))
+ifneq ($(strip $(UDHCP-y)),)
libraries-y+=$(UDHCP_DIR)$(UDHCP_AR)
+endif
UDHCP-y:=$(patsubst %,$(srcdir)/%,$(UDHCP-y))
UDHCP-a:=$(wildcard $(srcdir)/*.c)
diff --git a/procps/Makefile.in b/procps/Makefile.in
index c177c90..261c49b 100644
--- a/procps/Makefile.in
+++ b/procps/Makefile.in
@@ -21,7 +21,9 @@
PROCPS-$(CONFIG_UPTIME) += uptime.o
PROCPS-$(CONFIG_FUSER) += fuser.o
+ifneq ($(strip $(PROCPS-y)),)
libraries-y+=$(PROCPS_DIR)$(PROCPS_AR)
+endif
PROCPS_SRC-y:=$(patsubst %.o,$(srcdir)/%.c,$(PROCPS-y))
PROCPS_SRC-a:=$(wildcard $(srcdir)/*.c)
diff --git a/shell/Makefile.in b/shell/Makefile.in
index a204099..fcd93f3 100644
--- a/shell/Makefile.in
+++ b/shell/Makefile.in
@@ -17,7 +17,9 @@
SHELLT-$(CONFIG_MSH) += msh.o
SHELLT-$(CONFIG_FEATURE_COMMAND_EDITING) += cmdedit.o
+ifneq ($(strip $(SHELLT-y)),)
libraries-y+=$(SHELL_DIR)$(SHELL_AR)
+endif
SHELLT_SRC-y:=$(patsubst %.o,$(srcdir)/%.c,$(SHELLT-y))
SHELLT_SRC-a:=$(wildcard $(srcdir)/*.c)
diff --git a/sysklogd/Makefile.in b/sysklogd/Makefile.in
index 2312212..83f77be 100644
--- a/sysklogd/Makefile.in
+++ b/sysklogd/Makefile.in
@@ -16,7 +16,9 @@
SYSKLOGD-$(CONFIG_LOGREAD) += logread.o
SYSKLOGD-$(CONFIG_SYSLOGD) += syslogd.o
+ifneq ($(strip $(SYSKLOGD-y)),)
libraries-y+=$(SYSKLOGD_DIR)$(SYSKLOGD_AR)
+endif
SYSKLOGD_SRC-y:=$(patsubst %.o,$(srcdir)/%.c,$(SYSKLOGD-y))
SYSKLOGD_SRC-a:=$(wildcard $(srcdir)/*.c)
diff --git a/util-linux/Makefile.in b/util-linux/Makefile.in
index 423d4b6..f6a50b7 100644
--- a/util-linux/Makefile.in
+++ b/util-linux/Makefile.in
@@ -38,8 +38,9 @@
UTILLINUX-$(CONFIG_SWITCH_ROOT) +=switch_root.o
UTILLINUX-$(CONFIG_UMOUNT) +=umount.o
-
+ifneq ($(strip $(UTILLINUX-y)),)
libraries-y+=$(UTILLINUX_DIR)$(UTILLINUX_AR)
+endif
UTILLINUX_SRC-y:=$(patsubst %.o,$(srcdir)/%.c,$(UTILLINUX-y))
UTILLINUX_SRC-a:=$(wildcard $(srcdir)/*.c)