Collection of DPF-based plugins for packaging
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

338 lines
12KB

  1. # ===========================================================================
  2. # https://www.gnu.org/software/autoconf-archive/ax_sys_weak_alias.html
  3. # ===========================================================================
  4. #
  5. # SYNOPSIS
  6. #
  7. # AX_SYS_WEAK_ALIAS
  8. #
  9. # DESCRIPTION
  10. #
  11. # Determines whether weak aliases are supported on the system, and if so,
  12. # what scheme is used to declare them. Also checks to see if aliases can
  13. # cross object file boundaries, as some systems don't permit them to.
  14. #
  15. # Most systems permit something called a "weak alias" or "weak symbol."
  16. # These aliases permit a library to provide a stub form of a routine
  17. # defined in another library, thus allowing the first library to operate
  18. # even if the other library is not linked. This macro will check for
  19. # support of weak aliases, figure out what schemes are available, and
  20. # determine some characteristics of the weak alias support -- primarily,
  21. # whether a weak alias declared in one object file may be referenced from
  22. # another object file.
  23. #
  24. # There are four known schemes of declaring weak symbols; each scheme is
  25. # checked in turn, and the first one found is prefered. Note that only one
  26. # of the mentioned preprocessor macros will be defined!
  27. #
  28. # 1. Function attributes
  29. #
  30. # This scheme was first introduced by the GNU C compiler, and attaches
  31. # attributes to particular functions. It is among the easiest to use, and
  32. # so is the first one checked. If this scheme is detected, the
  33. # preprocessor macro HAVE_SYS_WEAK_ALIAS_ATTRIBUTE will be defined to 1.
  34. # This scheme is used as in the following code fragment:
  35. #
  36. # void __weakf(int c)
  37. # {
  38. # /* Function definition... */
  39. # }
  40. #
  41. # void weakf(int c) __attribute__((weak, alias("__weakf")));
  42. #
  43. # 2. #pragma weak
  44. #
  45. # This scheme is in use by many compilers other than the GNU C compiler.
  46. # It is also particularly easy to use, and fairly portable -- well, as
  47. # portable as these things get. If this scheme is detected first, the
  48. # preprocessor macro HAVE_SYS_WEAK_ALIAS_PRAGMA will be defined to 1. This
  49. # scheme is used as in the following code fragment:
  50. #
  51. # extern void weakf(int c);
  52. # #pragma weak weakf = __weakf
  53. # void __weakf(int c)
  54. # {
  55. # /* Function definition... */
  56. # }
  57. #
  58. # 3. #pragma _HP_SECONDARY_DEF
  59. #
  60. # This scheme appears to be in use by the HP compiler. As it is rather
  61. # specialized, this is one of the last schemes checked. If it is the first
  62. # one detected, the preprocessor macro HAVE_SYS_WEAK_ALIAS_HPSECONDARY
  63. # will be defined to 1. This scheme is used as in the following code
  64. # fragment:
  65. #
  66. # extern void weakf(int c);
  67. # #pragma _HP_SECONDARY_DEF __weakf weakf
  68. # void __weakf(int c)
  69. # {
  70. # /* Function definition... */
  71. # }
  72. #
  73. # 4. #pragma _CRI duplicate
  74. #
  75. # This scheme appears to be in use by the Cray compiler. As it is rather
  76. # specialized, it too is one of the last schemes checked. If it is the
  77. # first one detected, the preprocessor macro
  78. # HAVE_SYS_WEAK_ALIAS_CRIDUPLICATE will be defined to 1. This scheme is
  79. # used as in the following code fragment:
  80. #
  81. # extern void weakf(int c);
  82. # #pragma _CRI duplicate weakf as __weakf
  83. # void __weakf(int c)
  84. # {
  85. # /* Function definition... */
  86. # }
  87. #
  88. # In addition to the preprocessor macros listed above, if any scheme is
  89. # found, the preprocessor macro HAVE_SYS_WEAK_ALIAS will also be defined
  90. # to 1.
  91. #
  92. # Once a weak aliasing scheme has been found, a check will be performed to
  93. # see if weak aliases are honored across object file boundaries. If they
  94. # are, the HAVE_SYS_WEAK_ALIAS_CROSSFILE preprocessor macro is defined to
  95. # 1.
  96. #
  97. # This Autoconf macro also makes two substitutions. The first, WEAK_ALIAS,
  98. # contains the name of the scheme found (one of "attribute", "pragma",
  99. # "hpsecondary", or "criduplicate"), or "no" if no weak aliasing scheme
  100. # was found. The second, WEAK_ALIAS_CROSSFILE, is set to "yes" or "no"
  101. # depending on whether or not weak aliases may cross object file
  102. # boundaries.
  103. #
  104. # LICENSE
  105. #
  106. # Copyright (c) 2008 Kevin L. Mitchell <klmitch@mit.edu>
  107. #
  108. # Copying and distribution of this file, with or without modification, are
  109. # permitted in any medium without royalty provided the copyright notice
  110. # and this notice are preserved. This file is offered as-is, without any
  111. # warranty.
  112. #serial 7
  113. AU_ALIAS([KLM_SYS_WEAK_ALIAS], [AX_SYS_WEAK_ALIAS])
  114. AC_DEFUN([AX_SYS_WEAK_ALIAS], [
  115. # starting point: no aliasing scheme yet...
  116. ax_sys_weak_alias=no
  117. # Figure out what kind of aliasing may be supported...
  118. _AX_SYS_WEAK_ALIAS_ATTRIBUTE
  119. _AX_SYS_WEAK_ALIAS_PRAGMA
  120. _AX_SYS_WEAK_ALIAS_HPSECONDARY
  121. _AX_SYS_WEAK_ALIAS_CRIDUPLICATE
  122. # Do we actually support aliasing?
  123. AC_CACHE_CHECK([how to create weak aliases with $CC],
  124. [ax_cv_sys_weak_alias],
  125. [ax_cv_sys_weak_alias=$ax_sys_weak_alias])
  126. # OK, set a #define
  127. AS_IF([test $ax_cv_sys_weak_alias != no], [
  128. AC_DEFINE([HAVE_SYS_WEAK_ALIAS], 1,
  129. [Define this if your system can create weak aliases])
  130. ])
  131. # Can aliases cross object file boundaries?
  132. _AX_SYS_WEAK_ALIAS_CROSSFILE
  133. # OK, remember the results
  134. AC_SUBST([WEAK_ALIAS], [$ax_cv_sys_weak_alias])
  135. AC_SUBST([WEAK_ALIAS_CROSSFILE], [$ax_cv_sys_weak_alias_crossfile])
  136. ])
  137. AC_DEFUN([_AX_SYS_WEAK_ALIAS_ATTRIBUTE],
  138. [ # Test whether compiler accepts __attribute__ form of weak aliasing
  139. AC_CACHE_CHECK([whether $CC accepts function __attribute__((weak,alias()))],
  140. [ax_cv_sys_weak_alias_attribute], [
  141. # We add -Werror if it's gcc to force an error exit if the weak attribute
  142. # isn't understood
  143. AS_IF([test $GCC = yes], [
  144. save_CFLAGS=$CFLAGS
  145. CFLAGS=-Werror])
  146. # Try linking with a weak alias...
  147. AC_LINK_IFELSE([
  148. AC_LANG_PROGRAM([
  149. void __weakf(int c) {}
  150. void weakf(int c) __attribute__((weak, alias("__weakf")));],
  151. [weakf(0)])],
  152. [ax_cv_sys_weak_alias_attribute=yes],
  153. [ax_cv_sys_weak_alias_attribute=no])
  154. # Restore original CFLAGS
  155. AS_IF([test $GCC = yes], [
  156. CFLAGS=$save_CFLAGS])
  157. ])
  158. # What was the result of the test?
  159. AS_IF([test $ax_sys_weak_alias = no &&
  160. test $ax_cv_sys_weak_alias_attribute = yes], [
  161. ax_sys_weak_alias=attribute
  162. AC_DEFINE([HAVE_SYS_WEAK_ALIAS_ATTRIBUTE], 1,
  163. [Define this if weak aliases may be created with __attribute__])
  164. ])
  165. ])
  166. AC_DEFUN([_AX_SYS_WEAK_ALIAS_PRAGMA],
  167. [ # Test whether compiler accepts #pragma form of weak aliasing
  168. AC_CACHE_CHECK([whether $CC supports @%:@pragma weak],
  169. [ax_cv_sys_weak_alias_pragma], [
  170. # Try linking with a weak alias...
  171. AC_LINK_IFELSE([
  172. AC_LANG_PROGRAM([
  173. extern void weakf(int c);
  174. @%:@pragma weak weakf = __weakf
  175. void __weakf(int c) {}],
  176. [weakf(0)])],
  177. [ax_cv_sys_weak_alias_pragma=yes],
  178. [ax_cv_sys_weak_alias_pragma=no])
  179. ])
  180. # What was the result of the test?
  181. AS_IF([test $ax_sys_weak_alias = no &&
  182. test $ax_cv_sys_weak_alias_pragma = yes], [
  183. ax_sys_weak_alias=pragma
  184. AC_DEFINE([HAVE_SYS_WEAK_ALIAS_PRAGMA], 1,
  185. [Define this if weak aliases may be created with @%:@pragma weak])
  186. ])
  187. ])
  188. AC_DEFUN([_AX_SYS_WEAK_ALIAS_HPSECONDARY],
  189. [ # Test whether compiler accepts _HP_SECONDARY_DEF pragma from HP...
  190. AC_CACHE_CHECK([whether $CC supports @%:@pragma _HP_SECONDARY_DEF],
  191. [ax_cv_sys_weak_alias_hpsecondary], [
  192. # Try linking with a weak alias...
  193. AC_LINK_IFELSE([
  194. AC_LANG_PROGRAM([
  195. extern void weakf(int c);
  196. @%:@pragma _HP_SECONDARY_DEF __weakf weakf
  197. void __weakf(int c) {}],
  198. [weakf(0)])],
  199. [ax_cv_sys_weak_alias_hpsecondary=yes],
  200. [ax_cv_sys_weak_alias_hpsecondary=no])
  201. ])
  202. # What was the result of the test?
  203. AS_IF([test $ax_sys_weak_alias = no &&
  204. test $ax_cv_sys_weak_alias_hpsecondary = yes], [
  205. ax_sys_weak_alias=hpsecondary
  206. AC_DEFINE([HAVE_SYS_WEAK_ALIAS_HPSECONDARY], 1,
  207. [Define this if weak aliases may be created with @%:@pragma _HP_SECONDARY_DEF])
  208. ])
  209. ])
  210. AC_DEFUN([_AX_SYS_WEAK_ALIAS_CRIDUPLICATE],
  211. [ # Test whether compiler accepts "_CRI duplicate" pragma from Cray
  212. AC_CACHE_CHECK([whether $CC supports @%:@pragma _CRI duplicate],
  213. [ax_cv_sys_weak_alias_criduplicate], [
  214. # Try linking with a weak alias...
  215. AC_LINK_IFELSE([
  216. AC_LANG_PROGRAM([
  217. extern void weakf(int c);
  218. @%:@pragma _CRI duplicate weakf as __weakf
  219. void __weakf(int c) {}],
  220. [weakf(0)])],
  221. [ax_cv_sys_weak_alias_criduplicate=yes],
  222. [ax_cv_sys_weak_alias_criduplicate=no])
  223. ])
  224. # What was the result of the test?
  225. AS_IF([test $ax_sys_weak_alias = no &&
  226. test $ax_cv_sys_weak_alias_criduplicate = yes], [
  227. ax_sys_weak_alias=criduplicate
  228. AC_DEFINE([HAVE_SYS_WEAK_ALIAS_CRIDUPLICATE], 1,
  229. [Define this if weak aliases may be created with @%:@pragma _CRI duplicate])
  230. ])
  231. ])
  232. dnl Note: This macro is modeled closely on AC_LINK_IFELSE, and in fact
  233. dnl depends on some implementation details of that macro, particularly
  234. dnl its use of _AC_MSG_LOG_CONFTEST to log the failed test program and
  235. dnl its use of ac_link for running the linker.
  236. AC_DEFUN([_AX_SYS_WEAK_ALIAS_CROSSFILE],
  237. [ # Check to see if weak aliases can cross object file boundaries
  238. AC_CACHE_CHECK([whether $CC supports weak aliases across object file boundaries],
  239. [ax_cv_sys_weak_alias_crossfile], [
  240. AS_IF([test $ax_cv_sys_weak_alias = no],
  241. [ax_cv_sys_weak_alias_crossfile=no], [
  242. dnl Must build our own test files...
  243. # conftest1 contains our weak alias definition...
  244. cat >conftest1.$ac_ext <<_ACEOF
  245. /* confdefs.h. */
  246. _ACEOF
  247. cat confdefs.h >>conftest1.$ac_ext
  248. cat >>conftest1.$ac_ext <<_ACEOF
  249. /* end confdefs.h. */
  250. @%:@ifndef HAVE_SYS_WEAK_ALIAS_ATTRIBUTE
  251. extern void weakf(int c);
  252. @%:@endif
  253. @%:@if defined(HAVE_SYS_WEAK_ALIAS_PRAGMA)
  254. @%:@pragma weak weakf = __weakf
  255. @%:@elif defined(HAVE_SYS_WEAK_ALIAS_HPSECONDARY)
  256. @%:@pragma _HP_SECONDARY_DEF __weakf weakf
  257. @%:@elif defined(HAVE_SYS_WEAK_ALIAS_CRIDUPLICATE)
  258. @%:@pragma _CRI duplicate weakf as __weakf
  259. @%:@endif
  260. void __weakf(int c) {}
  261. @%:@ifdef HAVE_SYS_WEAK_ALIAS_ATTRIBUTE
  262. void weakf(int c) __attribute((weak, alias("__weakf")));
  263. @%:@endif
  264. _ACEOF
  265. # And conftest2 contains our main routine that calls it
  266. cat >conftest2.$ac_ext <<_ACEOF
  267. /* confdefs.h. */
  268. _ACEOF
  269. cat confdefs.h >> conftest2.$ac_ext
  270. cat >>conftest2.$ac_ext <<_ACEOF
  271. /* end confdefs.h. */
  272. extern void weakf(int c);
  273. int
  274. main ()
  275. {
  276. weakf(0);
  277. return 0;
  278. }
  279. _ACEOF
  280. # We must remove the object files (if any) ourselves...
  281. rm -f conftest2.$ac_objext conftest$ac_exeext
  282. # Change ac_link to compile *2* files together
  283. save_aclink=$ac_link
  284. ac_link=`echo "$ac_link" | \
  285. sed -e 's/conftest\(\.\$ac_ext\)/conftest1\1 conftest2\1/'`
  286. dnl Substitute our own routine for logging the conftest
  287. m4_pushdef([_AC_MSG_LOG_CONFTEST],
  288. [echo "$as_me: failed program was:" >&AS_MESSAGE_LOG_FD
  289. echo ">>> conftest1.$ac_ext" >&AS_MESSAGE_LOG_FD
  290. sed "s/^/| /" conftest1.$ac_ext >&AS_MESSAGE_LOG_FD
  291. echo ">>> conftest2.$ac_ext" >&AS_MESSAGE_LOG_FD
  292. sed "s/^/| /" conftest2.$ac_ext >&AS_MESSAGE_LOG_FD
  293. ])dnl
  294. # Since we created the files ourselves, don't use SOURCE argument
  295. AC_LINK_IFELSE(, [ax_cv_sys_weak_alias_crossfile=yes],
  296. [ax_cv_sys_weak_alias_crossfile=no])
  297. dnl Restore _AC_MSG_LOG_CONFTEST
  298. m4_popdef([_AC_MSG_LOG_CONFTEST])dnl
  299. # Restore ac_link
  300. ac_link=$save_aclink
  301. # We must remove the object files (if any) and C files ourselves...
  302. rm -f conftest1.$ac_ext conftest2.$ac_ext \
  303. conftest1.$ac_objext conftest2.$ac_objext
  304. ])
  305. ])
  306. # What were the results of the test?
  307. AS_IF([test $ax_cv_sys_weak_alias_crossfile = yes], [
  308. AC_DEFINE([HAVE_SYS_WEAK_ALIAS_CROSSFILE], 1,
  309. [Define this if weak aliases in other files are honored])
  310. ])
  311. ])