~ubuntu-branches/ubuntu/oneiric/openvpn/oneiric

« back to all changes in this revision

Viewing changes to acinclude.m4

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2011-06-16 18:33:37 UTC
  • mfrom: (1.3.6 upstream)
  • mto: This revision was merged to the branch mainline in revision 46.
  • Revision ID: james.westby@ubuntu.com-20110616183337-etb3qgbwjkn8zniq
Tags: upstream-2.2.0
ImportĀ upstreamĀ versionĀ 2.2.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
90
90
      AC_MSG_CHECKING([for socklen_t equivalent])
91
91
      AC_CACHE_VAL([curl_cv_socklen_t_equiv],
92
92
      [
93
 
         # Systems have either "struct sockaddr *" or
94
 
         # "void *" as the second argument to getpeername
95
 
         curl_cv_socklen_t_equiv=
96
 
         for arg2 in "struct sockaddr" void; do
97
 
            for t in int size_t unsigned long "unsigned long"; do
98
 
               AC_TRY_COMPILE([
99
 
                  #ifdef _WIN32
100
 
                  #include <windows.h>
101
 
                  #define PREFIX1 WINSOCK_API_LINKAGE
102
 
                  #define PREFIX2 PASCAL
103
 
                  #else
104
 
                  #include <sys/types.h>
105
 
                  #include <sys/socket.h>
106
 
                  #define PREFIX1
107
 
                  #define PREFIX2
108
 
                  #define SOCKET int
109
 
                  #endif
 
93
         case "$host" in
 
94
         *-mingw*) curl_cv_socklen_t_equiv=int ;;
 
95
         *)
 
96
            # Systems have either "struct sockaddr *" or
 
97
            # "void *" as the second argument to getpeername
 
98
            curl_cv_socklen_t_equiv=
 
99
            for arg2 in "struct sockaddr" void; do
 
100
               for t in int size_t unsigned long "unsigned long"; do
 
101
                  AC_TRY_COMPILE([
 
102
                     #include <sys/types.h>
 
103
                     #include <sys/socket.h>
110
104
 
111
 
                  PREFIX1 int PREFIX2 getpeername (SOCKET, $arg2 *, $t *);
112
 
               ],[
113
 
                  $t len;
114
 
                  getpeername(0,0,&len);
115
 
               ],[
116
 
                  curl_cv_socklen_t_equiv="$t"
117
 
                  break
118
 
               ])
 
105
                     int getpeername (int, $arg2 *, $t *);
 
106
                  ],[
 
107
                     $t len;
 
108
                     getpeername(0,0,&len);
 
109
                  ],[
 
110
                     curl_cv_socklen_t_equiv="$t"
 
111
                     break
 
112
                  ])
 
113
               done
119
114
            done
120
 
         done
 
115
         ;;
 
116
         esac
121
117
 
122
118
         if test "x$curl_cv_socklen_t_equiv" = x; then
123
119
            AC_MSG_ERROR([Cannot find a type to use in place of socklen_t])
129
125
      [#include <sys/types.h>
130
126
#include <sys/socket.h>])
131
127
])
132
 
 
133
 
