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.

190 lines
6.1KB

  1. # ===========================================================================
  2. # https://www.gnu.org/software/autoconf-archive/ax_lib_trace.html
  3. # ===========================================================================
  4. #
  5. # SYNOPSIS
  6. #
  7. # AX_LIB_TRACE([MINIMUM-VERSION], [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
  8. #
  9. # DESCRIPTION
  10. #
  11. # Test for the libtrace libraries of a particular version (or newer)
  12. #
  13. # If no path to the installed library is given the macro searches under
  14. # /usr, /usr/local, /opt and /opt/local.
  15. #
  16. # This macro calls:
  17. #
  18. # AC_SUBST(LIBTRACE_CFLAGS) / AC_SUBST(LIBTRACE_LDFLAGS)
  19. #
  20. # And sets:
  21. #
  22. # HAVE_LIBTRACE
  23. #
  24. # LICENSE
  25. #
  26. # Copyright (c) 2011 Xiyue Deng <manphiz@gmail.com>
  27. #
  28. # Copying and distribution of this file, with or without modification, are
  29. # permitted in any medium without royalty provided the copyright notice
  30. # and this notice are preserved. This file is offered as-is, without any
  31. # warranty.
  32. #serial 2
  33. AC_DEFUN([AX_LIB_TRACE],
  34. [
  35. AC_ARG_WITH([libtrace],
  36. [AS_HELP_STRING([--with-libtrace@<:@=ARG@:>@],
  37. [use libtrace from a standard location (ARG=yes),
  38. from the specified location (ARG=<path>),
  39. or disable if (ARG=no)
  40. @<:@ARG=yes@:>@ ])],
  41. [
  42. if test "x$withval" = "xno"; then
  43. want_libtrace="no"
  44. elif test "x$withval" = "xyes"; then
  45. want_libtrace="yes"
  46. else
  47. want_libtrace="yes"
  48. ac_libtrace_path="$withval"
  49. fi
  50. ],
  51. [want_libtrace="yes"])
  52. AC_ARG_WITH([libtrace-include],
  53. [AS_HELP_STRING([--with-libtrace-include=INCLUDE_DIR],
  54. [Force given directory for libtrace include path. Note that this will overwrite general library path setting.])
  55. ], [
  56. if test -d "$withval"; then
  57. ac_libtrace_include_path="$withval"
  58. else
  59. AC_MSG_ERROR([--with-libtrace-include expected directory name])
  60. fi
  61. ],
  62. [ac_libtrace_include_path=""]
  63. )
  64. AC_ARG_WITH([libtrace-lib],
  65. [AS_HELP_STRING([--with-libtrace-lib=LIB_DIR],
  66. [Force given directory for libtrace libraries. Note that this will overwrite general library path setting.])
  67. ], [
  68. if test -d "$withval"; then
  69. ac_libtrace_lib_path="$withval"
  70. else
  71. AC_MSG_ERROR([--with-libtrace-lib expected directory name])
  72. fi
  73. ],
  74. [ac_libtrace_lib_path=""]
  75. )
  76. if test "x$want_libtrace" = "xyes"; then
  77. libtrace_version_req=ifelse([$1], ,3.0.0,$1)
  78. libtrace_version_req_major=`expr $libtrace_version_req : '\([[0-9]]*\)'`
  79. libtrace_version_req_minor=`expr $libtrace_version_req : '[[0-9]]*\.\([[0-9]]*\)'`
  80. libtrace_version_req_macro=`expr $libtrace_version_req : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'`
  81. if test "x$libtrace_version_req_macro" = "x"; then
  82. libtrace_version_req_macro="0"
  83. fi
  84. succeeded=no
  85. dnl On x86_64 systems check for system libraries in both lib64 and lib.
  86. dnl The former is specified by FHS, but e.g. Debian does not adhere to
  87. dnl this (as it rises problems for generic multi-arch support).
  88. dnl The last entry in the list is chosen by default when no libraries
  89. dnl are found, e.g. when only header-only libraries are installed!
  90. libsubdirs="lib"
  91. if test `uname -m` = x86_64; then
  92. libsubdirs="lib lib64"
  93. fi
  94. if test "x$ac_libtrace_path" != "x"; then
  95. for libsubdir in $libsubdirs ; do
  96. if ls "$ac_libtrace_path/$libsubdir/libtrace"* >/dev/null 2>&1 ; then
  97. LIBTRACE_LDFLAGS="-L$ac_libtrace_path/$libsubdir"
  98. LIBTRACE_CFLAGS="-I$ac_libtrace_path/include"
  99. break;
  100. fi
  101. done
  102. elif test "x$cross_compiling" != yes; then
  103. for ac_libtrace_path_tmp in /usr /usr/local /opt /opt/local ; do
  104. for libsubdir in $libsubdirs ; do
  105. if ls "$ac_libtrace_path_tmp/$libsubdir/libtrace"* >/dev/null 2>&1 ; then
  106. LIBTRACE_LDFLAGS="-L$ac_libtrace_path_tmp/$libsubdir"
  107. LIBTRACE_CFLAGS="-I$ac_libtrace_path_tmp/include"
  108. break;
  109. fi
  110. done
  111. done
  112. fi
  113. if test "x$ac_libtrace_include_path" != "x" ; then
  114. LIBTRACE_CFLAGS="-I$ac_libtrace_include_path"
  115. fi
  116. if test "x$ac_libtrace_lib_path" != "x" ; then
  117. LIBTRACE_LDFLAGS="-L$ac_libtrace_lib_path"
  118. fi
  119. CFLAGS_SAVED="$CFLAGS"
  120. CFLAGS="$CFLAGS $LIBTRACE_CFLAGS"
  121. export CFLAGS
  122. LDFLAGS_SAVED="$LDFLAGS"
  123. LDFLAGS="$LDFLAGS $LIBTRACE_LDFLAGS"
  124. export LDFLAGS
  125. AC_CACHE_CHECK([for libtrace >= $libtrace_version_req],
  126. ax_cv_libtrace_version_check,
  127. [AC_COMPILE_IFELSE(
  128. [AC_LANG_PROGRAM([[
  129. @%:@include <libtrace.h>
  130. ]], [[
  131. #if !defined(LIBTRACE_API_VERSION)
  132. || (LIBTRACE_API_VERSION < (($libtrace_version_req_major<<16)|($libtrace_version_req_minor<<8)|($libtrace_version_req_macro)))
  133. # error Version check failed!
  134. #endif
  135. return 0;
  136. ]]
  137. )], [
  138. ax_cv_libtrace_version_check=yes
  139. ], [
  140. ax_cv_libtrace_version_check=no
  141. ]
  142. )]
  143. )
  144. AS_IF([test "x$ax_cv_libtrace_version_check" != "xyes"], [
  145. AC_MSG_ERROR([Could not find working libtrace $libtrace_version_req installation.])
  146. ])
  147. AC_CHECK_LIB([trace], [main], [
  148. LIBTRACE_LDFLAGS="$LIBTRACE_LDFLAGS -ltrace"
  149. succeeded=yes
  150. ], [
  151. AC_MSG_ERROR([Could not find working libtrace library.])
  152. ax_cv_libtrace_link=no
  153. ])
  154. if test "x$succeeded" = "xyes"; then
  155. AC_SUBST(LIBTRACE_CFLAGS)
  156. AC_SUBST(LIBTRACE_LDFLAGS)
  157. AC_DEFINE(HAVE_LIBTRACE, , [define if libtrace is available])
  158. ifelse([$2], , :, [$2])
  159. else
  160. AC_MSG_NOTICE([[Could not detect the libtrace installation (>= $libtrace_version_req). Please make sure you have a working libtrace installation and specify its path with --with-libtrace option.]])
  161. ifelse([$3], , :, [$3])
  162. fi
  163. CFLAGS="$CFLAGS_SAVED"
  164. export CFLAGS
  165. LDFLAGS="$LDFLAGS_SAVED"
  166. export LDFLAGS
  167. fi
  168. ])