1dnl Test for a libkafs library or replacement.
2dnl
3dnl Check for a working libkafs library, and if not present, check how we can
4dnl simulate what one would do ourselves, adding the appropriate things to
5dnl LIBOBJS.  Provides the --with-libkafs configure option specify a
6dnl non-standard path to libkafs or (as --without-libkafs) to force use of the
7dnl internal implementation; --with-libkafs-include and --with-libkafs-lib to
8dnl specify paths at a more granular level; and --with-afs,
9dnl --with-afs-include, and --with-afs-lib configure options to specify the
10dnl location of the AFS libraries.
11dnl
12dnl Provides the macro RRA_LIB_KAFS and sets the substition variables
13dnl KAFS_CPPFLAGS, KAFS_LDFLAGS, and KAFS_LIBS.  If Kerberos libraries may be
14dnl needed, LIBS and LDFLAGS must already be set appropriately before calling
15dnl this.  Also provides RRA_LIB_KAFS_SWITCH to set CPPFLAGS, LDFLAGS, and
16dnl LIBS to include libkafs, saving the current values first, and
17dnl RRA_LIB_KAFS_RESTORE to restore those settings to before the last
18dnl RRA_LIB_KFS_SWITCH.
19dnl
20dnl Sets HAVE_K_HASAFS if the k_hasafs function was found in a libkafs
21dnl library.  Sets HAVE_LSETPAG if building against the AFS libraries and the
22dnl lsetpag function is present.  Sets HAVE_KAFS_REPLACEMENT if building the
23dnl replacement kafs library.  Defines HAVE_KAFS_DARWIN8, HAVE_KAFS_DARWIN10,
24dnl HAVE_KAFS_LINUX, HAVE_KAFS_SOLARIS, or HAVE_KAFS_SYSCALL as appropriate if
25dnl the replacement kafs library is needed.
26dnl
27dnl If building a replacement library is needed, sets rra_build_kafs to true.
28dnl Otherwise, sets it to false.  This is intended for use with an Automake
29dnl conditional, but the Automake conditional isn't set directly by this macro
30dnl since AFS support may be optional in the larger package.
31dnl
32dnl Depends on RRA_SET_LDFLAGS.
33dnl
34dnl The canonical version of this file is maintained in the rra-c-util
35dnl package, available at <http://www.eyrie.org/~eagle/software/rra-c-util/>.
36dnl
37dnl Written by Russ Allbery <eagle@eyrie.org>
38dnl Copyright 2008, 2009, 2010
39dnl     The Board of Trustees of the Leland Stanford Junior University
40dnl
41dnl This file is free software; the authors give unlimited permission to copy
42dnl and/or distribute it, with or without modifications, as long as this
43dnl notice is preserved.
44
45dnl Save the current CPPFLAGS, LDFLAGS, and LIBS settings and switch to
46dnl versions that include the libkafs flags.  Used as a wrapper, with
47dnl RRA_LIB_KAFS_RESTORE, around tests.
48AC_DEFUN([RRA_LIB_KAFS_SWITCH],
49[rra_kafs_save_CPPFLAGS="$CPPFLAGS"
50 rra_kafs_save_LDFLAGS="$LDFLAGS"
51 rra_kafs_save_LIBS="$LIBS"
52 CPPFLAGS="$KAFS_CPPFLAGS $CPPFLAGS"
53 LDFLAGS="$KAFS_LDFLAGS $LDFLAGS"
54 LIBS="$KAFS_LIBS $LIBS"])
55
56dnl Restore CPPFLAGS, LDFLAGS, and LIBS to their previous values (before
57dnl RRA_LIB_KAFS_SWITCH was called).
58AC_DEFUN([RRA_LIB_KAFS_RESTORE],
59[CPPFLAGS="$rra_kafs_save_CPPFLAGS"
60 LDFLAGS="$rra_kafs_save_LDFLAGS"
61 LIBS="$rra_kafs_save_LIBS"])
62
63dnl Set KAFS_CPPFLAGS and KAFS_LDFLAGS based on rra_kafs_root,
64dnl rra_kafs_libdir, rra_kafs_includedir, rra_afs_root, rra_afs_libdir, and
65dnl rra_afs_includedir.
66AC_DEFUN([_RRA_LIB_KAFS_PATHS],
67[KAFS_LDFLAGS=
68 AS_IF([test x"$rra_kafs_libdir" != x],
69    [KAFS_LDFLAGS="-L$rra_kafs_libdir"],
70    [AS_IF([test x"$rra_kafs_root" != x],
71        [RRA_SET_LDFLAGS([KAFS_LDFLAGS], [$rra_kafs_root])])])
72 AS_IF([test x"$rra_kafs_includedir" != x],
73    [KAFS_CPPFLAGS="-I$rra_kafs_includedir"],
74    [AS_IF([test x"$rra_kafs_root" != x],
75        [AS_IF([test x"$rra_kafs_root" != x/usr],
76            [KAFS_CPPFLAGS="-I${rra_kafs_root}/include"])])])
77 AS_IF([test x"$rra_afs_libdir" != x],
78    [KAFS_LDFLAGS="$KAFS_LDFLAGS -L$rra_afs_libdir"],
79    [AS_IF([test x"$rra_afs_root" != x],
80        [RRA_SET_LDFLAGS([KAFS_LDFLAGS], [$rra_afs_root])])
81         RRA_SET_LDFLAGS([KAFS_LDFLAGS], [$rra_afs_root], [afs])])
82 AS_IF([test x"$rra_afs_includedir" != x],
83    [KAFS_CPPFLAGS="-I$rra_afs_includedir"],
84    [AS_IF([test x"$rra_afs_root" != x],
85        [AS_IF([test x"$rra_afs_root" != x/usr],
86            [KAFS_CPPFLAGS="$KAFS_CPPFLAGS -I${rra_afs_root}/include"])])])])
87
88dnl Probe for lsetpag in the AFS libraries.  This is required on AIX and IRIX
89dnl since we can't use the regular syscall interface there.
90AC_DEFUN([_RRA_LIB_KAFS_LSETPAG],
91[RRA_LIB_KAFS_SWITCH
92 LIBS=
93 AC_SEARCH_LIBS([pthread_getspecific], [pthread])
94 AC_SEARCH_LIBS([res_search], [resolv], [],
95    [AC_SEARCH_LIBS([__res_search], [resolv])])
96 AC_SEARCH_LIBS([gethostbyname], [nsl])
97 AC_SEARCH_LIBS([socket], [socket], [],
98    [AC_CHECK_LIB([nsl], [socket], [LIBS="-lnsl -lsocket $LIBS"], [],
99        [-lsocket])])
100 rra_kafs_extra="$LIBS"
101 LIBS="$rra_kafs_save_LIBS"
102 AC_CHECK_LIB([afsauthent], [lsetpag],
103    [KAFS_LIBS="-lafsauthent -lafsrpc $rra_kafs_extra"
104     AC_DEFINE([HAVE_LSETPAG], [1],
105        [Define to 1 if you have the OpenAFS lsetpag function.])],
106    [AC_CHECK_LIB([sys], [lsetpag],
107        [KAFS_LIBS="-lsys $rra_kafs_extra"
108         AC_DEFINE([HAVE_LSETPAG], [1],
109            [Define to 1 if you have the OpenAFS lsetpag function.])], [],
110        [$rra_kafs_extra])],
111    [-lafsrpc $rra_kafs_extra])
112 AC_CHECK_HEADERS([afs/afssyscalls.h])
113 RRA_LIB_KAFS_RESTORE])
114
115dnl The public entry point.  Sets up the --with options and then decides what
116dnl to do based on the system.  Either RRA_LIB_KRB5 or RRA_LIB_KRB5_OPTIONAL
117dnl must be called before this function or the Heimdal libkafs may not be
118dnl available.
119AC_DEFUN([RRA_LIB_KAFS],
120[AC_REQUIRE([AC_CANONICAL_HOST])
121 rra_libkafs=true
122 rra_build_kafs=false
123 KAFS_CPPFLAGS=
124 KAFS_LDFLAGS=
125 KAFS_LIBS=
126 AC_SUBST([KAFS_CPPFLAGS])
127 AC_SUBST([KAFS_LDFLAGS])
128 AC_SUBST([KAFS_LIBS])
129
130 dnl In addition to the normal path-finding options, support --without-libkafs
131 dnl to force always using the internal AFS syscall code.
132 AC_ARG_WITH([libkafs],
133    AC_HELP_STRING([--with-libkafs=DIR],
134        [Location of kafs headers and libraries]),
135    [AS_IF([test x"$withval" = xno],
136        [rra_libkafs=false],
137        [AS_IF([test x"$withval" != xyes], [rra_krb5_root="$withval"])])])
138 AC_ARG_WITH([libkafs-include],
139    [AS_HELP_STRING([--with-libkafs-include=DIR],
140        [Location of kafs headers])],
141    [AS_IF([test x"$withval" != xyes && test x"$withval" != xno],
142        [rra_kafs_includedir="$withval"])])
143 AC_ARG_WITH([libkafs-lib],
144    [AS_HELP_STRING([--with-libkafs-lib=DIR],
145        [Location of kafs libraries])],
146    [AS_IF([test x"$withval" != xyes && test x"$withval" != xno],
147        [rra_kafs_libdir="$withval"])])
148
149 dnl The location of the AFS headers and libraries.  We may not use these
150 dnl results, but configure always includes the prompt, so always handle them.
151 dnl This should probably be in a separate macro file.
152 AC_ARG_WITH([afs],
153    [AC_HELP_STRING([--with-afs=DIR],
154        [Location of AFS headers and libraries])],
155    [AS_IF([test x"$withval" != xno && test x"$withval" != xyes],
156        [rra_afs_root="$withval"])])
157 AC_ARG_WITH([afs-include],
158    [AS_HELP_STRING([--with-afs-include=DIR],
159        [Location of AFS headers])],
160    [AS_IF([test x"$withval" != xyes && test x"$withval" != xno],
161        [rra_afs_includedir="$withval"])])
162 AC_ARG_WITH([afs-lib],
163    [AS_HELP_STRING([--with-afs-lib=DIR],
164        [Location of AFS libraries])],
165    [AS_IF([test x"$withval" != xyes && test x"$withval" != xno],
166        [rra_afs_libdir="$withval"])])
167
168 dnl If we may use the system libkafs, see if we can find one.  Enable the
169 dnl Kerberos libraries if we found any, in case libkafs depends on Kerberos.
170 AC_CHECK_HEADERS([sys/ioccom.h])
171 AS_IF([test x"$rra_libkafs" != xfalse],
172    [_RRA_LIB_KAFS_PATHS
173     AS_IF([test x"$rra_use_KRB5" = xtrue],
174         [RRA_LIB_KRB5_SWITCH])
175     RRA_LIB_KAFS_SWITCH
176     AC_CHECK_LIB([kafs], [k_hasafs],
177        [KAFS_LIBS="-lkafs"
178         AC_CHECK_HEADERS([kafs.h])],
179        [AC_CHECK_LIB([kopenafs], [k_hasafs],
180            [KAFS_LIBS="-lkopenafs"
181             AC_CHECK_HEADERS([kopenafs.h])],
182            [rra_libkafs=false])])
183     RRA_LIB_KAFS_RESTORE
184     RRA_LIB_KAFS_SWITCH
185     AC_CHECK_FUNCS([k_pioctl])
186     AC_REPLACE_FUNCS([k_haspag])
187     RRA_LIB_KAFS_RESTORE
188     AS_IF([test x"$rra_use_KRB5" = xtrue],
189         [RRA_LIB_KRB5_RESTORE])])
190
191 dnl If we found a libkafs, we have k_hasafs.  Set the appropriate
192 dnl preprocessor define.  Otherwise, we'll use our portability layer.
193 AS_IF([test x"$rra_libkafs" = xtrue],
194    [AC_DEFINE([HAVE_K_HASAFS], 1,
195        [Define to 1 if you have the k_hasafs function.])],
196    [AC_LIBOBJ([k_haspag])
197     AS_CASE([$host],
198        [[*-apple-darwin[89]*]],
199        [rra_build_kafs=true
200         AC_DEFINE([HAVE_KAFS_REPLACEMENT], [1],
201            [Define to 1 if the libkafs replacement is built.])
202         AC_DEFINE([HAVE_KAFS_DARWIN8], [1],
203            [Define to 1 to use the Mac OS X 10.4 /dev interface.])],
204
205        [*-apple-darwin1*],
206        [rra_build_kafs=true
207         AC_DEFINE([HAVE_KAFS_REPLACEMENT], [1],
208            [Define to 1 if the libkafs replacement is built.])
209         AC_DEFINE([HAVE_KAFS_DARWIN10], [1],
210            [Define to 1 to use the Mac OS X 10.6 /dev interface.])],
211
212        [*-aix*|*-irix*],
213        [_RRA_LIB_KAFS_LSETPAG],
214
215        [*-linux*],
216        [rra_build_kafs=true
217         AC_DEFINE([HAVE_KAFS_REPLACEMENT], [1],
218            [Define to 1 if the libkafs replacement is built.])
219         AC_DEFINE([HAVE_KAFS_LINUX], [1],
220            [Define to 1 to use the Linux AFS /proc interface.])],
221
222        [[*-solaris2.1[12345678]*]],
223        [rra_build_kafs=true
224         AC_DEFINE([HAVE_KAFS_REPLACEMENT], [1],
225            [Define to 1 if the libkafs replacement is built.])
226         AC_DEFINE([HAVE_KAFS_SOLARIS], [1],
227            [Define to 1 to use the Solaris 11 /dev interface.])
228         AC_DEFINE([_REENTRANT], [1],
229            [Define to 1 on Solaris for threaded errno handling.])],
230
231        [*],
232        [rra_build_kafs=true
233         _RRA_LIB_KAFS_PATHS
234         RRA_LIB_KAFS_SWITCH
235         AC_CHECK_HEADERS([afs/param.h], [],
236            [AC_MSG_ERROR([need afs/param.h to build libkafs replacement])])
237         RRA_LIB_KAFS_RESTORE
238         AC_DEFINE([HAVE_KAFS_REPLACEMENT], [1],
239            [Define to 1 if the libkafs replacement is built.])
240         AC_DEFINE([HAVE_KAFS_SYSCALL], [1],
241            [Define to 1 to use the AFS syscall interface.])
242         AC_DEFINE([_REENTRANT], [1],
243            [Define to 1 on Solaris for threaded errno handling.])])])])
244