source: trunk/m4/mysql.m4 @ 704

Revision 511, 5.0 KB checked in by dcarter, 4 years ago (diff)

Merged Sqlite development branch

Line 
1# Copyright (C) 2005-2008 David Carter <arm4@arm4.org>
2
3# This file is free software; as a special exception the author gives
4# unlimited permission to copy and/or distribute it, with or without
5# modifications, as long as this notice is preserved.
6#
7# This program is distributed in the hope that it will be useful, but
8# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
9# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
11# Macros to check the version for the MySql library, and to set whatever link flags are appropriate
12
13AC_DEFUN([__ARM4_MYSQL_CHECK_VERSION],
14[
15  min_mysql_version=ifelse([$1], ,5.0,$1)
16  mysql_config="$2"
17
18  no_mysql=""
19  AC_MSG_CHECKING(for mysql - version >= $min_mysql_version)
20  mysql_major_version=`$mysql_config --version | \
21             sed 's/^[[A-Za-z :]]*\([[0-9]]*\)\.\{0,1\}\([[0-9]]*\)\.\{0,1\}\([[0-9]]*\).*/\1/'`
22  if test "x${mysql_major_version}" = "x" ; then
23           mysql_major_version=0
24  fi
25       
26  mysql_minor_version=`$mysql_config --version | \
27             sed 's/^[[A-Za-z :]]*\([[0-9]]*\)\.\{0,1\}\([[0-9]]*\)\.\{0,1\}\([[0-9]]*\).*/\2/'`
28  if test "x${mysql_minor_version}" = "x" ; then
29           mysql_minor_version=0
30  fi
31       
32  mysql_micro_version=`$mysql_config --version | \
33             sed 's/^[[A-Za-z :]]*\([[0-9]]*\)\.\{0,1\}\([[0-9]]*\)\.\{0,1\}\([[0-9]]*\).*/\3/'`
34  if test "x${mysql_micro_version}" = "x" ; then
35           mysql_micro_version=0
36  fi
37       
38  rm -f conf.sqlitetest
39  AC_RUN_IFELSE([
40#include <stdio.h>
41#include <stdlib.h>
42#include <string.h>
43
44char* my_strdup (const char *str);
45
46char*
47my_strdup (const char *str)
48{
49  char *new_str;
50 
51  if (str)
52    {
53      new_str = (char *)malloc ((strlen (str) + 1) * sizeof(char));
54      strcpy (new_str, str);
55    }
56  else
57    new_str = NULL;
58 
59  return new_str;
60}
61
62int main (void)
63{
64  int major = 0, minor = 0, micro = 0;
65  int n;
66  char *tmp_version;
67
68  system ("touch conf.sqlitetest");
69
70  /* HP/UX 9 (%@#!) writes to sscanf strings */
71  tmp_version = my_strdup("$min_mysql_version");
72
73  n = sscanf(tmp_version, "%d.%d.%d", &major, &minor, &micro) ;
74
75  if (n != 2 && n != 3) {
76     printf("%s, bad version string\n", "$min_mysql_version");
77     exit(1);
78   }
79
80   if (($mysql_major_version > major) ||
81      (($mysql_major_version == major) && ($mysql_minor_version > minor)) ||
82      (($mysql_major_version == major) && ($mysql_minor_version == minor) && ($mysql_micro_version >= micro)))
83    {
84      exit(0);
85    }
86  else
87    {
88      printf("\n*** 'mysql -version' returned %d.%d.%d, but the minimum version\n", $mysql_major_version, $mysql_minor_version, $mysql_micro_version);
89      printf("*** of mysql required is %d.%d.%d. If mysql is correct, then it is\n", major, minor, micro);
90      printf("*** best to upgrade to the required version.\n");
91      exit(1);
92    }
93}
94
95],, no_mysql=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
96
97  if test "x$no_mysql" = x ; then
98    AC_MSG_RESULT(yes)
99  else
100    AC_MSG_ERROR([mysql version $min_mysql_version or greater is required])
101  fi
102])
103
104AC_DEFUN([ARM4_VERSION_MYSQL],
105[
106  min_mysql_version=ifelse([$1], ,5.0,$1)
107
108  AC_MSG_CHECKING(for MySQL configuration)
109  mysql_found="no"
110  mysql_config=""
111  AC_ARG_WITH(mysql,
112  [  --with-mysql=PATH       path to the mysql_config script],
113  [
114    if test "$withval" = "no" || test "$withval" = "yes"; then
115      AC_MSG_ERROR([--with-mysql requires the path to mysql_config to be provided])
116    fi
117
118    if test -x "$withval" > /dev/null 2>&1 ; then
119      mysql_found="yes"
120      mysql_config="$withval"
121    fi
122
123    dnl if --with-mysql is used, it is a fatal error for its argument
124    dnl to be invalid
125    if test "$mysql_found" != "yes"; then
126      AC_MSG_ERROR([the --with-mysql parameter is incorrect. It must specify the path to mysql_config.])
127    fi
128  ],[
129        mysql_path="`which mysql_config`"
130    if test -x "$mysql_path" > /dev/null 2>&1 ; then
131      mysql_found="yes"
132      mysql_config="$mysql_path"
133    else
134      AC_MSG_ERROR([unable to find mysql_config.])
135    fi
136  ])
137  AC_MSG_RESULT($mysql_found)
138 
139  if test "$mysql_found" = "yes" ; then
140      __ARM4_MYSQL_CHECK_VERSION([$min_mysql_version], [$mysql_config])
141      AC_MSG_CHECKING(for mysql flags)
142        MYSQL_CFLAGS="`$mysql_config --cflags`"
143        AC_SUBST(MYSQL_CFLAGS)
144      AC_MSG_RESULT($MYSQL_CFLAGS)
145      AC_MSG_CHECKING(for mysql libs)
146        MYSQL_LIBS="`$mysql_config --libs_r`"
147        AC_SUBST(MYSQL_LIBS)
148      AC_MSG_RESULT($MYSQL_LIBS)
149  fi
150])
151
152AC_DEFUN([ARM4_CHECK_MYSQL],
153[
154  min_mysql_version=ifelse([$1], ,5.0,$1)
155
156  AC_MSG_CHECKING(for MySQL)
157  AC_ARG_ENABLE(mysql,
158  [  --enable-mysql          enable MySQL database back end],
159  [case "${enableval}" in
160     yes) mysql=yes ;;
161     no)  mysql=no ;;
162     *) AC_MSG_ERROR([bad value ${enableval} for --enable-mysql]) ;;
163   esac],
164  [mysql=no])
165  AC_MSG_RESULT($mysql)
166  AM_CONDITIONAL([BUILD_MYSQL], [test "$mysql" = "yes" ])
167  if test "$mysql" = "yes" ; then
168    ARM4_VERSION_MYSQL([$min_mysql_version])
169    AC_DEFINE(HAVE_MYSQL, 1,
170      [Define wether the MySql back end is implemented on this platform])
171  fi
172])
Note: See TracBrowser for help on using the repository browser.