annotate m4/lseek.m4 @ 17627:4d899884c95c

m4: fix gl_TIMER_TIME() detection of threads on uClibc The timer_time.m4 gl_TIMER_TIME function determines which libraries need to be linked to get access to the timer function, generally -lrt for Linux systems. On platforms where threads are used, librt typically uses thread functions from libpthread. However, the test to determine whether the platform has thread or not is incorrect: it assumes that if the C library is uClibc, then threads are not available. This is actually not true: uClibc has configurable thread support, and when thread support is available, librt calls libpthread functions. This is important when static linking is used, because otherwise only -lrt is used at link time, which fails because librt calls undefined thread functions. Both -lrt and -lpthread must be passed. This problem is fixed by making the uClibc thread detection a bit smarter, thanks to the usage of the __HAS_NO_THREADS__ macro defined in <bits/uClibc_config.h>, which itself is included by <features.h>. Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com> Signed-off-by: Eric Blake <eblake@redhat.com>
author Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
date Sat, 22 Feb 2014 00:41:38 +0100
parents 344018b6e5d7
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16795
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 16783
diff changeset
1 # lseek.m4 serial 10
17587
344018b6e5d7 maint: update copyright
Eric Blake <eblake@redhat.com>
parents: 17249
diff changeset
2 dnl Copyright (C) 2007, 2009-2014 Free Software Foundation, Inc.
8872
dfee3b4fd46c Fix lseek on mingw.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
3 dnl This file is free software; the Free Software Foundation
dfee3b4fd46c Fix lseek on mingw.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
4 dnl gives unlimited permission to copy and/or distribute it,
dfee3b4fd46c Fix lseek on mingw.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
5 dnl with or without modifications, as long as this notice is preserved.
dfee3b4fd46c Fix lseek on mingw.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
6
dfee3b4fd46c Fix lseek on mingw.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
7 AC_DEFUN([gl_FUNC_LSEEK],
dfee3b4fd46c Fix lseek on mingw.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
8 [
dfee3b4fd46c Fix lseek on mingw.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
9 AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
16795
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 16783
diff changeset
10
16783
f3268ec22cb1 lseek: Make configure test independent of environment.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
11 AC_REQUIRE([AC_CANONICAL_HOST])
8872
dfee3b4fd46c Fix lseek on mingw.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
12 AC_REQUIRE([AC_PROG_CC])
15606
f62f29997e98 unistd et al.: Don't assume <unistd.h> exists.
Bruno Haible <bruno@clisp.org>
parents: 15026
diff changeset
13 AC_CHECK_HEADERS_ONCE([unistd.h])
8872
dfee3b4fd46c Fix lseek on mingw.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
14 AC_CACHE_CHECK([whether lseek detects pipes], [gl_cv_func_lseek_pipe],
16783
f3268ec22cb1 lseek: Make configure test independent of environment.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
15 [case "$host_os" in
f3268ec22cb1 lseek: Make configure test independent of environment.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
16 mingw*)
f3268ec22cb1 lseek: Make configure test independent of environment.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
17 dnl Native Windows.
f3268ec22cb1 lseek: Make configure test independent of environment.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
18 dnl The result of lseek (fd, (off_t)0, SEEK_CUR) or
f3268ec22cb1 lseek: Make configure test independent of environment.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
19 dnl SetFilePointer(handle, 0, NULL, FILE_CURRENT)
f3268ec22cb1 lseek: Make configure test independent of environment.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
20 dnl for a pipe depends on the environment: In a Cygwin 1.5
f3268ec22cb1 lseek: Make configure test independent of environment.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
21 dnl environment it succeeds (wrong); in a Cygwin 1.7 environment
f3268ec22cb1 lseek: Make configure test independent of environment.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
22 dnl it fails with a wrong errno value.
f3268ec22cb1 lseek: Make configure test independent of environment.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
23 gl_cv_func_lseek_pipe=no
f3268ec22cb1 lseek: Make configure test independent of environment.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
24 ;;
f3268ec22cb1 lseek: Make configure test independent of environment.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
25 *)
f3268ec22cb1 lseek: Make configure test independent of environment.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
26 if test $cross_compiling = no; then
f3268ec22cb1 lseek: Make configure test independent of environment.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
27 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
8878
a8cf4cce248b When not cross-compiling, perform a real runtime test.
Bruno Haible <bruno@clisp.org>
parents: 8872
diff changeset
28 #include <sys/types.h> /* for off_t */
a8cf4cce248b When not cross-compiling, perform a real runtime test.
Bruno Haible <bruno@clisp.org>
parents: 8872
diff changeset
29 #include <stdio.h> /* for SEEK_CUR */
15606
f62f29997e98 unistd et al.: Don't assume <unistd.h> exists.
Bruno Haible <bruno@clisp.org>
parents: 15026
diff changeset
30 #if HAVE_UNISTD_H
f62f29997e98 unistd et al.: Don't assume <unistd.h> exists.
Bruno Haible <bruno@clisp.org>
parents: 15026
diff changeset
31 # include <unistd.h>
f62f29997e98 unistd et al.: Don't assume <unistd.h> exists.
Bruno Haible <bruno@clisp.org>
parents: 15026
diff changeset
32 #else /* on Windows with MSVC */
f62f29997e98 unistd et al.: Don't assume <unistd.h> exists.
Bruno Haible <bruno@clisp.org>
parents: 15026
diff changeset
33 # include <io.h>
f62f29997e98 unistd et al.: Don't assume <unistd.h> exists.
Bruno Haible <bruno@clisp.org>
parents: 15026
diff changeset
34 #endif
f62f29997e98 unistd et al.: Don't assume <unistd.h> exists.
Bruno Haible <bruno@clisp.org>
parents: 15026
diff changeset
35 ]], [[
8878
a8cf4cce248b When not cross-compiling, perform a real runtime test.
Bruno Haible <bruno@clisp.org>
parents: 8872
diff changeset
36 /* Exit with success only if stdin is seekable. */
a8cf4cce248b When not cross-compiling, perform a real runtime test.
Bruno Haible <bruno@clisp.org>
parents: 8872
diff changeset
37 return lseek (0, (off_t)0, SEEK_CUR) < 0;
13582
9816edcb2151 lseek: fix link test
Eric Blake <eblake@redhat.com>
parents: 12893
diff changeset
38 ]])],
16783
f3268ec22cb1 lseek: Make configure test independent of environment.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
39 [if test -s conftest$ac_exeext \
f3268ec22cb1 lseek: Make configure test independent of environment.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
40 && ./conftest$ac_exeext < conftest.$ac_ext \
f3268ec22cb1 lseek: Make configure test independent of environment.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
41 && test 1 = "`echo hi \
f3268ec22cb1 lseek: Make configure test independent of environment.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
42 | { ./conftest$ac_exeext; echo $?; cat >/dev/null; }`"; then
f3268ec22cb1 lseek: Make configure test independent of environment.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
43 gl_cv_func_lseek_pipe=yes
f3268ec22cb1 lseek: Make configure test independent of environment.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
44 else
f3268ec22cb1 lseek: Make configure test independent of environment.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
45 gl_cv_func_lseek_pipe=no
f3268ec22cb1 lseek: Make configure test independent of environment.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
46 fi
f3268ec22cb1 lseek: Make configure test independent of environment.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
47 ],
f3268ec22cb1 lseek: Make configure test independent of environment.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
48 [gl_cv_func_lseek_pipe=no])
f3268ec22cb1 lseek: Make configure test independent of environment.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
49 else
f3268ec22cb1 lseek: Make configure test independent of environment.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
50 AC_COMPILE_IFELSE(
f3268ec22cb1 lseek: Make configure test independent of environment.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
51 [AC_LANG_SOURCE([[
f3268ec22cb1 lseek: Make configure test independent of environment.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
52 #if defined __BEOS__
f3268ec22cb1 lseek: Make configure test independent of environment.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
53 /* BeOS mistakenly return 0 when trying to seek on pipes. */
8872
dfee3b4fd46c Fix lseek on mingw.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
54 Choke me.
13582
9816edcb2151 lseek: fix link test
Eric Blake <eblake@redhat.com>
parents: 12893
diff changeset
55 #endif]])],
16783
f3268ec22cb1 lseek: Make configure test independent of environment.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
56 [gl_cv_func_lseek_pipe=yes], [gl_cv_func_lseek_pipe=no])
f3268ec22cb1 lseek: Make configure test independent of environment.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
57 fi
f3268ec22cb1 lseek: Make configure test independent of environment.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
58 ;;
f3268ec22cb1 lseek: Make configure test independent of environment.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
59 esac
f3268ec22cb1 lseek: Make configure test independent of environment.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
60 ])
8872
dfee3b4fd46c Fix lseek on mingw.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
61 if test $gl_cv_func_lseek_pipe = no; then
15026
a5ed10e5034d lseek: Move AC_LIBOBJ invocations to module description.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
62 REPLACE_LSEEK=1
a5ed10e5034d lseek: Move AC_LIBOBJ invocations to module description.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
63 AC_DEFINE([LSEEK_PIPE_BROKEN], [1],
a5ed10e5034d lseek: Move AC_LIBOBJ invocations to module description.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
64 [Define to 1 if lseek does not detect pipes.])
8872
dfee3b4fd46c Fix lseek on mingw.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
65 fi
16795
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 16783
diff changeset
66
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 16783
diff changeset
67 AC_REQUIRE([gl_SYS_TYPES_H])
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 16783
diff changeset
68 if test $WINDOWS_64_BIT_OFF_T = 1; then
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 16783
diff changeset
69 REPLACE_LSEEK=1
6a9ea5d7b466 Large File Support for native Windows platforms.
Bruno Haible <bruno@clisp.org>
parents: 16783
diff changeset
70 fi
8872
dfee3b4fd46c Fix lseek on mingw.
Eric Blake <ebb9@byu.net>
parents:
diff changeset
71 ])