ax_lib_postgresql.m4 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. # ===========================================================================
  2. # http://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_VERSION)
  33. #
  34. # And sets:
  35. #
  36. # HAVE_POSTGRESQL
  37. #
  38. # LICENSE
  39. #
  40. # Copyright (c) 2008 Mateusz Loskot <mateusz@loskot.net>
  41. #
  42. # Copying and distribution of this file, with or without modification, are
  43. # permitted in any medium without royalty provided the copyright notice
  44. # and this notice are preserved. This file is offered as-is, without any
  45. # warranty.
  46. #serial 9
  47. AC_DEFUN([AX_LIB_POSTGRESQL],
  48. [
  49. AC_ARG_WITH([postgresql],
  50. AS_HELP_STRING([--with-postgresql=@<:@ARG@:>@],
  51. [use PostgreSQL library @<:@default=yes@:>@, optionally specify path to pg_config]
  52. ),
  53. [
  54. if test "$withval" = "no"; then
  55. want_postgresql="no"
  56. elif test "$withval" = "yes"; then
  57. want_postgresql="yes"
  58. else
  59. want_postgresql="yes"
  60. PG_CONFIG="$withval"
  61. fi
  62. ],
  63. [want_postgresql="yes"]
  64. )
  65. POSTGRESQL_CPPFLAGS=""
  66. POSTGRESQL_LDFLAGS=""
  67. POSTGRESQL_VERSION=""
  68. dnl
  69. dnl Check PostgreSQL libraries (libpq)
  70. dnl
  71. if test "$want_postgresql" = "yes"; then
  72. if test -z "$PG_CONFIG" -o test; then
  73. AC_PATH_PROG([PG_CONFIG], [pg_config], [])
  74. fi
  75. if test ! -x "$PG_CONFIG"; then
  76. dnl AC_MSG_ERROR([$PG_CONFIG does not exist or it is not an exectuable file])
  77. PG_CONFIG="no"
  78. found_postgresql="no"
  79. fi
  80. if test "$PG_CONFIG" != "no"; then
  81. AC_MSG_CHECKING([for PostgreSQL libraries])
  82. POSTGRESQL_CPPFLAGS="-I`$PG_CONFIG --includedir`"
  83. POSTGRESQL_LDFLAGS="-L`$PG_CONFIG --libdir`"
  84. POSTGRESQL_VERSION=`$PG_CONFIG --version | sed -e 's#PostgreSQL ##'`
  85. AC_DEFINE([HAVE_POSTGRESQL], [1],
  86. [Define to 1 if PostgreSQL libraries are available])
  87. found_postgresql="yes"
  88. AC_MSG_RESULT([yes])
  89. else
  90. found_postgresql="no"
  91. AC_MSG_RESULT([no])
  92. fi
  93. fi
  94. dnl
  95. dnl Check if required version of PostgreSQL is available
  96. dnl
  97. postgresql_version_req=ifelse([$1], [], [], [$1])
  98. if test "$found_postgresql" = "yes" -a -n "$postgresql_version_req"; then
  99. AC_MSG_CHECKING([if PostgreSQL version is >= $postgresql_version_req])
  100. dnl Decompose required version string of PostgreSQL
  101. dnl and calculate its number representation
  102. postgresql_version_req_major=`expr $postgresql_version_req : '\([[0-9]]*\)'`
  103. postgresql_version_req_minor=`expr $postgresql_version_req : '[[0-9]]*\.\([[0-9]]*\)'`
  104. postgresql_version_req_micro=`expr $postgresql_version_req : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'`
  105. if test "x$postgresql_version_req_micro" = "x"; then
  106. postgresql_version_req_micro="0"
  107. fi
  108. postgresql_version_req_number=`expr $postgresql_version_req_major \* 1000000 \
  109. \+ $postgresql_version_req_minor \* 1000 \
  110. \+ $postgresql_version_req_micro`
  111. dnl Decompose version string of installed PostgreSQL
  112. dnl and calculate its number representation
  113. postgresql_version_major=`expr $POSTGRESQL_VERSION : '\([[0-9]]*\)'`
  114. postgresql_version_minor=`expr $POSTGRESQL_VERSION : '[[0-9]]*\.\([[0-9]]*\)'`
  115. postgresql_version_micro=`expr $POSTGRESQL_VERSION : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'`
  116. if test "x$postgresql_version_micro" = "x"; then
  117. postgresql_version_micro="0"
  118. fi
  119. postgresql_version_number=`expr $postgresql_version_major \* 1000000 \
  120. \+ $postgresql_version_minor \* 1000 \
  121. \+ $postgresql_version_micro`
  122. postgresql_version_check=`expr $postgresql_version_number \>\= $postgresql_version_req_number`
  123. if test "$postgresql_version_check" = "1"; then
  124. AC_MSG_RESULT([yes])
  125. else
  126. AC_MSG_RESULT([no])
  127. fi
  128. fi
  129. AC_SUBST([POSTGRESQL_VERSION])
  130. AC_SUBST([POSTGRESQL_CPPFLAGS])
  131. AC_SUBST([POSTGRESQL_LDFLAGS])
  132. ])