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.

165 lines
5.4KB

  1. # ===========================================================================
  2. # https://www.gnu.org/software/autoconf-archive/ax_lib_postgresql.html
  3. # ===========================================================================
  4. #
  5. # SYNOPSIS
  6. #
  7. # AX_LIB_POSTGRESQL([MINIMUM-VERSION])
  8. #
  9. # DESCRIPTION
  10. #
  11. # This macro provides tests of availability of PostgreSQL 'libpq' library
  12. # of particular version or newer.
  13. #
  14. # AX_LIB_POSTGRESQL macro takes only one argument which is optional. If
  15. # there is no required version passed, then macro does not run version
  16. # test.
  17. #
  18. # The --with-postgresql option takes one of three possible values:
  19. #
  20. # no - do not check for PostgreSQL client library
  21. #
  22. # yes - do check for PostgreSQL library in standard locations (pg_config
  23. # should be in the PATH)
  24. #
  25. # path - complete path to pg_config utility, use this option if pg_config
  26. # can't be found in the PATH
  27. #
  28. # This macro calls:
  29. #
  30. # AC_SUBST(POSTGRESQL_CPPFLAGS)
  31. # AC_SUBST(POSTGRESQL_LDFLAGS)
  32. # AC_SUBST(POSTGRESQL_LIBS)
  33. # AC_SUBST(POSTGRESQL_VERSION)
  34. #
  35. # And sets:
  36. #
  37. # HAVE_POSTGRESQL
  38. #
  39. # LICENSE
  40. #
  41. # Copyright (c) 2008 Mateusz Loskot <mateusz@loskot.net>
  42. # Copyright (c) 2014 Sree Harsha Totakura <sreeharsha@totakura.in>
  43. #
  44. # Copying and distribution of this file, with or without modification, are
  45. # permitted in any medium without royalty provided the copyright notice
  46. # and this notice are preserved. This file is offered as-is, without any
  47. # warranty.
  48. #serial 15
  49. AC_DEFUN([AX_LIB_POSTGRESQL],
  50. [
  51. AC_ARG_WITH([postgresql],
  52. AS_HELP_STRING([--with-postgresql=@<:@ARG@:>@],
  53. [use PostgreSQL library @<:@default=yes@:>@, optionally specify path to pg_config]
  54. ),
  55. [
  56. if test "$withval" = "no"; then
  57. want_postgresql="no"
  58. elif test "$withval" = "yes"; then
  59. want_postgresql="yes"
  60. else
  61. want_postgresql="yes"
  62. PG_CONFIG="$withval"
  63. fi
  64. ],
  65. [want_postgresql="yes"]
  66. )
  67. POSTGRESQL_CPPFLAGS=""
  68. POSTGRESQL_LDFLAGS=""
  69. POSTGRESQL_LIBS=""
  70. POSTGRESQL_VERSION=""
  71. dnl
  72. dnl Check PostgreSQL libraries (libpq)
  73. dnl
  74. if test "$want_postgresql" = "yes"; then
  75. if test -z "$PG_CONFIG" -o test; then
  76. AC_PATH_PROG([PG_CONFIG], [pg_config], [])
  77. fi
  78. if test ! -x "$PG_CONFIG"; then
  79. AC_MSG_ERROR([$PG_CONFIG does not exist or it is not an executable file])
  80. PG_CONFIG="no"
  81. found_postgresql="no"
  82. fi
  83. if test "$PG_CONFIG" != "no"; then
  84. AC_MSG_CHECKING([for PostgreSQL libraries])
  85. POSTGRESQL_CPPFLAGS="-I`$PG_CONFIG --includedir`"
  86. POSTGRESQL_LDFLAGS="-L`$PG_CONFIG --libdir`"
  87. POSTGRESQL_LIBS="-lpq"
  88. POSTGRESQL_VERSION=`$PG_CONFIG --version | sed -e 's#PostgreSQL ##'`
  89. AC_DEFINE([HAVE_POSTGRESQL], [1],
  90. [Define to 1 if PostgreSQL libraries are available])
  91. found_postgresql="yes"
  92. AC_MSG_RESULT([yes])
  93. else
  94. found_postgresql="no"
  95. AC_MSG_RESULT([no])
  96. fi
  97. fi
  98. dnl
  99. dnl Check if required version of PostgreSQL is available
  100. dnl
  101. postgresql_version_req=ifelse([$1], [], [], [$1])
  102. if test "$found_postgresql" = "yes" -a -n "$postgresql_version_req"; then
  103. AC_MSG_CHECKING([if PostgreSQL version is >= $postgresql_version_req])
  104. dnl Decompose required version string of PostgreSQL
  105. dnl and calculate its number representation
  106. postgresql_version_req_major=`expr $postgresql_version_req : '\([[0-9]]*\)'`
  107. postgresql_version_req_minor=`expr $postgresql_version_req : '[[0-9]]*\.\([[0-9]]*\)'`
  108. postgresql_version_req_micro=`expr $postgresql_version_req : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'`
  109. if test "x$postgresql_version_req_micro" = "x"; then
  110. postgresql_version_req_micro="0"
  111. fi
  112. postgresql_version_req_number=`expr $postgresql_version_req_major \* 1000000 \
  113. \+ $postgresql_version_req_minor \* 1000 \
  114. \+ $postgresql_version_req_micro`
  115. dnl Decompose version string of installed PostgreSQL
  116. dnl and calculate its number representation
  117. postgresql_version_major=`expr $POSTGRESQL_VERSION : '\([[0-9]]*\)'`
  118. postgresql_version_minor=`expr $POSTGRESQL_VERSION : '[[0-9]]*\.\([[0-9]]*\)'`
  119. postgresql_version_micro=`expr $POSTGRESQL_VERSION : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'`
  120. if test "x$postgresql_version_micro" = "x"; then
  121. postgresql_version_micro="0"
  122. fi
  123. postgresql_version_number=`expr $postgresql_version_major \* 1000000 \
  124. \+ $postgresql_version_minor \* 1000 \
  125. \+ $postgresql_version_micro`
  126. postgresql_version_check=`expr $postgresql_version_number \>\= $postgresql_version_req_number`
  127. if test "$postgresql_version_check" = "1"; then
  128. AC_MSG_RESULT([yes])
  129. else
  130. AC_MSG_RESULT([no])
  131. AC_DEFINE([HAVE_POSTGRESQL], [0],
  132. [A required version of PostgreSQL is not found])
  133. POSTGRESQL_CPPFLAGS=""
  134. POSTGRESQL_LDFLAGS=""
  135. POSTGRESQL_LIBS=""
  136. fi
  137. fi
  138. AC_SUBST([POSTGRESQL_VERSION])
  139. AC_SUBST([POSTGRESQL_CPPFLAGS])
  140. AC_SUBST([POSTGRESQL_LDFLAGS])
  141. AC_SUBST([POSTGRESQL_LIBS])
  142. ])