~ubuntu-branches/ubuntu/trusty/erlang/trusty

« back to all changes in this revision

Viewing changes to lib/odbc/aclocal.m4

  • Committer: Bazaar Package Importer
  • Author(s): Clint Byrum
  • Date: 2011-05-05 15:48:43 UTC
  • mfrom: (3.5.13 sid)
  • Revision ID: james.westby@ubuntu.com-20110505154843-0om6ekzg6m7ugj27
Tags: 1:14.b.2-dfsg-3ubuntu1
* Merge from debian unstable.  Remaining changes:
  - Drop libwxgtk2.8-dev build dependency. Wx isn't in main, and not
    supposed to.
  - Drop erlang-wx binary.
  - Drop erlang-wx dependency from -megaco, -common-test, and -reltool, they
    do not really need wx. Also drop it from -debugger; the GUI needs wx,
    but it apparently has CLI bits as well, and is also needed by -megaco,
    so let's keep the package for now.
  - debian/patches/series: Do what I meant, and enable build-options.patch
    instead.
* Additional changes:
  - Drop erlang-wx from -et
* Dropped Changes:
  - patches/pcre-crash.patch: CVE-2008-2371: outer level option with
    alternatives caused crash. (Applied Upstream)
  - fix for ssl certificate verification in newSSL: 
    ssl_cacertfile_fix.patch (Applied Upstream)
  - debian/patches/series: Enable native.patch again, to get stripped beam
    files and reduce the package size again. (build-options is what
    actually accomplished this)
  - Remove build-options.patch on advice from upstream and because it caused
    odd build failures.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
dnl
 
2
dnl %CopyrightBegin%
 
3
dnl
 
4
dnl Copyright Ericsson AB 1998-2010. All Rights Reserved.
 
5
dnl
 
6
dnl The contents of this file are subject to the Erlang Public License,
 
7
dnl Version 1.1, (the "License"); you may not use this file except in
 
8
dnl compliance with the License. You should have received a copy of the
 
9
dnl Erlang Public License along with this software. If not, it can be
 
10
dnl retrieved online at http://www.erlang.org/.
 
11
dnl
 
12
dnl Software distributed under the License is distributed on an "AS IS"
 
13
dnl basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
 
14
dnl the License for the specific language governing rights and limitations
 
15
dnl under the License.
 
16
dnl
 
17
dnl %CopyrightEnd%
 
18
dnl
 
19
 
 
20
dnl
 
21
dnl aclocal.m4
 
22
dnl
 
23
dnl Local macros used in configure.in. The Local Macros which
 
24
dnl could/should be part of autoconf are prefixed LM_, macros specific
 
25
dnl to the Erlang system are prefixed ERL_.
 
26
dnl
 
27
 
 
28
AC_DEFUN(LM_PRECIOUS_VARS,
 
29
[
 
30
 
 
31
dnl ERL_TOP
 
32
AC_ARG_VAR(ERL_TOP, [Erlang/OTP top source directory])
 
33
 
 
34
dnl Tools
 
35
AC_ARG_VAR(CC, [C compiler])
 
36
AC_ARG_VAR(CFLAGS, [C compiler flags])
 
37
AC_ARG_VAR(STATIC_CFLAGS, [C compiler static flags])
 
38
AC_ARG_VAR(CFLAG_RUNTIME_LIBRARY_PATH, [runtime library path linker flag passed via C compiler])
 
39
AC_ARG_VAR(CPP, [C/C++ preprocessor])
 
40
AC_ARG_VAR(CPPFLAGS, [C/C++ preprocessor flags])
 
41
AC_ARG_VAR(CXX, [C++ compiler])
 
42
AC_ARG_VAR(CXXFLAGS, [C++ compiler flags])
 
43
AC_ARG_VAR(LD, [linker (is often overridden by configure)])
 
44
AC_ARG_VAR(LDFLAGS, [linker flags (can be risky to set since LD may be overriden by configure)])
 
45
AC_ARG_VAR(LIBS, [libraries])
 
46
AC_ARG_VAR(DED_LD, [linker for Dynamic Erlang Drivers (set all DED_LD* variables or none)])
 
47
AC_ARG_VAR(DED_LDFLAGS, [linker flags for Dynamic Erlang Drivers (set all DED_LD* variables or none)])
 
48
AC_ARG_VAR(DED_LD_FLAG_RUNTIME_LIBRARY_PATH, [runtime library path linker flag for Dynamic Erlang Drivers (set all DED_LD* variables or none)])
 
49
AC_ARG_VAR(LFS_CFLAGS, [large file support C compiler flags (set all LFS_* variables or none)])
 
50
AC_ARG_VAR(LFS_LDFLAGS, [large file support linker flags (set all LFS_* variables or none)])
 
51
AC_ARG_VAR(LFS_LIBS, [large file support libraries (set all LFS_* variables or none)])
 
52
AC_ARG_VAR(RANLIB, [ranlib])
 
53
AC_ARG_VAR(AR, [ar])
 
54
AC_ARG_VAR(GETCONF, [getconf])
 
55
 
 
56
dnl Cross system root
 
57
AC_ARG_VAR(erl_xcomp_sysroot, [Absolute cross system root path (only used when cross compiling)])
 
58
AC_ARG_VAR(erl_xcomp_isysroot, [Absolute cross system root include path (only used when cross compiling)])
 
59
 
 
60
dnl Cross compilation variables
 
61
AC_ARG_VAR(erl_xcomp_bigendian, [big endian system: yes|no (only used when cross compiling)])
 
62
AC_ARG_VAR(erl_xcomp_linux_clock_gettime_correction, [clock_gettime() can be used for time correction: yes|no (only used when cross compiling)])
 
63
AC_ARG_VAR(erl_xcomp_linux_nptl, [have Native POSIX Thread Library: yes|no (only used when cross compiling)])
 
64
AC_ARG_VAR(erl_xcomp_linux_usable_sigusrx, [SIGUSR1 and SIGUSR2 can be used: yes|no (only used when cross compiling)])
 
65
AC_ARG_VAR(erl_xcomp_linux_usable_sigaltstack, [have working sigaltstack(): yes|no (only used when cross compiling)])
 
66
AC_ARG_VAR(erl_xcomp_poll, [have working poll(): yes|no (only used when cross compiling)])
 
67
AC_ARG_VAR(erl_xcomp_kqueue, [have working kqueue(): yes|no (only used when cross compiling)])
 
68
AC_ARG_VAR(erl_xcomp_putenv_copy, [putenv() stores key-value copy: yes|no (only used when cross compiling)])
 
69
AC_ARG_VAR(erl_xcomp_reliable_fpe, [have reliable floating point exceptions: yes|no (only used when cross compiling)])
 
70
AC_ARG_VAR(erl_xcomp_getaddrinfo, [have working getaddrinfo() for both IPv4 and IPv6: yes|no (only used when cross compiling)])
 
71
AC_ARG_VAR(erl_xcomp_gethrvtime_procfs_ioctl, [have working gethrvtime() which can be used with procfs ioctl(): yes|no (only used when cross compiling)])
 
72
AC_ARG_VAR(erl_xcomp_clock_gettime_cpu_time, [clock_gettime() can be used for retrieving process CPU time: yes|no (only used when cross compiling)])
 
73
AC_ARG_VAR(erl_xcomp_after_morecore_hook, [__after_morecore_hook can track malloc()s core memory usage: yes|no (only used when cross compiling)])
 
74
AC_ARG_VAR(erl_xcomp_dlsym_brk_wrappers, [dlsym(RTLD_NEXT, _) brk wrappers can track malloc()s core memory usage: yes|no (only used when cross compiling)])
 
75
 
 
76
])
 
77
 
 
78
AC_DEFUN(ERL_XCOMP_SYSROOT_INIT,
 
79
[
 
80
erl_xcomp_without_sysroot=no
 
81
if test "$cross_compiling" = "yes"; then
 
82
    test "$erl_xcomp_sysroot" != "" || erl_xcomp_without_sysroot=yes
 
83
    test "$erl_xcomp_isysroot" != "" || erl_xcomp_isysroot="$erl_xcomp_sysroot"
 
84
else
 
85
    erl_xcomp_sysroot=
 
86
    erl_xcomp_isysroot=
 
87
fi
 
88
])
 
