1 | # $Id: sqlite_drv.m4,v 1.4 2009/12/01 23:05:06 sbajic Exp $ |
---|
2 | # Autoconf macros for checking for SQLite |
---|
3 | # |
---|
4 | # Public available macro: |
---|
5 | # DS_SQLITE([sqlite_cppflags_out], |
---|
6 | # [sqlite_ldflags_out], |
---|
7 | # [sqlite_libs_out], |
---|
8 | # [sqlite_version_major_out], |
---|
9 | # [sqlite_version_minor_out], |
---|
10 | # [sqlite_version_patchlevel_out], |
---|
11 | # [additional-action-if-found], |
---|
12 | # [additional-action-if-not-found] |
---|
13 | # ) |
---|
14 | # |
---|
15 | # Another macros are considered as private for implementation and |
---|
16 | # sould not be used in the configure.ac. At this time these are: |
---|
17 | # DS_SQLITE_HEADERS() |
---|
18 | # DS_SQLITE_LIBS() |
---|
19 | # |
---|
20 | |
---|
21 | # DS_SQLITE_HEADERS([sqlite_cppflags_out], |
---|
22 | # [sqlite_version_major_out], |
---|
23 | # [sqlite_version_minor_out], |
---|
24 | # [sqlite_version_patchelevel_out], |
---|
25 | # [additional-action-if-found], |
---|
26 | # [additional-action-if-not-found] |
---|
27 | # ) |
---|
28 | AC_DEFUN([DS_SQLITE_HEADERS], |
---|
29 | [ |
---|
30 | AC_REQUIRE([AC_PROG_AWK]) |
---|
31 | |
---|
32 | ds_sqlite_headers_save_CPPFLAGS="$CPPFLAGS" |
---|
33 | ds_sqlite_headers_CPPFLAGS='' |
---|
34 | ds_sqlite_headers_success=yes |
---|
35 | ds_sqlite_headers_version_major='' |
---|
36 | ds_sqlite_headers_version_minor='' |
---|
37 | ds_sqlite_headers_version_patchlevel='' |
---|
38 | |
---|
39 | # unistd.h and errno.h are needed for header version check below. |
---|
40 | AC_CHECK_HEADERS([unistd.h errno.h]) |
---|
41 | |
---|
42 | AC_ARG_WITH(sqlite-includes, |
---|
43 | [AS_HELP_STRING([--with-sqlite-includes=DIR], |
---|
44 | [Where to find SQLite headers])]) |
---|
45 | if test x"$with_sqlite_includes" != x |
---|
46 | then |
---|
47 | if test -d "$with_sqlite_includes" |
---|
48 | then |
---|
49 | : |
---|
50 | else |
---|
51 | AC_MSG_ERROR([required include path for sqlite headers ($with_sqlite_includes) is not a directory]) |
---|
52 | fi |
---|
53 | ds_sqlite_headers_CPPFLAGS="-I$with_sqlite_includes" |
---|
54 | CPPFLAGS="$ds_sqlite_headers_CPPFLAGS $CPPFLAGS" |
---|
55 | fi |
---|
56 | AC_CHECK_HEADER([sqlite.h], |
---|
57 | [], |
---|
58 | [ ds_sqlite_headers_success=no ]) |
---|
59 | if test x"$ds_sqlite_headers_success" = xyes |
---|
60 | then |
---|
61 | # Determine SQLite hearder version |
---|
62 | AC_LANG_PUSH(C) |
---|
63 | AC_MSG_CHECKING([SQLite header version]) |
---|
64 | AC_RUN_IFELSE([AC_LANG_SOURCE([[ |
---|
65 | #include <sqlite.h> |
---|
66 | #include <stdio.h> |
---|
67 | #include <stdlib.h> |
---|
68 | #ifdef HAVE_UNISTD_H |
---|
69 | # include <unistd.h> |
---|
70 | #endif |
---|
71 | #ifdef HAVE_ERRNO_H |
---|
72 | # include <errno.h> |
---|
73 | #endif |
---|
74 | |
---|
75 | #define OUTFILE "conftest.libsqlitever" |
---|
76 | |
---|
77 | int main(void) |
---|
78 | { |
---|
79 | FILE* fd; |
---|
80 | int rc; |
---|
81 | |
---|
82 | rc = unlink(OUTFILE); /* avoid symlink attack */ |
---|
83 | if (rc < 0 && errno != ENOENT) |
---|
84 | { |
---|
85 | fprintf(stderr, "error unlinking '%s'", OUTFILE); |
---|
86 | exit(1); |
---|
87 | } |
---|
88 | |
---|
89 | fd = fopen(OUTFILE, "w"); |
---|
90 | if (!fd) |
---|
91 | { |
---|
92 | /* Don't try to investigate errno for portability reasons */ |
---|
93 | fprintf(stderr, "error opening '%s' for writing", OUTFILE); |
---|
94 | exit(1); |
---|
95 | } |
---|
96 | |
---|
97 | rc = fprintf(fd, "%s", SQLITE_VERSION); |
---|
98 | if (rc < 0) |
---|
99 | { |
---|
100 | fprintf(stderr, "error writing to the '%s'", OUTFILE); |
---|
101 | exit(1); |
---|
102 | } |
---|
103 | exit(0); |
---|
104 | } |
---|
105 | ]])], |
---|
106 | [ |
---|
107 | dnl In following AWK calls `$[1]' is used instead of `$1' |
---|
108 | dnl for preventing substitution by macro arguments. Don't |
---|
109 | dnl worry, in final `configure' these `$[1]' will appears as |
---|
110 | dnl required: `$1'. |
---|
111 | |
---|
112 | ds_sqlite_headers_verstr=`cat conftest.libsqlitever` |
---|
113 | ds_sqlite_headers_version_major=`cat conftest.libsqlitever | $AWK -F. '{print $[1]}'` |
---|
114 | ds_sqlite_headers_version_minor=`cat conftest.libsqlitever | $AWK -F. '{print $[2]}'` |
---|
115 | ds_sqlite_headers_version_patchlevel=`cat conftest.libsqlitever | $AWK -F. '{print $[3]}'` |
---|
116 | |
---|
117 | AC_MSG_RESULT([$ds_sqlite_headers_version_major.$ds_sqlite_headers_version_minor.$ds_sqlite_headers_version_patchlevel]) |
---|
118 | ], |
---|
119 | [ |
---|
120 | AC_MSG_RESULT([failure (unsupported version?)]) |
---|
121 | ds_sqlite_headers_success=no |
---|
122 | ], |
---|
123 | [ # cross-compilation |
---|
124 | AC_MSG_ERROR([cross-compilation is unsupported, sorry]) |
---|
125 | ds_sqlite_headers_success=no |
---|
126 | ]) |
---|
127 | AC_LANG_POP(C) |
---|
128 | fi |
---|
129 | CPPFLAGS="$ds_sqlite_headers_save_CPPFLAGS" |
---|
130 | if test x"$ds_sqlite_headers_success" = xyes |
---|
131 | then |
---|
132 | ifelse([$1], [], [:], [$1="$ds_sqlite_headers_CPPFLAGS"]) |
---|
133 | ifelse([$2], [], [:], [$2="$ds_sqlite_headers_version_major"]) |
---|
134 | ifelse([$3], [], [:], [$3="$ds_sqlite_headers_version_minor"]) |
---|
135 | ifelse([$4], [], [:], [$4="$ds_sqlite_headers_version_patchlevel"]) |
---|
136 | ifelse([$5], [], [:], [$5]) |
---|
137 | : |
---|
138 | else |
---|
139 | ifelse([$6], [], [:], [$6]) |
---|
140 | : |
---|
141 | fi |
---|
142 | ]) |
---|
143 | |
---|
144 | # |
---|
145 | # DS_SQLITE_LIBS([sqlite_ldflags_out], |
---|
146 | # [sqlite_libs_out], |
---|
147 | # [sqlite_version_major_in], |
---|
148 | # [sqlite_version_minor_in], |
---|
149 | # [sqlite_version_patchelevel_in], # unused |
---|
150 | # [additional-action-if-found], |
---|
151 | # [additional-action-if-not-found] |
---|
152 | # ) |
---|
153 | AC_DEFUN([DS_SQLITE_LIBS], |
---|
154 | [ |
---|
155 | ds_sqlite_libs_save_LIBS="$LIBS" |
---|
156 | ds_sqlite_libs_save_LDFLAGS="$LDFLAGS" |
---|
157 | ds_sqlite_libs_LIBS='' |
---|
158 | ds_sqlite_libs_LDFLAGS='' |
---|
159 | ds_sqlite_libs_success=no |
---|
160 | |
---|
161 | ds_sqlite_libs_ver_major="${$3}" |
---|
162 | ds_sqlite_libs_ver_minor="${$4}" |
---|
163 | |
---|
164 | if test x"$ds_sqlite_libs_ver_major" = x |
---|
165 | then |
---|
166 | AC_MSG_ERROR([[DS@&t@_SQLITE_LIBS: non-optional argument _ds_sqlite_libs_version_major_in is omited]]); |
---|
167 | fi |
---|
168 | if test x"$ds_sqlite_libs_ver_minor" = x |
---|
169 | then |
---|
170 | AC_MSG_ERROR([[DS@&t@_SQLITE_LIBS: non-optional argument _ds_sqlite_libs_version_minor_in is omited]]); |
---|
171 | fi |
---|
172 | |
---|
173 | AC_ARG_WITH(sqlite-libraries, |
---|
174 | [AS_HELP_STRING([--with-sqlite-libraries=DIR], |
---|
175 | [Where to find SQLite libraries])]) |
---|
176 | if test x"$with_sqlite_libraries" != x |
---|
177 | then |
---|
178 | if test -d "$with_sqlite_libraries" |
---|
179 | then |
---|
180 | : |
---|
181 | else |
---|
182 | AC_MSG_ERROR([required path for sqlite libraries ($with_sqlite_libraries) is not a directory]) |
---|
183 | fi |
---|
184 | ds_sqlite_libs_LDFLAGS="-L$with_sqlite_libraries" |
---|
185 | fi |
---|
186 | |
---|
187 | AC_MSG_CHECKING([how to link SQLite libraries]) |
---|
188 | for ds_sqlite_libs_tmp_sqlite in \ |
---|
189 | "-lsqlite" |
---|
190 | do |
---|
191 | LDFLAGS="$ds_sqlite_libs_LDFLAGS $ds_sqlite_libs_save_LDFLAGS" |
---|
192 | for ds_sqlite_libs_tmp_libpth in '' |
---|
193 | do |
---|
194 | ds_sqlite_libs_LIBS="$ds_sqlite_libs_tmp_sqlite $ds_sqlite_libs_tmp_libpth" |
---|
195 | LIBS="$ds_sqlite_libs_LIBS $ds_sqlite_libs_save_LIBS" |
---|
196 | AC_LINK_IFELSE([AC_LANG_PROGRAM([[ |
---|
197 | #include <sqlite.h> |
---|
198 | ]], |
---|
199 | [[ |
---|
200 | const char *v = 0; |
---|
201 | v = sqlite_version; |
---|
202 | ]])], |
---|
203 | [ ds_sqlite_libs_success=yes ], |
---|
204 | [ ds_sqlite_libs_success=no ] |
---|
205 | ) |
---|
206 | |
---|
207 | if test x"$ds_sqlite_libs_success" != xyes |
---|
208 | then |
---|
209 | continue |
---|
210 | fi |
---|
211 | |
---|
212 | AC_RUN_IFELSE([AC_LANG_PROGRAM([[ |
---|
213 | #include <stdio.h> |
---|
214 | #include <sqlite.h> |
---|
215 | #include <stdlib.h> |
---|
216 | #include <string.h> |
---|
217 | ]], |
---|
218 | [[ |
---|
219 | const char *x = sqlite_version; |
---|
220 | char *y; |
---|
221 | char header_version[16]; |
---|
222 | int major, minor, patchlevel; |
---|
223 | int hmajor, hminor, hpatchlevel; |
---|
224 | int is_match; |
---|
225 | |
---|
226 | strcpy(header_version, x); |
---|
227 | y = strtok(header_version, "."); |
---|
228 | major = atoi(y); |
---|
229 | y = strtok(NULL, "."); |
---|
230 | minor = atoi(y); |
---|
231 | y = strtok(NULL, "."); |
---|
232 | patchlevel = atoi(y); |
---|
233 | |
---|
234 | strcpy(header_version, SQLITE_VERSION); |
---|
235 | y = strtok(header_version, "."); |
---|
236 | hmajor = atoi(y); |
---|
237 | y = strtok(NULL, "."); |
---|
238 | hminor = atoi(y); |
---|
239 | y = strtok(NULL, "."); |
---|
240 | hpatchlevel = atoi(y); |
---|
241 | |
---|
242 | fprintf(stderr, "sqlite version from header: %d.%d.%d\n", |
---|
243 | hmajor, hminor, hpatchlevel |
---|
244 | ); |
---|
245 | |
---|
246 | fprintf(stderr, "sqlite version from library: %d.%d.%d\n", |
---|
247 | major, |
---|
248 | minor, |
---|
249 | patchlevel |
---|
250 | ); |
---|
251 | if (major == hmajor |
---|
252 | && minor == hminor |
---|
253 | && patchlevel == hpatchlevel |
---|
254 | ) |
---|
255 | { |
---|
256 | is_match = 1; |
---|
257 | } |
---|
258 | else |
---|
259 | { |
---|
260 | is_match = 0; |
---|
261 | } |
---|
262 | return is_match ? 0 : 1; |
---|
263 | ]])], |
---|
264 | [ ds_sqlite_libs_success=yes], |
---|
265 | [ ds_sqlite_libs_success=no ], |
---|
266 | [ ds_sqlite_libs_success=yes] # Assume success for cross-compiling |
---|
267 | ) |
---|
268 | |
---|
269 | if test x"$ds_sqlite_libs_success" = xyes |
---|
270 | then |
---|
271 | break 2 |
---|
272 | fi |
---|
273 | done |
---|
274 | done |
---|
275 | |
---|
276 | if test x"$ds_sqlite_libs_success" = xyes |
---|
277 | then |
---|
278 | AC_MSG_RESULT([$ds_sqlite_libs_LIBS]) |
---|
279 | else |
---|
280 | AC_MSG_RESULT([failure]) |
---|
281 | fi |
---|
282 | |
---|
283 | LIBS="$ds_sqlite_libs_save_LIBS" |
---|
284 | LDFLAGS="$ds_sqlite_libs_save_LDFLAGS" |
---|
285 | if test x"$ds_sqlite_libs_success" = xyes |
---|
286 | then |
---|
287 | ifelse([$1], [], [:], [$1="$ds_sqlite_libs_LDFLAGS"]) |
---|
288 | ifelse([$2], [], [:], [$2="$ds_sqlite_libs_LIBS"]) |
---|
289 | ifelse([$6], [], [:], [$6]); |
---|
290 | : |
---|
291 | else |
---|
292 | ifelse([$7], [], [:], [$7]) |
---|
293 | : |
---|
294 | fi |
---|
295 | ]) |
---|
296 | |
---|
297 | # |
---|
298 | # DS_SQLITE([sqlite_cppflags_out], |
---|
299 | # [sqlite_ldflags_out], |
---|
300 | # [sqlite_libs_out], |
---|
301 | # [sqlite_version_major_out], |
---|
302 | # [sqlite_version_minor_out], |
---|
303 | # [sqlite_version_patchlevel_out], |
---|
304 | # [additional-action-if-found], |
---|
305 | # [additional-action-if-not-found] |
---|
306 | # ) |
---|
307 | AC_DEFUN([DS_SQLITE], |
---|
308 | [ |
---|
309 | ds_sqlite_save_CPPFLAGS="$CPPFLAGS" |
---|
310 | ds_sqlite_save_LIBS="$LIBS" |
---|
311 | ds_sqlite_save_LDFLAGS="$LDFLAGS" |
---|
312 | |
---|
313 | ds_sqlite_CPPFLAGS='' |
---|
314 | ds_sqlite_LIBS='' |
---|
315 | ds_sqlite_LDFLAGS='' |
---|
316 | |
---|
317 | ds_sqlite_success=yes |
---|
318 | ds_sqlite_version_major='' |
---|
319 | ds_sqlite_version_minor='' |
---|
320 | ds_sqlite_version_patchlevel='' |
---|
321 | |
---|
322 | DS_SQLITE_HEADERS([ds_sqlite_CPPFLAGS], |
---|
323 | [ds_sqlite_version_major], |
---|
324 | [ds_sqlite_version_minor], |
---|
325 | [ds_sqlite_version_patchlevel], |
---|
326 | [], |
---|
327 | [ds_sqlite_success=no]) |
---|
328 | |
---|
329 | if test x"$ds_sqlite_success" = xyes |
---|
330 | then |
---|
331 | CPPFLAGS="$ds_sqlite_CPPFLAGS $CPPFLAGS" |
---|
332 | DS_SQLITE_LIBS([ds_sqlite_LDFLAGS], |
---|
333 | [ds_sqlite_LIBS], |
---|
334 | [ds_sqlite_version_major], |
---|
335 | [ds_sqlite_version_minor], |
---|
336 | [ds_sqlite_version_patchlevel], |
---|
337 | [], |
---|
338 | [ds_sqlite_success=no]) |
---|
339 | fi |
---|
340 | |
---|
341 | CPPFLAGS="$ds_sqlite_save_CPPFLAGS" |
---|
342 | LIBS="$ds_sqlite_save_LIBS" |
---|
343 | LDFLAGS="$ds_sqlite_save_LDFLAGS" |
---|
344 | |
---|
345 | if test x"$ds_sqlite_success" = xyes |
---|
346 | then |
---|
347 | ifelse([$1], [], [:], [$1="$ds_sqlite_CPPFLAGS"]) |
---|
348 | ifelse([$2], [], [:], [$2="$ds_sqlite_LDFLAGS"]) |
---|
349 | ifelse([$3], [], [:], [$3="$ds_sqlite_LIBS"]) |
---|
350 | |
---|
351 | ifelse([$4], [], [:], [$4="$ds_sqlite_version_major"]) |
---|
352 | ifelse([$5], [], [:], [$5="$ds_sqlite_version_minor"]) |
---|
353 | ifelse([$6], [], [:], [$6="$ds_sqlite_version_patchlevel"]) |
---|
354 | |
---|
355 | ifelse([$7], [], [:], [$7]) |
---|
356 | : |
---|
357 | else |
---|
358 | ifelse([$8], [], [:], [$8]) |
---|
359 | : |
---|
360 | fi |
---|
361 | ]) |
---|