dnl @synopsis ACX_PTHREAD([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
134
 
dnl
135
 
dnl This macro figures out how to build C programs using POSIX
136
 
dnl threads.  It sets the PTHREAD_LIBS output variable to the threads
137
 
dnl library and linker flags, and the PTHREAD_CFLAGS output variable
138
 
dnl to any special C compiler flags that are needed.  (The user can also
139
 
dnl force certain compiler flags/libs to be tested by setting these
140
 
dnl environment variables.)
141
 
dnl
142
 
dnl Also sets PTHREAD_CC to any special C compiler that is needed for
143
 
dnl multi-threaded programs (defaults to the value of CC otherwise).
144
 
dnl (This is necessary on AIX to use the special cc_r compiler alias.)
145
 
dnl
146
 
dnl If you are only building threads programs, you may wish to
147
 
dnl use these variables in your default LIBS, CFLAGS, and CC:
148
 
dnl
149
 
dnl        LIBS="$PTHREAD_LIBS $LIBS"
150
 
dnl        CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
151
 
dnl        CC="$PTHREAD_CC"
152
 
dnl
153
 
dnl In addition, if the PTHREAD_CREATE_JOINABLE thread-attribute
154
 
dnl constant has a nonstandard name, defines PTHREAD_CREATE_JOINABLE
155
 
dnl to that name (e.g. PTHREAD_CREATE_UNDETACHED on AIX).
156
 
dnl
157
 
dnl ACTION-IF-FOUND is a list of shell commands to run if a threads
158
 
dnl library is found, and ACTION-IF-NOT-FOUND is a list of commands
159
 
dnl to run it if it is not found.  If ACTION-IF-FOUND is not specified,
160
 
dnl the default action will define HAVE_PTHREAD.
161
 
dnl
162
 
dnl Please let the authors know if this macro fails on any platform,
163
 
dnl or if you have any other suggestions or comments.  This macro was
164
 
dnl based on work by SGJ on autoconf scripts for FFTW (www.fftw.org)
165
 
dnl (with help from M. Frigo), as well as ac_pthread and hb_pthread
166
 
dnl macros posted by AFC to the autoconf macro repository.  We are also
167
 
dnl grateful for the helpful feedback of numerous users.
168
 
dnl
169
 
dnl @author Steven G. Johnson <stevenj@alum.mit.edu> and Alejandro Forero Cuervo <bachue@bachue.com>
170
 
 
171
 
AC_DEFUN([ACX_PTHREAD], [
172
 
AC_REQUIRE([AC_CANONICAL_HOST])
173
 
acx_pthread_ok=no
174
 
 
175
 
# We used to check for pthread.h first, but this fails if pthread.h
176
 
# requires special compiler flags (e.g. on True64 or Sequent).
177
 
# It gets checked for in the link test anyway.
178
 
 
179
 
# First of all, check if the user has set any of the PTHREAD_LIBS,
180
 
# etcetera environment variables, and if threads linking works using
181
 
# them:
182
 
if test x"$PTHREAD_LIBS$PTHREAD_CFLAGS" != x; then
183
 
        save_CFLAGS="$CFLAGS"
184
 
        CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
185
 
        save_LIBS="$LIBS"
186
 
        LIBS="$PTHREAD_LIBS $LIBS"
187
 
        AC_MSG_CHECKING([for pthread_join in LIBS=$PTHREAD_LIBS with CFLAGS=$PTHREAD_CFLAGS])
188
 
        AC_TRY_LINK_FUNC(pthread_join, acx_pthread_ok=yes)
189
 
        AC_MSG_RESULT($acx_pthread_ok)
190
 
        if test x"$acx_pthread_ok" = xno; then
191
 
                PTHREAD_LIBS=""
192
 
                PTHREAD_CFLAGS=""
193
 
        fi
194
 
        LIBS="$save_LIBS"
195
 
        CFLAGS="$save_CFLAGS"
196
 
fi
197
 
 
198
 
# We must check for the threads library under a number of different
199
 
# names; the ordering is very important because some systems
200
 
# (e.g. DEC) have both -lpthread and -lpthreads, where one of the
201
 
# libraries is broken (non-POSIX).
202
 
 
203
 
# Create a list of thread flags to try.  Items starting with a "-" are
204
 
# C compiler flags, and other items are library names, except for "none"
205
 
# which indicates that we try without any flags at all.
206
 
 
207
 
acx_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt"
208
 
 
209
 
# The ordering *is* (sometimes) important.  Some notes on the
210
 
# individual items follow:
211
 
 
212
 
# pthreads: AIX (must check this before -lpthread)
213
 
# none: in case threads are in libc; should be tried before -Kthread and
214
 
#       other compiler flags to prevent continual compiler warnings
215
 
# -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h)
216
 
# -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able)
217
 
# lthread: LinuxThreads port on FreeBSD (also preferred to -pthread)
218
 
# -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads)
219
 
# -pthreads: Solaris/gcc
220
 
# -mthreads: Mingw32/gcc, Lynx/gcc
221
 
# -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it
222
 
#      doesn't hurt to check since this sometimes defines pthreads too;
223
 
#      also defines -D_REENTRANT)
224
 
# pthread: Linux, etcetera
225
 
# --thread-safe: KAI C++
226
 
 
227
 
case "$target" in
228
 
        *solaris*)
229
 
 
230
 
        # On Solaris (at least, for some versions), libc contains stubbed
231
 
        # (non-functional) versions of the pthreads routines, so link-based
232
 
        # tests will erroneously succeed.  (We need to link with -pthread or
233
 
        # -lpthread.)  (The stubs are missing pthread_cleanup_push, or rather
234
 
        # a function called by this macro, so we could check for that, but
235
 
        # who knows whether they'll stub that too in a future libc.)  So,
236
 
        # we'll just look for -pthreads and -lpthread first:
237
 
 
238
 
        acx_pthread_flags="-pthread -pthreads pthread -mt $acx_pthread_flags"
239
 
        ;;
240
 
esac
241
 
 
242
 
if test x"$acx_pthread_ok" = xno; then
243
 
for flag in $acx_pthread_flags; do
244
 
 
245
 
        case $flag in
246
 
                none)
247
 
                AC_MSG_CHECKING([whether pthreads work without any flags])
248
 
                ;;
249
 
 
250
 
                -*)
251
 
                AC_MSG_CHECKING([whether pthreads work with $flag])
252
 
                PTHREAD_CFLAGS="$flag"
253
 
                ;;
254
 
 
255
 
                *)
256
 
                AC_MSG_CHECKING([for the pthreads library -l$flag])
