7426671624abc8475990c23420c9bb5e78477c1c
[openafs.git] / src / cf / roken.m4
1
2 AC_DEFUN([_OPENAFS_ROKEN_INTERNAL], [
3   DIR_roken=roken
4   CPPFLAGS_roken=
5   LDFLAGS_roken="-L\$(TOP_LIBDIR)"
6   LIB_roken=-lrokenafs
7 ])
8
9 dnl _OPENAFS_ROKEN_PATHS()
10 dnl Set CPPFLAGS_roken, LDFLAGS_roken, and LIB_roken based on the values
11 dnl of roken_root, roken_libdir, and roken_includedir.
12 AC_DEFUN([_OPENAFS_ROKEN_PATHS], [
13   AS_IF([test x"$roken_libdir" != x],
14     [LDFLAGS_roken="-L$roken_libdir"],
15     [AS_IF([test x"$roken_root" != x],
16       [LDFLAGS_roken="-L$roken_root/lib"])])
17   AS_IF([test x"$roken_includedir" != x],
18     [CPPFLAGS_roken="-I$roken_includedir"],
19     [AS_IF([test x"$roken_root" != x],
20       [CPPFLAGS_roken="-I$roken_root/include"])])
21   LIB_roken="-lroken"])
22
23 dnl _OPENAFS_ROKEN_CHECK($action-if-found,
24 dnl                      $action-if-not-found)
25 dnl Find a roken library using $roken_root, $roken_libdir, and $roken_includedir
26 dnl
27 dnl If none of the three paths are specified,
28 dnl try to find one in the standard locations on the system.
29 dnl
30 dnl If we fail, and at least one path was given, then error out. Otherwise,
31 dnl fall back to the internal roken implementation.
32 AC_DEFUN([_OPENAFS_ROKEN_CHECK], [
33
34   _OPENAFS_ROKEN_PATHS
35   save_CPPFLAGS=$CPPFLAGS
36   save_LDFLAGS=$LDFLAGS
37   save_LIBS=$LIBS
38   AS_IF([test x"$CPPFLAGS_roken" != x],
39         [CPPFLAGS="$CPPFLAGS_roken $CPPFLAGS"])
40   AS_IF([test x"$LDFLAGS_roken" != x],
41         [LDFLAGS="$LDFLAGS_roken $LDFLAGS"])
42   AS_IF([test x"$roken_libdir" != x || test x"$roken_includedir" != x],
43         [checkstr=" with specified include and lib paths"],
44         [AS_IF([test x"$roken_root" != x],
45                 [checkstr=" in $roken_root"])])
46
47   AC_MSG_CHECKING([for usable system libroken$checkstr])
48
49   LIBS="$LIBS $LIB_roken"
50   dnl Need to be careful what we check for here, as libroken contains
51   dnl different symbols on different platforms. We cannot simply check
52   dnl if e.g. rk_rename is a symbol or not, since on most platforms it
53   dnl will be a preprocessor define, but on others it will be a symbol.
54   dnl
55   dnl Also note that we need to check for the specific functionality in
56   dnl roken that we use, not just the existence of the library itself,
57   dnl since older versions of roken do not contain all of the functions
58   dnl we need. It may not be practical to check everything we use, so
59   dnl just add functions to check here as we find installations where
60   dnl this breaks.
61   AC_LINK_IFELSE(
62    [AC_LANG_PROGRAM(
63     [[#include <roken.h>]],
64     [[ct_memcmp(NULL, NULL, 0); rk_rename(NULL, NULL);]])],
65    [roken_found=true
66     AC_MSG_RESULT([yes])],
67    [AC_MSG_RESULT([no])])
68
69   CPPFLAGS=$save_CPPFLAGS
70   LDFLAGS=$save_LDFLAGS
71   LIBS=$save_LIBS
72
73   AS_IF([test x"$roken_found" = xtrue],
74          [$1], [$2])
75 ])
76
77 AC_DEFUN([OPENAFS_ROKEN], [
78   roken_root=
79   AC_SUBST(LIB_roken)
80   AC_SUBST(CPPFLAGS_roken)
81   AC_SUBST(LDFLAGS_roken)
82   AC_SUBST(DIR_roken)
83
84   AC_ARG_WITH([roken],
85     [AS_HELP_STRING([--with-roken=DIR],
86         [Location of the roken library, or 'internal'])],
87     [AS_IF([test x"$withval" = xno],
88            [AC_ERROR("OpenAFS requires roken to build")],
89            [AS_IF([test x"$withval" != xyes],
90                   [roken_root="$withval"])
91            ])
92     ])
93   AC_ARG_WITH([roken-include],
94     [AS_HELP_STRING([--with-roken-include=DIR],
95         [Location of roken headers])],
96     [AS_IF([test x"$withval" != xyes && test x"$withval" != xno],
97         [roken_includedir="$withval"])])
98   AC_ARG_WITH([roken-lib],
99     [AS_HELP_STRING([--with-roken-lib=DIR],
100         [Location of roken libraries])],
101     [AS_IF([test x"$withval" != xyes && test x"$withval" != xno],
102         [roken_libdir="$withval"])])
103
104   AS_IF([test x"$roken_root" = xinternal],
105         [_OPENAFS_ROKEN_INTERNAL()],
106         [AS_IF([test x"$roken_root" = x && test x"$roken_libdir" = x &&
107                 test x"$roken_includedir" = x],
108             [_OPENAFS_ROKEN_CHECK([], [_OPENAFS_ROKEN_INTERNAL()])],
109             [_OPENAFS_ROKEN_CHECK([],
110                 [AC_MSG_ERROR([Cannot find roken at that location])])
111             ])
112         ])
113 ])