File: db3-check.m4

package info (click to toggle)
netatalk 2.0.3-11%2Blenny1
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 9,428 kB
  • ctags: 6,161
  • sloc: ansic: 67,633; sh: 8,393; perl: 1,187; makefile: 1,060
file content (238 lines) | stat: -rw-r--r-- 6,742 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
dnl $Id: db3-check.m4,v 1.11.6.9 2004/08/11 03:01:11 bfernhomberg Exp $
dnl Autoconf macros to check for the Berkeley DB library


AC_DEFUN([NETATALK_BDB_LINK_TRY],
[if test $atalk_cv_lib_db = no ; then
	AC_MSG_CHECKING([for Berkeley DB link (]ifelse($2,,default,$2)[)])
	atalk_DB_LIB=ifelse($2,,-ldb,$2)
	atalk_LIBS=$LIBS
	LIBS="$atalk_DB_LIB $LIBS"

	AC_TRY_LINK([
#include <db.h>
],[
	char *version;
	int major, minor, patch;

	version = db_version( &major, &minor, &patch );
	return (0);
],[$1=yes],[$1=no])

	AC_MSG_RESULT([$$1])
	LIBS="$atalk_LIBS"
	if test $$1 = yes ; then
		atalk_cv_lib_db=ifelse($2,,-ldb,$2)
	fi
fi
])


AC_DEFUN([NETATALK_BDB_CHECK_VERSION],
[
	atalk_LIBS=$LIBS
	LIBS="${atalk_cv_lib_db} $LIBS"

	AC_MSG_CHECKING([Berkeley DB library version >= ${DB_MAJOR_REQ}.${DB_MINOR_REQ}.${DB_PATCH_REQ}])
	AC_TRY_RUN([
#if STDC_HEADERS
#include <stdlib.h>
#endif
#include <stdio.h>
#include <db.h>

int main(void) {
        int major, minor, patch;
        char *version_str;

        version_str = db_version(&major, &minor, &patch);

        /* check library version */
        if (major < DB_MAJOR_REQ || minor < DB_MINOR_REQ || patch < DB_PATCH_REQ) {
                printf("library version too old (%d.%d.%d), ",major, minor, patch);
                return (2);
        }

        /* check header and library match */
        if ( major != DB_VERSION_MAJOR || minor != DB_VERSION_MINOR || patch != DB_VERSION_PATCH) {
                printf("header/library version mismatch (%d.%d.%d/%d.%d.%d), ",
                         DB_VERSION_MAJOR, DB_VERSION_MINOR, DB_VERSION_PATCH, major, minor, patch);
                return (3);
        }

        printf("%d.%d.%d, ",major, minor, patch);
        return (0);
}
], atalk_cv_bdb_version="yes", atalk_cv_bdb_version="no", atalk_cv_bdb_version="cross")


        if test ${atalk_cv_bdb_version} = "yes"; then
        	AC_MSG_RESULT(yes)
        else
		AC_MSG_RESULT(no)
        fi
	LIBS="$atalk_LIBS"
])


AC_DEFUN([NETATALK_BDB_HEADER],
[
	savedcflags="$CFLAGS"
	CFLAGS="-I$1 $CFLAGS"
	dnl check for header version
        AC_MSG_CHECKING(ifelse($1,,default,$1)[/db.h version >= ${DB_MAJOR_REQ}.${DB_MINOR_REQ}.${DB_PATCH_REQ}])
        AC_TRY_RUN([
#if STDC_HEADERS
#include <stdlib.h>
#endif
#include <stdio.h>
#include <db.h>

int main(void) {

        /* check header version */
        if (DB_VERSION_MAJOR < DB_MAJOR_REQ || DB_VERSION_MINOR < DB_MINOR_REQ ||
            DB_VERSION_PATCH < DB_PATCH_REQ ) {
                printf("header file version too old (%d.%d.%d), ", DB_VERSION_MAJOR, DB_VERSION_MINOR, DB_VERSION_PATCH);
                return (1);
        }

        printf("%d.%d.%d, ", DB_VERSION_MAJOR, DB_VERSION_MINOR, DB_VERSION_PATCH);
        return (0);
}
], atalk_cv_bdbheader="yes", atalk_cv_bdbheader="no", atalk_cv_bdbheader="cross")

        if test ${atalk_cv_bdbheader} = "no"; then
        	bdbfound=no
	        AC_MSG_RESULT([no])
        else
                AC_MSG_RESULT([yes])
        fi
	CFLAGS="$savedcflags"
])


AC_DEFUN([NETATALK_BERKELEY_LINK],
[
atalk_cv_lib_db=no
NETATALK_BDB_LINK_TRY(atalk_cv_db_db_4_dot_2,[-ldb-4.2])
NETATALK_BDB_LINK_TRY(atalk_cv_db_db42,[-ldb42])
NETATALK_BDB_LINK_TRY(atalk_cv_db_db_42,[-ldb-42])
NETATALK_BDB_LINK_TRY(atalk_cv_db_db_4_2,[-ldb-4-2])
NETATALK_BDB_LINK_TRY(atalk_cv_db_db_4_dot_1,[-ldb-4.1])
NETATALK_BDB_LINK_TRY(atalk_cv_db_db41,[-ldb41])
NETATALK_BDB_LINK_TRY(atalk_cv_db_db_41,[-ldb-41])
NETATALK_BDB_LINK_TRY(atalk_cv_db_db_4_1,[-ldb-4-1])
NETATALK_BDB_LINK_TRY(atalk_cv_db_db_4,[-ldb-4])
NETATALK_BDB_LINK_TRY(atalk_cv_db_db4,[-ldb4])
NETATALK_BDB_LINK_TRY(atalk_cv_db_db,[-ldb])
])


