bf3b9656a8a4fa3bc6e64f2390fcc0c402d59acb
[gnulib.git] / m4 / largefile.m4
1 #serial 11
2
3 dnl By default, many hosts won't let programs access large files;
4 dnl one must use special compiler options to get large-file access to work.
5 dnl For more details about this brain damage please see:
6 dnl http://www.sas.com/standards/large.file/x_open.20Mar96.html
7
8 dnl Written by Paul Eggert <eggert@twinsun.com>.
9
10 dnl Internal subroutine of AC_SYS_LARGEFILE.
11 dnl AC_SYS_LARGEFILE_FLAGS(FLAGSNAME)
12 AC_DEFUN(AC_SYS_LARGEFILE_FLAGS,
13   [AC_CACHE_CHECK([for $1 value to request large file support],
14      ac_cv_sys_largefile_$1,
15      [if ($GETCONF LFS_$1) >conftest.1 2>conftest.2 && test ! -s conftest.2
16       then
17         ac_cv_sys_largefile_$1=`cat conftest.1`
18       else
19         ac_cv_sys_largefile_$1=no
20         ifelse($1, CFLAGS,
21           [case "$host_os" in
22            # HP-UX 10.20 requires -D__STDC_EXT__ with gcc 2.95.1.
23 [          hpux10.[2-9][0-9]* | hpux1[1-9]* | hpux[2-9][0-9]*)]
24              if test "$GCC" = yes; then
25                ac_cv_sys_largefile_CFLAGS=-D__STDC_EXT__
26              fi
27              ;;
28            # IRIX 6.2 and later do not support large files by default,
29            # so use the -n32 ABI unless the installer said otherwise.
30 [          irix6.[2-9]* | irix6.1[0-9]* | irix[7-9].* | irix[1-9][0-9]*)]
31              if test "$GCC" != yes; then
32                case "$CC $CFLAGS " in
33                *' -o32 '*|*' -n32 '*|*' -64 '*) ;;
34                *) ac_cv_sys_largefile_CFLAGS=-n32 ;;
35                esac
36              fi
37            esac
38            if test "$ac_cv_sys_largefile_CFLAGS" != no; then
39              ac_save_CC="$CC"
40              CC="$CC $ac_cv_sys_largefile_CFLAGS"
41              AC_TRY_LINK(, , , ac_cv_sys_largefile_CFLAGS=no)
42              CC="$ac_save_CC"
43            fi])
44       fi
45       rm -f conftest*])])
46
47 dnl Internal subroutine of AC_SYS_LARGEFILE.
48 dnl AC_SYS_LARGEFILE_SPACE_APPEND(VAR, VAL)
49 AC_DEFUN(AC_SYS_LARGEFILE_SPACE_APPEND,
50   [case $2 in
51    no) ;;
52    ?*)
53      case "[$]$1" in
54      '') $1=$2 ;;
55      *) $1=[$]$1' '$2 ;;
56      esac ;;
57    esac])
58
59 dnl Internal subroutine of AC_SYS_LARGEFILE.
60 dnl AC_SYS_LARGEFILE_MACRO_VALUE(C-MACRO, CACHE-VAR, COMMENT, CODE-TO-SET-DEFAULT)
61 AC_DEFUN(AC_SYS_LARGEFILE_MACRO_VALUE,
62   [AC_CACHE_CHECK([for $1], $2,
63      [$2=no
64       $4
65       for ac_flag in $ac_cv_sys_largefile_CFLAGS no; do
66         case "$ac_flag" in
67         -D$1)
68           $2=1 ;;
69         -D$1=*)
70           $2=`expr " $ac_flag" : '[[^=]]*=\(.*\)'` ;;
71         esac
72       done
73       ])
74    if test "[$]$2" != no; then
75      AC_DEFINE_UNQUOTED([$1], [$]$2, [$3])
76    fi])
77
78 AC_DEFUN(AC_SYS_LARGEFILE,
79   [AC_REQUIRE([AC_CANONICAL_HOST])
80    AC_ARG_ENABLE(largefile,
81      [  --disable-largefile     omit support for large files])
82    if test "$enable_largefile" != no; then
83      AC_CHECK_TOOL(GETCONF, getconf)
84      AC_SYS_LARGEFILE_FLAGS(CFLAGS)
85      AC_SYS_LARGEFILE_FLAGS(LDFLAGS)
86      AC_SYS_LARGEFILE_FLAGS(LIBS)
87
88      for ac_flag in $ac_cv_sys_largefile_CFLAGS no; do
89        case "$ac_flag" in
90        no) ;;
91        -D_FILE_OFFSET_BITS=*) ;;
92        -D_LARGEFILE_SOURCE | -D_LARGEFILE_SOURCE=*) ;;
93        -D_LARGE_FILES | -D_LARGE_FILES=*) ;;
94        -D?* | -I?*)
95          AC_SYS_LARGEFILE_SPACE_APPEND(CPPFLAGS, "$ac_flag") ;;
96        *)
97          AC_SYS_LARGEFILE_SPACE_APPEND(CFLAGS, "$ac_flag") ;;
98        esac
99      done
100      AC_SYS_LARGEFILE_SPACE_APPEND(LDFLAGS, "$ac_cv_sys_largefile_LDFLAGS")
101      AC_SYS_LARGEFILE_SPACE_APPEND(LIBS, "$ac_cv_sys_largefile_LIBS")
102      AC_SYS_LARGEFILE_MACRO_VALUE(_FILE_OFFSET_BITS,
103        ac_cv_sys_file_offset_bits,
104        [Number of bits in a file offset, on hosts where this is settable.],
105        [case "$host_os" in
106         # HP-UX 10.20 and later
107 [       hpux10.[2-9][0-9]* | hpux1[1-9]* | hpux[2-9][0-9]*)]
108           ac_cv_sys_file_offset_bits=64 ;;
109         esac])
110      AC_SYS_LARGEFILE_MACRO_VALUE(_LARGEFILE_SOURCE,
111        ac_cv_sys_largefile_source,
112        [Define to make ftello visible on some hosts (e.g. HP-UX 10.20).],
113        [AC_TRY_COMPILE([#include <stdio.h>], [return !ftello;], ,
114           [AC_TRY_COMPILE([#define _LARGEFILE_SOURCE 1
115 #include <stdio.h>], [return !ftello;],
116              ac_cv_sys_largefile_source=1)])])
117      AC_SYS_LARGEFILE_MACRO_VALUE(_LARGE_FILES,
118        ac_cv_sys_large_files,
119        [Define for large files, on AIX-style hosts.],
120        [case "$host_os" in
121         # AIX 4.2 and later
122 [       aix4.[2-9]* | aix4.1[0-9]* | aix[5-9].* | aix[1-9][0-9]*)]
123           ac_cv_sys_large_files=1 ;;
124         esac])
125      AC_SYS_LARGEFILE_MACRO_VALUE(_XOPEN_SOURCE,
126        ac_cv_sys_xopen_source,
127        [Define to make ftello visible on some hosts (e.g. glibc 2.1.3).],
128        [AC_TRY_COMPILE([#include <stdio.h>], [return !ftello;], ,
129           [AC_TRY_COMPILE([#define _XOPEN_SOURCE 500
130 #include <stdio.h>],
131              [return !ftello;],
132              ac_cv_sys_xopen_source=500)])])
133    fi
134   ])