minidlna support now Samsung TV C550/C650 (thx amir909)
[tomato.git] / release / src / router / openvpn / acinclude.m4
blobf099de539894feaa771ff0f2637e944e37e08f67
1 dnl Special Autoconf Macros for OpenVPN
3 dnl OPENVPN_ADD_LIBS(LIB)
4 AC_DEFUN([OPENVPN_ADD_LIBS], [
5   LIBS="$1 $LIBS"
6 ])
8 dnl @synopsis AX_EMPTY_ARRAY
9 dnl
10 dnl Define EMPTY_ARRAY_SIZE to be either "0"
11 dnl or "" depending on which syntax the compiler
12 dnl prefers for empty arrays in structs.
13 dnl
14 dnl @version
15 dnl @author James Yonan <jim@yonan.net>
18 AC_DEFUN([AX_EMPTY_ARRAY], [
19   AC_MSG_RESULT([checking for C compiler empty array support])
20   AC_COMPILE_IFELSE(
21     [
22         struct { int foo; int bar[[0]]; } mystruct;
23     ], [
24         AC_DEFINE_UNQUOTED(EMPTY_ARRAY_SIZE, 0, [Dimension to use for empty array declaration])
25     ], [
26         AC_COMPILE_IFELSE(
27             [
28                 struct { int foo; int bar[[]]; } mystruct;
29             ], [
30                 AC_DEFINE_UNQUOTED(EMPTY_ARRAY_SIZE,, [Dimension to use for empty array declaration])
31             ], [
32                 AC_MSG_ERROR([C compiler is unable to creaty empty arrays])
33             ])
34     ])
35   ]
38 dnl @synopsis AX_CPP_VARARG_MACRO_GCC
39 dnl
40 dnl Test if the preprocessor understands GNU GCC-style vararg macros.
41 dnl If it does, defines HAVE_CPP_VARARG_MACRO_GCC to 1.
42 dnl
43 dnl @version
44 dnl @author James Yonan <jim@yonan.net>, Matthias Andree <matthias.andree@web.de>
45 AC_DEFUN([AX_CPP_VARARG_MACRO_GCC], [dnl
46     AS_VAR_PUSHDEF([VAR],[ax_cv_cpp_vararg_macro_gcc])dnl
47     AC_CACHE_CHECK([for GNU GCC vararg macro support], VAR, [dnl
48       AC_COMPILE_IFELSE([
49         #define macro(a, b...) func(a, b)
50         int func(int a, int b, int c);
51         int test() { return macro(1, 2, 3); }
52         ], [ VAR=yes ], [VAR=no])])
53     if test $VAR = yes ; then
54     AC_DEFINE([HAVE_CPP_VARARG_MACRO_GCC], 1, 
55       [Define to 1 if your compiler supports GNU GCC-style variadic macros])
56     fi
57     AS_VAR_POPDEF([VAR])dnl
60 dnl @synopsis AX_CPP_VARARG_MACRO_ISO
61 dnl
62 dnl Test if the preprocessor understands ISO C 1999 vararg macros.
63 dnl If it does, defines HAVE_CPP_VARARG_MACRO_ISO to 1.
64 dnl
65 dnl @version
66 dnl @author James Yonan <jim@yonan.net>, Matthias Andree <matthias.andree@web.de>
67 AC_DEFUN([AX_CPP_VARARG_MACRO_ISO], [dnl
68     AS_VAR_PUSHDEF([VAR],[ax_cv_cpp_vararg_macro_iso])dnl
69     AC_CACHE_CHECK([for ISO C 1999 vararg macro support], VAR, [dnl
70       AC_COMPILE_IFELSE([
71 #define macro(a, ...) func(a, __VA_ARGS__)
72         int func(int a, int b, int c);
73         int test() { return macro(1, 2, 3); }
74         ], [ VAR=yes ], [VAR=no])])
75     if test $VAR = yes ; then
76     AC_DEFINE([HAVE_CPP_VARARG_MACRO_ISO], 1, 
77       [Define to 1 if your compiler supports ISO C99 variadic macros])
78     fi
79     AS_VAR_POPDEF([VAR])dnl
82 dnl -- The following is taken from curl's acinclude.m4 --
83 dnl Check for socklen_t: historically on BSD it is an int, and in
84 dnl POSIX 1g it is a type of its own, but some platforms use different
85 dnl types for the argument to getsockopt, getpeername, etc.  So we
86 dnl have to test to find something that will work.
87 AC_DEFUN([TYPE_SOCKLEN_T],
89    AC_CHECK_TYPE([socklen_t], ,[
90       AC_MSG_CHECKING([for socklen_t equivalent])
91       AC_CACHE_VAL([curl_cv_socklen_t_equiv],
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
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                ])
119             done
120          done
122          if test "x$curl_cv_socklen_t_equiv" = x; then
123             AC_MSG_ERROR([Cannot find a type to use in place of socklen_t])
124          fi
125       ])
126       AC_MSG_RESULT($curl_cv_socklen_t_equiv)
127       AC_DEFINE_UNQUOTED(socklen_t, $curl_cv_socklen_t_equiv,
128                         [type to use in place of socklen_t if not defined])],
129       [#include <sys/types.h>
130 #include <sys/socket.h>])
133 dnl @synopsis ACX_PTHREAD([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
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.)
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.)
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:
149 dnl        LIBS="$PTHREAD_LIBS $LIBS"
150 dnl        CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
151 dnl        CC="$PTHREAD_CC"
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).
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.
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.
169 dnl @author Steven G. Johnson <stevenj@alum.mit.edu> and Alejandro Forero Cuervo <bachue@bachue.com>
171 AC_DEFUN([ACX_PTHREAD], [
172 AC_REQUIRE([AC_CANONICAL_HOST])
173 acx_pthread_ok=no
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.
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"
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).
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.
207 acx_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt"
209 # The ordering *is* (sometimes) important.  Some notes on the
210 # individual items follow:
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++
227 case "$target" in
228         *solaris*)
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:
238         acx_pthread_flags="-pthread -pthreads pthread -mt $acx_pthread_flags"
239         ;;
240 esac
242 if test x"$acx_pthread_ok" = xno; then
243 for flag in $acx_pthread_flags; do
245         case $flag in
246                 none)
247                 AC_MSG_CHECKING([whether pthreads work without any flags])
248                 ;;
250                 -*)
251                 AC_MSG_CHECKING([whether pthreads work with $flag])
252                 PTHREAD_CFLAGS="$flag"
253                 ;;
255                 *)
256                 AC_MSG_CHECKING([for the pthreads library -l$flag])
257                 PTHREAD_LIBS="-l$flag"
258                 ;;
259         esac
261         save_LIBS="$LIBS"
262         save_CFLAGS="$CFLAGS"
263         LIBS="$PTHREAD_LIBS $LIBS"
264         CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
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])
281         LIBS="$save_LIBS"
282         CFLAGS="$save_CFLAGS"
284         AC_MSG_RESULT($acx_pthread_ok)
285         if test "x$acx_pthread_ok" = xyes; then
286                 break;
287         fi
289         PTHREAD_LIBS=""
290         PTHREAD_CFLAGS=""
291 done
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"
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
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
333         LIBS="$save_LIBS"
334         CFLAGS="$save_CFLAGS"
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"
342 AC_SUBST(PTHREAD_LIBS)
343 AC_SUBST(PTHREAD_CFLAGS)
344 AC_SUBST(PTHREAD_CC)
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
355 ])dnl ACX_PTHREAD