source: trunk/m4/db.m4 @ 704

Revision 641, 6.6 KB checked in by dcarter, 4 years ago (diff)

see #111 - merge release 0.8 to main branch

Line 
1# Copyright (c) 2005-2008 David Carter <dcarter@arm4.org> and others.
2# All rights reserved.   This program and the accompanying materials
3# are made available under the terms of the Eclipse Public License v1.0
4# which accompanies this distribution, and is available at
5# http://www.eclipse.org/legal/epl-v10.html
6
7# Macros to check the version for the Berkeley DB library, and to set whatever link flags are appropriate
8
9AC_DEFUN([__ARM4_DB_CHECKLINK],
10[
11  DB_LIBS="$1"
12  ac_save_LIBS="$LIBS"
13  LIBS="$LIBS $DB_LIBS"
14  AC_LINK_IFELSE([
15#include <db.h>
16
17main ()
18{
19        DB_ENV  *environment_ptr;
20        db_env_create (&environment_ptr, 0);
21}
22], ,[DB_LIBS=""])
23  LIBS="$ac_save_libs"
24  AC_SUBST(DB_LIBS)
25])
26
27AC_DEFUN([__ARM4_DB_CHECK_DBSTAT],
28[
29  DB_STAT=""
30  AC_MSG_CHECKING(for db_stat)
31  AC_ARG_WITH(berkeley-db-stat,
32  [  --with-berkeley-db-stat=PATH to the db_stat program],
33  [
34    if test "$withval" = "no" || test "$withval" = "yes"; then
35      AC_MSG_ERROR([--with-berkeley-db-stat requires the path to the db_stat program be provided])
36    fi
37
38    if test -x "$withval" > /dev/null 2>&1 ; then
39      DB_STAT="$withval"
40    fi
41  ],
42  [
43    AC_PATH_PROG(DB_STAT, db_stat, no)
44    if test "$DB_STAT" = "no" ; then
45      DB_STAT=""
46    fi
47  ])
48  if test "x$DB_STAT" = "x"; then
49    AC_MSG_RESULT(no)
50  else
51    AC_MSG_RESULT(yes)
52  fi
53  AC_SUBST(DB_STAT)
54])
55
56AC_DEFUN([ARM4_VERSION_DB],
57[
58  min_db_version=ifelse([$1], ,4.1,$1)
59  AC_ARG_WITH(berkeley-db,
60  [  --with-berkeley-db=PATH prefix for installed Berkeley DB,
61                          or the path to the Berkeley DB build tree],
62  [
63    db_found="no"
64    db_root=""
65    if test "$withval" = "no" || test "$withval" = "yes"; then
66      AC_MSG_ERROR([--with-berkeley-db requires a directory to be provided])
67    fi
68
69    if test "$db_found" != "yes" && test -d "$withval" > /dev/null 2>&1 ; then
70      db_found="yes"
71      db_root="$withval"
72    fi
73
74    dnl if --with-berkeley-db is used, it is a fatal error for its argument
75    dnl to be invalid
76    if test "$db_found" != "yes"; then
77      AC_MSG_ERROR([the --with-berkeley-db parameter is incorrect. It must specify an install prefix, or a a build directory.])
78    else
79      CPPFLAGS="-I$db_root/include $CPPFLAGS"
80      AC_MSG_CHECKING(for db flags)
81      __ARM4_DB_CHECKLINK([-L$db_root/lib -ldb])
82      if test "x$DB_LIBS" = x ; then
83        __ARM4_DB_CHECKLINK([-L$db_root/lib -ldb -lpthread])
84      fi
85      AC_MSG_RESULT($DB_LIBS)
86    fi
87  ],[
88    __ARM4_DB_CHECK_DBSTAT
89    AC_MSG_CHECKING(for db - version >= $min_db_version)
90    no_db=""
91    if test "$DB_STAT" = "no" || test "x$DB_STAT" = "x" ; then
92      no_db=yes
93    else
94      db_major_version=`$DB_STAT -V | \
95           sed 's/^[[A-Za-z :]]*\([[0-9]]*\)\.\{0,1\}\([[0-9]]*\)\.\{0,1\}\([[0-9]]*\).*/\1/'`
96      if test "x${db_major_version}" = "x" ; then
97         db_major_version=0
98      fi
99
100      db_minor_version=`$DB_STAT -V | \
101           sed 's/^[[A-Za-z :]]*\([[0-9]]*\)\.\{0,1\}\([[0-9]]*\)\.\{0,1\}\([[0-9]]*\).*/\2/'`
102      if test "x${db_minor_version}" = "x" ; then
103         db_minor_version=0
104      fi
105
106      db_micro_version=`$DB_STAT -V | \
107           sed 's/^[[A-Za-z :]]*\([[0-9]]*\)\.\{0,1\}\([[0-9]]*\)\.\{0,1\}\([[0-9]]*\).*/\3/'`
108      if test "x${db_micro_version}" = "x" ; then
109         db_micro_version=0
110      fi
111
112      enable_dbtest=yes
113      if test "x$enable_dbtest" = "xyes" ; then
114        rm -f conf.dbtest
115        AC_RUN_IFELSE([
116#include <stdio.h>
117#include <stdlib.h>
118#include <string.h>
119
120char* my_strdup (const char *str);
121
122char*
123my_strdup (const char *str)
124{
125  char *new_str;
126 
127  if (str)
128    {
129      new_str = (char *)malloc ((strlen (str) + 1) * sizeof(char));
130      strcpy (new_str, str);
131    }
132  else
133    new_str = NULL;
134 
135  return new_str;
136}
137
138int main (void)
139{
140  int major = 0, minor = 0, micro = 0;
141  int n;
142  char *tmp_version;
143
144  system ("touch conf.dbtest");
145
146  /* HP/UX 9 (%@#!) writes to sscanf strings */
147  tmp_version = my_strdup("$min_db_version");
148
149  n = sscanf(tmp_version, "%d.%d.%d", &major, &minor, &micro) ;
150
151  if (n != 2 && n != 3) {
152     printf("%s, bad version string\n", "$min_db_version");
153     exit(1);
154   }
155
156   if (($db_major_version > major) ||
157      (($db_major_version == major) && ($db_minor_version > minor)) ||
158      (($db_major_version == major) && ($db_minor_version == minor) && ($db_micro_version >= micro)))
159    {
160      exit(0);
161    }
162  else
163    {
164      printf("\n*** 'db_stat -V' returned %d.%d.%d, but the minimum version\n", $db_major_version, $db_minor_version, $db_micro_version);
165      printf("*** of DB required is %d.%d.%d. If db_stat is correct, then it is\n", major, minor, micro);
166      printf("*** best to upgrade to the required version.\n");
167      exit(1);
168    }
169}
170
171],, no_db=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
172       fi
173    fi
174    if test "x$no_db" = x ; then
175       AC_MSG_RESULT(yes)
176       AC_MSG_CHECKING(for db flags)
177       __ARM4_DB_CHECKLINK([-ldb])
178       if test "x$DB_LIBS" = x ; then
179         __ARM4_DB_CHECKLINK([-ldb -lpthread])
180       fi
181       AC_MSG_RESULT($DB_LIBS)
182       ifelse([$2], , :, [$2])     
183    else
184       AC_MSG_RESULT(no)
185       if test "$DB_STAT" = "no" ; then
186         echo "*** The db_stat program could not be found"
187         echo "*** If DB was installed in PREFIX, make sure PREFIX/bin is in"
188         echo "*** your path."
189       else
190         if test -f conf.dbtest ; then
191          :
192         else
193          echo "*** Could not run DB test program, checking why..."
194          AC_LINK_IFELSE([AC_LANG_PROGRAM([[
195#include <stdio.h>
196]], [[ return 0; ]])],[ echo "*** The test program compiled, but did not run. This usually means"
197            echo "*** that the run-time linker is not finding DB or finding the wrong"
198            echo "*** version of DB. If it is not finding DB, you'll need to set your"
199            echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
200            echo "*** to the installed location  Also, make sure you have run ldconfig if that"
201            echo "*** is required on your system"
202            echo "***"
203            echo "*** If you have an old version installed, it is best to remove it, although"
204            echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"],[ echo "*** The test program failed to compile or link. See the file config.log for the"
205            echo "*** exact error that occured. This usually means DB was incorrectly installed"
206            echo "*** or that you have moved DB since it was installed. In the latter case, you"
207            echo "*** may want to edit the db_stat script: $DB_STAT" ])
208         fi
209       fi
210       ifelse([$3], , :, [$3])
211    fi
212    rm -f conf.dbtest
213  ])
214])
215
216
Note: See TracBrowser for help on using the repository browser.