ax_check_vscript.m4 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. # ===========================================================================
  2. # https://www.gnu.org/software/autoconf-archive/ax_check_vscript.html
  3. # ===========================================================================
  4. #
  5. # SYNOPSIS
  6. #
  7. # AX_CHECK_VSCRIPT
  8. #
  9. # DESCRIPTION
  10. #
  11. # Check whether the linker supports version scripts. Version scripts are
  12. # used when building shared libraries to bind symbols to version nodes
  13. # (helping to detect incompatibilities) or to limit the visibility of
  14. # non-public symbols.
  15. #
  16. # Output:
  17. #
  18. # If version scripts are supported, VSCRIPT_LDFLAGS will contain the
  19. # appropriate flag to pass to the linker. On GNU systems this would
  20. # typically be "-Wl,--version-script", and on Solaris it would typically
  21. # be "-Wl,-M".
  22. #
  23. # Two Automake conditionals are also set:
  24. #
  25. # HAVE_VSCRIPT is true if the linker supports version scripts with
  26. # entries that use simple wildcards, like "local: *".
  27. #
  28. # HAVE_VSCRIPT_COMPLEX is true if the linker supports version scripts with
  29. # pattern matching wildcards, like "global: Java_*".
  30. #
  31. # On systems that do not support symbol versioning, such as Mac OS X, both
  32. # conditionals will be false. They will also be false if the user passes
  33. # "--disable-symvers" on the configure command line.
  34. #
  35. # Example:
  36. #
  37. # configure.ac:
  38. #
  39. # AX_CHECK_VSCRIPT
  40. #
  41. # Makefile.am:
  42. #
  43. # if HAVE_VSCRIPT
  44. # libfoo_la_LDFLAGS += $(VSCRIPT_LDFLAGS),@srcdir@/libfoo.map
  45. # endif
  46. #
  47. # if HAVE_VSCRIPT_COMPLEX
  48. # libbar_la_LDFLAGS += $(VSCRIPT_LDFLAGS),@srcdir@/libbar.map
  49. # endif
  50. #
  51. # LICENSE
  52. #
  53. # Copyright (c) 2014 Kevin Cernekee <cernekee@gmail.com>
  54. #
  55. # Copying and distribution of this file, with or without modification, are
  56. # permitted in any medium without royalty provided the copyright notice
  57. # and this notice are preserved. This file is offered as-is, without any
  58. # warranty.
  59. #serial 2
  60. # _AX_CHECK_VSCRIPT(flag, global-sym, action-if-link-succeeds, [junk-file=no])
  61. AC_DEFUN([_AX_CHECK_VSCRIPT], [
  62. AC_LANG_PUSH([C])
  63. ax_check_vscript_save_flags="$LDFLAGS"
  64. echo "V1 { global: $2; local: *; };" > conftest.map
  65. AS_IF([test x$4 = xyes], [
  66. echo "{" >> conftest.map
  67. ])
  68. LDFLAGS="$LDFLAGS -Wl,$1,conftest.map"
  69. AC_LINK_IFELSE([AC_LANG_PROGRAM([[int show, hide;]], [])], [$3])
  70. LDFLAGS="$ax_check_vscript_save_flags"
  71. rm -f conftest.map
  72. AC_LANG_POP([C])
  73. ]) dnl _AX_CHECK_VSCRIPT
  74. AC_DEFUN([AX_CHECK_VSCRIPT], [
  75. AC_ARG_ENABLE([symvers],
  76. AS_HELP_STRING([--disable-symvers],
  77. [disable library symbol versioning [default=auto]]),
  78. [want_symvers=$enableval],
  79. [want_symvers=yes]
  80. )
  81. AS_IF([test x$want_symvers = xyes], [
  82. dnl First test --version-script and -M with a simple wildcard.
  83. AC_CACHE_CHECK([linker version script flag], ax_cv_check_vscript_flag, [
  84. ax_cv_check_vscript_flag=unsupported
  85. _AX_CHECK_VSCRIPT([--version-script], [show], [
  86. ax_cv_check_vscript_flag=--version-script
  87. ])
  88. AS_IF([test x$ax_cv_check_vscript_flag = xunsupported], [
  89. _AX_CHECK_VSCRIPT([-M], [show], [ax_cv_check_vscript_flag=-M])
  90. ])
  91. dnl The linker may interpret -M (no argument) as "produce a load map."
  92. dnl If "-M conftest.map" doesn't fail when conftest.map contains
  93. dnl obvious syntax errors, assume this is the case.
  94. AS_IF([test x$ax_cv_check_vscript_flag != xunsupported], [
  95. _AX_CHECK_VSCRIPT([$ax_cv_check_vscript_flag], [show],
  96. [ax_cv_check_vscript_flag=unsupported], [yes])
  97. ])
  98. ])
  99. dnl If the simple wildcard worked, retest with a complex wildcard.
  100. AS_IF([test x$ax_cv_check_vscript_flag != xunsupported], [
  101. ax_check_vscript_flag=$ax_cv_check_vscript_flag
  102. AC_CACHE_CHECK([if version scripts can use complex wildcards],
  103. ax_cv_check_vscript_complex_wildcards, [
  104. ax_cv_check_vscript_complex_wildcards=no
  105. _AX_CHECK_VSCRIPT([$ax_cv_check_vscript_flag], [sh*], [
  106. ax_cv_check_vscript_complex_wildcards=yes])
  107. ])
  108. ax_check_vscript_complex_wildcards="$ax_cv_check_vscript_complex_wildcards"
  109. ], [
  110. ax_check_vscript_flag=
  111. ax_check_vscript_complex_wildcards=no
  112. ])
  113. ], [
  114. AC_MSG_CHECKING([linker version script flag])
  115. AC_MSG_RESULT([disabled])
  116. ax_check_vscript_flag=
  117. ax_check_vscript_complex_wildcards=no
  118. ])
  119. AS_IF([test x$ax_check_vscript_flag != x], [
  120. VSCRIPT_LDFLAGS="-Wl,$ax_check_vscript_flag"
  121. AC_SUBST([VSCRIPT_LDFLAGS])
  122. ])
  123. AM_CONDITIONAL([HAVE_VSCRIPT],
  124. [test x$ax_check_vscript_flag != x])
  125. AM_CONDITIONAL([HAVE_VSCRIPT_COMPLEX],
  126. [test x$ax_check_vscript_complex_wildcards = xyes])
  127. ]) dnl AX_CHECK_VSCRIPT