1AC_DEFUN([AC_NETATALK_CNID], [
2    dnl Don't use BDB unless it's needed
3    bdb_required=no
4    compiled_backends=""
5
6    dnl Determine whether or not to use Database Daemon CNID backend
7    AC_MSG_CHECKING([whether or not to use Database Daemon CNID backend])
8    AC_ARG_WITH(cnid-dbd-backend,
9    [  --with-cnid-dbd-backend       build CNID with Database Daemon Data Store [[yes]]],
10    [   if test x"$withval" = x"no"; then
11            use_dbd_backend=no
12            AC_MSG_RESULT([no])
13        else
14            use_dbd_backend=yes
15            AC_MSG_RESULT([yes])
16        fi
17    ],[
18        use_dbd_backend=yes
19        AC_MSG_RESULT([yes])
20    ])
21
22    if test $use_dbd_backend = yes; then
23        compiled_backends="$compiled_backends dbd"
24        AC_DEFINE(CNID_BACKEND_DBD, 1, [Define if CNID Database Daemon backend should be compiled.])
25        if test x"$DEFAULT_CNID_SCHEME" = x; then
26            DEFAULT_CNID_SCHEME=dbd
27        fi
28        bdb_required=yes
29    fi
30    AM_CONDITIONAL(BUILD_DBD_DAEMON, test x"$use_dbd_backend" = x"yes")
31
32    dnl Determine whether or not to use BDB Concurrent Data Store
33    AC_MSG_CHECKING([whether or not to use BDB Concurrent Data Store])
34    AC_ARG_WITH(cnid-cdb-backend,
35	[  --with-cnid-cdb-backend	build CNID with Concurrent BDB Data Store  [[no]]],[
36	    if test x"$withval" = x"no"; then
37	        use_cdb_backend=no
38        else
39            use_cdb_backend=yes
40        fi
41    ],[
42        use_cdb_backend=no
43    ])
44
45
46    if test $use_cdb_backend = yes; then
47        AC_MSG_RESULT([yes])
48        AC_DEFINE(CNID_BACKEND_CDB, 1, [Define if CNID Concurrent BDB backend should be compiled.])
49        if test x"$DEFAULT_CNID_SCHEME" = x; then
50            DEFAULT_CNID_SCHEME=cdb
51        fi
52        bdb_required=yes
53        compiled_backends="$compiled_backends cdb"
54    else
55        AC_MSG_RESULT([no])
56    fi
57    AM_CONDITIONAL(USE_CDB_BACKEND, test x"$use_cdb_backend" = x"yes")
58
59    dnl Determine whether or not to use LAST DID scheme
60    AC_MSG_CHECKING([whether or not to use LAST DID scheme])
61    AC_ARG_WITH(cnid-last-backend,
62	[  --with-cnid-last-backend	build LAST CNID scheme                     [[yes]]],
63	[
64        if test x"$withval" = x"no"; then
65            use_last_backend=no
66        else
67            use_last_backend=yes
68        fi
69    ],[
70        use_last_backend=yes
71    ])
72
73    if test $use_last_backend = yes; then
74        AC_MSG_RESULT([yes])
75        AC_DEFINE(CNID_BACKEND_LAST, 1, [Define if CNID LAST scheme backend should be compiled.])
76        if test x"$DEFAULT_CNID_SCHEME" = x; then
77            DEFAULT_CNID_SCHEME=last
78        fi
79        compiled_backends="$compiled_backends last"
80    else
81        AC_MSG_RESULT([no])
82    fi
83    AM_CONDITIONAL(USE_LAST_BACKEND, test x"$use_last_backend" = x"yes")
84
85    dnl Determine whether or not to use TDB DID scheme
86    AC_MSG_CHECKING([whether or not to use TDB DID scheme])
87    AC_ARG_WITH(cnid-tdb-backend,
88	[  --with-cnid-tdb-backend	build TDB CNID scheme                      [[yes]]],
89    [
90        if test x"$withval" = x"no"; then
91            use_tdb_backend=no
92        else
93            use_tdb_backend=yes
94        fi
95    ],[
96        use_tdb_backend=yes
97    ])
98
99    if test $use_tdb_backend = yes; then
100        AC_MSG_RESULT([yes])
101        AC_DEFINE(CNID_BACKEND_TDB, 1, [Define if CNID TDB scheme backend should be compiled.])
102        if test x"$DEFAULT_CNID_SCHEME" = x; then
103            DEFAULT_CNID_SCHEME=tdb
104        fi
105        compiled_backends="$compiled_backends tdb"
106    else
107        AC_MSG_RESULT([no])
108    fi
109    AM_CONDITIONAL(USE_TDB_BACKEND, test x"$use_tdb_backend" = x"yes")
110
111    dnl Check for mysql CNID backend
112    AC_ARG_VAR(MYSQL_CFLAGS, [C compiler flags for MySQL, overriding checks])
113    AC_ARG_VAR(MYSQL_LIBS, [linker flags for MySQL, overriding checks])
114
115    AC_MSG_CHECKING([MySQL library and headers])
116    AC_ARG_WITH(
117        mysql-config,
118        [AS_HELP_STRING([--with-mysql-config=PATH],[Path to mysql-config binary (default: mysql_config)])],
119        MYSQL_CONFIG=$withval
120    )
121
122    if test -z "$MYSQL_CONFIG" -a -z "$MYSQL_CFLAGS" -a -z "$MYSQL_LIBS" ; then
123        AC_PATH_PROG(MYSQL_CONFIG, mysql_config)
124    fi
125
126    if test -x "$MYSQL_CONFIG" ; then
127        AC_MSG_RESULT([$MYSQL_CONFIG])
128        MYSQL_CFLAGS="`$MYSQL_CONFIG --cflags`"
129        MYSQL_LIBS="`$MYSQL_CONFIG --libs`"
130        ac_cv_with_cnid_mysql="yes"
131    elif test -n "$MYSQL_CFLAGS" -a -n "$MYSQL_LIBS" ; then
132        ac_cv_with_cnid_mysql="yes"
133    fi
134
135    if test x"$ac_cv_with_cnid_mysql" = x"yes" ; then
136        compiled_backends="$compiled_backends mysql"
137        AC_DEFINE(CNID_BACKEND_MYSQL, 1, [whether the MySQL CNID module is available])
138    fi
139
140    AC_SUBST(MYSQL_CFLAGS)
141    AC_SUBST(MYSQL_LIBS)
142    AM_CONDITIONAL(USE_MYSQL_BACKEND, test x"$ac_cv_with_cnid_mysql" = x"yes")
143
144    dnl Set default DID scheme
145    AC_MSG_CHECKING([default DID scheme])
146    AC_ARG_WITH(cnid-default-backend,
147	[  --with-cnid-default-backend=val	set default DID scheme [[dbd]]],
148    [
149        if test x"$withval" = x; then
150            AC_MSG_RESULT([ignored])
151        else
152            DEFAULT_CNID_SCHEME=$withval
153            AC_MSG_RESULT($DEFAULT_CNID_SCHEME)
154        fi
155    ],[
156        AC_MSG_RESULT($DEFAULT_CNID_SCHEME)
157    ])
158
159    if test x"$DEFAULT_CNID_SCHEME" = x; then
160        AC_MSG_ERROR([No DID schemes compiled in ])
161    fi
162
163    AC_MSG_CHECKING([whether default CNID scheme has been activated])
164    found_scheme=no
165    for scheme in $compiled_backends ; do
166        if test x"$scheme" = x"$DEFAULT_CNID_SCHEME"; then
167            found_scheme=yes
168        fi
169    done
170    if test x"$found_scheme" = x"no"; then
171        AC_MSG_RESULT([no])
172        AC_MSG_ERROR([Specified default CNID scheme $DEFAULT_CNID_SCHEME was not selected for compilation])
173    else
174        AC_MSG_RESULT([yes])
175    fi
176
177    AC_DEFINE_UNQUOTED(DEFAULT_CNID_SCHEME, "$DEFAULT_CNID_SCHEME", [Default CNID scheme to be used])
178    AC_SUBST(DEFAULT_CNID_SCHEME)
179    AC_SUBST(compiled_backends)
180
181    if test "x$bdb_required" = "xyes"; then
182	ifelse([$1], , :, [$1])
183    else
184	ifelse([$2], , :, [$2])
185    fi
186])
187