Robustify Linux kernel headers configure checks
[platform/upstream/glibc.git] / sysdeps / unix / sysv / linux / configure.ac
1 GLIBC_PROVIDES dnl See aclocal.m4 in the top level source directory.
2 # Local configure fragment for sysdeps/unix/sysv/linux.
3
4 define([LIBC_LINUX_VERSION],[2.6.32])dnl
5 if test -n "$sysheaders"; then
6   OLD_CPPFLAGS=$CPPFLAGS
7   CPPFLAGS="$CPPFLAGS $SYSINCLUDES"
8 fi
9 define([libc_cv_linuxVER], [libc_cv_linux]patsubst(LIBC_LINUX_VERSION,[\.]))dnl
10 AC_CACHE_CHECK(installed Linux kernel header files, libc_cv_linuxVER, [dnl
11 AC_TRY_COMPILE([#include <linux/version.h>
12 #if !defined LINUX_VERSION_CODE || LINUX_VERSION_CODE < ]dnl
13 patsubst(LIBC_LINUX_VERSION,[^\([^.]*\)\.\([^.]*\)\.\([^.]*\)$],dnl
14 [ (\1 *65536+ \2 *256+ \3) /* \1.\2.\3 */])[
15 # error kernel headers missing or too old
16 #endif], [],
17                [libc_cv_linuxVER='LIBC_LINUX_VERSION or later'],
18                [libc_cv_linuxVER='missing or too old!'])])
19 if test "$libc_cv_linuxVER" != 'LIBC_LINUX_VERSION or later'; then
20   AC_MSG_ERROR([GNU libc requires kernel header files from
21 Linux LIBC_LINUX_VERSION or later to be installed before configuring.
22 The kernel header files are found usually in /usr/include/asm and
23 /usr/include/linux; make sure these directories use files from
24 Linux LIBC_LINUX_VERSION or later.  This check uses <linux/version.h>, so
25 make sure that file was built correctly when installing the kernel header
26 files.  To use kernel headers not from /usr/include/linux, use the
27 configure option --with-headers.])
28 fi
29
30 # If the user gave a minimal version number test whether the available
31 # kernel headers are young enough.  Additionally we have minimal
32 # kernel versions for some architectures.  If a previous configure fragment
33 # set arch_minimum_kernel already, let that override our defaults here.
34 # Note that we presume such a fragment has set libc_cv_gcc_unwind_find_fde
35 # if appropriate too.
36 test -n "$arch_minimum_kernel" || arch_minimum_kernel=2.6.32
37 if test -n "$minimum_kernel"; then
38   changequote(,)
39   user_version=$((`echo "$minimum_kernel.0.0.0" | sed 's/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\1 \* 65536 + \2 \* 256 + \3/'`))
40   arch_version=$((`echo "$arch_minimum_kernel.0.0.0" | sed 's/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\1 \* 65536 + \2 \* 256 + \3/'`))
41   changequote([,])
42   if test $user_version -lt $arch_version; then
43     AC_MSG_WARN([minimum kernel version reset to $arch_minimum_kernel])
44     minimum_kernel=$arch_minimum_kernel
45   fi
46 else
47   minimum_kernel=$arch_minimum_kernel
48 fi
49
50 AC_MSG_CHECKING(for kernel header at least $minimum_kernel)
51 changequote(,)dnl
52 decnum=`echo "$minimum_kernel.0.0.0" | sed 's/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/(\1 * 65536 + \2 * 256 + \3)/'`;
53 abinum=`echo "$minimum_kernel.0.0.0" | sed 's/\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\1,\2,\3/'`;
54 changequote([,])dnl
55 AC_TRY_COMPILE([#include <linux/version.h>
56 #if LINUX_VERSION_CODE < $decnum
57 # error kernel headers too old
58 #endif], [], [libc_minimum_kernel=ok], [libc_minimum_kernel='too old!'])
59 AC_MSG_RESULT($libc_minimum_kernel)
60 if test "$libc_minimum_kernel" = ok; then
61   AC_DEFINE_UNQUOTED(__LINUX_KERNEL_VERSION, $decnum)
62   AC_DEFINE_UNQUOTED(__ABI_TAG_VERSION, $abinum)
63 else
64   AC_MSG_ERROR([*** The available kernel headers are older than the requested
65 *** compatible kernel version])
66 fi
67
68 # Until we start requiring 2.6.37+ headers, we need to check for the
69 # availability of linux/fanotify.h for testing purposes.
70 AC_CHECK_HEADER(linux/fanotify.h,
71   [AC_DEFINE(HAVE_LINUX_FANOTIFY_H)], ,
72   [/* No default includes.  */])
73
74 # The result of the above test for the use of the FDE code is invalid if
75 # the user overrides the decision about the minimum ABI.
76 if test "$oldest_abi" != default && test "2.2.4" \< "$oldest_abi"; then
77   libc_cv_gcc_unwind_find_fde=no
78 fi
79
80 if test -n "$sysheaders"; then
81   CPPFLAGS=$OLD_CPPFLAGS
82 fi
83
84 # Under Linux the NPTL add-on should be available.
85 case $add_ons in
86   # It is available.  Good.
87   *nptl*)
88     nptl_missing=
89     ;;
90   *)
91     nptl_missing=yes
92     ;;
93 esac
94
95 if test "$nptl_missing"; then
96   if test $enable_sanity = yes; then
97     echo "\
98 *** On GNU/Linux systems it is normal to compile GNU libc with the
99 *** \`nptl' add-on.  Without that, the library will be
100 *** incompatible with normal GNU/Linux systems.
101 *** If you really mean to not use this add-on, run configure again
102 *** using the extra parameter \`--disable-sanity-checks'."
103     exit 1
104   else
105     echo "\
106 *** WARNING: Are you sure you do not want to use the \`nptl'
107 *** add-on?"
108   fi
109 fi
110
111 if test "$prefix" = "/usr/local" -o "$prefix" = "/usr/local/" -o "$prefix" = "NONE"; then
112   if test $enable_sanity = yes; then
113     echo "\
114 *** On GNU/Linux systems the GNU C Library should not be installed into
115 *** /usr/local since this might make your system totally unusable.
116 *** We strongly advise to use a different prefix.  For details read the FAQ.
117 *** If you really mean to do this, run configure again using the extra
118 *** parameter \`--disable-sanity-checks'."
119     exit 1
120   else
121     echo "\
122 *** WARNING: Do you really want to install the GNU C Library into /usr/local?
123 *** This might make your system totally unusable, for details read the FAQ."
124   fi
125 fi
126
127
128 # One Linux we use ldconfig.
129 use_ldconfig=yes
130
131 if test $host = $build; then
132   # If $prefix/include/{net,scsi} are symlinks, make install will
133   # clobber what they're linked to (probably a kernel tree).
134   # test -L ought to work on all Linux boxes.
135   if test "x$prefix" != xNONE; then
136     ac_prefix=$prefix
137   else
138     ac_prefix=$ac_default_prefix
139   fi
140   AC_MSG_CHECKING([for symlinks in ${ac_prefix}/include])
141   ac_message=
142   if test -L ${ac_prefix}/include/net; then
143     ac_message="$ac_message
144    ${ac_prefix}/include/net is a symlink"
145   fi
146   if test -L ${ac_prefix}/include/scsi; then
147     ac_message="$ac_message
148    ${ac_prefix}/include/scsi is a symlink"
149   fi
150   if test -n "$ac_message"; then
151     AC_MSG_ERROR([$ac_message
152 \`make install' will destroy the target of the link(s).
153 Delete the links and re-run configure, or better still, move the entire
154 ${ac_prefix}/include directory out of the way.])
155   else
156     AC_MSG_RESULT(ok)
157   fi
158 fi
159
160 # We have inlined syscalls.
161 AC_DEFINE(HAVE_INLINED_SYSCALLS)