257
 
                PTHREAD_LIBS="-l$flag"
258
 
                ;;
259
 
        esac
260
 
 
261
 
        save_LIBS="$LIBS"
262
 
        save_CFLAGS="$CFLAGS"
263
 
        LIBS="$PTHREAD_LIBS $LIBS"
264
 
        CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
265
 
 
266
 
        # Check for various functions.  We must include pthread.h,
267
 
        # since some functions may be macros.  (On the Sequent, we
268
 
        # need a special flag -Kthread to make this header compile.)
269
 
        # We check for pthread_join because it is in -lpthread on IRIX
270
 
        # while pthread_create is in libc.  We check for pthread_attr_init
271
 
        # due to DEC craziness with -lpthreads.  We check for
272
 
        # pthread_cleanup_push because it is one of the few pthread
273
 
        # functions on Solaris that doesn't have a non-functional libc stub.
274
 
        # We try pthread_create on general principles.
275
 
        AC_TRY_LINK([#include <pthread.h>],
276
 
                    [pthread_t th; pthread_join(th, 0);
277
 
                     pthread_attr_init(0); pthread_cleanup_push(0, 0);
278
 
                     pthread_create(0,0,0,0); pthread_cleanup_pop(0); ],
279
 
                    [acx_pthread_ok=yes])
280
 
 
281
 
        LIBS="$save_LIBS"
282
 
        CFLAGS="$save_CFLAGS"
283
 
 
284
 
        AC_MSG_RESULT($acx_pthread_ok)
285
 
        if test "x$acx_pthread_ok" = xyes; then
286
 
                break;
287
 
        fi
288
 
 
289
 
        PTHREAD_LIBS=""
290
 
        PTHREAD_CFLAGS=""
291
 
done
292
 
fi
293
 
 
294
 
# Various other checks:
295
 
if test "x$acx_pthread_ok" = xyes; then
296
 
        save_LIBS="$LIBS"
297
 
        LIBS="$PTHREAD_LIBS $LIBS"
298
 
        save_CFLAGS="$CFLAGS"
299
 
        CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
300
 
 
301
 
        # Detect AIX lossage: threads are created detached by default
302
 
        # and the JOINABLE attribute has a nonstandard name (UNDETACHED).
303
 
        AC_MSG_CHECKING([for joinable pthread attribute])
304
 
        AC_TRY_LINK([#include <pthread.h>],
305
 
                    [int attr=PTHREAD_CREATE_JOINABLE;],
306
 
                    ok=PTHREAD_CREATE_JOINABLE, ok=unknown)
307
 
        if test x"$ok" = xunknown; then
308
 
                AC_TRY_LINK([#include <pthread.h>],
309
 
                            [int attr=PTHREAD_CREATE_UNDETACHED;],
310
 
                            ok=PTHREAD_CREATE_UNDETACHED, ok=unknown)
311
 
        fi
312
 
        if test x"$ok" != xPTHREAD_CREATE_JOINABLE; then
313
 
                AC_DEFINE(PTHREAD_CREATE_JOINABLE, $ok,
314
 
                          [Define to the necessary symbol if this constant
315
 
                           uses a non-standard name on your system.])
316
 
        fi
317
 
        AC_MSG_RESULT(${ok})
318
 
        if test x"$ok" = xunknown; then
319
 
                AC_MSG_WARN([we do not know how to create joinable pthreads])
320
 
        fi
321
 
 
322
 
        AC_MSG_CHECKING([if more special flags are required for pthreads])
323
 
        flag=no
324
 
        case "$target" in
325
 
                *-aix* | *-freebsd*)               flag="-D_THREAD_SAFE";;
326
 
                *solaris* | alpha*-osf* | *linux*) flag="-D_REENTRANT";;
327
 
        esac
328
 
        AC_MSG_RESULT(${flag})
329
 
        if test "x$flag" != xno; then
330
 
                PTHREAD_CFLAGS="$flag $PTHREAD_CFLAGS"
331
 
        fi
332
 
 
333
 
        LIBS="$save_LIBS"
334
 
        CFLAGS="$save_CFLAGS"
335
 
 
336
 
        # More AIX lossage: must compile with cc_r
337
 
        AC_CHECK_PROG(PTHREAD_CC, cc_r, cc_r, ${CC})
338
 
else
339
 
        PTHREAD_CC="$CC"
340
 
fi
341
 
 
342
 
AC_SUBST(PTHREAD_LIBS)
343
 
AC_SUBST(PTHREAD_CFLAGS)
344
 
AC_SUBST(PTHREAD_CC)
345
 
 
346
 
# Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
347
 
if test x"$acx_pthread_ok" = xyes; then
348
 
        ifelse([$1],,AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.]),[$1])
349
 
        :
350
 
else
351
 
        acx_pthread_ok=no
352
 
        $2
353
 
fi
354
 
 
355
 
])dnl ACX_PTHREAD