PageRenderTime 28ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/m4/ax_lib_postgresql.m4

http://github.com/mozy/mordor
m4 | 152 lines | 86 code | 22 blank | 44 comment | 0 complexity | a4d69012d99fe944b518f6f152fd162f MD5 | raw file
Possible License(s): BSD-3-Clause
  1. # ===========================================================================
  2. # http://autoconf-archive.cryp.to/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_CFLAGS)
  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.
  45. AC_DEFUN([AX_LIB_POSTGRESQL],
  46. [
  47. AC_ARG_WITH([postgresql],
  48. AC_HELP_STRING([--with-postgresql=@<:@ARG@:>@],
  49. [use PostgreSQL library @<:@default=yes@:>@, optionally specify path to pg_config]
  50. ),
  51. [
  52. if test "$withval" = "no"; then
  53. want_postgresql="no"
  54. elif test "$withval" = "yes"; then
  55. want_postgresql="yes"
  56. else
  57. want_postgresql="yes"
  58. PG_CONFIG="$withval"
  59. fi
  60. ],
  61. [want_postgresql="yes"]
  62. )
  63. POSTGRESQL_CFLAGS=""
  64. POSTGRESQL_LDFLAGS=""
  65. POSTGRESQL_VERSION=""
  66. dnl
  67. dnl Check PostgreSQL libraries (libpq)
  68. dnl
  69. if test "$want_postgresql" = "yes"; then
  70. if test -z "$PG_CONFIG" -o test; then
  71. AC_PATH_PROG([PG_CONFIG], [pg_config], [])
  72. fi
  73. if test ! -x "$PG_CONFIG"; then
  74. AC_MSG_ERROR([$PG_CONFIG does not exist or it is not an exectuable file])
  75. PG_CONFIG="no"
  76. found_postgresql="no"
  77. fi
  78. if test "$PG_CONFIG" != "no"; then
  79. AC_MSG_CHECKING([for PostgreSQL libraries])
  80. POSTGRESQL_CFLAGS="-I`$PG_CONFIG --includedir`"
  81. POSTGRESQL_LDFLAGS="-L`$PG_CONFIG --libdir` -lpq"
  82. POSTGRESQL_VERSION=`$PG_CONFIG --version | sed -e 's#PostgreSQL ##'`
  83. AC_DEFINE([HAVE_POSTGRESQL], [1],
  84. [Define to 1 if PostgreSQL libraries are available])
  85. found_postgresql="yes"
  86. AC_MSG_RESULT([yes])
  87. else
  88. found_postgresql="no"
  89. AC_MSG_RESULT([no])
  90. fi
  91. fi
  92. dnl
  93. dnl Check if required version of PostgreSQL is available
  94. dnl
  95. postgresql_version_req=ifelse([$1], [], [], [$1])
  96. if test "$found_postgresql" = "yes" -a -n "$postgresql_version_req"; then
  97. AC_MSG_CHECKING([if PostgreSQL version is >= $postgresql_version_req])
  98. dnl Decompose required version string of PostgreSQL
  99. dnl and calculate its number representation
  100. postgresql_version_req_major=`expr $postgresql_version_req : '\([[0-9]]*\)'`
  101. postgresql_version_req_minor=`expr $postgresql_version_req : '[[0-9]]*\.\([[0-9]]*\)'`
  102. postgresql_version_req_micro=`expr $postgresql_version_req : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'`
  103. if test "x$postgresql_version_req_micro" = "x"; then
  104. postgresql_version_req_micro="0"
  105. fi
  106. postgresql_version_req_number=`expr $postgresql_version_req_major \* 1000000 \
  107. \+ $postgresql_version_req_minor \* 1000 \
  108. \+ $postgresql_version_req_micro`
  109. dnl Decompose version string of installed PostgreSQL
  110. dnl and calculate its number representation
  111. postgresql_version_major=`expr $POSTGRESQL_VERSION : '\([[0-9]]*\)'`
  112. postgresql_version_minor=`expr $POSTGRESQL_VERSION : '[[0-9]]*\.\([[0-9]]*\)'`
  113. postgresql_version_micro=`expr $POSTGRESQL_VERSION : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'`
  114. if test "x$postgresql_version_micro" = "x"; then
  115. postgresql_version_micro="0"
  116. fi
  117. postgresql_version_number=`expr $postgresql_version_major \* 1000000 \
  118. \+ $postgresql_version_minor \* 1000 \
  119. \+ $postgresql_version_micro`
  120. postgresql_version_check=`expr $postgresql_version_number \>\= $postgresql_version_req_number`
  121. if test "$postgresql_version_check" = "1"; then
  122. AC_MSG_RESULT([yes])
  123. else
  124. AC_MSG_RESULT([no])
  125. fi
  126. fi
  127. AC_SUBST([POSTGRESQL_VERSION])
  128. AC_SUBST([POSTGRESQL_CFLAGS])
  129. AC_SUBST([POSTGRESQL_LDFLAGS])
  130. ])