1#
2# Get the linker version string.
3#
4# This macro is specific to LLVM.
5#
6AC_DEFUN([AC_LINK_GET_VERSION],
7  [AC_CACHE_CHECK([for linker version],[llvm_cv_link_version],
8  [
9   version_string="$(ld -v 2>&1 | head -1)"
10
11   # Check for ld64.
12   if (echo "$version_string" | grep -q "ld64"); then
13     llvm_cv_link_version=$(echo "$version_string" | sed -e "s#.*ld64-\([^ ]*\)\( (.*)\)\{0,1\}#\1#")
14   else
15     llvm_cv_link_version=$(echo "$version_string" | sed -e "s#[^0-9]*\([0-9.]*\).*#\1#")
16   fi
17  ])
18  AC_DEFINE_UNQUOTED([HOST_LINK_VERSION],"$llvm_cv_link_version",
19                     [Linker version detected at compile time.])
20])
21
22#
23# Determine if the system can handle the -R option being passed to the linker.
24#
25# This macro is specific to LLVM.
26#
27AC_DEFUN([AC_LINK_USE_R],
28[AC_CACHE_CHECK([for compiler -Wl,-R<path> option],[llvm_cv_link_use_r],
29[ AC_LANG_PUSH([C])
30  oldcflags="$CFLAGS"
31  CFLAGS="$CFLAGS -Wl,-R."
32  AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],[[]])],
33    [llvm_cv_link_use_r=yes],[llvm_cv_link_use_r=no])
34  CFLAGS="$oldcflags"
35  AC_LANG_POP([C])
36])
37if test "$llvm_cv_link_use_r" = yes ; then
38  AC_DEFINE([HAVE_LINK_R],[1],[Define if you can use -Wl,-R. to pass -R. to the linker, in order to add the current directory to the dynamic linker search path.])
39  fi
40])
41
42#
43# Determine if the system can handle the -R option being passed to the linker.
44#
45# This macro is specific to LLVM.
46#
47AC_DEFUN([AC_LINK_EXPORT_DYNAMIC],
48[AC_CACHE_CHECK([for compiler -Wl,-export-dynamic option],
49                [llvm_cv_link_use_export_dynamic],
50[ AC_LANG_PUSH([C])
51  oldcflags="$CFLAGS"
52  CFLAGS="$CFLAGS -Wl,-export-dynamic"
53  AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],[[]])],
54    [llvm_cv_link_use_export_dynamic=yes],[llvm_cv_link_use_export_dynamic=no])
55  CFLAGS="$oldcflags"
56  AC_LANG_POP([C])
57])
58if test "$llvm_cv_link_use_export_dynamic" = yes ; then
59  AC_DEFINE([HAVE_LINK_EXPORT_DYNAMIC],[1],[Define if you can use -Wl,-export-dynamic.])
60  fi
61])
62
63#
64# Determine if the system can handle the --version-script option being
65# passed to the linker.
66#
67# This macro is specific to LLVM.
68#
69AC_DEFUN([AC_LINK_VERSION_SCRIPT],
70[AC_CACHE_CHECK([for compiler -Wl,--version-script option],
71                [llvm_cv_link_use_version_script],
72[ AC_LANG_PUSH([C])
73  oldcflags="$CFLAGS"
74
75  # The following code is from the autoconf manual,
76  # "11.13: Limitations of Usual Tools".
77  # Create a temporary directory $tmp in $TMPDIR (default /tmp).
78  # Use mktemp if possible; otherwise fall back on mkdir,
79  # with $RANDOM to make collisions less likely.
80  : ${TMPDIR=/tmp}
81  {
82    tmp=`
83      (umask 077 && mktemp -d "$TMPDIR/fooXXXXXX") 2>/dev/null
84    ` &&
85    test -n "$tmp" && test -d "$tmp"
86  } || {
87    tmp=$TMPDIR/foo$$-$RANDOM
88    (umask 077 && mkdir "$tmp")
89  } || exit $?
90
91  echo "{" > "$tmp/export.map"
92  echo "  global: main;" >> "$tmp/export.map"
93  echo "  local: *;" >> "$tmp/export.map"
94  echo "};" >> "$tmp/export.map"
95
96  CFLAGS="$CFLAGS -Wl,--version-script=$tmp/export.map"
97  AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],[[]])],
98    [llvm_cv_link_use_version_script=yes],[llvm_cv_link_use_version_script=no])
99  rm "$tmp/export.map"
100  rmdir "$tmp"
101  CFLAGS="$oldcflags"
102  AC_LANG_POP([C])
103])
104if test "$llvm_cv_link_use_version_script" = yes ; then
105  AC_SUBST(HAVE_LINK_VERSION_SCRIPT,1)
106  fi
107])
108
109