e96abd6d4a558b0cc21ff3d654fa2b95e5557e4b
[nfs-utils.git] / aclocal.m4
1 dnl aclocal.m4 -- custom autoconf macros for various purposes
2 dnl Updated for Autoconf v2
3 dnl
4 dnl ******** save/restore stuff **********
5 define(AC_KNFSD_SAVE,
6   [AC_LANG_SAVE
7    save_LDFLAGS=$LDFLAGS
8    save_CFLAGS=$CFLAGS
9    save_CXXFLAGS=$CXXFLAGS
10    save_LIBS=$LIBS
11 ])dnl
12 define(AC_KNFSD_RESTORE,
13   [LDFLAGS=$save_LDFLAGS
14    CFLAGS=$save_CFLAGS
15    CXXFLAGS=$save_CXXFLAGS
16    LIBS=$save_LIBS
17    AC_LANG_RESTORE
18 ])dnl
19 dnl *********** GNU libc 2 ***************
20 define(AC_GNULIBC,
21   [AC_MSG_CHECKING(for GNU libc2)
22   AC_CACHE_VAL(knfsd_cv_glibc2,
23   [AC_TRY_CPP([
24       #include <features.h>
25       #if !defined(__GLIBC__)
26       # error Nope
27       #endif], knfsd_cv_glibc2=yes, knfsd_cv_glibc2=no)])
28   AC_MSG_RESULT($knfsd_cv_glibc2)
29   if test $knfsd_cv_glibc2 = yes; then
30     CFLAGS="$CFLAGS -D_GNU_SOURCE"
31     CXXFLAGS="$CXXFLAGS -D_GNU_SOURCE"
32   fi
33 ]) dnl
34 dnl
35 dnl ************* egcs *******************
36 define(AC_PROG_EGCS,
37   [AC_MSG_CHECKING(for egcs)
38   AC_CACHE_VAL(knfsd_cv_prog_EGCS,
39   [case `$CC --version 2>/dev/null` in
40    egcs*)
41         knfsd_cv_prog_EGCS=yes;;
42    *)
43         knfsd_cv_prog_EGCS=no;;
44    esac
45   ])
46   AC_MSG_RESULT($knfsd_cv_prog_EGCS)
47   test $knfsd_cv_prog_EGCS = yes && AC_DEFINE(HAVE_EGCS)
48 ]) dnl
49 dnl *********** sizeof(dev_t) **************
50 dnl ** We have to kludge this rather than use AC_CHECK_SIZEOF because
51 dnl ** we have to include sys/types.h. Ugh.
52 define(AC_DEV_T_SIZE,
53   [AC_MSG_CHECKING(size of dev_t)
54    AC_CACHE_VAL(ac_cv_sizeof_dev_t,
55    [AC_TRY_LINK(
56     [#include <stdio.h>
57      #include <sys/types.h>
58      main()
59      {
60       FILE *f=fopen("conftestval", "w");
61       if (!f) exit(1);
62       fprintf(f, "%d\n", sizeof(dev_t));
63       exit(0);
64     }], ac_cv_sizeof_dev_t=`cat conftestval`, ac_cv_sizeof_dev_t=0)])
65     AC_MSG_RESULT($ac_cv_sizeof_dev_t)
66     AC_DEFINE(SIZEOF_DEV_T,$ac_cv_sizeof_dev_t)
67   ])
68 dnl *********** sizeof(xxx_t) **************
69 dnl ** Overwrite the AC_CHECK_SIZEOF macro as we must include sys/types.h
70 define([AC_CHECK_SIZEOF],
71   [changequote(<<, >>)dnl
72    define(<<AC_TYPE_NAME>>,translit(sizeof_$1, [a-z *], [A-Z_P]))dnl
73    define(<<AC_CV_NAME>>, translit(ac_cv_sizeof_$1, [ *], [_p]))dnl
74    changequote([, ])dnl
75    AC_MSG_CHECKING(size of $1)
76    AC_CACHE_VAL(AC_CV_NAME,
77    [AC_TRY_RUN(
78     [#include <stdio.h>
79      #include <sys/types.h>
80      main()
81      {
82       FILE *f=fopen("conftestval", "w");
83       if (!f) exit(1);
84       fprintf(f, "%d\n", sizeof($1));
85       exit(0);
86     }], AC_CV_NAME=`cat conftestval`, AC_CV_NAME=0)])
87     AC_MSG_RESULT($AC_CV_NAME)
88     AC_DEFINE_UNQUOTED(AC_TYPE_NAME,$AC_CV_NAME)
89     undefine([AC_TYPE_NAME])dnl
90     undefine([AC_CV_NAME])dnl
91   ])
92 dnl *********** BSD vs. POSIX signal handling **************
93 define([AC_BSD_SIGNALS],
94   [AC_MSG_CHECKING(for BSD signal semantics)
95   AC_CACHE_VAL(knfsd_cv_bsd_signals,
96     [AC_TRY_RUN([
97         #include <signal.h>
98         #include <unistd.h>
99         #include <sys/wait.h>
100
101         static int counter = 0;
102         static RETSIGTYPE handler(int num) { counter++; }
103
104         int main()
105         {
106                 int     s;
107                 if ((s = fork()) < 0) return 1;
108                 if (s != 0) {
109                         if (wait(&s) < 0) return 1;
110                         return WIFSIGNALED(s)? 1 : 0;
111                 }
112
113                 signal(SIGHUP, handler);
114                 kill(getpid(), SIGHUP); kill(getpid(), SIGHUP);
115                 return (counter == 2)? 0 : 1;
116         }
117     ], knfsd_cv_bsd_signals=yes, knfsd_cv_bsd_signals=no)]) dnl
118     AC_MSG_RESULT($knfsd_cv_bsd_signals)
119     test $knfsd_cv_bsd_signals = yes && AC_DEFINE(HAVE_BSD_SIGNALS)
120 ])dnl
121 dnl *********** the tcp wrapper library ***************
122 define(AC_TCP_WRAPPER,
123   [AC_MSG_CHECKING(for the tcp wrapper library)
124   AC_CACHE_VAL(knfsd_cv_tcp_wrapper,
125   [old_LIBS="$LIBS"
126    LIBS="$LIBS -lwrap $LIBNSL"
127    AC_TRY_LINK([
128       int deny_severity = 0;
129       int allow_severity = 0;],
130       [return hosts_ctl ("nfsd", "", "")],
131       knfsd_cv_tcp_wrapper=yes, knfsd_cv_tcp_wrapper=no)
132    LIBS="$old_LIBS"])
133   AC_MSG_RESULT($knfsd_cv_tcp_wrapper)
134   if test "$knfsd_cv_tcp_wrapper" = yes; then
135     CFLAGS="$CFLAGS -DHAVE_TCP_WRAPPER"
136     CXXFLAGS="$CXXFLAGS -DHAVE_TCP_WRAPPER"
137     LIBWRAP="-lwrap"
138   fi
139 ]) dnl