AC_DEFUN([AC_PATH_BDB], 
[
	trybdbdir=""
	dobdbsearch=yes
	bdb_search_dirs="/usr/local/include /usr/include"
	search_subdirs="/db4.2 /db42 /db4.1 /db41 /db4 /"

dnl required BDB version
	DB_MAJOR_REQ=4
	DB_MINOR_REQ=1
	DB_PATCH_REQ=0

dnl make sure atalk_libname is defined beforehand
[[ -n "$atalk_libname" ]] || AC_MSG_ERROR([internal error, atalk_libname undefined])

dnl define the required BDB version
	AC_DEFINE_UNQUOTED(DB_MAJOR_REQ, ${DB_MAJOR_REQ}, [Required BDB version, major])
	AC_DEFINE_UNQUOTED(DB_MINOR_REQ, ${DB_MINOR_REQ}, [Required BDB version, minor])
	AC_DEFINE_UNQUOTED(DB_PATCH_REQ, ${DB_PATCH_REQ}, [Required BDB version, patch])


	AC_ARG_WITH(bdb,
		[  --with-bdb=PATH         specify path to Berkeley DB installation[[auto]]],
		if test "x$withval" = "xno"; then
			dobdbsearch=no
		elif test "x$withval" = "xyes"; then
			dobdbsearch=yes
		else
			bdb_search_dirs="$withval/include $withval"
		fi
	)


	bdbfound=no
        savedcflags="$CFLAGS"
	savedldflags="$LDFLAGS"
	savedcppflags="$CPPFLAGS"
	savedlibs="$LIBS"

	if test "x$dobdbsearch" = "xyes"; then
	    for bdbdir in $bdb_search_dirs; do
		if test $bdbfound = "yes"; then
			break;
		fi
		for subdir in ${search_subdirs}; do
		    AC_MSG_CHECKING([for Berkeley DB headers in ${bdbdir}${subdir}])
		    if test -f "${bdbdir}${subdir}/db.h" ; then
			AC_MSG_RESULT([yes])
			NETATALK_BDB_HEADER([${bdbdir}${subdir}])
			if test ${atalk_cv_bdbheader} != "no"; then
			
dnl			  bdblibdir="`echo $bdbdir | sed 's/\/include\/db4\.*.*//'`"
			  bdblibdir="`echo $bdbdir | sed 's/\/include\/db4.*//'`"
			  bdblibdir="`echo $bdblibdir | sed 's/\/include$//'`"
			  bdblibdir="${bdblibdir}/${atalk_libname}"
dnl			  bdbbindir="`echo $bdbdir | sed 's/include\/db4\.*.*/bin/'`"
			  bdbbindir="`echo $bdbdir | sed 's/\/include\/db4.*/bin/'`"
			  bdbbindir="`echo $bdbbindir | sed 's/include$/bin/'`"

			  CPPFLAGS="-I${bdbdir}${subdir} $CFLAGS"
			  CFLAGS=""
			  LDFLAGS="-L$bdblibdir $LDFLAGS"
			  NETATALK_BERKELEY_LINK
			  if test x"${atalk_cv_lib_db}" != x"no"; then
				NETATALK_BDB_CHECK_VERSION
				if test x"${atalk_cv_bdb_version}" != x"no"; then
				    BDB_LIBS="-L${bdblibdir} ${atalk_cv_lib_db}"
				    BDB_CFLAGS="-I${bdbdir}${subdir}"
                                    BDB_BIN=$bdbbindir
                                    BDB_PATH="`echo $bdbdir | sed 's,include\/db4$,,'`"
                                    BDB_PATH="`echo $BDB_PATH | sed 's,include$,,'`"
				    bdbfound=yes
				    break;
				fi
			  fi	
			  CFLAGS="$savedcflags"
			  LDFLAGS="$savedldflags"
			  CPPFLAGS="$savedcppflags"
			  LIBS="$savedlibs"
			fi
		    else
			AC_MSG_RESULT([no])
		    fi
	        done
	    done
	fi

        CFLAGS="$savedcflags"
        LDFLAGS="$savedldflags"
        CPPFLAGS="$savedcppflags"
        LIBS="$savedlibs"

	if test "x$bdbfound" = "xyes"; then
		ifelse([$1], , :, [$1])
	else
		ifelse([$2], , :, [$2])     
	fi

        CFLAGS_REMOVE_USR_INCLUDE(BDB_CFLAGS)
        LIB_REMOVE_USR_LIB(BDB_LIBS)
	AC_SUBST(BDB_CFLAGS)
	AC_SUBST(BDB_LIBS)
	AC_SUBST(BDB_BIN)
	AC_SUBST(BDB_PATH)
])