Port to AIX and HP-UX. Support cross-compilation.
[gnulib.git] / m4 / lfs.m4
1 #serial 3
2
3 dnl The problem is that the default compilation flags in Solaris 2.6 won't
4 dnl let programs access large files;  you need to tell the compiler that
5 dnl you actually want your programs to work on large files.  For more
6 dnl details about this brain damage please see:
7 dnl http://www.sas.com/standards/large.file/x_open.20Mar96.html
8
9 dnl Written by Paul Eggert <eggert@twinsun.com>.
10
11 dnl Internal subroutine of AC_LFS.
12 dnl AC_LFS_FLAGS(FLAGSNAME)
13 AC_DEFUN(AC_LFS_FLAGS,
14   [AC_CACHE_CHECK([for $1 value to request large file support], ac_cv_lfs_$1,
15      [ac_cv_lfs_$1=`($GETCONF LFS_$1) 2>/dev/null` || {
16         ac_cv_lfs_$1=no
17         ifelse($1, CFLAGS,
18           [case "$host_os" in
19              # IRIX 6.2 and later
20              irix6.[[2-9]]* | irix6.1[[0-9]]* | irix[[7-9]].* | irix[[1-9]][[0-9]]*)
21                if test "$GCC" != yes; then
22                  ac_cv_lfs_CFLAGS=-n32
23                fi
24                ac_save_CC="$CC"
25                CC="$ac_save_CC $ac_cv_lfs_CFLAGS"
26                AC_TRY_LINK(, , , ac_cv_lfs_CFLAGS=no)
27                CC="$ac_save_CC"
28            esac])
29       }])])
30
31 dnl Internal subroutine of AC_LFS.
32 dnl AC_LFS_SPACE_APPEND(VAR, VAL)
33 AC_DEFUN(AC_LFS_SPACE_APPEND,
34   [case $2 in
35      no) ;;
36      ?*)
37        case "[$]$1" in
38          '') $1=$2 ;;
39          *) $1=[$]$1' '$2 ;;
40        esac ;;
41    esac])
42
43 dnl Internal subroutine of AC_LFS.
44 dnl AC_LFS_MACRO_VALUE(C-MACRO, CACHE-VAR, COMMENT, CODE-TO-SET-DEFAULT)
45 AC_DEFUN(AC_LFS_MACRO_VALUE,
46   [AC_CACHE_CHECK([for $1], $2,
47      [[$2=no
48        $4
49        for ac_flag in $ac_cv_lfs_CFLAGS no; do
50          case "$ac_flag" in
51            -D$1)
52              $2=1 ;;
53            -D$1=*)
54              $2=`expr " $ac_flag" : '[^=]*=\(.*\)'` ;;
55          esac
56        done]])
57    if test "[$]$2" != no; then
58      AC_DEFINE_UNQUOTED([$1], [$]$2, [$3])
59    fi])
60
61 AC_DEFUN(AC_LFS,
62   [AC_REQUIRE([AC_CANONICAL_HOST])
63    AC_ARG_ENABLE(lfs,
64      [  --disable-lfs           omit Large File Support])
65    if test "$enable_lfs" != no; then
66      AC_CHECK_TOOL(GETCONF, getconf)
67      AC_LFS_FLAGS(CFLAGS)
68      AC_LFS_FLAGS(LDFLAGS)
69      AC_LFS_FLAGS(LIBS)
70      for ac_flag in $ac_cv_lfs_CFLAGS no; do
71        case "$ac_flag" in
72          no) ;;
73          -D_FILE_OFFSET_BITS=*) ;;
74          -D_LARGEFILE_SOURCE | -D_LARGEFILE_SOURCE=*) ;;
75          -D_LARGE_FILES | -D_LARGE_FILES=*) ;;
76          -[[DI]]?* | -[[no]]32 | -n64)
77            AC_LFS_SPACE_APPEND(CPPFLAGS, "$ac_flag") ;;
78          *)
79            AC_LFS_SPACE_APPEND(CFLAGS, "$ac_flag") ;;
80        esac
81      done
82      AC_LFS_SPACE_APPEND(LDFLAGS, "$ac_cv_lfs_LDFLAGS")
83      AC_LFS_SPACE_APPEND(LIBS, "$ac_cv_lfs_LIBS")
84      AC_LFS_MACRO_VALUE(_FILE_OFFSET_BITS, ac_cv_file_offset_bits,
85        [Number of bits in a file offset, on hosts where this is settable. ],
86        [case "$host_os" in
87           # HP-UX 10.20 and later
88           hpux10.[2-9][0-9]* | hpux1[1-9]* | hpux[2-9][0-9]*)
89             ac_cv_file_offset_bits=64 ;;
90         esac])
91      AC_LFS_MACRO_VALUE(_LARGEFILE_SOURCE, ac_cv_largefile_source,
92        [Define to make fseeko etc. visible, on some hosts. ],
93        [case "$host_os" in
94           # HP-UX 10.20 and later
95           hpux10.[2-9][0-9]* | hpux1[1-9]* | hpux[2-9][0-9]*)
96             ac_cv_largefile_source=1 ;;
97         esac])
98      AC_LFS_MACRO_VALUE(_LARGE_FILES, ac_cv_large_files,
99        [Define for large files, on AIX-style hosts. ],
100        [case "$host_os" in
101           # AIX 4.2 and later
102           aix4.[2-9]* | aix4.1[0-9]* | aix[5-9].* | aix[1-9][0-9]*)
103             ac_cv_large_files=1 ;;
104         esac])
105    fi
106   ])