autoconf: only link binaries that need it to libtirpc
[nfs-utils.git] / aclocal / libtirpc.m4
1 dnl Checks for TI-RPC library and headers
2 dnl
3 AC_DEFUN([AC_LIBTIRPC], [
4
5   AC_ARG_WITH([tirpcinclude],
6               [AC_HELP_STRING([--with-tirpcinclude=DIR],
7                               [use TI-RPC headers in DIR])],
8               [tirpc_header_dir=$withval],
9               [tirpc_header_dir=/usr/include/tirpc])
10
11   dnl if --enable-tirpc was specifed, the following components
12   dnl must be present, and we set up HAVE_ macros for them.
13
14   if test "$enable_tirpc" != "no"; then
15
16     dnl look for the library
17     AC_CHECK_LIB([tirpc], [clnt_tli_create], [:],
18                  [if test "$enable_tirpc" = "yes"; then
19                         AC_MSG_ERROR([libtirpc not found.])
20                   else
21                         AC_MSG_WARN([libtirpc not found. TIRPC disabled!])
22                         enable_tirpc="no"
23                   fi])
24   fi
25
26   if test "$enable_tirpc" != "no"; then
27     dnl also must have the headers installed where we expect
28     dnl look for headers; add -I compiler option if found
29     AC_CHECK_HEADERS([${tirpc_header_dir}/netconfig.h],
30                       AC_SUBST([AM_CPPFLAGS], ["-I${tirpc_header_dir}"]),
31                       [if test "$enable_tirpc" = "yes"; then
32                          AC_MSG_ERROR([libtirpc headers not found.])
33                        else
34                          AC_MSG_WARN([libtirpc headers not found. TIRPC disabled!])
35                          enable_tirpc="no"
36                        fi])
37
38   fi
39
40   dnl now set $LIBTIRPC accordingly
41   if test "$enable_tirpc" != "no"; then
42     AC_DEFINE([HAVE_LIBTIRPC], 1,
43               [Define to 1 if you have and wish to use libtirpc.])
44     LIBTIRPC="-ltirpc"
45   else
46     LIBTIRPC=""
47   fi
48
49   AC_SUBST(LIBTIRPC)
50
51 ])dnl