89
 
 
90
AC_DEFUN(LM_CHECK_GETCONF,
 
91
[
 
92
if test "$cross_compiling" != "yes"; then
 
93
    AC_CHECK_PROG([GETCONF], [getconf], [getconf], [false])
 
94
else
 
95
    dnl First check if we got a `<HOST>-getconf' in $PATH
 
96
    host_getconf="$host_alias-getconf"
 
97
    AC_CHECK_PROG([GETCONF], [$host_getconf], [$host_getconf], [false])
 
98
    if test "$GETCONF" = "false" && test "$erl_xcomp_sysroot" != ""; then
 
99
        dnl We should perhaps give up if we have'nt found it by now, but at
 
100
        dnl least in one Tilera MDE `getconf' under sysroot is a bourne
 
101
        dnl shell script which we can use. We try to find `<HOST>-getconf'
 
102
        dnl or `getconf' under sysconf, but only under sysconf since
 
103
        dnl `getconf' in $PATH is almost guaranteed to be for the build
 
104
        dnl machine.
 
105
        GETCONF=
 
106
        prfx="$erl_xcomp_sysroot"
 
107
        AC_PATH_TOOL([GETCONF], [getconf], [false],
 
108
                     ["$prfx/usr/bin:$prfx/bin:$prfx/usr/local/bin"])
 
109
    fi
 
110
fi
 
111
])
 
112
 
 
113
dnl ----------------------------------------------------------------------
 
114
dnl
 
115
dnl LM_FIND_EMU_CC
 
116
dnl
 
117
dnl
 
118
dnl Tries fairly hard to find a C compiler that can handle jump tables.
 
119
dnl Defines the @EMU_CC@ variable for the makefiles and 
 
120
dnl inserts NO_JUMP_TABLE in the header if one cannot be found...
 
121
dnl
 
122
 
 
123
AC_DEFUN(LM_FIND_EMU_CC,
 
124
        [AC_CACHE_CHECK(for a compiler that handles jumptables,
 
125
                        ac_cv_prog_emu_cc,
 
126
                        [
 
127
AC_TRY_COMPILE([],[
 
128
    __label__ lbl1;
 
129
    __label__ lbl2;
 
130
    int x = magic();
 
131
    static void *jtab[2];
 
132
 
 
133
    jtab[0] = &&lbl1;
 
134
    jtab[1] = &&lbl2;
 
135
    goto *jtab[x];
 
136
lbl1:
 
137
    return 1;
 
138
lbl2:
 
139
    return 2;
 
140
],ac_cv_prog_emu_cc=$CC,ac_cv_prog_emu_cc=no)
 
141
 
 
142
if test $ac_cv_prog_emu_cc = no; then
 
143
        for ac_progname in emu_cc.sh gcc; do
 
144
                IFS="${IFS=     }"; ac_save_ifs="$IFS"; IFS=":"
 
145
                ac_dummy="$PATH"
 
146
                for ac_dir in $ac_dummy; do
 
147
                        test -z "$ac_dir" && ac_dir=.
 
148
                        if test -f $ac_dir/$ac_progname; then
 
149
                                ac_cv_prog_emu_cc=$ac_dir/$ac_progname
 
150
                                break
 
151
                        fi
 
152
                done
 
153
                IFS="$ac_save_ifs"
 
154
                if test $ac_cv_prog_emu_cc != no; then
 
155
                        break
 
156
                fi
 
157
        done
 
158
fi
 
159
 
 
160
if test $ac_cv_prog_emu_cc != no; then
 
161
        save_CC=$CC
 
162
        save_CFLAGS=$CFLAGS
 
163
        save_CPPFLAGS=$CPPFLAGS
 
164
        CC=$ac_cv_prog_emu_cc
 
165
        CFLAGS=""
 
166
        CPPFLAGS=""
 
167
        AC_TRY_COMPILE([],[
 
168
        __label__ lbl1;
 
169
        __label__ lbl2;
 
170
        int x = magic();
 
171
        static void *jtab[2];
 
172
 
 
173
        jtab[0] = &&lbl1;
 
174
        jtab[1] = &&lbl2;
 
175
        goto *jtab[x];
 
176
        lbl1:
 
177
        return 1;
 
178
        lbl2:
 
179
        return 2;
 
180
        ],ac_cv_prog_emu_cc=$CC,ac_cv_prog_emu_cc=no)
 
181
        CC=$save_CC
 
182
        CFLAGS=$save_CFLAGS
 
183
        CPPFLAGS=$save_CPPFLAGS
 
184
fi
 
185
])
 
186
if test $ac_cv_prog_emu_cc = no; then
 
187
        AC_DEFINE(NO_JUMP_TABLE,[],[Defined if no found C compiler can handle jump tables])
 
188
        EMU_CC=$CC
 
189
else
 
190
        EMU_CC=$ac_cv_prog_emu_cc
 
191
fi
 
192
AC_SUBST(EMU_CC)
 
193
])              
 
194
                        
 
195
 
 
196
 
 
197
dnl ----------------------------------------------------------------------
 
198
dnl
 
199
dnl LM_PROG_INSTALL_DIR
 
200
dnl
 
201
dnl This macro may be used by any OTP application.
 
202
dnl
 
203
dnl Figure out how to create directories with parents.
 
204
dnl (In my opinion INSTALL_DIR is a bad name, MKSUBDIRS or something is better)
 
205
dnl
 
206
dnl We prefer 'install -d', but use 'mkdir -p' if it exists.
 
207
dnl If none of these methods works, we give up.
 
208
dnl
 
209
 
 
210
 
 
211
AC_DEFUN(LM_PROG_INSTALL_DIR,
 
212
[AC_CACHE_CHECK(how to create a directory including parents,
 
213
ac_cv_prog_mkdir_p,
 
214
[
 
215
temp_name_base=config.$$
 
216
temp_name=$temp_name_base/x/y/z
 
217
$INSTALL -d $temp_name >/dev/null 2>&1
 
218
ac_cv_prog_mkdir_p=none
 
219
if test -d $temp_name; then
 
220
        ac_cv_prog_mkdir_p="$INSTALL -d"
 
221
else
 
222
        mkdir -p $temp_name >/dev/null 2>&1
 
223
        if test -d $temp_name; then
 
224
                ac_cv_prog_mkdir_p="mkdir -p"
 
225
        fi
 
226
fi
 
227
rm -fr $temp_name_base           
 
228
])
 
229
 
 
230
case "${ac_cv_prog_mkdir_p}" in
 
231
  none) AC_MSG_ERROR(don't know how create directories with parents) ;;
 
232
  *)    INSTALL_DIR="$ac_cv_prog_mkdir_p" AC_SUBST(INSTALL_DIR)     ;;
 
233
esac
 
234
])
 
235
 
 
236
 
 
237
dnl ----------------------------------------------------------------------
 
238
dnl
 
239
dnl LM_PROG_PERL5
 
240
dnl
 
241
dnl Try to find perl version 5. If found set PERL to the absolute path
 
242
dnl of the program, if not found set PERL to false.
 
243
dnl
 
244
dnl On some systems /usr/bin/perl is perl 4 and e.g.
 
245
dnl /usr/local/bin/perl is perl 5. We try to handle this case by
 
246
dnl putting a couple of 
 
247
dnl Tries to handle the case that there are two programs called perl
 
248
dnl in the path and one of them is perl 5 and the other isn't. 
 
249
dnl
 
250
AC_DEFUN(LM_PROG_PERL5,
 
251
[AC_PATH_PROGS(PERL, perl5 perl, false,
 
252
   /usr/local/bin:/opt/local/bin:/usr/local/gnu/bin:${PATH})
 
253
changequote(, )dnl
 
254
dnl[ That bracket is needed to balance the right bracket below
 
255
if test "$PERL" = "false" || $PERL -e 'exit ($] >= 5)'; then
 
256
changequote([, ])dnl
 
257
  ac_cv_path_PERL=false
 
258
  PERL=false
 
259
dnl  AC_MSG_WARN(perl version 5 not found)
 
260
fi
 
261
])dnl
 
262
 
 
263
 
 
264
dnl ----------------------------------------------------------------------
 
265
dnl
 
266
dnl LM_DECL_SO_BSDCOMPAT
 
267
dnl
 
268
dnl Check if the system has the SO_BSDCOMPAT flag on sockets (linux) 
 
269
dnl
 
270
AC_DEFUN(LM_DECL_SO_BSDCOMPAT,
 
271
[AC_CACHE_CHECK([for SO_BSDCOMPAT declaration], ac_cv_decl_so_bsdcompat,
 
272
AC_TRY_COMPILE([#include <sys/socket.h>], [int i = SO_BSDCOMPAT;],
 
273
               ac_cv_decl_so_bsdcompat=yes,
 
274
               ac_cv_decl_so_bsdcompat=no))
 
275
 
 
276
case "${ac_cv_decl_so_bsdcompat}" in
 
277
  "yes" ) AC_DEFINE(HAVE_SO_BSDCOMPAT,[],
 
278
                [Define if you have SO_BSDCOMPAT flag on sockets]) ;;
 
279
  * ) ;;
 
280
esac
 
281
])
 
282
 
 
283
 
 
284
dnl ----------------------------------------------------------------------
 
285
dnl
 
286
dnl LM_DECL_INADDR_LOOPBACK
 
287
dnl
 
288
dnl Try to find declaration of INADDR_LOOPBACK, if nowhere provide a default
 
289
dnl
 
290
 
 
291
AC_DEFUN(LM_DECL_INADDR_LOOPBACK,
 
292
[AC_CACHE_CHECK([for INADDR_LOOPBACK in netinet/in.h],
 
293
 ac_cv_decl_inaddr_loopback,
 
294
[AC_TRY_COMPILE([#include <sys/types.h>
 
295
#include <netinet/in.h>], [int i = INADDR_LOOPBACK;],
 
296
ac_cv_decl_inaddr_loopback=yes, ac_cv_decl_inaddr_loopback=no)
 
297
])
 
298
 
 
299
if test ${ac_cv_decl_inaddr_loopback} = no; then
 
300
  AC_CACHE_CHECK([for INADDR_LOOPBACK in rpc/types.h],
 
301
                   ac_cv_decl_inaddr_loopback_rpc,
 
302
                   AC_TRY_COMPILE([#include <rpc/types.h>],
 
303
                                   [int i = INADDR_LOOPBACK;],
 
304
                                   ac_cv_decl_inaddr_loopback_rpc=yes,
 
305
                                   ac_cv_decl_inaddr_loopback_rpc=no))
 
306
 
 
307
   case "${ac_cv_decl_inaddr_loopback_rpc}" in
 
308
     "yes" )
 
309
        AC_DEFINE(DEF_INADDR_LOOPBACK_IN_RPC_TYPES_H,[],
 
310
                [Define if you need to include rpc/types.h to get INADDR_LOOPBACK defined]) ;;
 
311
      * )
 
312
        AC_CACHE_CHECK([for INADDR_LOOPBACK in winsock2.h],
 
313
                   ac_cv_decl_inaddr_loopback_winsock2,
 
314
                   AC_TRY_COMPILE([#define WIN32_LEAN_AND_MEAN
 
315
                                   #include <winsock2.h>],
 
316
                                   [int i = INADDR_LOOPBACK;],
 
317
                                   ac_cv_decl_inaddr_loopback_winsock2=yes,
 
318
                                   ac_cv_decl_inaddr_loopback_winsock2=no))
 
319
        case "${ac_cv_decl_inaddr_loopback_winsock2}" in
 
320
                "yes" )
 
321
                        AC_DEFINE(DEF_INADDR_LOOPBACK_IN_WINSOCK2_H,[],
 
322
                                [Define if you need to include winsock2.h to get INADDR_LOOPBACK defined]) ;;
 
323
                * )
 
324
                        # couldn't find it anywhere
 
325
                        AC_DEFINE(HAVE_NO_INADDR_LOOPBACK,[],
 
326
                                [Define if you don't have a definition of INADDR_LOOPBACK]) ;;
 
327
        esac;;
 
328
   esac
 
329
fi
 
330
])
 
331
 
 
332
 
 
333
dnl ----------------------------------------------------------------------
 
334
dnl
 
335
dnl LM_STRUCT_SOCKADDR_SA_LEN
 
336
dnl
 
337
dnl Check if the sockaddr structure has the field sa_len
 
338
dnl
 
339
 
 
340
AC_DEFUN(LM_STRUCT_SOCKADDR_SA_LEN,
 
341
[AC_CACHE_CHECK([whether struct sockaddr has sa_len field],
 
342
                ac_cv_struct_sockaddr_sa_len,
 
343
AC_TRY_COMPILE([#include <sys/types.h>
 
344
#include <sys/socket.h>], [struct sockaddr s; s.sa_len = 10;],
 
345
  ac_cv_struct_sockaddr_sa_len=yes, ac_cv_struct_sockaddr_sa_len=no))
 
346
 
 
347
dnl FIXME convbreak
 
348
case ${ac_cv_struct_sockaddr_sa_len} in
 
349
  "no" ) AC_DEFINE(NO_SA_LEN,[1],[Define if you dont have salen]) ;;
 
350
  *) ;;
 
351
esac
 
352
])
 
353
 
 
354
dnl ----------------------------------------------------------------------
 
355
dnl
 
356
dnl LM_STRUCT_EXCEPTION
 
357
dnl
 
358
dnl Check to see whether the system supports the matherr function
 
359
dnl and its associated type "struct exception".
 
360
dnl
 
361
 
 
362
AC_DEFUN(LM_STRUCT_EXCEPTION,
 
363
[AC_CACHE_CHECK([for struct exception (and matherr function)],
 
364
 ac_cv_struct_exception,
 
365
AC_TRY_COMPILE([#include <math.h>],
 
366
  [struct exception x; x.type = DOMAIN; x.type = SING;],
 
367
  ac_cv_struct_exception=yes, ac_cv_struct_exception=no))
 
368
 
 
369
case "${ac_cv_struct_exception}" in
 
370
  "yes" ) AC_DEFINE(USE_MATHERR,[1],[Define if you have matherr() function and struct exception type]) ;;
 
371
  *  ) ;;
 
372
esac
 
373
])
 
374
 
 
375
 
 
376
dnl ----------------------------------------------------------------------
 
377
dnl
 
378
dnl LM_SYS_IPV6
 
379
dnl
 
380
dnl Check for ipv6 support and what the in6_addr structure is called.
 
381
dnl (early linux used in_addr6 insted of in6_addr)
 
382
dnl
 
383
 
 
384
AC_DEFUN(LM_SYS_IPV6,
 
385
[AC_MSG_CHECKING(for IP version 6 support)
 
386
AC_CACHE_VAL(ac_cv_sys_ipv6_support,
 
387
[ok_so_far=yes
 
388
 AC_TRY_COMPILE([#include <sys/types.h>
 
389
#ifdef __WIN32__
 
390
#include <winsock2.h>
 
391
#include <ws2tcpip.h>
 
392
#else
 
393
#include <netinet/in.h>
 
394
#endif],
 
395
   [struct in6_addr a6; struct sockaddr_in6 s6;], ok_so_far=yes, ok_so_far=no)
 
396
 
 
397
if test $ok_so_far = yes; then
 
398
  ac_cv_sys_ipv6_support=yes
 
399
else
 
400
  AC_TRY_COMPILE([#include <sys/types.h>
 
401
#ifdef __WIN32__
 
402
#include <winsock2.h>
 
403
#include <ws2tcpip.h>
 
404
#else
 
405
#include <netinet/in.h>
 
406
#endif],
 
407
    [struct in_addr6 a6; struct sockaddr_in6 s6;],
 
408
    ac_cv_sys_ipv6_support=in_addr6, ac_cv_sys_ipv6_support=no)
 
409
fi
 
410
])dnl
 
411
 
 
412
dnl
 
413
dnl Have to use old style AC_DEFINE due to BC with old autoconf.
 
414
dnl
 
415
 
 
416
case ${ac_cv_sys_ipv6_support} in
 
417
  yes)
 
418
    AC_MSG_RESULT(yes)
 
419
    AC_DEFINE(HAVE_IN6,[1],[Define if ipv6 is present])
 
420
    ;;
 
421
  in_addr6)
 
422
    AC_MSG_RESULT([yes (but I am redefining in_addr6 to in6_addr)])
 
423
    AC_DEFINE(HAVE_IN6,[1],[Define if ipv6 is present])
 
424
    AC_DEFINE(HAVE_IN_ADDR6_STRUCT,[],[Early linux used in_addr6 instead of in6_addr, define if you have this])
 
425
    ;;
 
426
  *)
 
427
    AC_MSG_RESULT(no)
 
428
    ;;
 
429
esac
 
430
])
 
431
 
 
432
 
 
433
dnl ----------------------------------------------------------------------
 
434
dnl
 
435
dnl LM_SYS_MULTICAST
 
436
dnl
 
437
dnl Check for multicast support. Only checks for multicast options in
 
438
dnl setsockopt(), no check is performed that multicasting actually works.
 
439
dnl If options are found defines HAVE_MULTICAST_SUPPORT
 
440
dnl
 
441
 
 
442
AC_DEFUN(LM_SYS_MULTICAST,
 
443
[AC_CACHE_CHECK([for multicast support], ac_cv_sys_multicast_support,
 
444
[AC_EGREP_CPP(yes,
 
445
[#include <sys/types.h>
 
446
#include <sys/socket.h>
 
447
#include <netinet/in.h>
 
448
#if defined(IP_MULTICAST_TTL) && defined(IP_MULTICAST_LOOP) && defined(IP_MULTICAST_IF) && defined(IP_ADD_MEMBERSHIP) && defined(IP_DROP_MEMBERSHIP)
 
449
yes
 
450
#endif
 
451
], ac_cv_sys_multicast_support=yes, ac_cv_sys_multicast_support=no)])
 
452
if test $ac_cv_sys_multicast_support = yes; then
 
453
  AC_DEFINE(HAVE_MULTICAST_SUPPORT,[1],
 
454
        [Define if setsockopt() accepts multicast options])
 
455
fi
 
456
])dnl
 
457
 
 
458
 
 
459
dnl ----------------------------------------------------------------------
 
460
dnl
 
461
dnl LM_DECL_SYS_ERRLIST
 
462
dnl
 
463
dnl Define SYS_ERRLIST_DECLARED if the variable sys_errlist is declared
 
464
dnl in a system header file, stdio.h or errno.h.
 
465
dnl
 
466
 
 
467
AC_DEFUN(LM_DECL_SYS_ERRLIST,
 
468
[AC_CACHE_CHECK([for sys_errlist declaration in stdio.h or errno.h],
 
469
  ac_cv_decl_sys_errlist,
 
470
[AC_TRY_COMPILE([#include <stdio.h>
 
471
#include <errno.h>], [char *msg = *(sys_errlist + 1);],
 
472
  ac_cv_decl_sys_errlist=yes, ac_cv_decl_sys_errlist=no)])
 
473
if test $ac_cv_decl_sys_errlist = yes; then
 
474
  AC_DEFINE(SYS_ERRLIST_DECLARED,[],
 
475
        [define if the variable sys_errlist is declared in a system header file])
 
476
fi
 
477
])
 
478
 
 
479
 
 
480
dnl ----------------------------------------------------------------------
 
481
dnl
 
482
dnl LM_CHECK_FUNC_DECL( funname, declaration [, extra includes 
 
483
dnl                     [, action-if-found [, action-if-not-found]]] )
 
484
dnl
 
485
dnl Checks if the declaration "declaration" of "funname" conflicts
 
486
dnl with the header files idea of how the function should be
 
487
dnl declared. It is useful on systems which lack prototypes and you
 
488
dnl need to provide your own (e.g. when you want to take the address
 
489
dnl of a function). The 4'th argument is expanded if conflicting, 
 
490
dnl the 5'th argument otherwise
 
491
dnl
 
492
dnl
 
493
 
 
494
AC_DEFUN(LM_CHECK_FUNC_DECL,
 
495
[AC_MSG_CHECKING([for conflicting declaration of $1])
 
496
AC_CACHE_VAL(ac_cv_func_decl_$1,
 
497
[AC_TRY_COMPILE([#include <stdio.h>
 
498
$3],[$2
 
499
char *c = (char *)$1;
 
500
], eval "ac_cv_func_decl_$1=no", eval "ac_cv_func_decl_$1=yes")])
 
501
if eval "test \"`echo '$ac_cv_func_decl_'$1`\" = yes"; then
 
502
  AC_MSG_RESULT(yes)
 
503
  ifelse([$4], , :, [$4])
 
504
else
 
505
  AC_MSG_RESULT(no)
 
506
ifelse([$5], , , [$5
 
507
])dnl
 
508
fi
 
509
])
 
510
 
 
511
 
 
512
dnl ----------------------------------------------------------------------
 
513
dnl
 
514
dnl LM_CHECK_THR_LIB
 
515
dnl
 
516
dnl This macro may be used by any OTP application.
 
517
dnl
 
518
dnl LM_CHECK_THR_LIB sets THR_LIBS, THR_DEFS, and THR_LIB_NAME. It also
 
519
dnl checks for some pthread headers which will appear in DEFS or config.h.
 
520
dnl
 
521
 
 
522
AC_DEFUN(LM_CHECK_THR_LIB,
 
523
[
 
524
 
 
525
NEED_NPTL_PTHREAD_H=no
 
526
 
 
527
dnl win32?
 
528
AC_MSG_CHECKING([for native win32 threads])
 
529
if test "X$host_os" = "Xwin32"; then
 
530
    AC_MSG_RESULT(yes)
 
531
    THR_DEFS="-DWIN32_THREADS"
 
532
    THR_LIBS=
 
533
    THR_LIB_NAME=win32_threads
 
534
    THR_LIB_TYPE=win32_threads
 
535
else
 
536
    AC_MSG_RESULT(no)
 
537
    THR_DEFS=
 
538
    THR_LIBS=
 
539
    THR_LIB_NAME=
 
540
    THR_LIB_TYPE=posix_unknown
 
541
 
 
542
dnl Try to find POSIX threads
 
543
 
 
544
dnl The usual pthread lib...
 
545
    AC_CHECK_LIB(pthread, pthread_create, THR_LIBS="-lpthread")
 
546
 
 
547
dnl FreeBSD has pthreads in special c library, c_r...
 
548
    if test "x$THR_LIBS" = "x"; then
 
549
        AC_CHECK_LIB(c_r, pthread_create, THR_LIBS="-lc_r")
 
550
    fi
 
551
 
 
552
dnl On ofs1 the '-pthread' switch should be used
 
553
    if test "x$THR_LIBS" = "x"; then
 
554
        AC_MSG_CHECKING([if the '-pthread' switch can be used])
 
555
        saved_cflags=$CFLAGS
 
556
        CFLAGS="$CFLAGS -pthread"
 
557
        AC_TRY_LINK([#include <pthread.h>],
 
558
                    pthread_create((void*)0,(void*)0,(void*)0,(void*)0);,
 
559
                    [THR_DEFS="-pthread"
 
560
                     THR_LIBS="-pthread"])
 
561
        CFLAGS=$saved_cflags
 
562
        if test "x$THR_LIBS" != "x"; then
 
563
            AC_MSG_RESULT(yes)
 
564
        else
 
565
            AC_MSG_RESULT(no)
 
566
        fi
 
567
    fi
 
568
 
 
569
    if test "x$THR_LIBS" != "x"; then
 
570
        THR_DEFS="$THR_DEFS -D_THREAD_SAFE -D_REENTRANT -DPOSIX_THREADS"
 
571
        THR_LIB_NAME=pthread
 
572
        case $host_os in
 
573
            solaris*)
 
574
                THR_DEFS="$THR_DEFS -D_POSIX_PTHREAD_SEMANTICS" ;;
 
575
            linux*)
 
576
                THR_DEFS="$THR_DEFS -D_POSIX_THREAD_SAFE_FUNCTIONS"
 
577
 
 
578
                LM_CHECK_GETCONF
 
579
                AC_MSG_CHECKING(for Native POSIX Thread Library)
 
580
                libpthr_vsn=`$GETCONF GNU_LIBPTHREAD_VERSION 2>/dev/null`
 
581
                if test $? -eq 0; then
 
582
                    case "$libpthr_vsn" in
 
583
                        *nptl*|*NPTL*) nptl=yes;;
 
584
                        *) nptl=no;;
 
585
                    esac
 
586
                elif test "$cross_compiling" = "yes"; then
 
587
                    case "$erl_xcomp_linux_nptl" in
 
588
                        "") nptl=cross;;
 
589
                        yes|no) nptl=$erl_xcomp_linux_nptl;;
 
590
                        *) AC_MSG_ERROR([Bad erl_xcomp_linux_nptl value: $erl_xcomp_linux_nptl]);;
 
591
                    esac
 
592
                else
 
593
                    nptl=no
 
594
                fi
 
595
                AC_MSG_RESULT($nptl)
 
596
                if test $nptl = cross; then
 
597
                    nptl=yes
 
598
                    AC_MSG_WARN([result yes guessed because of cross compilation])
 
599
                fi
 
600
                if test $nptl = yes; then
 
601
                    THR_LIB_TYPE=posix_nptl
 
602
                    need_nptl_incldir=no
 
603
                    AC_CHECK_HEADER(nptl/pthread.h,
 
604
                                    [need_nptl_incldir=yes
 
605
                                     NEED_NPTL_PTHREAD_H=yes])
 
606
                    if test $need_nptl_incldir = yes; then
 
607
                        # Ahh...
 
608
                        nptl_path="$C_INCLUDE_PATH:$CPATH"
 
609
                        if test X$cross_compiling != Xyes; then
 
610
                            nptl_path="$nptl_path:/usr/local/include:/usr/include"
 
611
                        else
 
612
                            IROOT="$erl_xcomp_isysroot"
 
613
                            test "$IROOT" != "" || IROOT="$erl_xcomp_sysroot"
 
614
                            test "$IROOT" != "" || AC_MSG_ERROR([Don't know where to search for includes! Please set erl_xcomp_isysroot])
 
615
                            nptl_path="$nptl_path:$IROOT/usr/local/include:$IROOT/usr/include"
 
616
                        fi
 
617
                        nptl_ws_path=
 
618
                        save_ifs="$IFS"; IFS=":"
 
619
                        for dir in $nptl_path; do
 
620
                            if test "x$dir" != "x"; then
 
621
                                nptl_ws_path="$nptl_ws_path $dir"
 
622
                            fi
 
623
                        done
 
624
                        IFS=$save_ifs
 
625
                        nptl_incldir=
 
626
                        for dir in $nptl_ws_path; do
 
627
                            AC_CHECK_HEADER($dir/nptl/pthread.h,
 
628
                                            nptl_incldir=$dir/nptl)
 
629
                            if test "x$nptl_incldir" != "x"; then
 
630
                                THR_DEFS="$THR_DEFS -isystem $nptl_incldir"
 
631
                                break
 
632
                            fi
 
633
                        done
 
634
                        if test "x$nptl_incldir" = "x"; then
 
635
                            AC_MSG_ERROR(Failed to locate nptl system include directory)
 
636
                        fi
 
637
                    fi
 
638
                fi
 
639
                ;;
 
640
            *) ;;
 
641
        esac
 
642
 
 
643
        dnl We sometimes need THR_DEFS in order to find certain headers
 
644
        dnl (at least for pthread.h on osf1).
 
645
        saved_cppflags=$CPPFLAGS
 
646
        CPPFLAGS="$CPPFLAGS $THR_DEFS"
 
647
 
 
648
        dnl
 
649
        dnl Check for headers
 
650
        dnl
 
651
 
 
652
        AC_CHECK_HEADER(pthread.h,
 
653
                        AC_DEFINE(HAVE_PTHREAD_H, 1, \
 
654
[Define if you have the <pthread.h> header file.]))
 
655
 
 
656
        dnl Some Linuxes have <pthread/mit/pthread.h> instead of <pthread.h>
 
657
        AC_CHECK_HEADER(pthread/mit/pthread.h, \
 
658
                        AC_DEFINE(HAVE_MIT_PTHREAD_H, 1, \
 
659
[Define if the pthread.h header file is in pthread/mit directory.]))
 
660
 
 
661
        dnl restore CPPFLAGS
 
662
        CPPFLAGS=$saved_cppflags
 
663
 
 
664
    fi
 
665
fi
 
666
 
 
667
])
 
668
 
 
669
AC_DEFUN(ERL_INTERNAL_LIBS,
 
670
[
 
671
 
 
672
ERTS_INTERNAL_X_LIBS=
 
673
 
 
674
AC_CHECK_LIB(kstat, kstat_open,
 
675
[AC_DEFINE(HAVE_KSTAT, 1, [Define if you have kstat])
 
676
ERTS_INTERNAL_X_LIBS="$ERTS_INTERNAL_X_LIBS -lkstat"])
 
677
 
 
678
AC_SUBST(ERTS_INTERNAL_X_LIBS)
 
679
 
 
680
])
 
681
 
 
682
dnl ----------------------------------------------------------------------
 
683
dnl
 
684
dnl ERL_FIND_ETHR_LIB
 
685
dnl
 
686
dnl NOTE! This macro may be changed at any time! Should *only* be used by
 
687
dnl       ERTS!
 
688
dnl
 
689
dnl Find a thread library to use. Sets ETHR_LIBS to libraries to link
 
690
dnl with, ETHR_X_LIBS to extra libraries to link with (same as ETHR_LIBS
 
691
dnl except that the ethread lib itself is not included), ETHR_DEFS to
 
692
dnl defines to compile with, ETHR_THR_LIB_BASE to the name of the
 
693
dnl thread library which the ethread library is based on, and ETHR_LIB_NAME
 
694
dnl to the name of the library where the ethread implementation is located.
 
695
dnl  ERL_FIND_ETHR_LIB currently searches for 'pthreads', and
 
696
dnl 'win32_threads'. If no thread library was found ETHR_LIBS, ETHR_X_LIBS,
 
697
dnl ETHR_DEFS, ETHR_THR_LIB_BASE, and ETHR_LIB_NAME are all set to the
 
698
dnl empty string.
 
699
dnl
 
700
 
 
701
AC_DEFUN(ERL_FIND_ETHR_LIB,
 
702
[
 
703
 
 
704
LM_CHECK_THR_LIB
 
705
ERL_INTERNAL_LIBS
 
706
 
 
707
ethr_have_native_atomics=no
 
708
ethr_have_native_spinlock=no
 
709
ETHR_THR_LIB_BASE="$THR_LIB_NAME"
 
710
ETHR_THR_LIB_BASE_TYPE="$THR_LIB_TYPE"
 
711
ETHR_DEFS="$THR_DEFS"
 
712
ETHR_X_LIBS="$THR_LIBS $ERTS_INTERNAL_X_LIBS"
 
713
ETHR_LIBS=
 
714
ETHR_LIB_NAME=
 
715
 
 
716
ethr_modified_default_stack_size=
 
717
 
 
718
dnl Name of lib where ethread implementation is located
 
719
ethr_lib_name=ethread
 
720
 
 
721
case "$THR_LIB_NAME" in
 
722
 
 
723
    win32_threads)
 
724
        ETHR_THR_LIB_BASE_DIR=win
 
725
        # * _WIN32_WINNT >= 0x0400 is needed for
 
726
        #   TryEnterCriticalSection
 
727
        # * _WIN32_WINNT >= 0x0403 is needed for
 
728
        #   InitializeCriticalSectionAndSpinCount
 
729
        # The ethread lib will refuse to build if _WIN32_WINNT < 0x0403.
 
730
        #
 
731
        # -D_WIN32_WINNT should have been defined in $CPPFLAGS; fetch it
 
732
        # and save it in ETHR_DEFS.
 
733
        found_win32_winnt=no
 
734
        for cppflag in $CPPFLAGS; do
 
735
            case $cppflag in
 
736
                -DWINVER*)
 
737
                    ETHR_DEFS="$ETHR_DEFS $cppflag"
 
738
                    ;;
 
739
                -D_WIN32_WINNT*)
 
740
                    ETHR_DEFS="$ETHR_DEFS $cppflag"
 
741
                    found_win32_winnt=yes
 
742
                    ;;
 
743
                *)
 
744
                    ;;
 
745
            esac
 
746
        done
 
747
        if test $found_win32_winnt = no; then
 
748
            AC_MSG_ERROR([-D_WIN32_WINNT missing in CPPFLAGS])
 
749
        fi
 
750
 
 
751
        AC_DEFINE(ETHR_WIN32_THREADS, 1, [Define if you have win32 threads])
 
752
 
 
753
        have_ilckd=no
 
754
        AC_MSG_CHECKING([for _InterlockedCompareExchange64()])
 
755
        AC_TRY_LINK([
 
756
                        #define WIN32_LEAN_AND_MEAN
 
757
                        #include <windows.h>
 
758
                    ],
 
759
                    [
 
760
                        volatile __int64 *var;
 
761
                        _InterlockedCompareExchange64(var, (__int64) 1, (__int64) 0);
 
762
                        return 0;
 
763
                    ],
 
764
                    have_ilckd=yes)
 
765
        AC_MSG_RESULT([$have_ilckd])
 
766
        test $have_ilckd = yes && AC_DEFINE(ETHR_HAVE__INTERLOCKEDCOMPAREEXCHANGE64, 1, [Define if you have _InterlockedCompareExchange64()])
 
767
 
 
768
        AC_CHECK_SIZEOF(void *)
 
769
        case "$ac_cv_sizeof_void_p-$have_ilckd" in
 
770
            8-no)
 
771
                ethr_have_native_atomics=no
 
772
                ethr_have_native_spinlock=no;;
 
773
            *)
 
774
                ethr_have_native_atomics=yes
 
775
                ethr_have_native_spinlock=yes;;
 
776
        esac
 
777
 
 
778
        have_ilckd=no
 
779
        AC_MSG_CHECKING([for _InterlockedDecrement64()])
 
780
        AC_TRY_LINK([
 
781
                        #define WIN32_LEAN_AND_MEAN
 
782
                        #include <windows.h>
 
783
                    ],
 
784
                    [
 
785
                        volatile __int64 *var;
 
786
                        _InterlockedDecrement64(var);
 
787
                        return 0;
 
788
                    ],
 
789
                    have_ilckd=yes)
 
790
        AC_MSG_RESULT([$have_ilckd])
 
791
        test $have_ilckd = yes && AC_DEFINE(ETHR_HAVE__INTERLOCKEDDECREMENT64, 1, [Define if you have _InterlockedDecrement64()])
 
792
 
 
793
        have_ilckd=no
 
794
        AC_MSG_CHECKING([for _InterlockedIncrement64()])
 
795
        AC_TRY_LINK([
 
796
                        #define WIN32_LEAN_AND_MEAN
 
797
                        #include <windows.h>
 
798
                    ],
 
799
                    [
 
800
                        volatile __int64 *var;
 
801
                        _InterlockedIncrement64(var);
 
802
                        return 0;
 
803
                    ],
 
804
                    have_ilckd=yes)
 
805
        AC_MSG_RESULT([$have_ilckd])
 
806
        test $have_ilckd = yes && AC_DEFINE(ETHR_HAVE__INTERLOCKEDINCREMENT64, 1, [Define if you have _InterlockedIncrement64()])
 
807
 
 
808
        have_ilckd=no
 
809
        AC_MSG_CHECKING([for _InterlockedExchangeAdd64()])
 
810
        AC_TRY_LINK([
 
811
                        #define WIN32_LEAN_AND_MEAN
 
812
                        #include <windows.h>
 
813
                    ],
 
814
                    [
 
815
                        volatile __int64 *var;
 
816
                        _InterlockedExchangeAdd64(var, (__int64) 1);
 
817
                        return 0;
 
818
                    ],
 
819
                    have_ilckd=yes)
 
820
        AC_MSG_RESULT([$have_ilckd])
 
821
        test $have_ilckd = yes && AC_DEFINE(ETHR_HAVE__INTERLOCKEDEXCHANGEADD64, 1, [Define if you have _InterlockedExchangeAdd64()])
 
822
 
 
823
        have_ilckd=no
 
824
        AC_MSG_CHECKING([for _InterlockedExchange64()])
 
825
        AC_TRY_LINK([
 
826
                        #define WIN32_LEAN_AND_MEAN
 
827
                        #include <windows.h>
 
828
                    ],
 
829
                    [
 
830
                        volatile __int64 *var;
 
831
                        _InterlockedExchange64(var, (__int64) 1);
 
832
                        return 0;
 
833
                    ],
 
834
                    have_ilckd=yes)
 
835
        AC_MSG_RESULT([$have_ilckd])
 
836
        test $have_ilckd = yes && AC_DEFINE(ETHR_HAVE__INTERLOCKEDEXCHANGE64, 1, [Define if you have _InterlockedExchange64()])
 
837
 
 
838
        have_ilckd=no
 
839
        AC_MSG_CHECKING([for _InterlockedAnd64()])
 
840
        AC_TRY_LINK([
 
841
                        #define WIN32_LEAN_AND_MEAN
 
842
                        #include <windows.h>
 
843
                    ],
 
844
                    [
 
845
                        volatile __int64 *var;
 
846
                        _InterlockedAnd64(var, (__int64) 1);
 
847
                        return 0;
 
848
                    ],
 
849
                    have_ilckd=yes)
 
850
        AC_MSG_RESULT([$have_ilckd])
 
851
        test $have_ilckd = yes && AC_DEFINE(ETHR_HAVE__INTERLOCKEDAND64, 1, [Define if you have _InterlockedAnd64()])
 
852
 
 
853
        have_ilckd=no
 
854
        AC_MSG_CHECKING([for _InterlockedOr64()])
 
855
        AC_TRY_LINK([
 
856
                        #define WIN32_LEAN_AND_MEAN
 
857
                        #include <windows.h>
 
858
                    ],
 
859
                    [
 
860
                        volatile __int64 *var;
 
861
                        _InterlockedOr64(var, (__int64) 1);
 
862
                        return 0;
 
863
                    ],
 
864
                    have_ilckd=yes)
 
865
        AC_MSG_RESULT([$have_ilckd])
 
866
        test $have_ilckd = yes && AC_DEFINE(ETHR_HAVE__INTERLOCKEDOR64, 1, [Define if you have _InterlockedOr64()])
 
867
 
 
868
        ;;
 
869
 
 
870
    pthread)
 
871
        ETHR_THR_LIB_BASE_DIR=pthread
 
872
        AC_DEFINE(ETHR_PTHREADS, 1, [Define if you have pthreads])
 
873
        case $host_os in
 
874
            openbsd*)
 
875
                # The default stack size is insufficient for our needs
 
876
                # on OpenBSD. We increase it to 256 kilo words.
 
877
                ethr_modified_default_stack_size=256;;
 
878
            linux*)
 
879
                ETHR_DEFS="$ETHR_DEFS -D_GNU_SOURCE"
 
880
 
 
881
                if test X$cross_compiling = Xyes; then
 
882
                    case X$erl_xcomp_linux_usable_sigusrx in
 
883
                        X) usable_sigusrx=cross;;
 
884
                        Xyes|Xno) usable_sigusrx=$erl_xcomp_linux_usable_sigusrx;;
 
885
                        *) AC_MSG_ERROR([Bad erl_xcomp_linux_usable_sigusrx value: $erl_xcomp_linux_usable_sigusrx]);;
 
886
                    esac
 
887
                    case X$erl_xcomp_linux_usable_sigaltstack in
 
888
                        X) usable_sigaltstack=cross;;
 
889
                        Xyes|Xno) usable_sigaltstack=$erl_xcomp_linux_usable_sigaltstack;;
 
890
                        *) AC_MSG_ERROR([Bad erl_xcomp_linux_usable_sigaltstack value: $erl_xcomp_linux_usable_sigaltstack]);;
 
891
                    esac
 
892
                else
 
893
                    # FIXME: Test for actual problems instead of kernel versions
 
894
                    linux_kernel_vsn_=`uname -r`
 
895
                    case $linux_kernel_vsn_ in
 
896
                        [[0-1]].*|2.[[0-1]]|2.[[0-1]].*)
 
897
                            usable_sigusrx=no
 
898
                            usable_sigaltstack=no;;
 
899
                        2.[[2-3]]|2.[[2-3]].*)
 
900
                            usable_sigusrx=yes
 
901
                            usable_sigaltstack=no;;
 
902
                        *)
 
903
                            usable_sigusrx=yes
 
904
                            usable_sigaltstack=yes;;
 
905
                    esac
 
906
                fi
 
907
 
 
908
                AC_MSG_CHECKING(if SIGUSR1 and SIGUSR2 can be used)
 
909
                AC_MSG_RESULT($usable_sigusrx)
 
910
                if test $usable_sigusrx = cross; then
 
911
                    usable_sigusrx=yes
 
912
                    AC_MSG_WARN([result yes guessed because of cross compilation])
 
913
                fi
 
914
                if test $usable_sigusrx = no; then
 
915
                    ETHR_DEFS="$ETHR_DEFS -DETHR_UNUSABLE_SIGUSRX"
 
916
                fi
 
917
 
 
918
                AC_MSG_CHECKING(if sigaltstack can be used)
 
919
                AC_MSG_RESULT($usable_sigaltstack)
 
920
                if test $usable_sigaltstack = cross; then
 
921
                    usable_sigaltstack=yes
 
922
                    AC_MSG_WARN([result yes guessed because of cross compilation])
 
923
                fi
 
924
                if test $usable_sigaltstack = no; then
 
925
                    ETHR_DEFS="$ETHR_DEFS -DETHR_UNUSABLE_SIGALTSTACK"
 
926
                fi
 
927
                ;;
 
928
            *) ;;
 
929
        esac
 
930
 
 
931
        dnl We sometimes need ETHR_DEFS in order to find certain headers
 
932
        dnl (at least for pthread.h on osf1).
 
933
        saved_cppflags="$CPPFLAGS"
 
934
        CPPFLAGS="$CPPFLAGS $ETHR_DEFS"
 
935
 
 
936
        dnl We need the thread library in order to find some functions
 
937
        saved_libs="$LIBS"
 
938
        LIBS="$LIBS $ETHR_X_LIBS"
 
939
 
 
940
        dnl
 
941
        dnl Check for headers
 
942
        dnl
 
943
 
 
944
        AC_CHECK_HEADER(pthread.h, \
 
945
                        AC_DEFINE(ETHR_HAVE_PTHREAD_H, 1, \
 
946
[Define if you have the <pthread.h> header file.]))
 
947
 
 
948
        dnl Some Linuxes have <pthread/mit/pthread.h> instead of <pthread.h>
 
949
        AC_CHECK_HEADER(pthread/mit/pthread.h, \
 
950
                        AC_DEFINE(ETHR_HAVE_MIT_PTHREAD_H, 1, \
 
951
[Define if the pthread.h header file is in pthread/mit directory.]))
 
952
 
 
953
        if test $NEED_NPTL_PTHREAD_H = yes; then
 
954
            AC_DEFINE(ETHR_NEED_NPTL_PTHREAD_H, 1, \
 
955
[Define if you need the <nptl/pthread.h> header file.])
 
956
        fi
 
957
 
 
958
        AC_CHECK_HEADER(sched.h, \
 
959
                        AC_DEFINE(ETHR_HAVE_SCHED_H, 1, \
 
960
[Define if you have the <sched.h> header file.]))
 
961
 
 
962
        AC_CHECK_HEADER(sys/time.h, \
 
963
                        AC_DEFINE(ETHR_HAVE_SYS_TIME_H, 1, \
 
964
[Define if you have the <sys/time.h> header file.]))
 
965
 
 
966
        AC_TRY_COMPILE([#include <time.h>
 
967
                        #include <sys/time.h>], 
 
968
                        [struct timeval *tv; return 0;],
 
969
                        AC_DEFINE(ETHR_TIME_WITH_SYS_TIME, 1, \
 
970
[Define if you can safely include both <sys/time.h> and <time.h>.]))
 
971
 
 
972
 
 
973
        dnl
 
974
        dnl Check for functions
 
975
        dnl
 
976
 
 
977
        AC_CHECK_FUNC(pthread_spin_lock, \
 
978
                        [ethr_have_native_spinlock=yes \
 
979
                         AC_DEFINE(ETHR_HAVE_PTHREAD_SPIN_LOCK, 1, \
 
980
[Define if you have the pthread_spin_lock function.])])
 
981
 
 
982
        have_sched_yield=no
 
983
        have_librt_sched_yield=no
 
984
        AC_CHECK_FUNC(sched_yield, [have_sched_yield=yes])
 
985
        if test $have_sched_yield = no; then
 
986
            AC_CHECK_LIB(rt, sched_yield,
 
987
                         [have_librt_sched_yield=yes
 
988
                          ETHR_X_LIBS="$ETHR_X_LIBS -lrt"])
 
989
        fi
 
990
        if test $have_sched_yield = yes || test $have_librt_sched_yield = yes; then
 
991
            AC_DEFINE(ETHR_HAVE_SCHED_YIELD, 1, [Define if you have the sched_yield() function.])
 
992
            AC_MSG_CHECKING([whether sched_yield() returns an int])
 
993
            sched_yield_ret_int=no
 
994
            AC_TRY_COMPILE([
 
995
                                #ifdef ETHR_HAVE_SCHED_H
 
996
                                #include <sched.h>
 
997
                                #endif
 
998
                           ],
 
999
                           [int sched_yield();],
 
1000
                           [sched_yield_ret_int=yes])
 
1001
            AC_MSG_RESULT([$sched_yield_ret_int])
 
1002
            if test $sched_yield_ret_int = yes; then
 
1003
                AC_DEFINE(ETHR_SCHED_YIELD_RET_INT, 1, [Define if sched_yield() returns an int.])
 
1004
            fi
 
1005
        fi
 
1006
 
 
1007
        have_pthread_yield=no
 
1008
        AC_CHECK_FUNC(pthread_yield, [have_pthread_yield=yes])
 
1009
        if test $have_pthread_yield = yes; then
 
1010
            AC_DEFINE(ETHR_HAVE_PTHREAD_YIELD, 1, [Define if you have the pthread_yield() function.])
 
1011
            AC_MSG_CHECKING([whether pthread_yield() returns an int])
 
1012
            pthread_yield_ret_int=no
 
1013
            AC_TRY_COMPILE([
 
1014
                                #if defined(ETHR_NEED_NPTL_PTHREAD_H)
 
1015
                                #include <nptl/pthread.h>
 
1016
                                #elif defined(ETHR_HAVE_MIT_PTHREAD_H)
 
1017
                                #include <pthread/mit/pthread.h>
 
1018
                                #elif defined(ETHR_HAVE_PTHREAD_H)
 
1019
                                #include <pthread.h>
 
1020
                                #endif
 
1021
                           ],
 
1022
                           [int pthread_yield();],
 
1023
                           [pthread_yield_ret_int=yes])
 
1024
            AC_MSG_RESULT([$pthread_yield_ret_int])
 
1025
            if test $pthread_yield_ret_int = yes; then
 
1026
                AC_DEFINE(ETHR_PTHREAD_YIELD_RET_INT, 1, [Define if pthread_yield() returns an int.])
 
1027
            fi
 
1028
        fi
 
1029
 
 
1030
        have_pthread_rwlock_init=no
 
1031
        AC_CHECK_FUNC(pthread_rwlock_init, [have_pthread_rwlock_init=yes])
 
1032
        if test $have_pthread_rwlock_init = yes; then
 
1033
 
 
1034
            ethr_have_pthread_rwlockattr_setkind_np=no
 
1035
            AC_CHECK_FUNC(pthread_rwlockattr_setkind_np,
 
1036
                          [ethr_have_pthread_rwlockattr_setkind_np=yes])
 
1037
 
 
1038
            if test $ethr_have_pthread_rwlockattr_setkind_np = yes; then
 
1039
                AC_DEFINE(ETHR_HAVE_PTHREAD_RWLOCKATTR_SETKIND_NP, 1, \
 
1040
[Define if you have the pthread_rwlockattr_setkind_np() function.])
 
1041
 
 
1042
                AC_MSG_CHECKING([for PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP])
 
1043
                ethr_pthread_rwlock_writer_nonrecursive_initializer_np=no
 
1044
                AC_TRY_LINK([
 
1045
                                #if defined(ETHR_NEED_NPTL_PTHREAD_H)
 
1046
                                #include <nptl/pthread.h>
 
1047
                                #elif defined(ETHR_HAVE_MIT_PTHREAD_H)
 
1048
                                #include <pthread/mit/pthread.h>
 
1049
                                #elif defined(ETHR_HAVE_PTHREAD_H)
 
1050
                                #include <pthread.h>
 
1051
                                #endif
 
1052
                            ],
 
1053
                            [
 
1054
                                pthread_rwlockattr_t *attr;
 
1055
                                return pthread_rwlockattr_setkind_np(attr,
 
1056
                                    PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP);
 
1057
                            ],
 
1058
                            [ethr_pthread_rwlock_writer_nonrecursive_initializer_np=yes])
 
1059
                AC_MSG_RESULT([$ethr_pthread_rwlock_writer_nonrecursive_initializer_np])
 
1060
                if test $ethr_pthread_rwlock_writer_nonrecursive_initializer_np = yes; then
 
1061
                    AC_DEFINE(ETHR_HAVE_PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP, 1, \
 
1062
[Define if you have the PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP rwlock attribute.])
 
1063
                fi
 
1064
            fi
 
1065
        fi
 
1066
 
 
1067
        if test "$force_pthread_rwlocks" = "yes"; then
 
1068
 
 
1069
            AC_DEFINE(ETHR_FORCE_PTHREAD_RWLOCK, 1, \
 
1070
[Define if you want to force usage of pthread rwlocks])
 
1071
 
 
1072
            if test $have_pthread_rwlock_init = yes; then
 
1073
                AC_MSG_WARN([Forced usage of pthread rwlocks. Note that this implementation may suffer from starvation issues.])
 
1074
            else
 
1075
                AC_MSG_ERROR([User forced usage of pthread rwlock, but no such implementation was found])
 
1076
            fi
 
1077
        fi
 
1078
 
 
1079
        AC_CHECK_FUNC(pthread_attr_setguardsize, \
 
1080
                        AC_DEFINE(ETHR_HAVE_PTHREAD_ATTR_SETGUARDSIZE, 1, \
 
1081
[Define if you have the pthread_attr_setguardsize function.]))
 
1082
 
 
1083
        linux_futex=no
 
1084
        AC_MSG_CHECKING([for Linux futexes])
 
1085
        AC_TRY_LINK([
 
1086
                        #include <sys/syscall.h>
 
1087
                        #include <unistd.h>
 
1088
                        #include <linux/futex.h>
 
1089
                        #include <sys/time.h>
 
1090
                    ],
 
1091
                    [
 
1092
                        int i = 1;
 
1093
                        syscall(__NR_futex, (void *) &i, FUTEX_WAKE, 1,
 
1094
                                (void*)0,(void*)0, 0);
 
1095
                        syscall(__NR_futex, (void *) &i, FUTEX_WAIT, 0,
 
1096
                                (void*)0,(void*)0, 0);
 
1097
                        return 0;
 
1098
                    ],
 
1099
                    linux_futex=yes)
 
1100
        AC_MSG_RESULT([$linux_futex])
 
1101
        test $linux_futex = yes && AC_DEFINE(ETHR_HAVE_LINUX_FUTEX, 1, [Define if you have a linux futex implementation.])
 
1102
 
 
1103
        AC_MSG_CHECKING([for GCC atomic operations])
 
1104
        ethr_have_gcc_atomic_ops=no
 
1105
        AC_TRY_LINK([],
 
1106
                    [
 
1107
                        long res;
 
1108
                        volatile long val;
 
1109
                        res = __sync_val_compare_and_swap(&val, (long) 1, (long) 0);
 
1110
                        res = __sync_add_and_fetch(&val, (long) 1);
 
1111
                        res = __sync_sub_and_fetch(&val, (long) 1);
 
1112
                        res = __sync_fetch_and_and(&val, (long) 1);
 
1113
                        res = __sync_fetch_and_or(&val, (long) 1);
 
1114
                    ],
 
1115
                    [ethr_have_native_atomics=yes
 
1116
                     ethr_have_gcc_atomic_ops=yes])
 
1117
        AC_MSG_RESULT([$ethr_have_gcc_atomic_ops])
 
1118
        test $ethr_have_gcc_atomic_ops = yes && AC_DEFINE(ETHR_HAVE_GCC_ATOMIC_OPS, 1, [Define if you have gcc atomic operations])
 
1119
 
 
1120
        case "$host_cpu" in
 
1121
          sun4u | sparc64 | sun4v)
 
1122
                ethr_have_native_atomics=yes;; 
 
1123
          i86pc | i*86 | x86_64 | amd64)
 
1124
                ethr_have_native_atomics=yes;;
 
1125
          macppc | ppc | "Power Macintosh")
 
1126
                ethr_have_native_atomics=yes;;
 
1127
          tile)
 
1128
                ethr_have_native_atomics=yes;;
 
1129
          *)
 
1130
                ;;
 
1131
        esac
 
1132
 
 
1133
        AC_MSG_CHECKING([for a usable libatomic_ops implementation])
 
1134
        case "x$with_libatomic_ops" in
 
1135
            xno | xyes | x)
 
1136
                libatomic_ops_include=
 
1137
                ;;
 
1138
            *)
 
1139
                if test -d "${with_libatomic_ops}/include"; then
 
1140
                    libatomic_ops_include="-I$with_libatomic_ops/include"
 
1141
                    CPPFLAGS="$CPPFLAGS $libatomic_ops_include"
 
1142
                else
 
1143
                    AC_MSG_ERROR([libatomic_ops include directory $with_libatomic_ops/include not found])
 
1144
                fi;;
 
1145
        esac
 
1146
        ethr_have_libatomic_ops=no
 
1147
        AC_TRY_LINK([#include "atomic_ops.h"],
 
1148
                    [
 
1149
                        volatile AO_t x;
 
1150
                        AO_t y;
 
1151
                        int z;
 
1152
 
 
1153
                        AO_nop_full();
 
1154
                        AO_store(&x, (AO_t) 0);
 
1155
                        z = AO_load(&x);
 
1156
                        z = AO_compare_and_swap(&x, (AO_t) 0, (AO_t) 1);
 
1157
                    ],
 
1158
                    [ethr_have_native_atomics=yes
 
1159
                     ethr_have_libatomic_ops=yes])
 
1160
        AC_MSG_RESULT([$ethr_have_libatomic_ops])
 
1161
        if test $ethr_have_libatomic_ops = yes; then
 
1162
            AC_CHECK_SIZEOF(AO_t, ,
 
1163
                            [
 
1164
                                #include <stdio.h>
 
1165
                                #include "atomic_ops.h"
 
1166
                            ])
 
1167
            AC_DEFINE_UNQUOTED(ETHR_SIZEOF_AO_T, $ac_cv_sizeof_AO_t, [Define to the size of AO_t if libatomic_ops is used])
 
1168
 
 
1169
            AC_DEFINE(ETHR_HAVE_LIBATOMIC_OPS, 1, [Define if you have libatomic_ops atomic operations])
 
1170
            if test "x$with_libatomic_ops" != "xno" && test "x$with_libatomic_ops" != "x"; then
 
1171
                AC_DEFINE(ETHR_PREFER_LIBATOMIC_OPS_NATIVE_IMPLS, 1, [Define if you prefer libatomic_ops native ethread implementations])
 
1172
            fi
 
1173
            ETHR_DEFS="$ETHR_DEFS $libatomic_ops_include"
 
1174
        elif test "x$with_libatomic_ops" != "xno" && test "x$with_libatomic_ops" != "x"; then
 
1175
            AC_MSG_ERROR([No usable libatomic_ops implementation found])
 
1176
        fi
 
1177
 
 
1178
        dnl Restore LIBS
 
1179
        LIBS=$saved_libs
 
1180
        dnl restore CPPFLAGS
 
1181
        CPPFLAGS=$saved_cppflags
 
1182
 
 
1183
        ;;
 
1184
    *)
 
1185
        ;;
 
1186
esac
 
1187
 
 
1188
AC_MSG_CHECKING([whether default stack size should be modified])
 
1189
if test "x$ethr_modified_default_stack_size" != "x"; then
 
1190
        AC_DEFINE_UNQUOTED(ETHR_MODIFIED_DEFAULT_STACK_SIZE, $ethr_modified_default_stack_size, [Define if you want to modify the default stack size])
 
1191
        AC_MSG_RESULT([yes; to $ethr_modified_default_stack_size kilo words])
 
1192
else
 
1193
        AC_MSG_RESULT([no])
 
1194
fi
 
1195
 
 
1196
if test "x$ETHR_THR_LIB_BASE" != "x"; then
 
1197
        ETHR_DEFS="-DUSE_THREADS $ETHR_DEFS"
 
1198
        ETHR_LIBS="-l$ethr_lib_name -lerts_internal_r $ETHR_X_LIBS"
 
1199
        ETHR_LIB_NAME=$ethr_lib_name
 
1200
fi
 
1201
 
 
1202
AC_CHECK_SIZEOF(void *)
 
1203
AC_DEFINE_UNQUOTED(ETHR_SIZEOF_PTR, $ac_cv_sizeof_void_p, [Define to the size of pointers])
 
1204
 
 
1205
AC_CHECK_SIZEOF(int)
 
1206
AC_DEFINE_UNQUOTED(ETHR_SIZEOF_INT, $ac_cv_sizeof_int, [Define to the size of int])
 
1207
AC_CHECK_SIZEOF(long)
 
1208
AC_DEFINE_UNQUOTED(ETHR_SIZEOF_LONG, $ac_cv_sizeof_long, [Define to the size of long])
 
1209
AC_CHECK_SIZEOF(long long)
 
1210
AC_DEFINE_UNQUOTED(ETHR_SIZEOF_LONG_LONG, $ac_cv_sizeof_long_long, [Define to the size of long long])
 
1211
AC_CHECK_SIZEOF(__int64)
 
1212
AC_DEFINE_UNQUOTED(ETHR_SIZEOF___INT64, $ac_cv_sizeof___int64, [Define to the size of __int64])
 
1213
 
 
1214
 
 
1215
case X$erl_xcomp_bigendian in
 
1216
    X) ;;
 
1217
    Xyes|Xno) ac_cv_c_bigendian=$erl_xcomp_bigendian;;
 
1218
    *) AC_MSG_ERROR([Bad erl_xcomp_bigendian value: $erl_xcomp_bigendian]);;
 
1219
esac
 
1220
 
 
1221
AC_C_BIGENDIAN
 
1222
 
 
1223
if test "$ac_cv_c_bigendian" = "yes"; then
 
1224
    AC_DEFINE(ETHR_BIGENDIAN, 1, [Define if bigendian])
 
1225
fi
 
1226
 
 
1227
AC_ARG_ENABLE(native-ethr-impls,
 
1228
              AS_HELP_STRING([--disable-native-ethr-impls],
 
1229
                             [disable native ethread implementations]),
 
1230
[ case "$enableval" in
 
1231
    no) disable_native_ethr_impls=yes ;;
 
1232
    *)  disable_native_ethr_impls=no ;;
 
1233
  esac ], disable_native_ethr_impls=no)
 
1234
 
 
1235
test "X$disable_native_ethr_impls" = "Xyes" &&
 
1236
  AC_DEFINE(ETHR_DISABLE_NATIVE_IMPLS, 1, [Define if you want to disable native ethread implementations])
 
1237
 
 
1238
AC_ARG_ENABLE(prefer-gcc-native-ethr-impls,
 
1239
              AS_HELP_STRING([--enable-prefer-gcc-native-ethr-impls],
 
1240
                             [prefer gcc native ethread implementations]),
 
1241
[ case "$enableval" in
 
1242
    yes) enable_prefer_gcc_native_ethr_impls=yes ;;
 
1243
    *)  enable_prefer_gcc_native_ethr_impls=no ;;
 
1244
  esac ], enable_prefer_gcc_native_ethr_impls=no)
 
1245
 
 
1246
test $enable_prefer_gcc_native_ethr_impls = yes &&
 
1247
  AC_DEFINE(ETHR_PREFER_GCC_NATIVE_IMPLS, 1, [Define if you prefer gcc native ethread implementations])
 
1248
 
 
1249
AC_ARG_WITH(libatomic_ops,
 
1250
            AS_HELP_STRING([--with-libatomic_ops=PATH],
 
1251
                           [specify and prefer usage of libatomic_ops in the ethread library]))
 
1252
 
 
1253
AC_ARG_ENABLE(ethread-pre-pentium4-compatibility,
 
1254
              AS_HELP_STRING([--enable-ethread-pre-pentium4-compatibility],
 
1255
                             [enable compatibility with x86 processors before pentium 4 (back to 486) in the ethread library]),
 
1256
[
 
1257
  case "$enable_ethread_pre_pentium4_compatibility" in
 
1258
    yes|no) ;;
 
1259
    *) enable_ethread_pre_pentium4_compatibility=check;;
 
1260
  esac
 
1261
],
 
1262
[enable_ethread_pre_pentium4_compatibility=check])
 
1263
 
 
1264
test "$cross_compiling" != "yes" || enable_ethread_pre_pentium4_compatibility=no
 
1265
 
 
1266
case "$enable_ethread_pre_pentium4_compatibility-$host_cpu" in
 
1267
  check-i86pc | check-i*86)
 
1268
    AC_MSG_CHECKING([whether pre pentium 4 compatibility should forced])
 
1269
    AC_RUN_IFELSE([
 
1270
#if defined(__GNUC__)
 
1271
#  if defined(ETHR_PREFER_LIBATOMIC_OPS_NATIVE_IMPLS)
 
1272
#    define CHECK_LIBATOMIC_OPS__
 
1273
#  else
 
1274
#    define CHECK_GCC_ASM__
 
1275
#  endif
 
1276
#elif defined(ETHR_HAVE_LIBATOMIC_OPS)
 
1277
#  define CHECK_LIBATOMIC_OPS__
 
1278
#endif
 
1279
#if defined(CHECK_LIBATOMIC_OPS__)
 
1280
#include "atomic_ops.h"
 
1281
#endif
 
1282
int main(void)
 
1283
{
 
1284
#if defined(CHECK_GCC_ASM__)
 
1285
    __asm__ __volatile__("mfence" : : : "memory");
 
1286
#elif defined(CHECK_LIBATOMIC_OPS__)
 
1287
    AO_nop_full();
 
1288
#endif
 
1289
    return 0;
 
1290
}
 
1291
        ],
 
1292
        [enable_ethread_pre_pentium4_compatibility=no],
 
1293
        [enable_ethread_pre_pentium4_compatibility=yes],
 
1294
        [enable_ethread_pre_pentium4_compatibility=no])
 
1295
    AC_MSG_RESULT([$enable_ethread_pre_pentium4_compatibility]);;
 
1296
  *)
 
1297
    ;;
 
1298
esac
 
1299
 
 
1300
test $enable_ethread_pre_pentium4_compatibility = yes &&
 
1301
  AC_DEFINE(ETHR_PRE_PENTIUM4_COMPAT, 1, [Define if you want compatibilty with x86 processors before pentium4.])
 
1302
 
 
1303
AC_DEFINE(ETHR_HAVE_ETHREAD_DEFINES, 1, \
 
1304
[Define if you have all ethread defines])
 
1305
 
 
1306
AC_SUBST(ETHR_X_LIBS)
 
1307
AC_SUBST(ETHR_LIBS)
 
1308
AC_SUBST(ETHR_LIB_NAME)
 
1309
AC_SUBST(ETHR_DEFS)
 
1310
AC_SUBST(ETHR_THR_LIB_BASE)
 
1311
AC_SUBST(ETHR_THR_LIB_BASE_DIR)
 
1312
 
 
1313
])
 
1314
 
 
1315
 
 
1316
 
 
1317
dnl ----------------------------------------------------------------------
 
1318
dnl
 
1319
dnl ERL_TIME_CORRECTION
 
1320
dnl
 
1321
dnl In the presence of a high resolution realtime timer Erlang can adapt
 
1322
dnl its view of time relative to this timer. On solaris such a timer is
 
1323
dnl available with the syscall gethrtime(). On other OS's a fallback
 
1324
dnl solution using times() is implemented. (However on e.g. FreeBSD times()
 
1325
dnl is implemented using gettimeofday so it doesn't make much sense to
 
1326
dnl use it there...) On second thought, it seems to be safer to do it the
 
1327
dnl other way around. I.e. only use times() on OS's where we know it will
 
1328
dnl work...
 
1329
dnl
 
1330
 
 
1331
AC_DEFUN(ERL_TIME_CORRECTION,
 
1332
[if test x$ac_cv_func_gethrtime = x; then
 
1333
  AC_CHECK_FUNC(gethrtime)
 
1334
fi
 
1335
if test x$clock_gettime_correction = xunknown; then
 
1336
        AC_TRY_COMPILE([#include <time.h>],
 
1337
                        [struct timespec ts;
 
1338
                         long long result;
 
1339
                         clock_gettime(CLOCK_MONOTONIC,&ts);
 
1340
                         result = ((long long) ts.tv_sec) * 1000000000LL + 
 
1341
                         ((long long) ts.tv_nsec);],
 
1342
                        clock_gettime_compiles=yes,
 
1343
                        clock_gettime_compiles=no)
 
1344
else
 
1345
        clock_gettime_compiles=no
 
1346
fi
 
1347
                        
 
1348
 
 
1349
AC_CACHE_CHECK([how to correct for time adjustments], erl_cv_time_correction,
 
1350
[
 
1351
case $clock_gettime_correction in
 
1352
    yes)
 
1353
        erl_cv_time_correction=clock_gettime;;  
 
1354
    no|unknown)
 
1355
        case $ac_cv_func_gethrtime in
 
1356
            yes)
 
1357
                erl_cv_time_correction=hrtime ;;
 
1358
            no)
 
1359
                case $host_os in
 
1360
                    linux*)
 
1361
                        case $clock_gettime_correction in
 
1362
                            unknown)
 
1363
                                if test x$clock_gettime_compiles = xyes; then
 
1364
                                    if test X$cross_compiling != Xyes; then
 
1365
                                        linux_kernel_vsn_=`uname -r`
 
1366
                                        case $linux_kernel_vsn_ in
 
1367
                                            [[0-1]].*|2.[[0-5]]|2.[[0-5]].*)
 
1368
                                                erl_cv_time_correction=times ;;
 
1369
                                            *)
 
1370
                                                erl_cv_time_correction=clock_gettime;;
 
1371
                                        esac
 
1372
                                    else
 
1373
                                        case X$erl_xcomp_linux_clock_gettime_correction in
 
1374
                                            X)
 
1375
                                                erl_cv_time_correction=cross;;
 
1376
                                            Xyes|Xno)
 
1377
                                                if test $erl_xcomp_linux_clock_gettime_correction = yes; then
 
1378
                                                    erl_cv_time_correction=clock_gettime
 
1379
                                                else
 
1380
                                                    erl_cv_time_correction=times
 
1381
                                                fi;;
 
1382
                                            *)
 
1383
                                                AC_MSG_ERROR([Bad erl_xcomp_linux_clock_gettime_correction value: $erl_xcomp_linux_clock_gettime_correction]);;
 
1384
                                        esac
 
1385
                                    fi
 
1386
                                else
 
1387
                                    erl_cv_time_correction=times
 
1388
                                fi
 
1389
                                ;;
 
1390
                             *)                         
 
1391
                                erl_cv_time_correction=times ;;
 
1392
                        esac
 
1393
                        ;;
 
1394
                    *)
 
1395
                        erl_cv_time_correction=none ;;
 
1396
                esac
 
1397
                ;;
 
1398
        esac
 
1399
        ;;
 
1400
esac
 
1401
])
 
1402
 
 
1403
xrtlib=""
 
1404
case $erl_cv_time_correction in
 
1405
  times)
 
1406
    AC_DEFINE(CORRECT_USING_TIMES,[],
 
1407
        [Define if you do not have a high-res. timer & want to use times() instead])
 
1408
    ;;
 
1409
  clock_gettime|cross)
 
1410
    if test $erl_cv_time_correction = cross; then
 
1411
        erl_cv_time_correction=clock_gettime
 
1412
        AC_MSG_WARN([result clock_gettime guessed because of cross compilation])
 
1413
    fi
 
1414
    xrtlib="-lrt"
 
1415
    AC_DEFINE(GETHRTIME_WITH_CLOCK_GETTIME,[1],
 
1416
        [Define if you want to use clock_gettime to simulate gethrtime])
 
1417
    ;;
 
1418
esac
 
1419
dnl
 
1420
dnl Check if gethrvtime is working, and if to use procfs ioctl
 
1421
dnl or (yet to be written) write to the procfs ctl file.
 
1422
dnl
 
1423
 
 
1424
AC_MSG_CHECKING([if gethrvtime works and how to use it])
 
1425
AC_TRY_RUN([
 
1426
/* gethrvtime procfs ioctl test */
 
1427
/* These need to be undef:ed to not break activation of
 
1428
 * micro level process accounting on /proc/self 
 
1429
 */
 
1430
#ifdef _LARGEFILE_SOURCE
 
1431
#  undef _LARGEFILE_SOURCE
 
1432
#endif
 
1433
#ifdef _FILE_OFFSET_BITS
 
1434
#  undef _FILE_OFFSET_BITS
 
1435
#endif
 
1436
#include <stdlib.h>
 
1437
#include <unistd.h>
 
1438
#include <string.h>
 
1439
#include <stdio.h>
 
1440
#include <sys/time.h>
 
1441
#include <sys/types.h>
 
1442
#include <sys/stat.h>
 
1443
#include <sys/signal.h>
 
1444
#include <sys/fault.h>
 
1445
#include <sys/syscall.h>
 
1446
#include <sys/procfs.h>
 
1447
#include <fcntl.h>
 
1448
 
 
1449
int main() {
 
1450
    long msacct = PR_MSACCT;
 
1451
    int fd;
 
1452
    long long start, stop;
 
1453
    int i;
 
1454
    pid_t pid = getpid();
 
1455
    char proc_self[30] = "/proc/";
 
1456
 
 
1457
    sprintf(proc_self+strlen(proc_self), "%lu", (unsigned long) pid);
 
1458
    if ( (fd = open(proc_self, O_WRONLY)) == -1)
 
1459
        exit(1);
 
1460
    if (ioctl(fd, PIOCSET, &msacct) < 0)
 
1461
        exit(2);
 
1462
    if (close(fd) < 0)
 
1463
        exit(3);
 
1464
    start = gethrvtime();
 
1465
    for (i = 0; i < 100; i++)
 
1466
        stop = gethrvtime();
 
1467
    if (start == 0)
 
1468
        exit(4);
 
1469
    if (start == stop)
 
1470
        exit(5);
 
1471
    exit(0); return 0;
 
1472
}
 
1473
],
 
1474
erl_gethrvtime=procfs_ioctl,
 
1475
erl_gethrvtime=false,
 
1476
[
 
1477
case X$erl_xcomp_gethrvtime_procfs_ioctl in
 
1478
    X)
 
1479
        erl_gethrvtime=cross;;
 
1480
    Xyes|Xno)
 
1481
        if test $erl_xcomp_gethrvtime_procfs_ioctl = yes; then
 
1482
            erl_gethrvtime=procfs_ioctl
 
1483
        else
 
1484
            erl_gethrvtime=false
 
1485
        fi;;
 
1486
    *)
 
1487
        AC_MSG_ERROR([Bad erl_xcomp_gethrvtime_procfs_ioctl value: $erl_xcomp_gethrvtime_procfs_ioctl]);;
 
1488
esac
 
1489
])
 
1490
 
 
1491
case $erl_gethrvtime in
 
1492
  procfs_ioctl)
 
1493
        AC_DEFINE(HAVE_GETHRVTIME_PROCFS_IOCTL,[1],
 
1494
                [define if gethrvtime() works and uses ioctl() to /proc/self])
 
1495
        AC_MSG_RESULT(uses ioctl to procfs)
 
1496
        ;;
 
1497
  *)
 
1498
        if test $erl_gethrvtime = cross; then
 
1499
            erl_gethrvtime=false
 
1500
            AC_MSG_RESULT(cross)
 
1501
            AC_MSG_WARN([result 'not working' guessed because of cross compilation])
 
1502
        else
 
1503
            AC_MSG_RESULT(not working)
 
1504
        fi
 
1505
 
 
1506
        dnl
 
1507
        dnl Check if clock_gettime (linux) is working
 
1508
        dnl
 
1509
 
 
1510
        AC_MSG_CHECKING([if clock_gettime can be used to get process CPU time])
 
1511
        save_libs=$LIBS
 
1512
        LIBS="-lrt"
 
1513
        AC_TRY_RUN([
 
1514
        #include <stdlib.h>
 
1515
        #include <unistd.h>
 
1516
        #include <string.h>
 
1517
        #include <stdio.h>
 
1518
        #include <time.h>
 
1519
        int main() {
 
1520
            long long start, stop;
 
1521
            int i;
 
1522
            struct timespec tp;
 
1523
 
 
1524
            if (clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &tp) < 0)
 
1525
              exit(1);
 
1526
            start = ((long long)tp.tv_sec * 1000000000LL) + (long long)tp.tv_nsec;
 
1527
            for (i = 0; i < 100; i++)
 
1528
              clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &tp);
 
1529
            stop = ((long long)tp.tv_sec * 1000000000LL) + (long long)tp.tv_nsec;
 
1530
            if (start == 0)
 
1531
              exit(4);
 
1532
            if (start == stop)
 
1533
              exit(5);
 
1534
            exit(0); return 0;
 
1535
          }
 
1536
        ],
 
1537
        erl_clock_gettime=yes,
 
1538
        erl_clock_gettime=no,
 
1539
        [
 
1540
        case X$erl_xcomp_clock_gettime_cpu_time in
 
1541
            X) erl_clock_gettime=cross;;
 
1542
            Xyes|Xno) erl_clock_gettime=$erl_xcomp_clock_gettime_cpu_time;;
 
1543
            *) AC_MSG_ERROR([Bad erl_xcomp_clock_gettime_cpu_time value: $erl_xcomp_clock_gettime_cpu_time]);;
 
1544
        esac
 
1545
        ])
 
1546
        LIBS=$save_libs
 
1547
        case $host_os in
 
1548
                linux*)
 
1549
                        AC_MSG_RESULT([no; not stable])
 
1550
                        LIBRT=$xrtlib
 
1551
                        ;;
 
1552
                *)
 
1553
                        AC_MSG_RESULT($erl_clock_gettime)
 
1554
                        case $erl_clock_gettime in
 
1555
                                yes)
 
1556
                                        AC_DEFINE(HAVE_CLOCK_GETTIME,[],
 
1557
                                                  [define if clock_gettime() works for getting process time])
 
1558
                                        LIBRT=-lrt
 
1559
                                        ;;
 
1560
                                cross)
 
1561
                                        erl_clock_gettime=no
 
1562
                                        AC_MSG_WARN([result no guessed because of cross compilation])
 
1563
                                        LIBRT=$xrtlib
 
1564
                                        ;;
 
1565
                                *)
 
1566
                                        LIBRT=$xrtlib
 
1567
                                        ;;
 
1568
                        esac
 
1569
                        ;;
 
1570
        esac
 
1571
        AC_SUBST(LIBRT)
 
1572
        ;;
 
1573
esac
 
1574
])dnl
 
1575
 
 
1576
dnl ERL_TRY_LINK_JAVA(CLASSES, FUNCTION-BODY
 
1577
dnl                   [ACTION_IF_FOUND [, ACTION-IF-NOT-FOUND]])
 
1578
dnl Freely inspired by AC_TRY_LINK. (Maybe better to create a 
 
1579
dnl AC_LANG_JAVA instead...)
 
1580
AC_DEFUN(ERL_TRY_LINK_JAVA,
 
1581
[java_link='$JAVAC conftest.java 1>&AC_FD_CC'
 
1582
changequote(�, �)dnl
 
1583
cat > conftest.java <<EOF
 
1584
�$1�
 
1585
class conftest { public static void main(String[] args) {
 
1586
   �$2�
 
1587
   ; return; }}
 
1588
EOF
 
1589
changequote([, ])dnl
 
1590
if AC_TRY_EVAL(java_link) && test -s conftest.class; then
 
1591
   ifelse([$3], , :, [rm -rf conftest*
 
1592
   $3])
 
1593
else
 
1594
   echo "configure: failed program was:" 1>&AC_FD_CC
 
1595
   cat conftest.java 1>&AC_FD_CC
 
1596
   echo "configure: PATH was $PATH" 1>&AC_FD_CC
 
1597
ifelse([$4], , , [  rm -rf conftest*
 
1598
  $4
 
1599
])dnl
 
1600
fi
 
1601
rm -f conftest*])
 
1602
#define UNSAFE_MASK  0xc0000000 /* Mask for bits that must be constant */
 
1603
 
 
1604