tools/mtd-utils: prefer static linking
authorJo-Philipp Wich <jow@openwrt.org>
Mon, 14 Sep 2015 14:51:07 +0000 (14:51 +0000)
committerJo-Philipp Wich <jow@openwrt.org>
Mon, 14 Sep 2015 14:51:07 +0000 (14:51 +0000)
 - Add patch for optional static linking preference
 - Prefer static linking on Linux systems
 - Enable verbose compiler messages when building with V=c

Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
SVN-Revision: 46908

tools/mtd-utils/Makefile
tools/mtd-utils/patches/310-add-static-linking-option.patch [new file with mode: 0644]

index f831e3c..e06d137 100644 (file)
@@ -25,6 +25,9 @@ HOST_CFLAGS += -I$(STAGING_DIR_HOST)/include/e2fsprogs
 CFLAGS := $(HOST_CFLAGS) -I$(HOST_BUILD_DIR)/include -L$(HOST_BUILD_DIR) -L$(STAGING_DIR_HOST)/lib -DNO_NATIVE_SUPPORT
 ifneq ($(HOST_OS),Linux)
 CFLAGS += -Dloff_t=off_t -D__BYTE_ORDER=BYTE_ORDER -include getline.h -include endian.h -I$(CURDIR)/include -include fls.h
+MTD_STATIC := 0
+else
+MTD_STATIC := 1
 endif
 
 MTD_MAKEOPTS = \
@@ -32,7 +35,9 @@ MTD_MAKEOPTS = \
        LDFLAGS="$(HOST_LDFLAGS)" \
        WITHOUT_LZO=1 WITHOUT_XATTR=1 \
        SUBDIRS="" \
-       BUILDDIR="$(HOST_BUILD_DIR)"
+       BUILDDIR="$(HOST_BUILD_DIR)" \
+       STATIC=$(MTD_STATIC) \
+       V=$(if $(findstring c,$(OPENWRT_VERBOSE)),1)
 
 define Host/Compile
        $(MAKE) -C $(HOST_BUILD_DIR) \
diff --git a/tools/mtd-utils/patches/310-add-static-linking-option.patch b/tools/mtd-utils/patches/310-add-static-linking-option.patch
new file mode 100644 (file)
index 0000000..273aa85
--- /dev/null
@@ -0,0 +1,23 @@
+--- a/common.mk
++++ b/common.mk
+@@ -2,6 +2,11 @@ CC := $(CROSS)gcc
+ AR := $(CROSS)ar
+ RANLIB := $(CROSS)ranlib
++ifeq ($(STATIC),1)
++  LD_STATIC_ON := -Wl,-Bstatic
++  LD_STATIC_OFF := -Wl,-Bdynamic
++endif
++
+ # Stolen from Linux build system
+ comma = ,
+ try-run = $(shell set -e; ($(1)) >/dev/null 2>&1 && echo "$(2)" || echo "$(3)")
+@@ -68,7 +73,7 @@ endef
+ %: %.o $(LDDEPS)
+       $(call BECHO,LD)
+-      $(Q)$(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_$(notdir $@)) -g -o $@ $^ $(LDLIBS) $(LDLIBS_$(notdir $@))
++      $(Q)$(CC) $(CFLAGS) $(LDFLAGS) $(LDFLAGS_$(notdir $@)) -g -o $@ $(LD_STATIC_ON) $^ $(LDLIBS) $(LDLIBS_$(notdir $@)) $(LD_STATIC_OFF)
+ $(BUILDDIR)/%.a:
+       $(call BECHO,AR)