Test whether ld flags exist before using them
[ghc.git] / aclocal.m4
index f6f1f2b..4d65e4e 100644 (file)
@@ -426,8 +426,16 @@ AC_DEFUN([FPTOOLS_SET_C_LD_FLAGS],
     fi
 
     # Reduce memory usage when linking. See trac #5240.
-    $3="$$3 -Wl,--hash-size=31 -Wl,--reduce-memory-overheads"
-    $4="$$4     --hash-size=31     --reduce-memory-overheads"
+    if test -n "$LdHashSize31"
+    then
+        $3="$$3 -Wl,$LdHashSize31"
+        $4="$$4     $LdHashSize31"
+    fi
+    if test -n "$LdReduceMemoryOverheads"
+    then
+        $3="$$3 -Wl,$LdReduceMemoryOverheads"
+        $4="$$4     $LdReduceMemoryOverheads"
+    fi
 
     rm -f conftest.c conftest.o
     AC_MSG_RESULT([done])
@@ -774,30 +782,57 @@ AC_SUBST(Alex3)
 ])
 
 
-# FP_PROG_LD_X
-# ------------
-# Sets the output variable LdXFlag to -x if ld supports this flag, otherwise the
-# variable's value is empty.
-AC_DEFUN([FP_PROG_LD_X],
+# FP_PROG_LD_FLAG
+# ---------------
+# Sets the output variable $2 to $1 if ld supports the $1 flag.
+# Otherwise the variable's value is empty.
+AC_DEFUN([FP_PROG_LD_FLAG],
 [
-AC_CACHE_CHECK([whether ld understands -x], [fp_cv_ld_x],
+AC_CACHE_CHECK([whether ld understands $1], [fp_cv_$2],
 [echo 'foo() {}' > conftest.c
 ${CC-cc} -c conftest.c
-if ${LdCmd} -r -x -o conftest2.o conftest.o > /dev/null 2>&1; then
-   fp_cv_ld_x=yes
+if ${LdCmd} -r $1 -o conftest2.o conftest.o > /dev/null 2>&1; then
+   fp_cv_$2=$1
 else
-   fp_cv_ld_x=no
+   fp_cv_$2=
 fi
 rm -rf conftest*])
-if test "$fp_cv_ld_x" = yes; then
-  LdXFlag=-x
-else
-  LdXFlag=
-fi
+$2=$fp_cv_$2
+])# FP_PROG_LD_FLAG
+
+
+# FP_PROG_LD_X
+# ------------
+# Sets the output variable LdXFlag to -x if ld supports this flag.
+# Otherwise the variable's value is empty.
+AC_DEFUN([FP_PROG_LD_X],
+[
+FP_PROG_LD_FLAG([-x],[LdXFlag])
 AC_SUBST([LdXFlag])
 ])# FP_PROG_LD_X
 
 
+# FP_PROG_LD_HashSize31
+# ------------
+# Sets the output variable LdHashSize31 to --hash-size=31 if ld supports
+# this flag. Otherwise the variable's value is empty.
+AC_DEFUN([FP_PROG_LD_HashSize31],
+[
+FP_PROG_LD_FLAG([--hash-size=31],[LdHashSize31])
+])# FP_PROG_LD_HashSize31
+
+
+# FP_PROG_LD_ReduceMemoryOverheads
+# ------------
+# Sets the output variable LdReduceMemoryOverheads to
+# --reduce-memory-overheads if ld supports this flag.
+# Otherwise the variable's value is empty.
+AC_DEFUN([FP_PROG_LD_ReduceMemoryOverheads],
+[
+FP_PROG_LD_FLAG([--reduce-memory-overheads],[LdReduceMemoryOverheads])
+])# FP_PROG_LD_ReduceMemoryOverheads
+
+
 # FP_PROG_LD_BUILD_ID
 # ------------