-> Clean up the use of autoconf macros a bit.
[tftp-hpa.git] / aclocal.m4
blobbf0e28f01f1179aa4a4c220a55db399cfa087dce
1 dnl --------------------------------------------------------------------------
2 dnl PA_ADD_CFLAGS()
3 dnl
4 dnl Attempt to add the given option to CFLAGS, if it doesn't break compilation
5 dnl --------------------------------------------------------------------------
6 AC_DEFUN(PA_ADD_CFLAGS,
7 [AC_MSG_CHECKING([if $CC accepts $1])
8  pa_add_cflags__old_cflags="$CFLAGS"
9  CFLAGS="$CFLAGS $1"
10  AC_TRY_COMPILE([#include <stdio.h>],
11  [printf("Hello, World!\n");],
12  AC_MSG_RESULT([yes]),
13  AC_MSG_RESULT([no])
14  CFLAGS="$pa_add_cflags__old_cflags")])
16 dnl --------------------------------------------------------------------------
17 dnl PA_SIGSETJMP
18 dnl
19 dnl Do we have sigsetjmp/siglongjmp?  (AC_CHECK_FUNCS doesn't seem to work
20 dnl for these particular functions.)
21 dnl --------------------------------------------------------------------------
22 AC_DEFUN(PA_SIGSETJMP,
23 [AC_MSG_CHECKING([for sigsetjmp])
24  AC_TRY_LINK([
25 #ifdef HAVE_SETJMP_H
26 #include <setjmp.h>
27 #endif],
28  [sigjmp_buf buf;
29   sigsetjmp(buf,1);
30   siglongjmp(buf,2);],
31  AC_MSG_RESULT([yes])
32  $1,
33  AC_MSG_RESULT([no])
34  $2)])
36 dnl --------------------------------------------------------------------------
37 dnl PA_MSGHDR_MSG_CONTROL
38 dnl
39 dnl Does struct msghdr have the msg_control field?
40 dnl --------------------------------------------------------------------------
41 AH_TEMPLATE([HAVE_MSGHDR_MSG_CONTROL],
42 [Define if struct msghdr has the msg_control field.])
44 AC_DEFUN(PA_MSGHDR_MSG_CONTROL,
45  [AC_CHECK_MEMBER(struct msghdr.msg_control,
46   [AC_DEFINE(HAVE_MSGHDR_MSG_CONTROL)],
47   [],
48   [
49 #include <sys/types.h>
50 #include <sys/socket.h>
51 #include <netinet/in.h>
52   ])])
54 dnl ------------------------------------------------------------------------
55 dnl  PA_STRUCT_IN_PKTINFO
56 dnl 
57 dnl Look for definition of struct in_pktinfo, which at least has an
58 dnl ipi_addr member.  Some versions of glibc lack struct in_pktinfo;
59 dnl if so we need to include the definition ourselves -- but we only
60 dnl want to do that if absolutely necessary!
61 dnl ------------------------------------------------------------------------
62 AH_TEMPLATE([HAVE_STRUCT_IN_PKTINFO],
63 [Define if struct in_pktinfo is defined.])
65 AC_DEFUN(PA_STRUCT_IN_PKTINFO,
66  [AC_CHECK_MEMBER(struct in_pktinfo.ipi_addr,
67   [AC_DEFINE(HAVE_STRUCT_IN_PKTINFO)],
68   [],
69   [
70 #include <sys/types.h>
71 #include <sys/socket.h>
72 #include <netinet/in.h>
73 #include <arpa/inet.h>
74 #include <stdlib.h>
75 #include <sys/uio.h>
76   ])])
78 dnl --------------------------------------------------------------------------
79 dnl PA_HAVE_TCPWRAPPERS
80 dnl
81 dnl Do we have the tcpwrappers -lwrap?  This can't be done using AC_CHECK_LIBS
82 dnl due to the need to provide "allow_severity" and "deny_severity" variables
83 dnl --------------------------------------------------------------------------
84 AH_TEMPLATE([HAVE_TCPWRAPPERS],
85 [Define if we have tcpwrappers (-lwrap) and <tcpd.h>.])
87 AC_DEFUN(PA_HAVE_TCPWRAPPERS,
88 [AC_CHECK_LIB([wrap], [main])
89  AC_MSG_CHECKING([for tcpwrappers])
90  AC_TRY_LINK(
92 #include <tcpd.h>
93 int allow_severity = 0;
94 int deny_severity = 0;
97         hosts_ctl("sample_daemon", STRING_UNKNOWN, STRING_UNKNOWN, STRING_UNKNOWN);
100         AC_DEFINE(HAVE_TCPWRAPPERS)
101         AC_MSG_RESULT([yes])
104         AC_MSG_RESULT([no])
105 ])])
107 dnl ------------------------------------------------------------------------
108 dnl  PA_CHECK_INTTYPES_H_SANE
110 dnl  At least some versions of AIX 4 have <inttypes.h> macros which are
111 dnl  completely broken.  Try to detect those.
112 dnl --------------------------------------------------------------------------
113 AH_TEMPLATE([INTTYPES_H_IS_SANE],
114 [Define if the macros in <inttypes.h> are usable])
116 AC_DEFUN(PA_CHECK_INTTYPES_H_SANE,
117 [AC_CHECK_HEADERS(inttypes.h,
119   AC_MSG_CHECKING([if inttypes.h is sane])
120   AC_TRY_LINK(
121   [
122 #include <inttypes.h>
123 #include <stdio.h>
124   ],
125   [uintmax_t max = UINTMAX_C(0);
126    printf("%"PRIuMAX"\n", max);],
127   AC_MSG_RESULT([yes])
128   AC_DEFINE(INTTYPES_H_IS_SANE),
129   AC_MSG_RESULT([no (AIX, eh?)]))
130  ])
133 dnl ------------------------------------------------------------------------
134 dnl  PA_WITH_BOOL
136 dnl  PA_WITH_BOOL(option, default, help, enable, disable)
138 dnl  Provides a more convenient way to specify --with-option and
139 dnl  --without-option, with a default.  default should be either 0 or 1.
140 dnl ------------------------------------------------------------------------
141 AC_DEFUN(PA_WITH_BOOL,
142 [AC_ARG_WITH([$1], [$3],
143 if test ["$withval"] != no; then
144 [$4]
145 else
146 [$5]
148 if test [$2] -ne 0; then
149 [$4]
150 else
151 [$5]
152 fi)])
154 dnl --------------------------------------------------------------------------
155 dnl  PA_HEADER_DEFINES
157 dnl  PA_HEADER_DEFINES(header, type, value)
158 dnl --------------------------------------------------------------------------
159 AC_DEFUN(PA_HEADER_DEFINES,
160 [AC_MSG_CHECKING([if $1 defines $3])
161  AH_TEMPLATE([HAVE_$3_DEFINITION], [Define if $1 defines $3])
162  AC_TRY_COMPILE([
163 #include <$1>
166 int main()
168         $2 dummy = $3;
169         return 0;
173  pa_header_define=`echo HAVE_$3_DEFINITION | tr '[a-z]' '[A-Z]'`
174  AC_DEFINE_UNQUOTED($pa_header_define)
175  AC_MSG_RESULT(yes)
178  AC_MSG_RESULT(no)
179 ])])
181 dnl --------------------------------------------------------------------------