diff options
Diffstat (limited to 'm4/ax_lib_postgresql.m4')
-rw-r--r-- | m4/ax_lib_postgresql.m4 | 155 |
1 files changed, 155 insertions, 0 deletions
diff --git a/m4/ax_lib_postgresql.m4 b/m4/ax_lib_postgresql.m4 new file mode 100644 index 0000000..9eb4316 --- /dev/null +++ b/m4/ax_lib_postgresql.m4 | |||
@@ -0,0 +1,155 @@ | |||
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 | |||
47 | #serial 9 | ||
48 | |||
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 | |||
68 | POSTGRESQL_CPPFLAGS="" | ||
69 | POSTGRESQL_LDFLAGS="" | ||
70 | POSTGRESQL_VERSION="" | ||
71 | |||
72 | dnl | ||
73 | dnl Check PostgreSQL libraries (libpq) | ||
74 | dnl | ||
75 | |||
76 | if test "$want_postgresql" = "yes"; then | ||
77 | |||
78 | if test -z "$PG_CONFIG" -o test; then | ||
79 | AC_PATH_PROG([PG_CONFIG], [pg_config], []) | ||
80 | fi | ||
81 | |||
82 | if test ! -x "$PG_CONFIG"; then | ||
83 | dnl AC_MSG_ERROR([$PG_CONFIG does not exist or it is not an executable file]) | ||
84 | PG_CONFIG="no" | ||
85 | found_postgresql="no" | ||
86 | fi | ||
87 | |||
88 | if test "$PG_CONFIG" != "no"; then | ||
89 | AC_MSG_CHECKING([for PostgreSQL libraries]) | ||
90 | |||
91 | POSTGRESQL_CPPFLAGS="-I`$PG_CONFIG --includedir`" | ||
92 | POSTGRESQL_LDFLAGS="-L`$PG_CONFIG --libdir`" | ||
93 | |||
94 | POSTGRESQL_VERSION=`$PG_CONFIG --version | sed -e 's#PostgreSQL ##' | awk '{print $1}'` | ||
95 | |||
96 | AC_DEFINE([HAVE_POSTGRESQL], [1], | ||
97 | [Define to 1 if PostgreSQL libraries are available]) | ||
98 | |||
99 | found_postgresql="yes" | ||
100 | AC_MSG_RESULT([yes]) | ||
101 | else | ||
102 | found_postgresql="no" | ||
103 | AC_MSG_RESULT([no]) | ||
104 | fi | ||
105 | fi | ||
106 | |||
107 | dnl | ||
108 | dnl Check if required version of PostgreSQL is available | ||
109 | dnl | ||
110 | |||
111 | |||
112 | postgresql_version_req=ifelse([$1], [], [], [$1]) | ||
113 | |||
114 | if test "$found_postgresql" = "yes" -a -n "$postgresql_version_req"; then | ||
115 | |||
116 | AC_MSG_CHECKING([if PostgreSQL version $POSTGRESQL_VERSION is >= $postgresql_version_req]) | ||
117 | |||
118 | dnl Decompose required version string of PostgreSQL | ||
119 | dnl and calculate its number representation | ||
120 | postgresql_version_req_major=`expr $postgresql_version_req : '\([[0-9]]*\)'` | ||
121 | postgresql_version_req_minor=`expr $postgresql_version_req : '[[0-9]]*\.\([[0-9]]*\)'` | ||
122 | postgresql_version_req_micro=`expr $postgresql_version_req : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'` | ||
123 | if test "x$postgresql_version_req_micro" = "x"; then | ||
124 | postgresql_version_req_micro="0" | ||
125 | fi | ||
126 | |||
127 | postgresql_version_req_number=`expr $postgresql_version_req_major \* 1000000 \ | ||
128 | \+ $postgresql_version_req_minor \* 1000 \ | ||
129 | \+ $postgresql_version_req_micro` | ||
130 | |||
131 | dnl Decompose version string of installed PostgreSQL | ||
132 | dnl and calculate its number representation | ||
133 | postgresql_version_major=`expr $POSTGRESQL_VERSION : '\([[0-9]]*\)'` | ||
134 | postgresql_version_minor=`expr $POSTGRESQL_VERSION : '[[0-9]]*\.\([[0-9]]*\)'` | ||
135 | postgresql_version_micro=`expr $POSTGRESQL_VERSION : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'` | ||
136 | if test "x$postgresql_version_micro" = "x"; then | ||
137 | postgresql_version_micro="0" | ||
138 | fi | ||
139 | |||
140 | postgresql_version_number=`expr $postgresql_version_major \* 1000000 \ | ||
141 | \+ $postgresql_version_minor \* 1000 \ | ||
142 | \+ $postgresql_version_micro` | ||
143 | |||
144 | postgresql_version_check=`expr $postgresql_version_number \>\= $postgresql_version_req_number` | ||
145 | if test "$postgresql_version_check" = "1"; then | ||
146 | AC_MSG_RESULT([yes]) | ||
147 | else | ||
148 | AC_MSG_RESULT([no]) | ||
149 | fi | ||
150 | fi | ||
151 | |||
152 | AC_SUBST([POSTGRESQL_VERSION]) | ||
153 | AC_SUBST([POSTGRESQL_CPPFLAGS]) | ||
154 | AC_SUBST([POSTGRESQL_LDFLAGS]) | ||
155 | ]) | ||