William Ahern:
[platform/upstream/c-ares.git] / acinclude.m4
1 dnl Check for how to set a socket to non-blocking state. There seems to exist\r
2 dnl four known different ways, with the one used almost everywhere being POSIX\r
3 dnl and XPG3, while the other different ways for different systems (old BSD,\r
4 dnl Windows and Amiga).\r
5 dnl\r
6 dnl There are two known platforms (AIX 3.x and SunOS 4.1.x) where the\r
7 dnl O_NONBLOCK define is found but does not work. This condition is attempted\r
8 dnl to get caught in this script by using an excessive number of #ifdefs...\r
9 dnl\r
10 AC_DEFUN([CURL_CHECK_NONBLOCKING_SOCKET],\r
11 [\r
12   AC_MSG_CHECKING([non-blocking sockets style])\r
13 \r
14   AC_TRY_COMPILE([\r
15 /* headers for O_NONBLOCK test */\r
16 #include <sys/types.h>\r
17 #include <unistd.h>\r
18 #include <fcntl.h>\r
19 ],[\r
20 /* try to compile O_NONBLOCK */\r
21 \r
22 #if defined(sun) || defined(__sun__) || defined(__SUNPRO_C) || defined(__SUNPRO_CC)\r
23 # if defined(__SVR4) || defined(__srv4__)\r
24 #  define PLATFORM_SOLARIS\r
25 # else\r
26 #  define PLATFORM_SUNOS4\r
27 # endif\r
28 #endif\r
29 #if (defined(_AIX) || defined(__xlC__)) && !defined(_AIX4)\r
30 # define PLATFORM_AIX_V3\r
31 #endif\r
32 \r
33 #if defined(PLATFORM_SUNOS4) || defined(PLATFORM_AIX_V3) || defined(__BEOS__)\r
34 #error "O_NONBLOCK does not work on this platform"\r
35 #endif\r
36   int socket;\r
37   int flags = fcntl(socket, F_SETFL, flags | O_NONBLOCK);\r
38 ],[\r
39 dnl the O_NONBLOCK test was fine\r
40 nonblock="O_NONBLOCK"\r
41 AC_DEFINE(HAVE_O_NONBLOCK, 1, [use O_NONBLOCK for non-blocking sockets])\r
42 ],[\r
43 dnl the code was bad, try a different program now, test 2\r
44 \r
45   AC_TRY_COMPILE([\r
46 /* headers for FIONBIO test */\r
47 #include <unistd.h>\r
48 #include <stropts.h>\r
49 ],[\r
50 /* FIONBIO source test (old-style unix) */\r
51  int socket;\r
52  int flags = ioctl(socket, FIONBIO, &flags);\r
53 ],[\r
54 dnl FIONBIO test was good\r
55 nonblock="FIONBIO"\r
56 AC_DEFINE(HAVE_FIONBIO, 1, [use FIONBIO for non-blocking sockets])\r
57 ],[\r
58 dnl FIONBIO test was also bad\r
59 dnl the code was bad, try a different program now, test 3\r
60 \r
61   AC_TRY_COMPILE([\r
62 /* headers for ioctlsocket test (cygwin?) */\r
63 #include <windows.h>\r
64 ],[\r
65 /* ioctlsocket source code */\r
66  int socket;\r
67  unsigned long flags = ioctlsocket(socket, FIONBIO, &flags);\r
68 ],[\r
69 dnl ioctlsocket test was good\r
70 nonblock="ioctlsocket"\r
71 AC_DEFINE(HAVE_IOCTLSOCKET, 1, [use ioctlsocket() for non-blocking sockets])\r
72 ],[\r
73 dnl ioctlsocket didnt compile!, go to test 4\r
74 \r
75   AC_TRY_LINK([\r
76 /* headers for IoctlSocket test (Amiga?) */\r
77 #include <sys/ioctl.h>\r
78 ],[\r
79 /* IoctlSocket source code */\r
80  int socket;\r
81  int flags = IoctlSocket(socket, FIONBIO, (long)1);\r
82 ],[\r
83 dnl ioctlsocket test was good\r
84 nonblock="IoctlSocket"\r
85 AC_DEFINE(HAVE_IOCTLSOCKET_CASE, 1, [use Ioctlsocket() for non-blocking sockets])\r
86 ],[\r
87 dnl Ioctlsocket didnt compile, do test 5!\r
88   AC_TRY_COMPILE([\r
89 /* headers for SO_NONBLOCK test (BeOS) */\r
90 #include <socket.h>\r
91 ],[\r
92 /* SO_NONBLOCK source code */\r
93  long b = 1;\r
94  int socket;\r
95  int flags = setsockopt(socket, SOL_SOCKET, SO_NONBLOCK, &b, sizeof(b));\r
96 ],[\r
97 dnl the SO_NONBLOCK test was good\r
98 nonblock="SO_NONBLOCK"\r
99 AC_DEFINE(HAVE_SO_NONBLOCK, 1, [use SO_NONBLOCK for non-blocking sockets])\r
100 ],[\r
101 dnl test 5 didnt compile!\r
102 nonblock="nada"\r
103 AC_DEFINE(HAVE_DISABLED_NONBLOCKING, 1, [disabled non-blocking sockets])\r
104 ])\r
105 dnl end of fifth test\r
106 \r
107 ])\r
108 dnl end of forth test\r
109 \r
110 ])\r
111 dnl end of third test\r
112 \r
113 ])\r
114 dnl end of second test\r
115 \r
116 ])\r
117 dnl end of non-blocking try-compile test\r
118   AC_MSG_RESULT($nonblock)\r
119 \r
120   if test "$nonblock" = "nada"; then\r
121     AC_MSG_WARN([non-block sockets disabled])\r
122   fi\r
123 ])\r
124 \r
125 dnl We create a function for detecting which compiler we use and then set as\r
126 dnl pendantic compiler options as possible for that particular compiler. The\r
127 dnl options are only used for debug-builds.\r
128 \r
129 dnl This is a copy of the original found in curl's configure script. Don't\r
130 dnl modify this one, edit the one in curl and copy it back here when that one\r
131 dnl is changed.\r
132 \r
133 AC_DEFUN([CURL_CC_DEBUG_OPTS],\r
134 [\r
135     if test "$GCC" = "yes"; then\r
136 \r
137        dnl figure out gcc version!\r
138        AC_MSG_CHECKING([gcc version])\r
139        gccver=`$CC -dumpversion`\r
140        num1=`echo $gccver | cut -d . -f1`\r
141        num2=`echo $gccver | cut -d . -f2`\r
142        gccnum=`(expr $num1 "*" 100 + $num2) 2>/dev/null`\r
143        AC_MSG_RESULT($gccver)\r
144 \r
145        AC_MSG_CHECKING([if this is icc in disguise])\r
146        AC_EGREP_CPP([^__INTEL_COMPILER], [__INTEL_COMPILER],\r
147          dnl action if the text is found, this it has not been replaced by the\r
148          dnl cpp\r
149          ICC="no"\r
150          AC_MSG_RESULT([no]),\r
151          dnl the text was not found, it was replaced by the cpp\r
152          ICC="yes"\r
153          AC_MSG_RESULT([yes])\r
154        )\r
155 \r
156        if test "$ICC" = "yes"; then\r
157          dnl this is icc, not gcc.\r
158 \r
159          dnl ICC warnings we ignore:\r
160          dnl * 279 warns on static conditions in while expressions\r
161          dnl * 269 warns on our "%Od" printf formatters for curl_off_t output:\r
162          dnl   "invalid format string conversion"\r
163 \r
164          WARN="-wd279,269"\r
165 \r
166          if test "$gccnum" -gt "600"; then\r
167             dnl icc 6.0 and older doesn't have the -Wall flag\r
168             WARN="-Wall $WARN"\r
169          fi\r
170        else dnl $ICC = yes\r
171          dnl \r
172          WARN="-W -Wall -Wwrite-strings -pedantic -Wno-long-long -Wundef -Wpointer-arith -Wnested-externs -Winline -Wmissing-declarations -Wmissing-prototypes -Wsign-compare"\r
173 \r
174          dnl -Wcast-align is a bit too annoying ;-)\r
175 \r
176          if test "$gccnum" -ge "296"; then\r
177            dnl gcc 2.96 or later\r
178            WARN="$WARN -Wfloat-equal"\r
179 \r
180            if test "$gccnum" -gt "296"; then\r
181              dnl this option does not exist in 2.96\r
182              WARN="$WARN -Wno-format-nonliteral"\r
183            fi\r
184 \r
185            dnl -Wunreachable-code seems totally unreliable on my gcc 3.3.2 on\r
186            dnl on i686-Linux as it gives us heaps with false positives\r
187            if test "$gccnum" -ge "303"; then\r
188              dnl gcc 3.3 and later\r
189              WARN="$WARN -Wendif-labels -Wstrict-prototypes"\r
190            fi\r
191          fi\r
192 \r
193          for flag in $CPPFLAGS; do\r
194            case "$flag" in\r
195             -I*)\r
196               dnl include path\r
197               add=`echo $flag | sed 's/^-I/-isystem /g'`\r
198               WARN="$WARN $add"\r
199               ;;\r
200            esac\r
201          done\r
202 \r
203        fi dnl $ICC = no\r
204 \r
205        CFLAGS="$CFLAGS $WARN"\r
206 \r
207     fi dnl $GCC = yes\r
208 \r
209     dnl strip off optimizer flags\r
210     NEWFLAGS=""\r
211     for flag in $CFLAGS; do\r
212       case "$flag" in\r
213       -O*)\r
214         dnl echo "cut off $flag"\r
215         ;;\r
216       *)\r
217         NEWFLAGS="$NEWFLAGS $flag"\r
218         ;;\r
219       esac\r
220     done\r
221     CFLAGS=$NEWFLAGS\r
222 \r
223 ]) dnl end of AC_DEFUN()\r
224 \r
225 \r
226 dnl This macro determines if the specified struct exists in the specified file\r
227 dnl Syntax:\r
228 dnl CARES_CHECK_STRUCT(headers, struct name, if found, [if not found])\r
229 \r
230 AC_DEFUN([CARES_CHECK_STRUCT], [\r
231   AC_MSG_CHECKING([for struct $2])\r
232   AC_TRY_COMPILE([$1], \r
233     [\r
234       struct $2 struct_instance;\r
235     ], ac_struct="yes", ac_found="no")\r
236   if test "$ac_struct" = "yes" ; then\r
237     AC_MSG_RESULT(yes)\r
238     $3\r
239   else\r
240     AC_MSG_RESULT(no)\r
241     $4\r
242   fi\r
243 ])\r
244 \r
245 dnl This macro determins if the specified struct contains a specific member.\r
246 dnl Syntax:\r
247 dnl CARES_CHECK_STRUCT_MEMBER(headers, struct name, member name, if found, [if not found])\r
248 \r
249 AC_DEFUN([CARES_CHECK_STRUCT_MEMBER], [\r
250   AC_MSG_CHECKING([if struct $2 has member $3])\r
251   AC_TRY_COMPILE([$1], \r
252     [\r
253       struct $2 struct_instance;\r
254       struct_instance.$3 = 0;\r
255     ], ac_struct="yes", ac_found="no")\r
256   if test "$ac_struct" = "yes" ; then\r
257     AC_MSG_RESULT(yes)\r
258     $4\r
259   else\r
260     AC_MSG_RESULT(no)\r
261     $5\r
262   fi\r
263 ])\r
264 \r
265 dnl This macro determines if the specified constant exists in the specified file\r
266 dnl Syntax:\r
267 dnl CARES_CHECK_CONSTANT(headers, constant name, if found, [if not found])\r
268 \r
269 AC_DEFUN([CARES_CHECK_CONSTANT], [\r
270   AC_MSG_CHECKING([for $2])\r
271   AC_EGREP_CPP(VARIABLEWASDEFINED,\r
272    [\r
273       $1\r
274 \r
275       #ifdef $2\r
276         VARIABLEWASDEFINED\r
277       #else\r
278         NJET\r
279       #endif\r
280     ], ac_constant="yes", ac_constant="no"\r
281   )\r
282   if test "$ac_constant" = "yes" ; then\r
283     AC_MSG_RESULT(yes)\r
284     $3\r
285   else\r
286     AC_MSG_RESULT(no)\r
287     $4\r
288   fi\r
289 ])\r
290 \r
291 \r