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