summaryrefslogtreecommitdiff
path: root/m4/kaserver.m4
blob: 707a11362bb9240773ed2f5242edf8dacdab1c56 (plain)
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
dnl kaserver.m4 -- Find the compiler and linker flags for OpenAFS kaserver.
dnl
dnl If --with-kaserver is given, finds the compiler and linker flags for
dnl building with OpenAFS libraries; sets AFS_CPPFLAGS, AFS_LDFLAGS, and
dnl AFS_LIBS as appropriate; and defines HAVE_AFS.  Provides the macro
dnl RRA_LIB_AFS, which takes no arguments.
dnl
dnl This function also sets rra_kaserver to true if AFS was requested, which
dnl can be checked to determine if further checks should be done.
dnl
dnl Also provides RRA_LIB_AFS_SET to set CPPFLAGS, LDFLAGS, and LIBS to
dnl include the AFS libraries; RRA_LIB_AFS_SWITCH to do the same but save the
dnl current values first; and RRA_LIB_AFS_RESTORE to restore those settings to
dnl before the last RRA_LIB_AFS_SWITCH.
dnl
dnl Written by Russ Allbery <rra@stanford.edu>
dnl Based on code developed by Derrick Brashear and Ken Hornstein of Sine
dnl Nomine Associates, on behalf of Stanford University.
dnl Copyright 2006, 2007, 2008
dnl     Board of Trustees, Leland Stanford Jr. University
dnl
dnl See LICENSE for licensing terms.

dnl Set CPPFLAGS, LDFLAGS, and LIBS to values including the AFS settings.
AC_DEFUN([RRA_LIB_AFS_SET],
[CPPFLAGS="$AFS_CPPFLAGS $CPPFLAGS"
 LDFLAGS="$AFS_LDFLAGS $LDFLAGS"
 LIBS="$AFS_LIBS $LIBS"])

dnl Save the current CPPFLAGS, LDFLAGS, and LIBS settings and switch to
dnl versions that include the AFS flags.  Used as a wrapper, with
dnl RRA_LIB_AFS_RESTORE, around tests.
AC_DEFUN([RRA_LIB_AFS_SWITCH],
[rra_afs_save_CPPFLAGS="$CPPFLAGS"
 rra_afs_save_LDFLAGS="$LDFLAGS"
 rra_afs_save_LIBS="$LIBS"
 RRA_LIB_AFS_SET])

dnl Restore CPPFLAGS, LDFLAGS, and LIBS to their previous values (before
dnl RRA_LIB_AFS_SWITCH was called).
AC_DEFUN([RRA_LIB_AFS_RESTORE],
[CPPFLAGS="$rra_afs_save_CPPFLAGS"
 LDFLAGS="$rra_afs_save_LDFLAGS"
 LIBS="$rra_afs_save_LIBS"])

dnl The function that does the work checking for the AFS libraries.
AC_DEFUN([_RRA_LIB_AFS_CHECK],
[RRA_LIB_AFS_SET
 LIBS=
 AC_SEARCH_LIBS([pthread_getspecific], [pthread])
 AC_SEARCH_LIBS([res_search], [resolv], ,
    [AC_SEARCH_LIBS([__res_search], [resolv])])
 AC_SEARCH_LIBS([gethostbyname], [nsl])
 AC_SEARCH_LIBS([socket], [socket], ,
    [AC_CHECK_LIB([nsl], [socket], [LIBS="-lnsl -lsocket $LIBS"], ,
        [-lsocket])])
 AFS_LIBS="$AFS_LIBS $LIBS"
 LIBS="$AFS_LIBS"
 AC_CACHE_CHECK([whether linking with AFS libraries work], [rra_cv_lib_afs],
 [AC_TRY_LINK(
[#include <afs/param.h>
#include <afs/kautils.h>],
[char cell[256] = "EXAMPLE.COM";
char realm[256];
int local;

ka_CellToRealm(cell, realm, &local);],
      [rra_cv_lib_afs=yes],
      [rra_cv_lib_afs=no])])
 AS_IF([test "$rra_cv_lib_afs" = no],
    [AC_MSG_ERROR([unable to link test AFS program])])
 RRA_LIB_AFS_RESTORE])

dnl The public entry point.  Sets up the --with option and only does the
dnl library check if AFS linkage was requested.
AC_DEFUN([RRA_LIB_AFS],
[rra_afs=false
 AFS_CPPFLAGS=
 AFS_LDFLAGS=
 AFS_LIBS="-lafsauthent -lafsrpc"
 AC_SUBST([AFS_CPPFLAGS])
 AC_SUBST([AFS_LDFLAGS])
 AC_SUBST([AFS_LIBS])
 AC_ARG_WITH([kaserver],
    [AC_HELP_STRING([--with-kaserver@<:@=DIR@:>@],
        [Compile with AFS kaserver sync support])],
    [AS_IF([test x"$withval" != xno],
        [rra_afs=true
         AS_IF([test x"$withval" != xyes],
            [AFS_CPPFLAGS="-I${withval}/include"
             AFS_LDFLAGS="-L${withval}/lib"])
         _RRA_LIB_AFS_CHECK
         AC_DEFINE([HAVE_AFS], 1,
             [Define to enable AFS kaserver support.])])])])