merge with 0.30.213
[util-vserver.git] / m4 / ensc_dietlibc.m4
1 dnl $Id: ensc_dietlibc.m4 2453 2007-01-17 09:54:53Z dhozac $
2
3 dnl Copyright (C) 2002 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 AC_DEFUN([_ENSC_DIETLIBC_C99],
19 [
20         AH_TEMPLATE([ENSC_DIETLIBC_C99], [Define to 1 if dietlibc supports C99])
21
22         AC_CACHE_CHECK([whether dietlibc supports C99], [ensc_cv_c_dietlibc_c99],
23         [
24                 _ensc_dietlibc_c99_old_CFLAGS=$CFLAGS
25                 _ensc_dietlibc_c99_old_CC=$CC
26
27                 CFLAGS="-std=c99"
28                 CC="${DIET:-diet} $CC"
29
30                 AC_LANG_PUSH(C)
31                 AC_COMPILE_IFELSE([/* */],[
32                         AC_COMPILE_IFELSE([
33                                 #include <stdint.h>
34                                 #include <sys/cdefs.h>
35                                 #if defined(inline)
36                                 #  error 'inline' badly defined
37                                 #endif
38                                 volatile uint64_t       a;
39                         ],
40                         [ensc_cv_c_dietlibc_c99=yes],
41                         [ensc_cv_c_dietlibc_c99=no])],
42                         [ensc_cv_c_dietlibc_c99='skipped (compiler does not support C99)'])
43                 AC_LANG_POP
44
45                 CC=$_ensc_dietlibc_c99_old_CC
46                 CFLAGS=$_ensc_dietlibc_c99_old_CFLAGS
47         ])
48
49         if test x"$ensc_cv_c_dietlibc_c99" = xyes; then
50                 AC_DEFINE(ENSC_DIETLIBC_C99,1)
51         fi
52 ])
53
54 AC_DEFUN([_ENSC_DIETLIBC_SYSCALL],
55 [
56         AH_TEMPLATE([ENSC_DIETLIBC_HAS_SYSCALL], [Define to 1 if dietlibc declares syscall])
57
58         AC_CACHE_CHECK([whether dietlibc declares syscall], [ensc_cv_c_dietlibc_syscall],
59         [
60                 _ensc_dietlibc_syscall_old_CC="$CC"
61                 CC="${DIET:-diet} $CC"
62
63                 AC_LANG_PUSH(C)
64                 AC_COMPILE_IFELSE([
65                         #include <sys/syscall.h>
66                         long int syscall(long int __sysno, ...);
67                 ],
68                 [ensc_cv_c_dietlibc_syscall=no],
69                 [ensc_cv_c_dietlibc_syscall=yes])
70                 AC_LANG_POP
71
72                 CC="$_ensc_dietlibc_syscall_old_CC"
73         ])
74
75         if test x"$ensc_cv_c_dietlibc_syscall" = xyes; then
76                 AC_DEFINE(ENSC_DIETLIBC_HAS_SYSCALL,1)
77         fi
78 ])
79
80 dnl Usage: ENSC_ENABLE_DIETLIBC(<conditional>[,<min-version>])
81 dnl        <conditional> ... automake-conditional which will be set when
82 dnl                          dietlibc shall be enabled
83 dnl        provides:
84 dnl        * $ENSC_VERSION_DIETLIBC_NUM and
85 dnl        * $ENSC_VERSION_DIETLIBC
86
87 AC_DEFUN([ENSC_ENABLE_DIETLIBC],
88 [
89         AC_MSG_CHECKING([whether to enable dietlibc])
90
91         AC_ARG_VAR(DIET,      [The 'diet' wrapper (default: diet)])
92         AC_ARG_VAR(DIETFLAGS, [Flags passed to the 'diet' wrapper (default: -O)])
93
94         : ${DIET:=diet}
95         : ${DIETFLAGS=-Os}
96
97         AC_ARG_ENABLE([dietlibc],
98                       [AS_HELP_STRING([--disable-dietlibc],
99                                       [do not use dietlibc resp. enforce its usage
100                                        (with --enable-dietlibc) (default: autodetect dietlibc)])],
101                       [case "$enableval" in
102                           (yes) use_dietlibc=forced;;
103                           (no)  use_dietlibc=forced_no;;
104                           (*)   AC_MSG_ERROR(['$enableval' is not a valid value for --enable-dietlibc]);;
105                        esac],
106                       [which "$DIET" >/dev/null 2>/dev/null && use_dietlibc=detected || use_dietlibc=detected_no])
107
108         if test "$use_dietlibc" = detected -a "$2"; then
109             _dietlibc_ver=$($DIET -v 2>&1 | sed '1p;d')
110             _dietlibc_ver=${_dietlibc_ver##*diet version }
111             _dietlibc_ver=${_dietlibc_ver##*dietlibc-}
112             _dietlibc_ver_maj=${_dietlibc_ver%%.*}
113             _dietlibc_ver_min=${_dietlibc_ver##*.}
114             _dietlibc_ver_min=${_dietlibc_ver_min%%[[!0-9]]*}
115             _dietlibc_cmp="$2"
116             _dietlibc_cmp_maj=${_dietlibc_cmp%%.*}
117             _dietlibc_cmp_min=${_dietlibc_cmp##*.}
118
119             ENSC_VERSION_DIETLIBC=$_dietlibc_ver_maj.$_dietlibc_ver_min
120
121             let _dietlibc_ver=_dietlibc_ver_maj*1000+_dietlibc_ver_min 2>/dev/null || _dietlibc_ver=0
122             let _dietlibc_cmp=_dietlibc_cmp_maj*1000+_dietlibc_cmp_min
123
124             test $_dietlibc_ver -ge $_dietlibc_cmp || use_dietlibc=detected_old
125         else
126             ENSC_VERSION_DIETLIBC=
127             _dietlibc_ver=-1
128         fi
129
130         ENSC_VERSION_DIETLIBC_NUM=$_dietlibc_ver
131         ensc_have_dietlibc=no
132
133         case x"$use_dietlibc" in
134             xdetected)
135                 AM_CONDITIONAL($1, true)
136                 AC_MSG_RESULT([yes (autodetected, $ENSC_VERSION_DIETLIBC)])
137                 ensc_have_dietlibc=yes
138                 ;;
139             xforced)
140                 AM_CONDITIONAL($1, true)
141                 AC_MSG_RESULT([yes (forced)])
142                 ensc_have_dietlibc=yes
143                 ;;
144             xdetected_no)
145                 AM_CONDITIONAL($1, false)
146                 AC_MSG_RESULT([no (detected)])
147                 ;;
148             xdetected_old)
149                 AM_CONDITIONAL($1, false)
150                 AC_MSG_RESULT([no (too old; $2+ required, $ENSC_VERSION_DIETLIBC found)])
151                 ;;
152             xforced_no)
153                 AM_CONDITIONAL($1, false)
154                 AC_MSG_RESULT([no (forced)])
155                 ;;
156             *)
157                 AC_MSG_ERROR([internal error, use_dietlibc was "$use_dietlibc"])
158                 ;;
159         esac
160
161         if test x"$ensc_have_dietlibc" != xno; then
162                 _ENSC_DIETLIBC_C99
163                 _ENSC_DIETLIBC_SYSCALL
164         fi
165 ])
166