- add a macro to check for ld and as flags
authorBernhard Reutner-Fischer <rep.dot.nop@gmail.com>
Fri, 27 Jan 2006 15:45:56 +0000 (15:45 -0000)
committerBernhard Reutner-Fischer <rep.dot.nop@gmail.com>
Fri, 27 Jan 2006 15:45:56 +0000 (15:45 -0000)
  Very unreliable as e.g the ld check will see the flags supported by each emulation, not just the active one.
  good enough for now..
  Fix would be to crate one or more dummy .c files and accually try if a flag
  works.

Makefile
Rules.mak

index ce45583bca4d92f5c4e5f5d100b77fa10041a6a4..9841659fe43cfa055aae4cfabe7cc150e9f6afee 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -277,8 +277,7 @@ endif
        $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(LDFLAGS) -shared \
        $(CFLAGS_PIC) \
        -Wl,-soname=$(LD_LIBBUSYBOX).$(MAJOR_VERSION) \
-       -Wl,--enable-new-dtags -Wl,--reduce-memory-overheads \
-       -Wl,-z,combreloc -Wl,-shared -Wl,--as-needed -Wl,--warn-shared-textrel \
+       -Wl,-z,combreloc $(LIB_LDFLAGS) \
        -o $(@) \
        -Wl,--start-group -Wl,--whole-archive \
        $(LIBRARY_DEFINE) $(^) \
index 8652b00f4a2ae1e4d4f518e24a518d90b01f4c93..335cb3664fe002072b50a84935cbd919c5ff41fe 100644 (file)
--- a/Rules.mak
+++ b/Rules.mak
@@ -115,6 +115,20 @@ check_gcc=$(shell \
                then echo "$(1)"; else echo "$(2)"; fi \
        fi)
 
+# A not very robust macro to check for available ld flags
+check_ld=$(shell \
+       echo "checking='$(1)'" >> foo.txt ; \
+       if [ "x$(1)" != "x" ]; then \
+               $(LD) --help | grep -q \\$(1) && echo "-Wl,$(1)$(2)" ; \
+       fi)
+
+# A not very robust macro to check for available as flags
+check_as=$(shell \
+       if [ "x$(1)" != "x" ]; then \
+               $(AS) --help | grep -q "\\$(1)" && echo "-Wa,$(1)$(2)" ; \
+       fi)
+
+
 # Setup some shortcuts so that silent mode is silent like it should be
 ifeq ($(subst s,,$(MAKEFLAGS)),$(MAKEFLAGS))
 export MAKE_IS_SILENT=n
@@ -145,10 +159,15 @@ OPTIMIZATION+=$(call check_gcc,-funit-at-a-time,)
 PROG_CFLAGS+=$(call check_gcc,-fwhole-program,)
 endif # CONFIG_BUILD_AT_ONCE
 
+LIB_LDFLAGS:=$(call check_ld,--enable-new-dtags,)
+#LIB_LDFLAGS+=$(call check_ld,--reduce-memory-overheads,)
+#LIB_LDFLAGS+=$(call check_ld,--as-needed,)
+#LIB_LDFLAGS+=$(call check_ld,--warn-shared-textrel,)
+
+
 # Some nice architecture specific optimizations
 ifeq ($(strip $(TARGET_ARCH)),arm)
        OPTIMIZATION+=-fstrict-aliasing
-       OPTIMIZATION+=$(call check_gcc,-msingle-pic-base,)
 endif
 ifeq ($(strip $(TARGET_ARCH)),i386)
        OPTIMIZATION+=$(call check_gcc,-march=i386,)
@@ -169,7 +188,7 @@ ifeq ($(strip $(shell [ $(CC_MAJOR) -ge 4 -a $(CC_MINOR) -ge 1 ] ; echo $$?)),0)
        OPTIMIZATION+=$(call check_gcc,-fno-branch-count-reg,)
 endif # gcc-4.1 and beyond
 endif
-OPTIMIZATIONS:=$(OPTIMIZATION) -fomit-frame-pointer
+OPTIMIZATIONS:=$(OPTIMIZATION) $(call check_gcc,-fomit-frame-pointer,)
 
 #
 #--------------------------------------------------------
@@ -195,21 +214,22 @@ else
 endif
 ifeq ($(strip $(CONFIG_DEBUG)),y)
     CFLAGS  +=$(WARNINGS) -g -D_GNU_SOURCE
-    LDFLAGS +=-Wl,-warn-common
+    LDFLAGS += $(call check_ld,-warn-common,)
     STRIPCMD:=/bin/true -Not_stripping_since_we_are_debugging
 else
     CFLAGS+=$(WARNINGS) $(OPTIMIZATIONS) -D_GNU_SOURCE -DNDEBUG
-    LDFLAGS += -Wl,-warn-common -Wl,--sort-common 
+    LDFLAGS += $(call check_ld,-warn-common,)
+    LDFLAGS += $(call check_ld,--sort-common,)
     STRIPCMD:=$(STRIP) -s --remove-section=.note --remove-section=.comment
 endif
 ifeq ($(strip $(CONFIG_STATIC)),y)
-    LDFLAGS += --static
+    LDFLAGS += $(call check_ld,--static,)
 #else
 #    LIBRARIES += -ldl
 endif
 
 ifeq ($(strip $(CONFIG_BUILD_LIBBUSYBOX)),y)
-    CFLAGS_PIC:= -fPIC #-DPIC
+    CFLAGS_PIC:= $(call check_gcc,-fPIC,)
 endif
 
 ifeq ($(strip $(CONFIG_SELINUX)),y)