merge with 0.30.213
[util-vserver.git] / m4 / ensc_syscallnr.m4
1 dnl $Id: ensc_syscallnr.m4 2187 2005-10-28 16:01:19Z ensc $
2
3 dnl Copyright (C) 2004 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
4 dnl  
5 dnl This program is free software; you can redistribute it and/or modify
6 dnl it under the terms of the GNU General Public License as published by
7 dnl the Free Software Foundation; version 2 of the License.
8 dnl  
9 dnl This program is distributed in the hope that it will be useful,
10 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
11 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 dnl GNU General Public License for more details.
13 dnl  
14 dnl You should have received a copy of the GNU General Public License
15 dnl along with this program; if not, write to the Free Software
16 dnl Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
18 dnl Usage: ENSC_SYSCALLNR(<syscall>,<default>[,<fallback>])
19
20 AC_DEFUN([ENSC_SYSCALLNR],
21 [
22         AC_REQUIRE([AC_PROG_CPP])
23         AC_REQUIRE([AC_PROG_EGREP])
24
25         AC_CACHE_CHECK([for number of syscall '$1'], [ensc_cv_value_syscall_$1],
26         [
27                 AC_LANG_PUSH(C)
28                 AC_LANG_CONFTEST([
29 #ifdef ENSC_SYSCALL_FALLBACK
30 #  include ENSC_SYSCALL_FALLBACK
31 #else
32 #  include <asm/unistd.h>
33 #endif
34 #ifdef __NR_$1
35 ensc_syscall_tmp_nr=__NR_$1;
36 ensc_syscall_tmp_src=ENSC_MARK
37 #endif
38 ])
39                 ensc_syscall_tmp_nr=
40                 ensc_syscall_tmp_src=
41                 test x"$ensc_syscall_tmp_nr" != x || \
42                         eval $($CPP $CPPFLAGS -D ENSC_MARK='glibc'                                    conftest.c | $EGREP '^ensc_syscall_tmp_(nr=[[1-9]][[0-9]]*;|src=.*)$')
43                 test x"$ensc_syscall_tmp_nr" != x -o x'$3' = x || \
44                         eval $($CPP $CPPFLAGS -D ENSC_MARK='fallback' -D ENSC_SYSCALL_FALLBACK='"$3"' conftest.c | $EGREP '^ensc_syscall_tmp_(nr=[[1-9]][[0-9]]*;|src=.*)$')
45                 test "$ensc_syscall_tmp_nr" || {
46                         ensc_syscall_tmp_nr=$2
47                         ensc_syscall_tmp_src=default
48                 }
49
50                 if test x"$ensc_syscall_tmp_nr" = x; then
51                         AC_MSG_ERROR(
52 [Can not determine value of __NR_$1; please verify your glibc/kernelheaders, and/or set CPPFLAGS='-D__NR_$1=<value>' environment when calling configure.])
53                 fi
54                 AC_LANG_POP
55
56                 ensc_cv_value_syscall_$1="$ensc_syscall_tmp_nr/$ensc_syscall_tmp_src"
57         ])
58
59         ensc_syscall_tmp_nr=${ensc_cv_value_syscall_$1%/*}
60         ensc_syscall_tmp_src=${ensc_cv_value_syscall_$1#*/}
61
62         if test x"$ensc_syscall_tmp_src" != x'glibc'; then
63                 AC_DEFINE_UNQUOTED(ENSC_SYSCALL__NR_$1, $ensc_syscall_tmp_nr, [The number of the $1 syscall])
64         fi
65 ])